airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Fix alembic autogeneration and rename mismatching constraints

Open ephraimbuddy opened this issue 1 year ago • 2 comments

The alembic autogeneration is not working as expected and the tests were not detecting it because we use DBs created from the ORM to run tests. When a change is made in the ORM and the ORM is used to initialize the database for tests, the changes in the ORM will appear the same with what is in the migration file. To be sure that both match, we have to compare the database generated using the migration file to the database that could be created from the ORM. To fix this, I added 'use_migration_file' arg to resetdb function and updated the db reset in conftest to use migration file during test db reset.

As part of this fix, I also updated mismatching constraint names. The update was done in the migration file instead of the ORM as I take the ORM as the source of truth. New airflow users create their DB from the ORM with the correct naming because we have a naming convention. Old airflow users would have to upgrade to use these names from ORM instead of the reverse.

I also removed the sqlite_sequence table which is specific to sqlite and not needed for anything. An alternative would be to add sqlite_autoincrement to table args in the ORM and migration but this table is not that useful.

ephraimbuddy avatar Apr 15 '24 14:04 ephraimbuddy

The test_database_schema_and_sqlalchemy_model_are_in_sync test does not seem to agree with this…

uranusjr avatar Apr 23 '24 08:04 uranusjr

The test_database_schema_and_sqlalchemy_model_are_in_sync test does not seem to agree with this…

Should be fixed now

ephraimbuddy avatar Apr 30 '24 07:04 ephraimbuddy

Previously, I added the use_migration_files as just a parameter to the DB upgrade/reset functions. Now, I have extended it to be a CLI option so one can run airflow db reset --use-migration-files if they want to. I think that's how it should be

ephraimbuddy avatar May 03 '24 14:05 ephraimbuddy