lachaib · GitHub

Describe the use case
Add support for IF [NOT] EXISTS for ADDDROP COLUMN operations available on PostgreSQL

Databases / Backends / Drivers targeted
PostgreSQL

Example Use
The goal is to have automatically generated operations rewritable to add if_exists/if_not_exists attributes, then rendered with postgres compiler.

@writer.rewrites(ops.AddColumnOp)
def add_column(autogen_context, _revision, op: ops.AddColumnOp):
    op.if_not_exists = True

would generate following SQL

ALTER TABLE t ADD COLUMN IF NOT EXISTS c INTEGER;

Additional context
Spin-off of #524 for ADD/DROP COLUMN

Have a nice day!

Read the original on github.com ↗