response stringlengths 1 33.1k | instruction stringlengths 22 582k |
|---|---|
Apply Add ``creating_job_id`` to ``DagRun`` table | def upgrade():
"""Apply Add ``creating_job_id`` to ``DagRun`` table"""
op.add_column("dag_run", sa.Column("creating_job_id", sa.Integer)) |
Unapply Add job_id to DagRun table | def downgrade():
"""Unapply Add job_id to DagRun table"""
op.drop_column("dag_run", "creating_job_id") |
Apply add-k8s-yaml-to-rendered-templates | def upgrade():
"""Apply add-k8s-yaml-to-rendered-templates"""
with op.batch_alter_table(__tablename__, schema=None) as batch_op:
batch_op.add_column(k8s_pod_yaml) |
Unapply add-k8s-yaml-to-rendered-templates | def downgrade():
"""Unapply add-k8s-yaml-to-rendered-templates"""
with op.batch_alter_table(__tablename__, schema=None) as batch_op:
batch_op.drop_column("k8s_pod_yaml") |
Apply Map Airflow permissions. | def remap_permissions():
"""Apply Map Airflow permissions."""
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
for old, new in mapping.items():
(old_resource_name, old_action_name) = old
old_permission = appbuilder.sm.get_permission(old_action_name, old_resource_name)
... |
Unapply Map Airflow permissions | def undo_remap_permissions():
"""Unapply Map Airflow permissions"""
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
for old, new in mapping.items():
(new_resource_name, new_action_name) = new[0]
new_permission = appbuilder.sm.get_permission(new_action_name, new_resourc... |
Apply Resource based permissions. | def upgrade():
"""Apply Resource based permissions."""
log = logging.getLogger()
handlers = log.handlers[:]
remap_permissions()
log.handlers = handlers |
Unapply Resource based permissions. | def downgrade():
"""Unapply Resource based permissions."""
log = logging.getLogger()
handlers = log.handlers[:]
undo_remap_permissions()
log.handlers = handlers |
Apply Add description field to ``connection`` table | def upgrade():
"""Apply Add description field to ``connection`` table"""
conn = op.get_bind()
with op.batch_alter_table("connection") as batch_op:
if conn.dialect.name == "mysql":
# Handles case where on mysql with utf8mb4 this would exceed the size of row
# We have to set t... |
Unapply Add description field to ``connection`` table | def downgrade():
"""Unapply Add description field to ``connection`` table"""
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.drop_column("description") |
Apply Fix description field in ``connection`` to be ``text`` | def upgrade():
"""Apply Fix description field in ``connection`` to be ``text``"""
conn = op.get_bind()
if conn.dialect.name == "sqlite":
# in sqlite TEXT and STRING column types are the same
return
if conn.dialect.name == "mysql":
op.alter_column(
"connection",
... |
Unapply Fix description field in ``connection`` to be ``text`` | def downgrade():
"""Unapply Fix description field in ``connection`` to be ``text``"""
conn = op.get_bind()
if conn.dialect.name == "sqlite":
# in sqlite TEXT and STRING column types are the same
return
if conn.dialect.name == "mysql":
op.alter_column(
"connection",
... |
Remove can_read action from config resource for User and Viewer role | def upgrade():
"""Remove can_read action from config resource for User and Viewer role"""
log = logging.getLogger()
handlers = log.handlers[:]
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
roles_to_modify = [role for role in appbuilder.sm.get_all_roles() if role.name in ["U... |
Add can_read action on config resource for User and Viewer role | def downgrade():
"""Add can_read action on config resource for User and Viewer role"""
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
roles_to_modify = [role for role in appbuilder.sm.get_all_roles() if role.name in ["User", "Viewer"]]
can_read_on_config_perm = appbuilder.sm.get_... |
Apply increase_length_for_connection_password | def upgrade():
"""Apply increase_length_for_connection_password"""
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column(
"extra",
existing_type=sa.VARCHAR(length=5000),
type_=sa.TEXT(),
existing_nullable=True,
) |
Unapply increase_length_for_connection_password | def downgrade():
"""Unapply increase_length_for_connection_password"""
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column(
"extra",
existing_type=sa.TEXT(),
type_=sa.VARCHAR(length=5000),
existing_nullable=True,
... |
Change default ``pool_slots`` to ``1`` and make pool_slots not nullable | def upgrade():
"""Change default ``pool_slots`` to ``1`` and make pool_slots not nullable"""
op.execute("UPDATE task_instance SET pool_slots = 1 WHERE pool_slots IS NULL")
with op.batch_alter_table("task_instance", schema=None) as batch_op:
batch_op.alter_column("pool_slots", existing_type=sa.Intege... |
Unapply Change default ``pool_slots`` to ``1`` | def downgrade():
"""Unapply Change default ``pool_slots`` to ``1``"""
conn = op.get_bind()
if conn.dialect.name == "mssql":
inspector = sa.inspect(conn.engine)
columns = inspector.get_columns("task_instance")
for col in columns:
if col["name"] == "pool_slots" and col["... |
Apply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time`` | def upgrade():
"""Apply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time``"""
conn = op.get_bind()
if conn.dialect.name == "mssql":
with op.batch_alter_table("dag") as batch_op:
batch_op.alter_column(
"last_scheduler_run", new_column_name="last_... |
Unapply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time`` | def downgrade():
"""Unapply Rename ``last_scheduler_run`` column in ``DAG`` table to ``last_parsed_time``"""
conn = op.get_bind()
if conn.dialect.name == "mssql":
with op.batch_alter_table("dag") as batch_op:
batch_op.alter_column(
"last_parsed_time", new_column_name="las... |
Apply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters | def upgrade():
"""Apply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters"""
with op.batch_alter_table("task_instance") as batch_op:
batch_op.alter_column("pool", type_=sa.String(256), nullable=False) |
Unapply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters | def downgrade():
"""Unapply Increase maximum length of pool name in ``task_instance`` table to ``256`` characters"""
conn = op.get_bind()
if conn.dialect.name == "mssql":
with op.batch_alter_table("task_instance") as batch_op:
batch_op.drop_index("ti_pool")
batch_op.alter_col... |
Apply Add description field to ``Variable`` model | def upgrade():
"""Apply Add description field to ``Variable`` model"""
with op.batch_alter_table("variable", schema=None) as batch_op:
batch_op.add_column(sa.Column("description", sa.Text(), nullable=True)) |
Unapply Add description field to ``Variable`` model | def downgrade():
"""Unapply Add description field to ``Variable`` model"""
with op.batch_alter_table("variable", schema=None) as batch_op:
batch_op.drop_column("description") |
Apply Map Airflow permissions. | def remap_permissions():
"""Apply Map Airflow permissions."""
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
for old, new in mapping.items():
(old_resource_name, old_action_name) = old
old_permission = appbuilder.sm.get_permission(old_action_name, old_resource_name)
... |
Unapply Map Airflow permissions | def undo_remap_permissions():
"""Unapply Map Airflow permissions"""
appbuilder = cached_app(config={"FAB_UPDATE_PERMS": False}).appbuilder
for old, new in mapping.items():
(new_resource_name, new_action_name) = new[0]
new_permission = appbuilder.sm.get_permission(new_action_name, new_resourc... |
Apply Resource based permissions. | def upgrade():
"""Apply Resource based permissions."""
log = logging.getLogger()
handlers = log.handlers[:]
remap_permissions()
log.handlers = handlers |
Unapply Resource based permissions. | def downgrade():
"""Unapply Resource based permissions."""
log = logging.getLogger()
handlers = log.handlers[:]
undo_remap_permissions()
log.handlers = handlers |
Apply Add ``queued_at`` column in ``dag_run`` table | def upgrade():
"""Apply Add ``queued_at`` column in ``dag_run`` table"""
op.add_column("dag_run", sa.Column("queued_at", TIMESTAMP, nullable=True)) |
Unapply Add ``queued_at`` column in ``dag_run`` table | def downgrade():
"""Unapply Add ``queued_at`` column in ``dag_run`` table"""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.drop_column("queued_at") |
Apply Add ``max_active_runs`` column to ``dag_model`` table | def upgrade():
"""Apply Add ``max_active_runs`` column to ``dag_model`` table"""
op.add_column("dag", sa.Column("max_active_runs", sa.Integer(), nullable=True))
with op.batch_alter_table("dag_run", schema=None) as batch_op:
# Add index to dag_run.dag_id and also add index to dag_run.state where stat... |
Unapply Add ``max_active_runs`` column to ``dag_model`` table | def downgrade():
"""Unapply Add ``max_active_runs`` column to ``dag_model`` table"""
with op.batch_alter_table("dag") as batch_op:
batch_op.drop_column("max_active_runs")
with op.batch_alter_table("dag_run", schema=None) as batch_op:
# Drop index to dag_run.dag_id and also drop index to dag_... |
Apply Add index on state, dag_id for queued ``dagrun`` | def upgrade():
"""Apply Add index on state, dag_id for queued ``dagrun``"""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.create_index(
"idx_dag_run_queued_dags",
["state", "dag_id"],
postgresql_where=text("state='queued'"),
mssql_where=text("... |
Unapply Add index on state, dag_id for queued ``dagrun`` | def downgrade():
"""Unapply Add index on state, dag_id for queued ``dagrun``"""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.drop_index("idx_dag_run_queued_dags") |
This function checks if the MS SQL table is empty
:param conn: SQL connection object
:param table_name: table name
:return: Booelan indicating if the table is present | def is_table_empty(conn, table_name):
"""
This function checks if the MS SQL table is empty
:param conn: SQL connection object
:param table_name: table name
:return: Booelan indicating if the table is present
"""
return conn.execute(text(f"select TOP 1 * from {table_name}")).first() is None |
This function return primary and unique constraint
along with column name. some tables like task_instance
is missing primary key constraint name and the name is
auto-generated by sql server. so this function helps to
retrieve any primary or unique constraint name.
:param conn: sql connection object
:param table_name: ... | def get_table_constraints(conn, table_name) -> dict[tuple[str, str], list[str]]:
"""
This function return primary and unique constraint
along with column name. some tables like task_instance
is missing primary key constraint name and the name is
auto-generated by sql server. so this function helps t... |
Drop a primary key or unique constraint
:param operator: batch_alter_table for the table
:param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table | def drop_column_constraints(operator, column_name, constraint_dict):
"""
Drop a primary key or unique constraint
:param operator: batch_alter_table for the table
:param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
"""
for constraint, columns in con... |
Create a primary key or unique constraint
:param operator: batch_alter_table for the table
:param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table | def create_constraints(operator, column_name, constraint_dict):
"""
Create a primary key or unique constraint
:param operator: batch_alter_table for the table
:param constraint_dict: a dictionary of ((constraint name, constraint type), column name) of table
"""
for constraint, columns in constr... |
Drop the timestamp column and recreate it as
datetime or datetime2(6) | def recreate_mssql_ts_column(conn, op, table_name, column_name):
"""
Drop the timestamp column and recreate it as
datetime or datetime2(6)
"""
if _is_timestamp(conn, table_name, column_name) and is_table_empty(conn, table_name):
with op.batch_alter_table(table_name) as batch_op:
... |
Update the datetime column to datetime2(6) | def alter_mssql_datetime_column(conn, op, table_name, column_name, nullable):
"""Update the datetime column to datetime2(6)"""
op.alter_column(
table_name=table_name,
column_name=column_name,
type_=mssql.DATETIME2(precision=6),
nullable=nullable,
) |
Improve compatibility with MSSQL backend | def upgrade():
"""Improve compatibility with MSSQL backend"""
conn = op.get_bind()
if conn.dialect.name != "mssql":
return
recreate_mssql_ts_column(conn, op, "dag_code", "last_updated")
recreate_mssql_ts_column(conn, op, "rendered_task_instance_fields", "execution_date")
alter_mssql_date... |
Reverse MSSQL backend compatibility improvements | def downgrade():
"""Reverse MSSQL backend compatibility improvements"""
conn = op.get_bind()
if conn.dialect.name != "mssql":
return
op.alter_column(table_name="xcom", column_name="timestamp", type_=TIMESTAMP, nullable=True)
with op.batch_alter_table("task_reschedule") as task_reschedule_bat... |
Apply Make XCom primary key columns non-nullable | def upgrade():
"""Apply Make XCom primary key columns non-nullable"""
conn = op.get_bind()
with op.batch_alter_table("xcom") as bop:
bop.alter_column("key", type_=StringID(length=512), nullable=False)
bop.alter_column("execution_date", type_=TIMESTAMP, nullable=False)
if conn.dialect... |
Unapply Make XCom primary key columns non-nullable | def downgrade():
"""Unapply Make XCom primary key columns non-nullable"""
conn = op.get_bind()
with op.batch_alter_table("xcom") as bop:
# regardless of what the model defined, the `key` and `execution_date`
# columns were always non-nullable for mysql, sqlite and postgres, so leave them alo... |
Apply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks`` | def upgrade():
"""Apply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks``"""
conn = op.get_bind()
is_sqlite = bool(conn.dialect.name == "sqlite")
if is_sqlite:
op.execute("PRAGMA foreign_keys=off")
with op.batch_alter_table("dag") as batch_op:
batch_op.alter_col... |
Unapply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks`` | def downgrade():
"""Unapply Rename ``concurrency`` column in ``dag`` table to`` max_active_tasks``"""
with op.batch_alter_table("dag") as batch_op:
batch_op.alter_column(
"max_active_tasks",
new_column_name="concurrency",
type_=sa.Integer(),
nullable=False... |
Apply Adds ``trigger`` table and deferrable operator columns to task instance | def upgrade():
"""Apply Adds ``trigger`` table and deferrable operator columns to task instance"""
op.create_table(
"trigger",
sa.Column("id", sa.Integer(), primary_key=True, nullable=False),
sa.Column("classpath", sa.String(length=1000), nullable=False),
sa.Column("kwargs", Exte... |
Unapply Adds ``trigger`` table and deferrable operator columns to task instance | def downgrade():
"""Unapply Adds ``trigger`` table and deferrable operator columns to task instance"""
with op.batch_alter_table("task_instance", schema=None) as batch_op:
batch_op.drop_constraint("task_instance_trigger_id_fkey", type_="foreignkey")
batch_op.drop_index("ti_trigger_id")
b... |
Apply data_interval fields to DagModel and DagRun. | def upgrade():
"""Apply data_interval fields to DagModel and DagRun."""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.add_column(Column("data_interval_start", TIMESTAMP))
batch_op.add_column(Column("data_interval_end", TIMESTAMP))
with op.batch_alter_table("dag") as batch_op:
... |
Unapply data_interval fields to DagModel and DagRun. | def downgrade():
"""Unapply data_interval fields to DagModel and DagRun."""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.drop_column("data_interval_start")
batch_op.drop_column("data_interval_end")
with op.batch_alter_table("dag") as batch_op:
batch_op.drop_column("next... |
Apply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id. | def upgrade():
"""Apply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id."""
conn = op.get_bind()
dialect_name = conn.dialect.name
dt_type = TIMESTAMP
string_id_col_type = StringID()
if dialect_name == "sqlite":
naming_convention = {
"uq":... |
Unapply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id. | def downgrade():
"""Unapply Change ``TaskInstance`` and ``TaskReschedule`` tables from execution_date to run_id."""
dialect_name = op.get_bind().dialect.name
dt_type = TIMESTAMP
string_id_col_type = StringID()
op.add_column("task_instance", sa.Column("execution_date", dt_type, nullable=True))
o... |
Apply Add has_import_errors column to DagModel | def upgrade():
"""Apply Add has_import_errors column to DagModel"""
op.add_column("dag", sa.Column("has_import_errors", sa.Boolean(), server_default="0")) |
Unapply Add has_import_errors column to DagModel | def downgrade():
"""Unapply Add has_import_errors column to DagModel"""
with op.batch_alter_table("dag") as batch_op:
batch_op.drop_column("has_import_errors", mssql_drop_default=True) |
Apply Create a ``session`` table to store web session data | def upgrade():
"""Apply Create a ``session`` table to store web session data"""
op.create_table(
TABLE_NAME,
sa.Column("id", sa.Integer()),
sa.Column("session_id", sa.String(255)),
sa.Column("data", sa.LargeBinary()),
sa.Column("expiry", sa.DateTime()),
sa.Primary... |
Unapply Create a ``session`` table to store web session data | def downgrade():
"""Unapply Create a ``session`` table to store web session data"""
op.drop_table(TABLE_NAME) |
Apply Add index for ``dag_id`` column in ``job`` table. | def upgrade():
"""Apply Add index for ``dag_id`` column in ``job`` table."""
op.create_index("idx_job_dag_id", "job", ["dag_id"], unique=False) |
Unapply Add index for ``dag_id`` column in ``job`` table. | def downgrade():
"""Unapply Add index for ``dag_id`` column in ``job`` table."""
op.drop_index("idx_job_dag_id", table_name="job") |
Increase length of email from 64 to 256 characters | def upgrade():
"""Increase length of email from 64 to 256 characters"""
with op.batch_alter_table("ab_user") as batch_op:
batch_op.alter_column("username", type_=sa.String(256))
batch_op.alter_column("email", type_=sa.String(256))
with op.batch_alter_table("ab_register_user") as batch_op:
... |
Revert length of email from 256 to 64 characters | def downgrade():
"""Revert length of email from 256 to 64 characters"""
conn = op.get_bind()
if conn.dialect.name != "mssql":
with op.batch_alter_table("ab_user") as batch_op:
batch_op.alter_column("username", type_=sa.String(64), nullable=False)
batch_op.alter_column("email"... |
Apply Add ``timetable_description`` column to DagModel for UI. | def upgrade():
"""Apply Add ``timetable_description`` column to DagModel for UI."""
with op.batch_alter_table("dag", schema=None) as batch_op:
batch_op.add_column(sa.Column("timetable_description", sa.String(length=1000), nullable=True)) |
Unapply Add ``timetable_description`` column to DagModel for UI. | def downgrade():
"""Unapply Add ``timetable_description`` column to DagModel for UI."""
is_sqlite = bool(op.get_bind().dialect.name == "sqlite")
if is_sqlite:
op.execute("PRAGMA foreign_keys=off")
with op.batch_alter_table("dag") as batch_op:
batch_op.drop_column("timetable_description")... |
Add model for task log template and establish fk on task instance. | def upgrade():
"""Add model for task log template and establish fk on task instance."""
op.create_table(
"log_template",
Column("id", Integer, primary_key=True, autoincrement=True),
Column("filename", Text, nullable=False),
Column("elasticsearch_id", Text, nullable=False),
... |
Remove fk on task instance and model for task log filename template. | def downgrade():
"""Remove fk on task instance and model for task log filename template."""
with op.batch_alter_table("dag_run") as batch_op:
batch_op.drop_constraint("task_instance_log_template_id_fkey", type_="foreignkey")
batch_op.drop_column("log_template_id")
op.drop_table("log_template... |
Add ``map_index`` column to TaskInstance to identify task-mapping,
and a ``task_map`` table to track mapping values from XCom. | def upgrade():
"""
Add ``map_index`` column to TaskInstance to identify task-mapping,
and a ``task_map`` table to track mapping values from XCom.
"""
# We need to first remove constraints on task_reschedule since they depend on task_instance.
with op.batch_alter_table("task_reschedule") as batch... |
Remove TaskMap and map_index on TaskInstance. | def downgrade():
"""Remove TaskMap and map_index on TaskInstance."""
op.drop_table("task_map")
with op.batch_alter_table("task_reschedule") as batch_op:
batch_op.drop_constraint("task_reschedule_ti_fkey", type_="foreignkey")
batch_op.drop_index("idx_task_reschedule_dag_task_run")
ba... |
Switch XCom table to use run_id.
For performance reasons, this is done by creating a new table with needed
data pre-populated, adding back constraints we need, and renaming it to
replace the existing XCom table. | def upgrade():
"""Switch XCom table to use run_id.
For performance reasons, this is done by creating a new table with needed
data pre-populated, adding back constraints we need, and renaming it to
replace the existing XCom table.
"""
conn = op.get_bind()
is_sqlite = conn.dialect.name == "sq... |
Switch XCom table back to use execution_date.
Basically an inverse operation. | def downgrade():
"""Switch XCom table back to use execution_date.
Basically an inverse operation.
"""
conn = op.get_bind()
op.create_table("__airflow_tmp_xcom", *_get_old_xcom_columns())
xcom = Table("xcom", metadata, *_get_new_xcom_columns())
# Remoe XCom entries from mapped tis.
op.... |
Grabs a value from the source table ``dag_run`` and updates target with this value.
:param dialect_name: dialect in use
:param target_table: the table to update
:param target_column: the column to update | def _update_value_from_dag_run(
dialect_name: str,
target_table: sa.Table,
target_column: ColumnElement,
join_columns: list[str],
) -> Update:
"""
Grabs a value from the source table ``dag_run`` and updates target with this value.
:param dialect_name: dialect in use
:param target_table: ... |
Apply Update migration for FAB tables to add missing constraints | def upgrade():
"""Apply Update migration for FAB tables to add missing constraints"""
conn = op.get_bind()
if conn.dialect.name == "sqlite":
op.execute("PRAGMA foreign_keys=OFF")
with op.batch_alter_table("ab_view_menu", schema=None) as batch_op:
batch_op.create_unique_constraint... |
Unapply Update migration for FAB tables to add missing constraints | def downgrade():
"""Unapply Update migration for FAB tables to add missing constraints"""
conn = op.get_bind()
if conn.dialect.name == "sqlite":
op.execute("PRAGMA foreign_keys=OFF")
with op.batch_alter_table("ab_view_menu", schema=None) as batch_op:
batch_op.drop_constraint("ab_... |
Add map_index to Log. | def upgrade():
"""Add map_index to Log."""
op.add_column("log", Column("map_index", Integer)) |
Remove map_index from Log. | def downgrade():
"""Remove map_index from Log."""
with op.batch_alter_table("log") as batch_op:
batch_op.drop_column("map_index") |
Apply Add index for ``event`` column in ``log`` table. | def upgrade():
"""Apply Add index for ``event`` column in ``log`` table."""
op.create_index("idx_log_event", "log", ["event"], unique=False) |
Unapply Add index for ``event`` column in ``log`` table. | def downgrade():
"""Unapply Add index for ``event`` column in ``log`` table."""
op.drop_index("idx_log_event", table_name="log") |
Apply Add cascade to dag_tag foreignkey | def upgrade():
"""Apply Add cascade to dag_tag foreignkey"""
conn = op.get_bind()
if conn.dialect.name in ["sqlite", "mysql"]:
inspector = inspect(conn.engine)
foreignkey = inspector.get_foreign_keys("dag_tag")
with op.batch_alter_table(
"dag_tag",
) as batch_op:
... |
Unapply Add cascade to dag_tag foreignkey | def downgrade():
"""Unapply Add cascade to dag_tag foreignkey"""
conn = op.get_bind()
if conn.dialect.name == "sqlite":
with op.batch_alter_table("dag_tag") as batch_op:
batch_op.drop_constraint("dag_tag_dag_id_fkey", type_="foreignkey")
batch_op.create_foreign_key("fk_dag_ta... |
If user downgraded and is upgrading again, we have to check for existing
indexes on mysql because we can't (and don't) drop them as part of the
downgrade. | def _mysql_tables_where_indexes_already_present(conn):
"""
If user downgraded and is upgrading again, we have to check for existing
indexes on mysql because we can't (and don't) drop them as part of the
downgrade.
"""
to_check = [
("xcom", "idx_xcom_task_instance"),
("task_resche... |
Apply Add indexes for CASCADE deletes | def upgrade():
"""Apply Add indexes for CASCADE deletes"""
conn = op.get_bind()
tables_to_skip = set()
# mysql requires indexes for FKs, so adding had the effect of renaming, and we cannot remove.
if conn.dialect.name == "mysql" and not context.is_offline_mode():
tables_to_skip.update(_mysq... |
Unapply Add indexes for CASCADE deletes | def downgrade():
"""Unapply Add indexes for CASCADE deletes"""
conn = op.get_bind()
# mysql requires indexes for FKs, so adding had the effect of renaming, and we cannot remove.
if conn.dialect.name == "mysql":
return
with op.batch_alter_table("xcom", schema=None) as batch_op:
batc... |
Apply Add DagWarning model | def upgrade():
"""Apply Add DagWarning model"""
op.create_table(
"dag_warning",
sa.Column("dag_id", StringID(), primary_key=True),
sa.Column("warning_type", sa.String(length=50), primary_key=True),
sa.Column("message", sa.Text(), nullable=False),
sa.Column("timestamp", TI... |
Unapply Add DagWarning model | def downgrade():
"""Unapply Add DagWarning model"""
op.drop_table("dag_warning") |
Apply compare types between ORM and DB. | def upgrade():
"""Apply compare types between ORM and DB."""
conn = op.get_bind()
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column(
"extra",
existing_type=sa.TEXT(),
type_=sa.Text(),
existing_nullable=True,
... |
Unapply compare types between ORM and DB. | def downgrade():
"""Unapply compare types between ORM and DB."""
with op.batch_alter_table("connection", schema=None) as batch_op:
batch_op.alter_column(
"extra",
existing_type=sa.Text(),
type_=sa.TEXT(),
existing_nullable=True,
)
with op.batch... |
Apply Add Dataset model | def upgrade():
"""Apply Add Dataset model"""
_create_dataset_table()
_create_dag_schedule_dataset_reference_table()
_create_task_outlet_dataset_reference_table()
_create_dataset_dag_run_queue_table()
_create_dataset_event_table()
_create_dataset_event_dag_run_table() |
Unapply Add Dataset model | def downgrade():
"""Unapply Add Dataset model"""
op.drop_table("dag_schedule_dataset_reference")
op.drop_table("task_outlet_dataset_reference")
op.drop_table("dataset_dag_run_queue")
op.drop_table("dagrun_dataset_event")
op.drop_table("dataset_event")
op.drop_table("dataset") |
Apply Remove smart sensors | def upgrade():
"""Apply Remove smart sensors"""
op.drop_table("sensor_instance")
"""Minimal model definition for migrations"""
task_instance = table("task_instance", column("state", sa.String))
op.execute(task_instance.update().where(task_instance.c.state == "sensing").values({"state": "failed"})) |
Unapply Remove smart sensors | def downgrade():
"""Unapply Remove smart sensors"""
op.create_table(
"sensor_instance",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("task_id", StringID(), nullable=False),
sa.Column("dag_id", StringID(), nullable=False),
sa.Column("execution_date", TIMESTAMP,... |
Apply Add ``DagOwnerAttributes`` table | def upgrade():
"""Apply Add ``DagOwnerAttributes`` table"""
op.create_table(
"dag_owner_attributes",
sa.Column("dag_id", StringID(), nullable=False),
sa.Column("owner", sa.String(length=500), nullable=False),
sa.Column("link", sa.String(length=500), nullable=False),
sa.Fo... |
Unapply Add Dataset model | def downgrade():
"""Unapply Add Dataset model"""
op.drop_table("dag_owner_attributes") |
Apply add processor_subdir to DagModel and SerializedDagModel | def upgrade():
"""Apply add processor_subdir to DagModel and SerializedDagModel"""
conn = op.get_bind()
with op.batch_alter_table("dag") as batch_op:
if conn.dialect.name == "mysql":
batch_op.add_column(sa.Column("processor_subdir", sa.Text(length=2000), nullable=True))
else:
... |
Unapply Add processor_subdir to DagModel and SerializedDagModel | def downgrade():
"""Unapply Add processor_subdir to DagModel and SerializedDagModel"""
conn = op.get_bind()
with op.batch_alter_table("dag", schema=None) as batch_op:
batch_op.drop_column("processor_subdir")
with op.batch_alter_table("serialized_dag", schema=None) as batch_op:
batch_op.... |
Apply migration.
If these columns are already of the right type (i.e. created by our
migration in 1.10.13 rather than FAB itself in an earlier version), this
migration will issue an alter statement to change them to what they already
are -- i.e. its a no-op.
These tables are small (100 to low 1k rows at most), so it'... | def upgrade():
"""Apply migration.
If these columns are already of the right type (i.e. created by our
migration in 1.10.13 rather than FAB itself in an earlier version), this
migration will issue an alter statement to change them to what they already
are -- i.e. its a no-op.
These tables are ... |
Unapply add_missing_autoinc_fab | def downgrade():
"""Unapply add_missing_autoinc_fab""" |
Apply Add case-insensitive unique constraint | def upgrade():
"""Apply Add case-insensitive unique constraint"""
conn = op.get_bind()
if conn.dialect.name == "postgresql":
op.create_index("idx_ab_user_username", "ab_user", [sa.text("LOWER(username)")], unique=True)
op.create_index(
"idx_ab_register_user_username", "ab_registe... |
Unapply Add case-insensitive unique constraint | def downgrade():
"""Unapply Add case-insensitive unique constraint"""
conn = op.get_bind()
if conn.dialect.name == "postgresql":
op.drop_index("idx_ab_user_username", table_name="ab_user")
op.drop_index("idx_ab_register_user_username", table_name="ab_register_user")
elif conn.dialect.na... |
Apply add updated_at column to DagRun and TaskInstance | def upgrade():
"""Apply add updated_at column to DagRun and TaskInstance"""
with op.batch_alter_table("task_instance") as batch_op:
batch_op.add_column(sa.Column("updated_at", TIMESTAMP, default=sa.func.now))
with op.batch_alter_table("dag_run") as batch_op:
batch_op.add_column(sa.Column("u... |
Unapply add updated_at column to DagRun and TaskInstance | def downgrade():
"""Unapply add updated_at column to DagRun and TaskInstance"""
with op.batch_alter_table("task_instance") as batch_op:
batch_op.drop_column("updated_at")
with op.batch_alter_table("dag_run") as batch_op:
batch_op.drop_column("updated_at") |
Apply Add DagRunNote and TaskInstanceNote | def upgrade():
"""Apply Add DagRunNote and TaskInstanceNote"""
op.create_table(
"dag_run_note",
sa.Column("user_id", sa.Integer(), nullable=True),
sa.Column("dag_run_id", sa.Integer(), nullable=False),
sa.Column(
"content", sa.String(length=1000).with_variant(sa.Text(... |
Unapply Add DagRunNote and TaskInstanceNote | def downgrade():
"""Unapply Add DagRunNote and TaskInstanceNote"""
op.drop_table("task_instance_note")
op.drop_table("dag_run_note") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.