Schema migrations
Schema migration is sometimes referred to as “database migration”, but “database migration” also has other possible meanings.
There are many ways to handle schema migrations. Which one is best depends on your goals.
- You could handle it all manually and not keep a record of the schema changes, but this is usually not a good idea.
- Many projects use ORMs like SQLAlchemy or Prisma specifically because they have tools that automate parts of schema migrations.
- If you will use SQL directly rather than an ORM, there are still many helpful tools with different strengths and weaknesses including:
- pressly/goose
- Flyway
- liquibase/liquibase
- ariga/atlas
- Sqitch
- golang-migrate/migrate
- pgroll (Postgres only)
- jackc/tern (Postgres only)
- purcell/postgresql-migrations (Postgres only)
- rubenv/sql-migrate (Go only)
- Yoyo (Python only)
- ThomWright/postgres-migrations (Node and Postgres only)
- Here are more: mgramin/awesome-db-tools
- Many projects only need basic schema migration features and choose to implement their own commands, such as in the RoboDanny Discord bot.
Here’s an article about how to manually migrate without any downtime: SQL migrations in PostgreSQL, part 1 | by Nikolai Averin | Miro Engineering | Medium.