0

I've a simple migration script which is supposed to create a few tables.

For brevity, this is basically the content:

op.create_table(
    'a',
    sa.Column('id', sa.BIGINT, primary_key=True),
)

op.create_table(
    'b',
    sa.Column('id', sa.BIGINT, primary_key=True),
    sa.Column('id', sa.BIGINT, primary_key=True),
)

Table b has two id columns, which causes an error.

After fixing and restarting the server, I get an error for the fact, that table a already exists.

The table alembic_version does not contain a record of this revision:

mysql> select * from alembic_version;
Empty set (0.00 sec)

Yet the table actually exists:

mysql> show tables;
+-------------------------+
| Tables_in_fingerprinter |
+-------------------------+
| alembic_version         |
| a                       |
+-------------------------+

How can I make sure that alembic puts everything into one transaction and avoid committing partial changes to the database?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • @snakecharmerb Afaik MySQL 8.0 is able to rollback commits. – Stefan Falk Jan 30 '23 at 10:04
  • I think what matters is whether the RDBMSS supports transactional DDL, which MySQL doesn't according to the note near the top of [this page](https://dev.mysql.com/doc/refman/8.0/en/atomic-ddl.html). I presume that's why the relevant flag is set in the alembic [sourcfe](https://github.com/sqlalchemy/alembic/blob/08266a49db1ce69224e62fa89f34f03a2f0f9529/alembic/ddl/mysql.py#L42), but I'm not an expert. – snakecharmerb Jan 30 '23 at 10:17

0 Answers0