-
Notifications
You must be signed in to change notification settings - Fork 7
Squash migrations
Tim DeHof edited this page Jul 21, 2024
·
2 revisions
- Backup your database. This step is critical. Don’t skip it.
Tip
You backup the db by using pgadmin or run the following command in your terminal
pg_dump {dbname} > backup.sqlreplace dbname with the name you called the database
- Delete all contents in the “migrations” folder in your “prisma” directory.
Tip
This includes the migration_lock.toml file as it will be generated on the creation of a new migration.
- Create a new empty directory in the “migrations” folder in your “prisma” directory called
000000000000_squashed_migrations. Inside this, add a new emptymigration.sql. - Create a single migration that takes you:
- from an empty database
- to the current state of the production database schema as described in your
./prisma/schema.prismafile - and outputs this to the
migration.sqlfile created above
Tip
You can do this by using the migrate diff command. In terminal on the root directory, run the following command:
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel ./prisma/schema \
--script > ./prisma/migrations/000000000000_squashed_migrations/migration.sql- Mark this migration as having been applied on production and dev, to prevent it from being run there by using the migrate resolve command. In terminal on the root directory, run the following command:
npx prisma migrate resolve \
--applied 000000000000_squashed_migrationsTip
Remember to change DATABASE_URL variable in your local .env file to the appropriate remote database URL that can be found on clickup's BE/Important Resources page.
If you are running Docker, you can run this in a terminal there.