Member-only story
Version control your database Part 1: creating migrations and seeding
Easily plan, validate, and safely apply changes to your database
If you are not working with migrations in your database you’re missing out. Like Git manages changes to source code, you can use migrations to keep track of changes to your database. Execute and revert changes and get your database back into a previous state.
Setting up migrations is easier than you think and the advantages are huge. Migrations are database-independent, offer one source of the truth, track changes and can even seed your database with some data. When you’ve read this article you’ll be able to:
- Create tables with indices and foreign keys
- Easily plan, validate, and safely apply changes in a dev database and then sync all the changes to your production database
- reset your development database (undo all, migrate again)
- Create all specified tables in your database, including indices and associations
- Seed a database (insert data)
- Execute a migration to any database (e.g. both PostgreSQL and SQL Server)
I will try to showcase all of these features with examples that use real code that you can re-use. I’ve cut…