Migrations¶
- keg_elements.db.migrations.add_non_nullable_column(op, table_name, column, default_value=None, default_value_query=None, schema=None)¶
Create a new non-nullable column
- Parameters:
op – The operational module or batch operator imported from alembic.op
table_name – The name of the table to add the column to
column – An SQLAlchemy column declaration (i.e. sa.Column() expression)
default_value – The initial value for the column. Cannot be used with the default_value_query
default_value_query – An update query that sets the column value for all rows. Cannot be used with default_value
schema – The name of the table’s schema
- Returns:
- keg_elements.db.migrations.postgres_get_enum_values(op, enum_name, schema=None)¶
Get a list of values for an existing enum type.
- Parameters:
op – The operational module or batch operator imported from alembic.op
enum_name – The name of the enum type
- Returns:
A list of the enum’s values
- keg_elements.db.migrations.postgres_update_enum_options(op, table_column_list, enum_name, new_values)¶
Update an enum’s options within the migration transaction. In Postgres updating an enum is typically not permitted within a transaction. However, dropping and re-creating the type works.
Note: this function will remove the default value on every column it updates so you will need to reset any server-side defaults after running this function.
- Parameters:
op – The operational module or batch operator imported from alembic.op
table_column_list – A list of three item tuples (schema, table_name, column_name) for each column where this enum is used
enum_name – The name of the enum type
new_values – A list of the enum’s updated values