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

[AIRFLOW-3079] Improve migration scripts to support MSSQL Server #3964

Merged
merged 1 commit into from
Sep 29, 2018
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 @@ -39,6 +39,12 @@
TABLE_NAME = 'task_reschedule'
INDEX_NAME = 'idx_' + TABLE_NAME + '_dag_task_date'

# For Microsoft SQL Server, TIMESTAMP is a row-id type,
# having nothing to do with date-time. DateTime() will
# be sufficient.
def mssql_timestamp():
return sa.DateTime()

def mysql_timestamp():
return mysql.TIMESTAMP(fsp=6)

Expand All @@ -50,6 +56,8 @@ def upgrade():
conn = op.get_bind()
if conn.dialect.name == 'mysql':
timestamp = mysql_timestamp
elif conn.dialect.name == 'mssql':
timestamp = mssql_timestamp
else:
timestamp = sa_timestamp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def upgrade():
op.alter_column(table_name='xcom', column_name='timestamp', type_=mysql.TIMESTAMP(fsp=6))
op.alter_column(table_name='xcom', column_name='execution_date', type_=mysql.TIMESTAMP(fsp=6))
else:
# sqlite datetime is fine as is not converting
if conn.dialect.name == 'sqlite':
# sqlite and mssql datetime are fine as is. Therefore, not converting
if conn.dialect.name in ('sqlite', 'mssql'):
return

# we try to be database agnostic, but not every db (e.g. sqlserver)
Expand Down Expand Up @@ -182,7 +182,7 @@ def downgrade():
op.alter_column(table_name='xcom', column_name='DATETIME', type_=mysql.DATETIME(fsp=6))
op.alter_column(table_name='xcom', column_name='execution_date', type_=mysql.DATETIME(fsp=6))
else:
if conn.dialect.name == 'sqlite':
if conn.dialect.name in ('sqlite', 'mssql'):
return

# we try to be database agnostic, but not every db (e.g. sqlserver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@


def upgrade():

columns_and_constraints = [
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("resource_version", sa.String(255))
]

conn = op.get_bind()

# alembic creates an invalid SQL for mssql dialect
if conn.dialect.name not in ('mssql'):
columns_and_constraints.append(sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id"))

table = op.create_table(
RESOURCE_TABLE,
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("resource_version", sa.String(255)),
sa.CheckConstraint("one_row_id", name="kube_resource_version_one_row_id")
*columns_and_constraints
)

op.bulk_insert(table, [
{"resource_version": ""}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@


def upgrade():

columns_and_constraints = [
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("worker_uuid", sa.String(255))
]

conn = op.get_bind()

# alembic creates an invalid SQL for mssql dialect
if conn.dialect.name not in ('mssql'):
columns_and_constraints.append(sa.CheckConstraint("one_row_id", name="kube_worker_one_row_id"))

table = op.create_table(
RESOURCE_TABLE,
sa.Column("one_row_id", sa.Boolean, server_default=sa.true(), primary_key=True),
sa.Column("worker_uuid", sa.String(255)),
sa.CheckConstraint("one_row_id", name="kube_worker_one_row_id")
*columns_and_constraints
)

op.bulk_insert(table, [
{"worker_uuid": ""}
])
Expand Down