Skip to content

Commit

Permalink
Ensure include_deferred is not nullable (#33280)
Browse files Browse the repository at this point in the history
* Ensure include_deferred is not nullable

This uses a multi-step process to introduce the NOT NULL constraint to
the column, needed due to MSSQL restrictions.

* MSSQL does not even support boolean literals

* Postgres does not support 0 as boolean

This is fine. SQL is fun.

* Wrap raw SQL in text()
  • Loading branch information
uranusjr committed Aug 10, 2023
1 parent 369b9bc commit 4f6d597
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
def upgrade():
"""Apply add include_deferred column to pool"""
with op.batch_alter_table("slot_pool") as batch_op:
batch_op.add_column(sa.Column("include_deferred", sa.Boolean, default=False))
batch_op.add_column(sa.Column("include_deferred", sa.Boolean))
# Different databases support different literal for FALSE. This is fine.
op.execute(sa.text(f"UPDATE slot_pool SET include_deferred = {sa.false().compile(op.get_bind())}"))
with op.batch_alter_table("slot_pool") as batch_op:
batch_op.alter_column("include_deferred", existing_type=sa.Boolean, nullable=False)


def downgrade():
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 @@
52b0e45032fb1c60274374e0114cf199dfb759adc0a4fe32964136347457506a
266a8533dca6d9c7e984341bfe29e99f29217e44529455a49e7c4a5faccdcdf3
8 changes: 4 additions & 4 deletions docs/apache-airflow/img/airflow_erd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f6d597

Please sign in to comment.