Database migration framework.
What question should have this tag?
Database migration related question using a framework.
Basic Definitions
Database migration refers to the change of schema over time. It is common for a project's schemas to evolve depends on the need. Similarly, migration can help to add or remove columns from the schema/table.
Introduction
Typically a migration has an up
and down
method, so you can roll back any migrations. For example in nodejs
, a migration might look like this:
//20180722013000-location.ts
exports.up = (db: any) => {
return db.createTable("Location", {
description: "text",
geoCode: "jsonb",
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: "int",
},
locationId: "int",
name: "string",
open: "boolean",
});
};
exports.down = (db: any) => {
return db.dropTable("Location");
};
This migration will handle creating a table with that scheme on up
and dropTable
on down
.
Learn more
Sequelize cli // A simple solution for migration and even support seeding