Skip to content
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

Use keyword paramaters for migration methods for mssql #31309

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def upgrade():

conn = op.get_bind()
if conn.dialect.name == "mssql":
op.drop_index("ti_pool", table_name="task_instance")
op.drop_index(index_name="ti_pool", table_name="task_instance")

# use batch_alter_table to support SQLite workaround
with op.batch_alter_table("task_instance") as batch_op:
Expand All @@ -75,14 +75,16 @@ def upgrade():
)

if conn.dialect.name == "mssql":
op.create_index("ti_pool", "task_instance", ["pool", "state", "priority_weight"])
op.create_index(
index_name="ti_pool", table_name="task_instance", columns=["pool", "state", "priority_weight"]
)


def downgrade():
"""Make TaskInstance.pool field nullable."""
conn = op.get_bind()
if conn.dialect.name == "mssql":
op.drop_index("ti_pool", table_name="task_instance")
op.drop_index(index_name="ti_pool", table_name="task_instance")

# use batch_alter_table to support SQLite workaround
with op.batch_alter_table("task_instance") as batch_op:
Expand All @@ -93,7 +95,9 @@ def downgrade():
)

if conn.dialect.name == "mssql":
op.create_index("ti_pool", "task_instance", ["pool", "state", "priority_weight"])
op.create_index(
index_name="ti_pool", table_name="task_instance", columns=["pool", "state", "priority_weight"]
)

with create_session() as session:
session.query(TaskInstance).filter(TaskInstance.pool == "default_pool").update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ class SerializedDagModel(Base):
conn = op.get_bind()
if conn.dialect.name != "sqlite":
if conn.dialect.name == "mssql":
op.drop_index("idx_fileloc_hash", "serialized_dag")
op.drop_index(index_name="idx_fileloc_hash", table_name="serialized_dag")

op.alter_column(
table_name="serialized_dag", column_name="fileloc_hash", type_=sa.BigInteger(), nullable=False
)
if conn.dialect.name == "mssql":
op.create_index("idx_fileloc_hash", "serialized_dag", ["fileloc_hash"])
op.create_index(
index_name="idx_fileloc_hash", table_name="serialized_dag", columns=["fileloc_hash"]
)

sessionmaker = sa.orm.sessionmaker()
session = sessionmaker(bind=conn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def upgrade():
if "id" in xcom_columns:
if conn.dialect.name == "mssql":
constraint_dict = get_table_constraints(conn, "xcom")
drop_column_constraints(bop, "id", constraint_dict)
drop_column_constraints(operator=bop, column_name="id", constraint_dict=constraint_dict)
bop.drop_column("id")
bop.drop_index("idx_xcom_dag_task_date")
# mssql doesn't allow primary keys with nullable columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def upgrade():
bop.alter_column("key", type_=StringID(length=512), nullable=False)
bop.alter_column("execution_date", type_=TIMESTAMP, nullable=False)
if conn.dialect.name == "mssql":
bop.create_primary_key("pk_xcom", ["dag_id", "task_id", "key", "execution_date"])
bop.create_primary_key(
constraint_name="pk_xcom", columns=["dag_id", "task_id", "key", "execution_date"]
)


def downgrade():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ def downgrade():
constraints = get_mssql_table_constraints(conn, "xcom")
pk, _ = constraints["PRIMARY KEY"].popitem()
op.drop_constraint(pk, "xcom", type_="primary")
op.create_primary_key("pk_xcom", "xcom", ["dag_id", "task_id", "execution_date", "key"])
op.create_primary_key(
constraint_name="pk_xcom",
table_name="xcom",
columns=["dag_id", "task_id", "execution_date", "key"],
)
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 @@
4995c94849a5848e551e85ffeb99d3dda9f652f3c2d7b3cf3aa16c02911690d3
4987842fd67d29e194f1117e127d3291ba60d3fbc3e81cba75ce93884c263321
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# specific language governing permissions and limitations
# under the License.
"""Setup.py for the Airflow project."""
# This file can be modified if you want to make sure the CI build is using "upgrade to newer dependencies"
# Which is useful when you want to check if the dependencies are still compatible with the latest versions
# And they seem to break some unrelated tests in main. You can modify this number = 00001 to trigger it.
Comment on lines +19 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# This file can be modified if you want to make sure the CI build is using "upgrade to newer dependencies"
# Which is useful when you want to check if the dependencies are still compatible with the latest versions
# And they seem to break some unrelated tests in main. You can modify this number = 00001 to trigger it.
# This file can be modified if you want to make sure the CI build is using "upgrade to newer dependencies",
# which is useful when you want to check if the dependencies are still compatible with the latest versions
# as they seem to break some unrelated tests in main. You can modify this number = 00001 to trigger it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also which number can be modified to 00001 we meant here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh I guess I understood now what was meant here after reading the Slack message. Will it make sense to rephrase this to somewhat like the following?

To make sure the CI build is using "upgrade to newer dependencies", which is useful when you want to check if the dependencies are still compatible with the latest versions as they seem to break some unrelated tests in main, you can modify this file. The modification can be simply modifying this particular comment. e.g. you can modify the following number 00001 to something else to trigger this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Have not seen the comment> this number (i.e. 00001) can be modified. But if you think you can describe it better - feel free.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically any change to setup.py will do - even adding a space.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, GitHub is acting weird, my comments are going late. Earlier I tried to merge a couple of PRs and I felt I did but realised now that they were not merged :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to rephrase it here: #31312

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this time I simply did not refresh the PR. I wanted to merge it fast to fix main so I missed it :)

from __future__ import annotations

import glob
Expand Down