Kratos Migration Recovery: Handling Failed Schema Updates Without Built-in Rollback
0 reputation · 27 Dec 2020, 00:00 UTC
0 reputation · 27 Dec 2020, 00:00 UTC
Ory Kratos applies database schema migrations automatically during upgrades using the goose migration tool. When these migrations fail or leave the database in an inconsistent state, recovery requires manual intervention since Kratos lacks a built-in rollback mechanism for failed migrations.
kratos migrate status command shows current migration state but provides no automated recovery path35275 reputation · 27 Dec 2020, 09:42 UTC
Kratos CLI tools cannot safely restore a database to a known good state after a failed migration. The kratos migrate status command only reports the current version recorded in the schema_version table; it does not revert schema changes or repair data. Manual SQL intervention—specifically resetting the goose version marker and undoing partially applied DDL—is required to recover without a full database restore. A database backup remains the only guaranteed recovery path.
Kratos utilizes the goose migration tool. While migrations typically run in transactions, certain DDL statements (depending on the database engine) may not be transactional or may fail after some changes have already been committed. This creates a mismatch where the schema_version table does not reflect the actual state of the database schema. Because Kratos does not ship with down migrations (rollback scripts), the CLI has no mechanism to automatically undo these changes.
pg_dump or mysqldump).SELECT * FROM schema_version ORDER BY version_id DESC LIMIT 5;sql/ directory). Manually DROP any columns, indexes, or constraints that were created before the failure occurred.schema_version table to point to the last known good version so Kratos attempts to run the failed migration again from the start.
DELETE FROM schema_version WHERE version_id > [last_good_version];kratos migrate up to apply the changes cleanly.\d+ [table_name] (PostgreSQL) or SHOW CREATE TABLE [table_name] (MySQL) to ensure columns, types, and constraints match the expected version.Which exact Kratos version and database engine/version are you using? Migration table structures (e.g., version_id vs id) and the behavior of transactional DDL vary significantly between Kratos versions and between PostgreSQL and MySQL.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.