Any product that keeps shipping will keep changing its database schema. Doing those changes by hand is where the pain starts: a script pasted into a production console, a deploy that takes the app down, and after a few of those, a team that would rather not touch the schema at all. At One2N we think a migration should be a normal part of shipping a feature, not something people dread.
This post walks through one schema change done by hand, what can go wrong with it, and the same change done with an automated migration tool.
The dangers of manual migrations: a practical example
Say you work at an e-commerce startup that’s growing fast. Features go out every week, users are happy and nothing is on fire. Then product asks for order tracking. It sounds like a small job, and it turns into an afternoon of debugging.
Small schema changes done by hand break things more often than you’d expect. Here’s how this one can go wrong, and why a migration tool would have saved you.
Case Study: The order tracking debacle
To show customers live shipping updates, you need a new ‘status’ column (‘placed’, ‘shipped’, ‘delivered’, etc.) on the ‘Orders’ table, which already has columns such as ‘order_id’, ‘user_id’ and ‘tracking_id’. Done by hand, the change goes something like this:
Development: You change the code, add the
statuscolumn to your models and update the application logic that uses it.Deployment prep: You write an SQL script to run against the production database:
ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'placed'
Deployment day: You connect to production and run the script. Then the questions start.
Did you take a backup first? If you didn’t, this is a bad moment to remember.
One misplaced semicolon is enough. And did this exact statement ever run on staging?
The app is probably partly or fully down while the change runs.
Afterwards:
Existing code may assume things about the data that the new column breaks.
If you have to revert, is there a reverse script? Can you run it without losing the orders written since the change?
Three things commonly slip through here.
What went wrong?
The ‘user_id’ column in ‘Orders’ should be a foreign key to the ‘Users’ table. In a hand-written script it’s easy to leave the constraint out, and nothing complains until bad rows show up.
Cascades need a decision too. Should deleting a user delete their orders? Depending on your database, you may have to define those rules in the migration or change the ones that already exist. Without a fixed process, nobody remembers to check.
Then there’s code that quietly depends on the old structure. Those assumptions don’t show up in review. They show up as errors after the new column goes live.
None of these are hard problems. They slip through because a manual migration has no review step where someone checks for them, and in a production system a change that looks simple can still break something somewhere else. The rest of this post shows how automated schema migrations make that review part of every change.
The automated way: a comprehensive guide
Let’s go back and make the same change with a migration tool. We’ll use Flyway, but most tools work the same way.
Migration file: Write the change as a file. Flyway reads the version from the name, so call it something like
V1.1__add_order_status.sql:ALTER TABLE orders ADD COLUMN status varchar(255) DEFAULT 'placed'
If the column is NOT NULL, the rows already in the table make this change fail unless it has a default.
Execution: You don’t run the SQL yourself. You run the Flyway CLI, or call it from your deploy script. Flyway finds new migration files, applies them in version order and records which ones it has already applied.
A change of plan: After more discussion, ‘status’ has to hold more complex data. You don’t edit V1.1. You add a new migration file (
V1.2__modify_order_status.sql):ALTER TABLE orders ALTER COLUMN status DROP DEFAULT; ALTER TABLE orders ALTER COLUMN status TYPE JSONB USING jsonb_build_object('state', status); ALTER TABLE orders ALTER COLUMN status SET DEFAULT '{"state": "placed"}'; -- USING converts existing rows: 'shipped' becomes {"state": "shipped"}
Benefits of automation
So what changed compared to the manual version? Nobody types SQL into a production console any more. The file that ran on your laptop and in staging is the file that runs in production. If it goes wrong, most tools can undo it and put the schema back the way it was. The deploy script runs the migration, so there’s no separate step for someone to forget, and staging can’t quietly fall behind production. The files sit in git next to the code, which means the schema’s history is one git log away for anyone on the team.
What are the best practices?
Automating migrations is a good start. We’d add a few habits on top:
One change per migration. Add one table, or alter one column. A small file is easier to read, debug and roll back.
Use file names that sort by version, like
V1.2__description.sql.Remember the table isn’t empty. Give new columns a default, or write a data migration for the rows already there.
Run migrations in your test suite. Some tools have test support built in.
Read your tool’s docs for the advanced parts, such as branching and conditional logic.
Treat migrations like code and run them from your CI/CD pipeline, so the database and the codebase always match.
Choosing your tool
Which tool suits you depends mostly on your stack. Things to check while you look around:
Language and framework. Some tools work with any language. Others come built into a framework like Rails or Django. Pick one that fits what you already run.
Database support. Make sure it supports your engine, whether that’s MySQL, PostgreSQL or something else.
Features. Decide whether you need branching, complex data transformations or a particular way of rolling back.
Migration format. Some tools take plain SQL, others want migrations written in Java, Python and so on.
Your DBAs. If they’re closely involved, ask how much control and visibility they want.
Community and docs. When a migration fails, clear documentation and an active community get you unstuck faster.
Popular Tools:
Flyway: Language-agnostic, strong community, SQL-based migrations.
Liquibase: XML, JSON, or SQL formats, supports a wide range of databases.
Framework-Specific: Rails (Active Record Migrations), Django, Laravel, etc., offer built-in migration solutions.
One2N: Your partner in change
Need help migrating a legacy system, optimizing your migration process, or training your team? One2N offers database expertise for smooth and efficient migrations. See our backend engineering services or talk to us.
Any product that keeps shipping will keep changing its database schema. Doing those changes by hand is where the pain starts: a script pasted into a production console, a deploy that takes the app down, and after a few of those, a team that would rather not touch the schema at all. At One2N we think a migration should be a normal part of shipping a feature, not something people dread.
This post walks through one schema change done by hand, what can go wrong with it, and the same change done with an automated migration tool.
The dangers of manual migrations: a practical example
Say you work at an e-commerce startup that’s growing fast. Features go out every week, users are happy and nothing is on fire. Then product asks for order tracking. It sounds like a small job, and it turns into an afternoon of debugging.
Small schema changes done by hand break things more often than you’d expect. Here’s how this one can go wrong, and why a migration tool would have saved you.
Case Study: The order tracking debacle
To show customers live shipping updates, you need a new ‘status’ column (‘placed’, ‘shipped’, ‘delivered’, etc.) on the ‘Orders’ table, which already has columns such as ‘order_id’, ‘user_id’ and ‘tracking_id’. Done by hand, the change goes something like this:
Development: You change the code, add the
statuscolumn to your models and update the application logic that uses it.Deployment prep: You write an SQL script to run against the production database:
ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'placed'
Deployment day: You connect to production and run the script. Then the questions start.
Did you take a backup first? If you didn’t, this is a bad moment to remember.
One misplaced semicolon is enough. And did this exact statement ever run on staging?
The app is probably partly or fully down while the change runs.
Afterwards:
Existing code may assume things about the data that the new column breaks.
If you have to revert, is there a reverse script? Can you run it without losing the orders written since the change?
Three things commonly slip through here.
What went wrong?
The ‘user_id’ column in ‘Orders’ should be a foreign key to the ‘Users’ table. In a hand-written script it’s easy to leave the constraint out, and nothing complains until bad rows show up.
Cascades need a decision too. Should deleting a user delete their orders? Depending on your database, you may have to define those rules in the migration or change the ones that already exist. Without a fixed process, nobody remembers to check.
Then there’s code that quietly depends on the old structure. Those assumptions don’t show up in review. They show up as errors after the new column goes live.
None of these are hard problems. They slip through because a manual migration has no review step where someone checks for them, and in a production system a change that looks simple can still break something somewhere else. The rest of this post shows how automated schema migrations make that review part of every change.
The automated way: a comprehensive guide
Let’s go back and make the same change with a migration tool. We’ll use Flyway, but most tools work the same way.
Migration file: Write the change as a file. Flyway reads the version from the name, so call it something like
V1.1__add_order_status.sql:ALTER TABLE orders ADD COLUMN status varchar(255) DEFAULT 'placed'
If the column is NOT NULL, the rows already in the table make this change fail unless it has a default.
Execution: You don’t run the SQL yourself. You run the Flyway CLI, or call it from your deploy script. Flyway finds new migration files, applies them in version order and records which ones it has already applied.
A change of plan: After more discussion, ‘status’ has to hold more complex data. You don’t edit V1.1. You add a new migration file (
V1.2__modify_order_status.sql):ALTER TABLE orders ALTER COLUMN status DROP DEFAULT; ALTER TABLE orders ALTER COLUMN status TYPE JSONB USING jsonb_build_object('state', status); ALTER TABLE orders ALTER COLUMN status SET DEFAULT '{"state": "placed"}'; -- USING converts existing rows: 'shipped' becomes {"state": "shipped"}
Benefits of automation
So what changed compared to the manual version? Nobody types SQL into a production console any more. The file that ran on your laptop and in staging is the file that runs in production. If it goes wrong, most tools can undo it and put the schema back the way it was. The deploy script runs the migration, so there’s no separate step for someone to forget, and staging can’t quietly fall behind production. The files sit in git next to the code, which means the schema’s history is one git log away for anyone on the team.
What are the best practices?
Automating migrations is a good start. We’d add a few habits on top:
One change per migration. Add one table, or alter one column. A small file is easier to read, debug and roll back.
Use file names that sort by version, like
V1.2__description.sql.Remember the table isn’t empty. Give new columns a default, or write a data migration for the rows already there.
Run migrations in your test suite. Some tools have test support built in.
Read your tool’s docs for the advanced parts, such as branching and conditional logic.
Treat migrations like code and run them from your CI/CD pipeline, so the database and the codebase always match.
Choosing your tool
Which tool suits you depends mostly on your stack. Things to check while you look around:
Language and framework. Some tools work with any language. Others come built into a framework like Rails or Django. Pick one that fits what you already run.
Database support. Make sure it supports your engine, whether that’s MySQL, PostgreSQL or something else.
Features. Decide whether you need branching, complex data transformations or a particular way of rolling back.
Migration format. Some tools take plain SQL, others want migrations written in Java, Python and so on.
Your DBAs. If they’re closely involved, ask how much control and visibility they want.
Community and docs. When a migration fails, clear documentation and an active community get you unstuck faster.
Popular Tools:
Flyway: Language-agnostic, strong community, SQL-based migrations.
Liquibase: XML, JSON, or SQL formats, supports a wide range of databases.
Framework-Specific: Rails (Active Record Migrations), Django, Laravel, etc., offer built-in migration solutions.
One2N: Your partner in change
Need help migrating a legacy system, optimizing your migration process, or training your team? One2N offers database expertise for smooth and efficient migrations. See our backend engineering services or talk to us.
Any product that keeps shipping will keep changing its database schema. Doing those changes by hand is where the pain starts: a script pasted into a production console, a deploy that takes the app down, and after a few of those, a team that would rather not touch the schema at all. At One2N we think a migration should be a normal part of shipping a feature, not something people dread.
This post walks through one schema change done by hand, what can go wrong with it, and the same change done with an automated migration tool.
The dangers of manual migrations: a practical example
Say you work at an e-commerce startup that’s growing fast. Features go out every week, users are happy and nothing is on fire. Then product asks for order tracking. It sounds like a small job, and it turns into an afternoon of debugging.
Small schema changes done by hand break things more often than you’d expect. Here’s how this one can go wrong, and why a migration tool would have saved you.
Case Study: The order tracking debacle
To show customers live shipping updates, you need a new ‘status’ column (‘placed’, ‘shipped’, ‘delivered’, etc.) on the ‘Orders’ table, which already has columns such as ‘order_id’, ‘user_id’ and ‘tracking_id’. Done by hand, the change goes something like this:
Development: You change the code, add the
statuscolumn to your models and update the application logic that uses it.Deployment prep: You write an SQL script to run against the production database:
ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'placed'
Deployment day: You connect to production and run the script. Then the questions start.
Did you take a backup first? If you didn’t, this is a bad moment to remember.
One misplaced semicolon is enough. And did this exact statement ever run on staging?
The app is probably partly or fully down while the change runs.
Afterwards:
Existing code may assume things about the data that the new column breaks.
If you have to revert, is there a reverse script? Can you run it without losing the orders written since the change?
Three things commonly slip through here.
What went wrong?
The ‘user_id’ column in ‘Orders’ should be a foreign key to the ‘Users’ table. In a hand-written script it’s easy to leave the constraint out, and nothing complains until bad rows show up.
Cascades need a decision too. Should deleting a user delete their orders? Depending on your database, you may have to define those rules in the migration or change the ones that already exist. Without a fixed process, nobody remembers to check.
Then there’s code that quietly depends on the old structure. Those assumptions don’t show up in review. They show up as errors after the new column goes live.
None of these are hard problems. They slip through because a manual migration has no review step where someone checks for them, and in a production system a change that looks simple can still break something somewhere else. The rest of this post shows how automated schema migrations make that review part of every change.
The automated way: a comprehensive guide
Let’s go back and make the same change with a migration tool. We’ll use Flyway, but most tools work the same way.
Migration file: Write the change as a file. Flyway reads the version from the name, so call it something like
V1.1__add_order_status.sql:ALTER TABLE orders ADD COLUMN status varchar(255) DEFAULT 'placed'
If the column is NOT NULL, the rows already in the table make this change fail unless it has a default.
Execution: You don’t run the SQL yourself. You run the Flyway CLI, or call it from your deploy script. Flyway finds new migration files, applies them in version order and records which ones it has already applied.
A change of plan: After more discussion, ‘status’ has to hold more complex data. You don’t edit V1.1. You add a new migration file (
V1.2__modify_order_status.sql):ALTER TABLE orders ALTER COLUMN status DROP DEFAULT; ALTER TABLE orders ALTER COLUMN status TYPE JSONB USING jsonb_build_object('state', status); ALTER TABLE orders ALTER COLUMN status SET DEFAULT '{"state": "placed"}'; -- USING converts existing rows: 'shipped' becomes {"state": "shipped"}
Benefits of automation
So what changed compared to the manual version? Nobody types SQL into a production console any more. The file that ran on your laptop and in staging is the file that runs in production. If it goes wrong, most tools can undo it and put the schema back the way it was. The deploy script runs the migration, so there’s no separate step for someone to forget, and staging can’t quietly fall behind production. The files sit in git next to the code, which means the schema’s history is one git log away for anyone on the team.
What are the best practices?
Automating migrations is a good start. We’d add a few habits on top:
One change per migration. Add one table, or alter one column. A small file is easier to read, debug and roll back.
Use file names that sort by version, like
V1.2__description.sql.Remember the table isn’t empty. Give new columns a default, or write a data migration for the rows already there.
Run migrations in your test suite. Some tools have test support built in.
Read your tool’s docs for the advanced parts, such as branching and conditional logic.
Treat migrations like code and run them from your CI/CD pipeline, so the database and the codebase always match.
Choosing your tool
Which tool suits you depends mostly on your stack. Things to check while you look around:
Language and framework. Some tools work with any language. Others come built into a framework like Rails or Django. Pick one that fits what you already run.
Database support. Make sure it supports your engine, whether that’s MySQL, PostgreSQL or something else.
Features. Decide whether you need branching, complex data transformations or a particular way of rolling back.
Migration format. Some tools take plain SQL, others want migrations written in Java, Python and so on.
Your DBAs. If they’re closely involved, ask how much control and visibility they want.
Community and docs. When a migration fails, clear documentation and an active community get you unstuck faster.
Popular Tools:
Flyway: Language-agnostic, strong community, SQL-based migrations.
Liquibase: XML, JSON, or SQL formats, supports a wide range of databases.
Framework-Specific: Rails (Active Record Migrations), Django, Laravel, etc., offer built-in migration solutions.
One2N: Your partner in change
Need help migrating a legacy system, optimizing your migration process, or training your team? One2N offers database expertise for smooth and efficient migrations. See our backend engineering services or talk to us.
Any product that keeps shipping will keep changing its database schema. Doing those changes by hand is where the pain starts: a script pasted into a production console, a deploy that takes the app down, and after a few of those, a team that would rather not touch the schema at all. At One2N we think a migration should be a normal part of shipping a feature, not something people dread.
This post walks through one schema change done by hand, what can go wrong with it, and the same change done with an automated migration tool.
The dangers of manual migrations: a practical example
Say you work at an e-commerce startup that’s growing fast. Features go out every week, users are happy and nothing is on fire. Then product asks for order tracking. It sounds like a small job, and it turns into an afternoon of debugging.
Small schema changes done by hand break things more often than you’d expect. Here’s how this one can go wrong, and why a migration tool would have saved you.
Case Study: The order tracking debacle
To show customers live shipping updates, you need a new ‘status’ column (‘placed’, ‘shipped’, ‘delivered’, etc.) on the ‘Orders’ table, which already has columns such as ‘order_id’, ‘user_id’ and ‘tracking_id’. Done by hand, the change goes something like this:
Development: You change the code, add the
statuscolumn to your models and update the application logic that uses it.Deployment prep: You write an SQL script to run against the production database:
ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'placed'
Deployment day: You connect to production and run the script. Then the questions start.
Did you take a backup first? If you didn’t, this is a bad moment to remember.
One misplaced semicolon is enough. And did this exact statement ever run on staging?
The app is probably partly or fully down while the change runs.
Afterwards:
Existing code may assume things about the data that the new column breaks.
If you have to revert, is there a reverse script? Can you run it without losing the orders written since the change?
Three things commonly slip through here.
What went wrong?
The ‘user_id’ column in ‘Orders’ should be a foreign key to the ‘Users’ table. In a hand-written script it’s easy to leave the constraint out, and nothing complains until bad rows show up.
Cascades need a decision too. Should deleting a user delete their orders? Depending on your database, you may have to define those rules in the migration or change the ones that already exist. Without a fixed process, nobody remembers to check.
Then there’s code that quietly depends on the old structure. Those assumptions don’t show up in review. They show up as errors after the new column goes live.
None of these are hard problems. They slip through because a manual migration has no review step where someone checks for them, and in a production system a change that looks simple can still break something somewhere else. The rest of this post shows how automated schema migrations make that review part of every change.
The automated way: a comprehensive guide
Let’s go back and make the same change with a migration tool. We’ll use Flyway, but most tools work the same way.
Migration file: Write the change as a file. Flyway reads the version from the name, so call it something like
V1.1__add_order_status.sql:ALTER TABLE orders ADD COLUMN status varchar(255) DEFAULT 'placed'
If the column is NOT NULL, the rows already in the table make this change fail unless it has a default.
Execution: You don’t run the SQL yourself. You run the Flyway CLI, or call it from your deploy script. Flyway finds new migration files, applies them in version order and records which ones it has already applied.
A change of plan: After more discussion, ‘status’ has to hold more complex data. You don’t edit V1.1. You add a new migration file (
V1.2__modify_order_status.sql):ALTER TABLE orders ALTER COLUMN status DROP DEFAULT; ALTER TABLE orders ALTER COLUMN status TYPE JSONB USING jsonb_build_object('state', status); ALTER TABLE orders ALTER COLUMN status SET DEFAULT '{"state": "placed"}'; -- USING converts existing rows: 'shipped' becomes {"state": "shipped"}
Benefits of automation
So what changed compared to the manual version? Nobody types SQL into a production console any more. The file that ran on your laptop and in staging is the file that runs in production. If it goes wrong, most tools can undo it and put the schema back the way it was. The deploy script runs the migration, so there’s no separate step for someone to forget, and staging can’t quietly fall behind production. The files sit in git next to the code, which means the schema’s history is one git log away for anyone on the team.
What are the best practices?
Automating migrations is a good start. We’d add a few habits on top:
One change per migration. Add one table, or alter one column. A small file is easier to read, debug and roll back.
Use file names that sort by version, like
V1.2__description.sql.Remember the table isn’t empty. Give new columns a default, or write a data migration for the rows already there.
Run migrations in your test suite. Some tools have test support built in.
Read your tool’s docs for the advanced parts, such as branching and conditional logic.
Treat migrations like code and run them from your CI/CD pipeline, so the database and the codebase always match.
Choosing your tool
Which tool suits you depends mostly on your stack. Things to check while you look around:
Language and framework. Some tools work with any language. Others come built into a framework like Rails or Django. Pick one that fits what you already run.
Database support. Make sure it supports your engine, whether that’s MySQL, PostgreSQL or something else.
Features. Decide whether you need branching, complex data transformations or a particular way of rolling back.
Migration format. Some tools take plain SQL, others want migrations written in Java, Python and so on.
Your DBAs. If they’re closely involved, ask how much control and visibility they want.
Community and docs. When a migration fails, clear documentation and an active community get you unstuck faster.
Popular Tools:
Flyway: Language-agnostic, strong community, SQL-based migrations.
Liquibase: XML, JSON, or SQL formats, supports a wide range of databases.
Framework-Specific: Rails (Active Record Migrations), Django, Laravel, etc., offer built-in migration solutions.
One2N: Your partner in change
Need help migrating a legacy system, optimizing your migration process, or training your team? One2N offers database expertise for smooth and efficient migrations. See our backend engineering services or talk to us.
Any product that keeps shipping will keep changing its database schema. Doing those changes by hand is where the pain starts: a script pasted into a production console, a deploy that takes the app down, and after a few of those, a team that would rather not touch the schema at all. At One2N we think a migration should be a normal part of shipping a feature, not something people dread.
This post walks through one schema change done by hand, what can go wrong with it, and the same change done with an automated migration tool.
The dangers of manual migrations: a practical example
Say you work at an e-commerce startup that’s growing fast. Features go out every week, users are happy and nothing is on fire. Then product asks for order tracking. It sounds like a small job, and it turns into an afternoon of debugging.
Small schema changes done by hand break things more often than you’d expect. Here’s how this one can go wrong, and why a migration tool would have saved you.
Case Study: The order tracking debacle
To show customers live shipping updates, you need a new ‘status’ column (‘placed’, ‘shipped’, ‘delivered’, etc.) on the ‘Orders’ table, which already has columns such as ‘order_id’, ‘user_id’ and ‘tracking_id’. Done by hand, the change goes something like this:
Development: You change the code, add the
statuscolumn to your models and update the application logic that uses it.Deployment prep: You write an SQL script to run against the production database:
ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'placed'
Deployment day: You connect to production and run the script. Then the questions start.
Did you take a backup first? If you didn’t, this is a bad moment to remember.
One misplaced semicolon is enough. And did this exact statement ever run on staging?
The app is probably partly or fully down while the change runs.
Afterwards:
Existing code may assume things about the data that the new column breaks.
If you have to revert, is there a reverse script? Can you run it without losing the orders written since the change?
Three things commonly slip through here.
What went wrong?
The ‘user_id’ column in ‘Orders’ should be a foreign key to the ‘Users’ table. In a hand-written script it’s easy to leave the constraint out, and nothing complains until bad rows show up.
Cascades need a decision too. Should deleting a user delete their orders? Depending on your database, you may have to define those rules in the migration or change the ones that already exist. Without a fixed process, nobody remembers to check.
Then there’s code that quietly depends on the old structure. Those assumptions don’t show up in review. They show up as errors after the new column goes live.
None of these are hard problems. They slip through because a manual migration has no review step where someone checks for them, and in a production system a change that looks simple can still break something somewhere else. The rest of this post shows how automated schema migrations make that review part of every change.
The automated way: a comprehensive guide
Let’s go back and make the same change with a migration tool. We’ll use Flyway, but most tools work the same way.
Migration file: Write the change as a file. Flyway reads the version from the name, so call it something like
V1.1__add_order_status.sql:ALTER TABLE orders ADD COLUMN status varchar(255) DEFAULT 'placed'
If the column is NOT NULL, the rows already in the table make this change fail unless it has a default.
Execution: You don’t run the SQL yourself. You run the Flyway CLI, or call it from your deploy script. Flyway finds new migration files, applies them in version order and records which ones it has already applied.
A change of plan: After more discussion, ‘status’ has to hold more complex data. You don’t edit V1.1. You add a new migration file (
V1.2__modify_order_status.sql):ALTER TABLE orders ALTER COLUMN status DROP DEFAULT; ALTER TABLE orders ALTER COLUMN status TYPE JSONB USING jsonb_build_object('state', status); ALTER TABLE orders ALTER COLUMN status SET DEFAULT '{"state": "placed"}'; -- USING converts existing rows: 'shipped' becomes {"state": "shipped"}
Benefits of automation
So what changed compared to the manual version? Nobody types SQL into a production console any more. The file that ran on your laptop and in staging is the file that runs in production. If it goes wrong, most tools can undo it and put the schema back the way it was. The deploy script runs the migration, so there’s no separate step for someone to forget, and staging can’t quietly fall behind production. The files sit in git next to the code, which means the schema’s history is one git log away for anyone on the team.
What are the best practices?
Automating migrations is a good start. We’d add a few habits on top:
One change per migration. Add one table, or alter one column. A small file is easier to read, debug and roll back.
Use file names that sort by version, like
V1.2__description.sql.Remember the table isn’t empty. Give new columns a default, or write a data migration for the rows already there.
Run migrations in your test suite. Some tools have test support built in.
Read your tool’s docs for the advanced parts, such as branching and conditional logic.
Treat migrations like code and run them from your CI/CD pipeline, so the database and the codebase always match.
Choosing your tool
Which tool suits you depends mostly on your stack. Things to check while you look around:
Language and framework. Some tools work with any language. Others come built into a framework like Rails or Django. Pick one that fits what you already run.
Database support. Make sure it supports your engine, whether that’s MySQL, PostgreSQL or something else.
Features. Decide whether you need branching, complex data transformations or a particular way of rolling back.
Migration format. Some tools take plain SQL, others want migrations written in Java, Python and so on.
Your DBAs. If they’re closely involved, ask how much control and visibility they want.
Community and docs. When a migration fails, clear documentation and an active community get you unstuck faster.
Popular Tools:
Flyway: Language-agnostic, strong community, SQL-based migrations.
Liquibase: XML, JSON, or SQL formats, supports a wide range of databases.
Framework-Specific: Rails (Active Record Migrations), Django, Laravel, etc., offer built-in migration solutions.
One2N: Your partner in change
Need help migrating a legacy system, optimizing your migration process, or training your team? One2N offers database expertise for smooth and efficient migrations. See our backend engineering services or talk to us.


















