Support generating SQL script for upgrades#20962
Conversation
|
I think this is quite needed. I actually find Alembic much worse and less intuitive than other solution (say Django migrations). So some tooling and possibly better instructions for those who attempt to add migrations is most welcome! |
6d0a3cd to
9a6bd5f
Compare
9a6bd5f to
a674a85
Compare
ea6f10a to
db130b2
Compare
db130b2 to
12c5bae
Compare
uranusjr
left a comment
There was a problem hiding this comment.
LGTM except the server_default thing I don’t really understand. (SQLAlchemy is so complicated…)
|
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
b9c80b8 to
f0bb8f7
Compare
f0bb8f7 to
914ba56
Compare
914ba56 to
6589243
Compare
|
I will make a separate PR for SQLite & MSSQL. SQLite needs the |
6589243 to
15d0f59
Compare
04979c5 to
1307aa8
Compare
ashb
left a comment
There was a problem hiding this comment.
Few minor questions, looks good though.
23d9185 to
4d8c336
Compare
|
Using github rebase button just messed my local branch up while fixing conflicts. It was a lot |
kaxil
left a comment
There was a problem hiding this comment.
Can we also add user-facing docs about it somewhere plz
There was a problem hiding this comment.
We should have a pre-commit to verify that a tuple containing the current Airflow version is added to REVISION_HEADS_MAP to avoid forgetting it.
There was a problem hiding this comment.
It looks like a pre-commit won't be possible in this case as we only update the migration head when there's a new airflow release.
There was a problem hiding this comment.
How about something as simple as:
from airflow.utils.db import REVISION_HEADS_MAP
from airflow.version import version as airflow_version
from packaging.version import Version
if not Version(airflow_version).is_prerelease and airflow_version not in REVISION_HEADS_MAP:
raise Exception(f"Airflow version {airflow_version} is not in the revision map {REVISION_HEADS_MAP}")There was a problem hiding this comment.
i was also thinking about this issue. i saw that we had a table in the docs which contains this mapping. so what i was thinking to do was store that table in yaml form, and it could be used to generate the docs table and to support CLI commands which need to map version to revision, and that's what i do in #21601
There was a problem hiding this comment.
Looks good, I think the challenge would be to get the migration heads of the versions and discard every other migration in-between when going from version to version. It's still necessary to have a pre-commit or a ci job that makes sure we have the migration head updated before a release
8cad8ad to
ca29071
Compare
This PR attempts to add support for generating sql scripts for upgrade. Example command: `airflow db upgrade e8d98d8ss99 --sql` `airflow db upgrade --sql` Support offline mode from 2.0.0 upwards Add tests fixup! Add tests fixup! fixup! Add tests add server default to pool_slots Fix single digit revision in offline mode to start from 2.0.0 head fixup! Fix single digit revision in offline mode to start from 2.0.0 head Apply suggestions from code review Separate offline code from online to reduce log noise fixup! Separate offline code from online to reduce log noise Use version instead of revision fixup! Use version instead of revision add back revision range fixup! add back revision range Add instruction to update revision map during release Exclude offline migration for sqlite and mssql less than 2.2.0 Use version range instead of just version in cli parser print nice message for versions without migrations fixup! print nice message for versions without migrations Support generating SQL script for upgrades This PR attempts to add support for generating sql scripts for upgrade. Example command: `airflow db upgrade e8d98d8ss99 --sql` `airflow db upgrade --sql` Support offline mode from 2.0.0 upwards Add tests fixup! Add tests fixup! fixup! Add tests Fix single digit revision in offline mode to start from 2.0.0 head fixup! Fix single digit revision in offline mode to start from 2.0.0 head Separate offline code from online to reduce log noise Use version instead of revision print nice message for versions without migrations fixup! print nice message for versions without migrations Apply suggestions from code review Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com> use range instead of version-range Fix test Support generating SQL script for upgrades This PR attempts to add support for generating sql scripts for upgrade. Example command: `airflow db upgrade e8d98d8ss99 --sql` `airflow db upgrade --sql` Support offline mode from 2.0.0 upwards Add tests fixup! Add tests fixup! fixup! Add tests Fix single digit revision in offline mode to start from 2.0.0 head fixup! Fix single digit revision in offline mode to start from 2.0.0 head Separate offline code from online to reduce log noise Use version instead of revision add back revision range Use version range instead of just version in cli parser print nice message for versions without migrations fixup! print nice message for versions without migrations Support generating SQL script for upgrades This PR attempts to add support for generating sql scripts for upgrade. Example command: `airflow db upgrade e8d98d8ss99 --sql` `airflow db upgrade --sql` Support offline mode from 2.0.0 upwards Add tests fixup! Add tests fixup! fixup! Add tests Fix single digit revision in offline mode to start from 2.0.0 head fixup! Fix single digit revision in offline mode to start from 2.0.0 head Separate offline code from online to reduce log noise Use version instead of revision print nice message for versions without migrations fixup! print nice message for versions without migrations Apply suggestions from code review Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com> Apply suggestions from code review Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com> fix conflict
ca29071 to
b669f17
Compare
b669f17 to
3d19303
Compare
kaxil
left a comment
There was a problem hiding this comment.
Approving it so it is not blocked for adding pre-commit - that can be a follow-up PR.
This PR attempts to add support for generating sql scripts for upgrade.
Example command:
airflow db upgrade --revision-range e8d98d8ss99:78daisdu38dairflow db upgrade --range 2.0.0:2.2.3^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.