0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00
logto/packages/schemas/migrations
2022-09-26 11:27:12 +08:00
..
next-1663923211-machine-to-machine-app.ts feat(core,schemas): use timestamp to version migrations 2022-09-26 11:27:12 +08:00
README.md feat(core,schemas): use timestamp to version migrations 2022-09-26 11:27:12 +08:00
types.ts feat(core,schemas): use timestamp to version migrations 2022-09-26 11:27:12 +08:00

Database Migrations

The folder for all migration files.

Format

The migration files are named in the format of <version>-<timestamp>-name.js where <timestamp> is the unix timestamp of when the migration was created and name is the name of the migration, version is this npm package's version number.

As for development, the version is "next" until the package is released.

Note that, you SHOULD NOT change the content of the migration files after they are created. If you need to change the migration, you should create a new migration file with the new content.

Typing

type MigrationScript = {
  up: (connection: DatabaseTransactionConnection) => Promise<void>;
  down: (connection: DatabaseTransactionConnection) => Promise<void>;
};

When the migration script is executed, the up function is called to alter the database schema.

The down function is designed for the future downgrade feature.

Example

export const up = async (connection) => {
  await connection.query(`
    ALTER TABLE "user"
    ADD COLUMN "email" VARCHAR(255) NOT NULL;
  `);
};

export const down = async (connection) => {
  await connection.query(`
    ALTER TABLE "user"
    DROP COLUMN "email";
  `);
};