#58 Migrations fail on SQLite
Opened 2 years ago by lsedlar. Modified 2 years ago

Running migrations from no database fails. The migration that adds respin_of_id as foreign key fails in the middle. The column is created, but the foreign key constraint is not. The process exists and leaves the stamp pointing to previous migration.

$ PYTHONPATH=. CTS_DEVELOPER_ENV=1 python cts/manage.py db upgrade
WARN: Cannot open /etc/cts/config.py: No such file or directory
WARN: DevConfiguration will be used.
2021-09-03 12:26:01,772 - MainThread - cts - WARNING - Authorization is disabled in CTS configuration.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> dd4d36995e1c, Initial composes and users table.
INFO  [alembic.runtime.migration] Running upgrade dd4d36995e1c -> 08eb81dae631, Add ComposeInfo fields to composes table.
INFO  [alembic.runtime.migration] Running upgrade 08eb81dae631 -> d47535677af6, Add tags table and relations.
INFO  [alembic.runtime.migration] Running upgrade d47535677af6 -> d9397caba443, Add TagChange model.
INFO  [alembic.runtime.migration] Running upgrade d9397caba443 -> 3f4b23f8c3d5, Add compose_changes table.
INFO  [alembic.runtime.migration] Running upgrade 3f4b23f8c3d5 -> e2af98ac38f5, Add Compose.parents and Compose.children.
INFO  [alembic.runtime.migration] Running upgrade e2af98ac38f5 -> 16cd8140b6c7, Add Compose.respin_of.
$ echo $?
1
$ PYTHONPATH=. CTS_DEVELOPER_ENV=1 python cts/manage.py db current
WARN: Cannot open /etc/cts/config.py: No such file or directory
WARN: DevConfiguration will be used.
2021-09-03 12:26:07,757 - MainThread - cts - WARNING - Authorization is disabled in CTS configuration.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
e2af98ac38f5
$ 

Running the upgrade command again will fail with a long traceback complaining about the respin_of_id column already existing.

It's possible to sort-of resume by skipping the rest of the problematic migration.

$ PYTHONPATH=. CTS_DEVELOPER_ENV=1 python cts/manage.py db stamp 16cd8140b6c7
WARN: Cannot open /etc/cts/config.py: No such file or directory
WARN: DevConfiguration will be used.
2021-09-03 12:27:44,999 - MainThread - cts - WARNING - Authorization is disabled in CTS configuration.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running stamp_revision e2af98ac38f5 -> 16cd8140b6c7
$ PYTHONPATH=. CTS_DEVELOPER_ENV=1 python cts/manage.py db upgrade
WARN: Cannot open /etc/cts/config.py: No such file or directory
WARN: DevConfiguration will be used.
2021-09-03 12:28:08,566 - MainThread - cts - WARNING - Authorization is disabled in CTS configuration.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 16cd8140b6c7 -> 18c15f736b50, Add composes.compose_url
$

For local development on sqlite, it would not be the end of the world if the constraint was skipped.

Any fix needs to make sure that deployments that are already migrated to latest version continue to work fine.


Login to comment on this ticket.

Metadata