TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Member-only story

Version control your database Part 1: creating migrations and seeding

Mike Huls
TDS Archive
Published in
8 min readMay 20, 2021

--

Imagine these boxes are stuffed with schema’s and tables (Photo by Ketut Subiyanto on Pexels)

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…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Mike Huls
Mike Huls

Written by Mike Huls

I write about interesting programming-related things: techniques, system architecture, software design and how to apply them in the best way. — mikehuls.com

No responses yet