Squashing a history of migrations. #1572
Unanswered
jenstroeger
asked this question in
Usage Questions
Replies: 1 comment
-
hi - if you are making a dump file like that where that's to become the initial migration for a clean DB, then yes you have to attend to the alembic_version table in that dump file. that "INSERT INTO alembic_version (version_num) VALUES ('48de627e2.." is in your dump file. you have to remove those INSERT statements also. if you run your alembic with a SQL dump that has nothing about |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Looks like discussion #927 is somewhat related.
We have a lengthy history of Alembic migrations on a single Postgres db, and we want to squash them into one single migration step (mainly for performance reasons when testing, or standing up a deployment). So here’s where I am at the moment, with one detail still open (see below):
And that’s where things become a little tricky. First, as mentioned in comment psycopg/psycopg#958 (comment) the psycopg driver doesn’t really support the files written by
pg_dump
(though it doesn’t error out in our case).Second, the dump contains the
alembic_version
table as well, but that’s actually managed by Alembic as per documentation here:When I remove that table from the dump file, then running that new squashed migration against an empty db raises:
But the docs said the Alembic creates that table before running the migrations, no? So, I used the original dump file (the one with the
alembic_version
table) and then I get:So now that table exists? Not quite sure what’s going on.
But considering the aforementioned psycopg comment that dump files aren’t supported, and considering the previous conversation #927 I’m curious about the recommended approach to squash a history of migrations? Might Alembic not quite be suited here, and should we just restore the dump manually and start Alembic from that?
Beta Was this translation helpful? Give feedback.
All reactions