Skip to content

Prune the migration files for Airflow 3#41120

Merged
ephraimbuddy merged 2 commits intoapache:mainfrom
astronomer:prune-migration-file
Aug 13, 2024
Merged

Prune the migration files for Airflow 3#41120
ephraimbuddy merged 2 commits intoapache:mainfrom
astronomer:prune-migration-file

Conversation

@ephraimbuddy
Copy link
Contributor

For a long time now, we have been able to create the metadata database from the ORM without going through the migration files. However, the migration files were not pruned because it would result in users being unable to roll back to a previous version. There's now an opportunity to prune this and start afresh. The migration files are getting more significant, and there are benefits to this pruning. Top in my mind is that the FAB migrations will no longer be in the airflow migration file, which would help in removing FAB from the Airflow core.

This change also means we can no longer create a new database from the migration file. We can only do that through the ORM. I considered creating the 'current schema' in the migration file, which means having the database representation in the migration file and helping to create it from scratch. I dropped the idea because there would be elements of FAB in the migration files again.

Due to this change, the db command option "--use-migration-files" was removed since this creates the database from the migration file.

@ephraimbuddy ephraimbuddy added the airflow3.0:breaking Candidates for Airflow 3.0 that contain breaking changes label Jul 30, 2024
@ephraimbuddy ephraimbuddy force-pushed the prune-migration-file branch from 3c720ce to b67b0d4 Compare July 30, 2024 13:35
@ephraimbuddy ephraimbuddy force-pushed the prune-migration-file branch 3 times, most recently from 6eed845 to 2762f60 Compare August 12, 2024 07:55
@ephraimbuddy ephraimbuddy marked this pull request as ready for review August 12, 2024 07:55
@ephraimbuddy ephraimbuddy requested review from ashb, jedcunningham, kaxil and potiuk and removed request for XD-DENG, ashb, kaxil and potiuk August 12, 2024 07:55
@ephraimbuddy ephraimbuddy added the full tests needed We need to run full set of tests for this PR to merge label Aug 12, 2024
For a long time now, we have been able to create the metadata
database from the ORM without going through the migration files.
However, the migration files were not pruned because it would
result in users being unable to roll back to a previous version.
There's now an opportunity to prune this and start afresh.
The migration files are getting more significant, and there are
benefits to this pruning. Top in my mind is that the FAB migrations
will no longer be in the airflow migration file, which would help in
removing FAB from the Airflow core.

This change also means we can no longer create a new database from the
migration file. We can only do that through the ORM. I considered creating
the 'current schema' in the migration file, which means having the database
representation in the migration file and helping to create it from scratch.
I dropped the idea because there would be elements of FAB in the migration files again.

Due to this change, the db command option "--use-migration-files" was removed
since this creates the database from the migration file.
@ephraimbuddy ephraimbuddy added this to the Airflow 3.0.0 milestone Aug 12, 2024
@jedcunningham
Copy link
Member

Overall LGMT, but we need to figure out what the min version we support upgrading from should be (2.10 vs some earlier 2.x). Ephraim is going to see where the FAB things are so in the migration files so we can figure out the best balance here.

@potiuk
Copy link
Member

potiuk commented Aug 12, 2024

