-
Notifications
You must be signed in to change notification settings - Fork 16.4k
AIP-65: Add DAG versioning support #42913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
a3275a7
AIP-65: Add DAG versioning support
ephraimbuddy ae5b6da
fixup! AIP-65: Add DAG versioning support
ephraimbuddy ed89ca6
fixup! fixup! AIP-65: Add DAG versioning support
ephraimbuddy ef506f9
fix migration
ephraimbuddy 3821dbb
fix test
ephraimbuddy 683bbd7
more test fixes
ephraimbuddy fe655de
update query count
ephraimbuddy ff9be22
fix static checks
ephraimbuddy 7f50a3c
Fix query and add created_at to dag_version table
ephraimbuddy 57bd887
improve code
ephraimbuddy e2bdad3
Change to using UUID for primary keys
ephraimbuddy a4e3c78
DagCode.bulk_write_code is no longer used
ephraimbuddy e994074
fixup! Change to using UUID for primary keys
ephraimbuddy e06b752
fix tests
ephraimbuddy 0bef933
fixup! fix tests
ephraimbuddy d2bd271
use uuid for version_name
ephraimbuddy 99abb36
fixup! use uuid for version_name
ephraimbuddy 23204b8
use row lock when writing dag version
ephraimbuddy 2525902
use row lock when writing dag version
ephraimbuddy 610d3b1
fixup! use row lock when writing dag version
ephraimbuddy 2cf03f5
deactivating dag should not remove serialized dags
ephraimbuddy ad91949
save version_name as string not uuid
ephraimbuddy 11de3a2
Make dag_version_id unique
ephraimbuddy 108c80c
fixup! Make dag_version_id unique
ephraimbuddy 53a4837
Fix tests
ephraimbuddy 554dd15
Use uuid7
ephraimbuddy 72f2cc0
fix test
ephraimbuddy 903ed3c
fixup! fix test
ephraimbuddy db44170
use binary=False for uuid field to fix sqlite issue
ephraimbuddy c4ed8af
apply suggestions from code review
ephraimbuddy 4f011d2
Remove unnecessary version_name on dagmodel
ephraimbuddy 4bf8b1f
Fix sqlalchemy 2 warning
ephraimbuddy 0e0c127
Fix conflicts
ephraimbuddy e410f2c
Apply suggestions from code review
ephraimbuddy 76982f3
fixup! Apply suggestions from code review
ephraimbuddy c4171cb
fixup! fixup! Apply suggestions from code review
ephraimbuddy dad0f36
add test for dagversion model and make version_name, number and dag_i…
ephraimbuddy 13777e7
Remove commented test as serdag can no longer disappear
ephraimbuddy 9f96cb0
Add SQLAlchemy-utils to requirements
ephraimbuddy b2c4844
mark test_dag_version.py as db_test
ephraimbuddy 611a5cb
make version_name nullable
ephraimbuddy cc41fb6
Apply suggestions from code review
ephraimbuddy 621a407
fixup! Apply suggestions from code review
ephraimbuddy 108965b
remove file_updater
ephraimbuddy a51585e
Use dag_version for creating dagruns instead of dag_version_id
ephraimbuddy 01f3c58
fix conflicts
ephraimbuddy 11de1e9
use if TYPE_CHECKING
ephraimbuddy 569eb53
Add docstrings to methods
ephraimbuddy a7bba02
Move getting latest serdags to SerializedDagModel
ephraimbuddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
airflow/migrations/versions/0047_3_0_0_add_dag_versioning.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """ | ||
| add dag versioning. | ||
|
|
||
| Revision ID: 2b47dc6bc8df | ||
| Revises: d03e4a635aa3 | ||
| Create Date: 2024-10-09 05:44:04.670984 | ||
|
|
||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy_utils import UUIDType | ||
|
|
||
| from airflow.migrations.db_types import StringID | ||
| from airflow.models.base import naming_convention | ||
| from airflow.utils import timezone | ||
| from airflow.utils.sqlalchemy import UtcDateTime | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "2b47dc6bc8df" | ||
| down_revision = "d03e4a635aa3" | ||
| branch_labels = None | ||
| depends_on = None | ||
| airflow_version = "3.0.0" | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """Apply add dag versioning.""" | ||
| op.create_table( | ||
| "dag_version", | ||
| sa.Column("id", UUIDType(binary=False), nullable=False), | ||
| sa.Column("version_number", sa.Integer(), nullable=False), | ||
| sa.Column("version_name", StringID()), | ||
| sa.Column("dag_id", StringID(), nullable=False), | ||
| sa.Column("created_at", UtcDateTime(), nullable=False, default=timezone.utcnow), | ||
| sa.ForeignKeyConstraint( | ||
| ("dag_id",), ["dag.dag_id"], name=op.f("dag_version_dag_id_fkey"), ondelete="CASCADE" | ||
| ), | ||
| sa.PrimaryKeyConstraint("id", name=op.f("dag_version_pkey")), | ||
| sa.UniqueConstraint("dag_id", "version_number", name="dag_id_v_name_v_number_unique_constraint"), | ||
| ) | ||
| with op.batch_alter_table("dag_code", recreate="always", naming_convention=naming_convention) as batch_op: | ||
| batch_op.drop_constraint("dag_code_pkey", type_="primary") | ||
| batch_op.add_column( | ||
| sa.Column("id", UUIDType(binary=False), primary_key=True), insert_before="fileloc_hash" | ||
| ) | ||
| batch_op.create_primary_key("dag_code_pkey", ["id"]) | ||
| batch_op.add_column(sa.Column("dag_version_id", UUIDType(binary=False), nullable=False)) | ||
| batch_op.create_foreign_key( | ||
| batch_op.f("dag_code_dag_version_id_fkey"), | ||
| "dag_version", | ||
| ["dag_version_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
| batch_op.create_unique_constraint("dag_code_dag_version_id_uq", ["dag_version_id"]) | ||
|
|
||
| with op.batch_alter_table( | ||
| "serialized_dag", recreate="always", naming_convention=naming_convention | ||
| ) as batch_op: | ||
| batch_op.drop_constraint("serialized_dag_pkey", type_="primary") | ||
| batch_op.add_column(sa.Column("id", UUIDType(binary=False), primary_key=True)) | ||
| batch_op.drop_index("idx_fileloc_hash") | ||
| batch_op.drop_column("fileloc_hash") | ||
| batch_op.drop_column("fileloc") | ||
| batch_op.create_primary_key("serialized_dag_pkey", ["id"]) | ||
| batch_op.add_column(sa.Column("dag_version_id", UUIDType(binary=False), nullable=False)) | ||
| batch_op.create_foreign_key( | ||
| batch_op.f("serialized_dag_dag_version_id_fkey"), | ||
| "dag_version", | ||
| ["dag_version_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
| batch_op.create_unique_constraint("serialized_dag_dag_version_id_uq", ["dag_version_id"]) | ||
|
|
||
| with op.batch_alter_table("task_instance", schema=None) as batch_op: | ||
| batch_op.add_column(sa.Column("dag_version_id", UUIDType(binary=False))) | ||
| batch_op.create_foreign_key( | ||
| batch_op.f("task_instance_dag_version_id_fkey"), | ||
| "dag_version", | ||
| ["dag_version_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
|
|
||
| with op.batch_alter_table("task_instance_history", schema=None) as batch_op: | ||
| batch_op.add_column(sa.Column("dag_version_id", UUIDType(binary=False))) | ||
|
|
||
| with op.batch_alter_table("dag_run", schema=None) as batch_op: | ||
| batch_op.add_column(sa.Column("dag_version_id", UUIDType(binary=False))) | ||
| batch_op.create_foreign_key( | ||
| batch_op.f("dag_run_dag_version_id_fkey"), | ||
| "dag_version", | ||
| ["dag_version_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
| batch_op.drop_column("dag_hash") | ||
|
|
||
|
|
||
| def downgrade(): | ||
| """Unapply add dag versioning.""" | ||
| with op.batch_alter_table("task_instance_history", schema=None) as batch_op: | ||
| batch_op.drop_column("dag_version_id") | ||
|
|
||
| with op.batch_alter_table("task_instance", schema=None) as batch_op: | ||
| batch_op.drop_constraint(batch_op.f("task_instance_dag_version_id_fkey"), type_="foreignkey") | ||
| batch_op.drop_column("dag_version_id") | ||
|
|
||
| with op.batch_alter_table("dag_code", schema=None) as batch_op: | ||
| batch_op.drop_column("id") | ||
| batch_op.drop_constraint(batch_op.f("dag_code_dag_version_id_fkey"), type_="foreignkey") | ||
| batch_op.drop_column("dag_version_id") | ||
| batch_op.create_primary_key("dag_code_pkey", ["fileloc_hash"]) | ||
|
|
||
| with op.batch_alter_table("serialized_dag", schema=None, naming_convention=naming_convention) as batch_op: | ||
| batch_op.drop_column("id") | ||
| batch_op.add_column(sa.Column("fileloc", sa.String(length=2000), autoincrement=False, nullable=False)) | ||
| batch_op.add_column(sa.Column("fileloc_hash", sa.BIGINT(), autoincrement=False, nullable=False)) | ||
| batch_op.create_index("idx_fileloc_hash", ["fileloc_hash"], unique=False) | ||
| batch_op.create_primary_key("serialized_dag_pkey", ["dag_id"]) | ||
| batch_op.drop_constraint(batch_op.f("serialized_dag_dag_version_id_fkey"), type_="foreignkey") | ||
| batch_op.drop_column("dag_version_id") | ||
|
|
||
| with op.batch_alter_table("dag_run", schema=None) as batch_op: | ||
| batch_op.add_column(sa.Column("dag_hash", sa.String(length=32), autoincrement=False, nullable=True)) | ||
| batch_op.drop_constraint(batch_op.f("dag_run_dag_version_id_fkey"), type_="foreignkey") | ||
| batch_op.drop_column("dag_version_id") | ||
|
|
||
| op.drop_table("dag_version") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.