Skip to content

Commit

Permalink
fix for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimbuddy committed Nov 22, 2024
1 parent dfaec5d commit 7940140
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 20 deletions.
18 changes: 2 additions & 16 deletions airflow/migrations/versions/0041_3_0_0_rename_dataset_as_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,6 @@ def upgrade():
unique=False,
)

batch_op.create_foreign_key(
constraint_name="toar_asset_fkey",
referent_table="asset",
local_cols=["asset_id"],
remote_cols=["id"],
ondelete="CASCADE",
)
batch_op.create_foreign_key(
constraint_name="toar_dag_id_fkey",
referent_table="dag",
Expand Down Expand Up @@ -321,13 +314,6 @@ def upgrade():
unique=False,
)

batch_op.create_foreign_key(
constraint_name="adrq_asset_fkey",
referent_table="asset",
local_cols=["asset_id"],
remote_cols=["id"],
ondelete="CASCADE",
)
batch_op.create_foreign_key(
constraint_name="adrq_dag_fkey",
referent_table="dag",
Expand Down Expand Up @@ -565,7 +551,7 @@ def downgrade():
with op.batch_alter_table("task_outlet_dataset_reference", schema=None) as batch_op:
batch_op.alter_column("asset_id", new_column_name="dataset_id", type_=sa.Integer(), nullable=False)

batch_op.drop_constraint("toar_asset_fkey", type_="foreignkey")
# batch_op.drop_constraint("toar_asset_fkey", type_="foreignkey")
batch_op.drop_constraint("toar_dag_id_fkey", type_="foreignkey")

_rename_index(
Expand Down Expand Up @@ -600,7 +586,7 @@ def downgrade():
with op.batch_alter_table("dataset_dag_run_queue", schema=None) as batch_op:
batch_op.alter_column("asset_id", new_column_name="dataset_id", type_=sa.Integer(), nullable=False)

batch_op.drop_constraint("adrq_asset_fkey", type_="foreignkey")
# batch_op.drop_constraint("adrq_asset_fkey", type_="foreignkey")
batch_op.drop_constraint("adrq_dag_fkey", type_="foreignkey")

_rename_pk_constraint(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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.

"""
create foreign key constraints for assets.
Revision ID: c4a1639f0f67
Revises: 05234396c6fc
Create Date: 2024-11-22 09:49:41.813016
"""

from __future__ import annotations

from alembic import op

# revision identifiers, used by Alembic.
revision = "c4a1639f0f67"
down_revision = "05234396c6fc"
branch_labels = None
depends_on = None
airflow_version = "3.0.0"


def upgrade():
"""Apply create foreign key constraints for assets."""
with op.batch_alter_table("asset_dag_run_queue", schema=None) as batch_op:
batch_op.create_foreign_key("adrq_asset_fkey", "asset", ["asset_id"], ["id"], ondelete="CASCADE")

with op.batch_alter_table("task_outlet_asset_reference", schema=None) as batch_op:
batch_op.create_foreign_key("toar_asset_fkey", "asset", ["asset_id"], ["id"], ondelete="CASCADE")


def downgrade():
"""Unapply create foreign key constraints for assets."""
with op.batch_alter_table("task_outlet_asset_reference", schema=None) as batch_op:
batch_op.drop_constraint("toar_asset_fkey", type_="foreignkey")

with op.batch_alter_table("asset_dag_run_queue", schema=None) as batch_op:
batch_op.drop_constraint("adrq_asset_fkey", type_="foreignkey")
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Add UUID primary key to ``task_instance`` table.
Revision ID: d59cbbef95eb
Revises: 05234396c6fc
Revises: c4a1639f0f67
Create Date: 2024-10-21 22:39:12.394079
"""

Expand All @@ -33,7 +33,7 @@

# revision identifiers, used by Alembic.
revision = "d59cbbef95eb"
down_revision = "05234396c6fc"
down_revision = "c4a1639f0f67"
branch_labels = "None"
depends_on = None
airflow_version = "3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def upgrade():

def downgrade():
"""Unapply add dag versioning."""
_delete_serdag_and_code()
with op.batch_alter_table("task_instance_history", schema=None) as batch_op:
batch_op.drop_column("dag_version_id")

Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b12f6811bb7a340362e4b8774b3bb81db28a7d0258564b3431bd537368554cc3
7173ce2b98bc53467274ebe89bd3d4c8e7672f7b40b3f22989139ece45741f8f
4 changes: 3 additions & 1 deletion docs/apache-airflow/migrations-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Here's the list of all the Database Migrations that are executed via when you ru
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
| ``486ac7936b78`` | ``d59cbbef95eb`` | ``3.0.0`` | remove scheduler_lock column. |
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
| ``d59cbbef95eb`` | ``05234396c6fc`` | ``3.0.0`` | Add UUID primary key to ``task_instance`` table. |
| ``d59cbbef95eb`` | ``c4a1639f0f67`` | ``3.0.0`` | Add UUID primary key to ``task_instance`` table. |
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
| ``c4a1639f0f67`` | ``05234396c6fc`` | ``3.0.0`` | create foreign key constraints for assets. |
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
| ``05234396c6fc`` | ``3a8972ecb8f9`` | ``3.0.0`` | Rename dataset as asset. |
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
Expand Down

0 comments on commit 7940140

Please sign in to comment.