Squashing a history of migrations. #1572
-
|
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 Second, the dump contains the
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 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.
Replies: 3 comments 2 replies
-
|
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.
-
|
@zzzeek - is there a documented pattern for squashing a big set of existing migrations that have already been applied down into one? |
Beta Was this translation helpful? Give feedback.
-
For anyone running into this issue after trying to follow the steps above I think I found the issue. For me, pg_dump was erasing my default search_path Hopes this helps anyone that was spinning in circles like I was. |
Beta Was this translation helpful? Give feedback.
For anyone running into this issue after trying to follow the steps above I think I found the …