Good point - my proposal is that migration from 2.x & should be another migration step (possibly combined with the main migrate command (but done via "compat/migration tool" - to bring it to 2.10.0 version using old scripts and then follow from that using Airflow 3 migrations only.

This way we could allow a direct migration from pre 2.10 versions as well.

@ephraimbuddy
Copy link
Contributor Author

FAB-related migrations stopped at 2.6.0, so we are at liberty to still have the migration cut off way down, but I think we should cut 3.0.0 migration at 2.10 as in this PR and have a migration tool for anyone upgrading, as @potiuk suggested.

@ephraimbuddy
Copy link
Contributor Author

Merging this, we can still extend it to lower versions if need be

@ephraimbuddy ephraimbuddy merged commit ba4d4a0 into apache:main Aug 13, 2024
@ephraimbuddy ephraimbuddy deleted the prune-migration-file branch August 13, 2024 08:05
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Aug 20, 2024
* Prune the migration files for Airflow 3

For a long time now, we have been able to create the metadata
database from the ORM without going through the migration files.
However, the migration files were not pruned because it would
result in users being unable to roll back to a previous version.
There's now an opportunity to prune this and start afresh.
The migration files are getting more significant, and there are
benefits to this pruning. Top in my mind is that the FAB migrations
will no longer be in the airflow migration file, which would help in
removing FAB from the Airflow core.

This change also means we can no longer create a new database from the
migration file. We can only do that through the ORM. I considered creating
the 'current schema' in the migration file, which means having the database
representation in the migration file and helping to create it from scratch.
I dropped the idea because there would be elements of FAB in the migration files again.

Due to this change, the db command option "--use-migration-files" was removed
since this creates the database from the migration file.

* fixup! Prune the migration files for Airflow 3
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Feb 20, 2026
The `--use-migration-files` flag was removed in apache#41120 when we pruned the
migration history for Airflow 3. At the time, we couldn't create a database
from scratch using only migration files because the migration chain no
longer started from an empty database. The oldest migration assumed an
existing 2.6.2 schema.

Now that we have a squashed migration (0000_2_6_2) with
`down_revision = None` that creates the full baseline schema from scratch,
we can re-introduce this flag. This enables a critical development
workflow, which is: creating the database purely from migration files, then using
`alembic revision --autogenerate` to detect schema drift between the ORM
models and the migration-produced schema. Without this flag, `autogenerate`
compares against an ORM-created database (via `create_all`), which masks
any drift since both sides come from the same ORM definitions.
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Feb 20, 2026
… ORM/migration files

The `--use-migration-files` flag was removed in apache#41120 when we pruned the
migration history for Airflow 3. At the time, we couldn't create a database
from scratch using only migration files because the migration chain no
longer started from an empty database. The oldest migration assumed an
existing 2.6.2 schema.

Now that we have a squashed migration (0000_2_6_2) with
`down_revision = None` that creates the full baseline schema from scratch,
we can re-introduce this flag. This enables a critical development
workflow, which is: creating the database purely from migration files, then using
`alembic revision --autogenerate` to detect schema drift between the ORM
models and the migration-produced schema. Without this flag, `autogenerate`
compares against an ORM-created database (via `create_all`), which masks
any drift since both sides come from the same ORM definitions.
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Feb 23, 2026
… ORM/migration files

The `--use-migration-files` flag was removed in apache#41120 when we pruned the
migration history for Airflow 3. At the time, we couldn't create a database
from scratch using only migration files because the migration chain no
longer started from an empty database. The oldest migration assumed an
existing 2.6.2 schema.

Now that we have a squashed migration (0000_2_6_2) with
`down_revision = None` that creates the full baseline schema from scratch,
we can re-introduce this flag. This enables a critical development
workflow, which is: creating the database purely from migration files, then using
`alembic revision --autogenerate` to detect schema drift between the ORM
models and the migration-produced schema. Without this flag, `autogenerate`
compares against an ORM-created database (via `create_all`), which masks
any drift since both sides come from the same ORM definitions.
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Feb 25, 2026
… ORM/migration files

The `--use-migration-files` flag was removed in apache#41120 when we pruned the
migration history for Airflow 3. At the time, we couldn't create a database
from scratch using only migration files because the migration chain no
longer started from an empty database. The oldest migration assumed an
existing 2.6.2 schema.

Now that we have a squashed migration (0000_2_6_2) with
`down_revision = None` that creates the full baseline schema from scratch,
we can re-introduce this flag. This enables a critical development
workflow, which is: creating the database purely from migration files, then using
`alembic revision --autogenerate` to detect schema drift between the ORM
models and the migration-produced schema. Without this flag, `autogenerate`
compares against an ORM-created database (via `create_all`), which masks
any drift since both sides come from the same ORM definitions.
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Feb 26, 2026
… ORM/migration files

The `--use-migration-files` flag was removed in apache#41120 when we pruned the
migration history for Airflow 3. At the time, we couldn't create a database
from scratch using only migration files because the migration chain no
longer started from an empty database. The oldest migration assumed an
existing 2.6.2 schema.

Now that we have a squashed migration (0000_2_6_2) with
`down_revision = None` that creates the full baseline schema from scratch,
we can re-introduce this flag. This enables a critical development
workflow, which is: creating the database purely from migration files, then using
`alembic revision --autogenerate` to detect schema drift between the ORM
models and the migration-produced schema. Without this flag, `autogenerate`
compares against an ORM-created database (via `create_all`), which masks
any drift since both sides come from the same ORM definitions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-79 airflow3.0:breaking Candidates for Airflow 3.0 that contain breaking changes area:CLI area:db-migrations PRs with DB migration area:dev-tools full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants