sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.76k stars 241 forks source link

Generate the table DDLs with `if not exists` or `if exists` #1434

Closed CaselIT closed 3 weeks ago

CaselIT commented 7 months ago

Discussed in https://github.com/sqlalchemy/alembic/discussions/1432

Originally posted by **shaounak** February 27, 2024 Modern data warehouses supports `create table if not exists` or `drop table if exists`. Is there a way in alembic to run the migrations using this feature. e.g. in the op.create_table, can we create flag. If the value is set for the flag, then issue `CREATE TABLE IF NOT EXISTS` else issue the default `CREATE TABLE` statement.
shaounak commented 7 months ago

Just if you are wondering how this will be useful, one of the use cases I would like to present is the migration from tools like Liquibase or any other schema migration tools to Alembic. For the existing systems, many of the entities will already be deployed, hence when the first migration is executed in the upgrade scenario, there will no effect in the structural changes as all the statements will be executed as create table if not exists.

lachaib commented 3 weeks ago

👋 Isn't this about #1520 which has just been merged?

CaselIT commented 3 weeks ago

seems so, closing!