0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/schemas/alterations
Xiao Yijun 8bb82e981e
fix(schemas): field name in sie db data type should be camel-case (#2178)
Co-authored-by: wangsijie <wangsijie@silverhand.io>
2022-10-18 11:52:15 +08:00
..
1.0.0_beta.10-1663923211-machine-to-machine-app.ts release: v1.0.0-beta.10 2022-09-28 14:30:24 +00:00
1.0.0_beta.10-1664265197-custom-phrases.ts release: v1.0.0-beta.10 2022-09-28 14:30:24 +00:00
next-1664356000-add-created-at-column-to-users.ts refactor(core): count new users by created_at (#2027) 2022-09-29 15:32:43 +08:00
next-1664462389-correct-user-created-at-column-by-user-logs.ts chore(schemas): add db alteration script to repair user created_at column by user logs (#2031) 2022-09-30 10:27:06 +08:00
next-1665300135-sign-in-sign-up.ts fix(schemas): field name in sie db data type should be camel-case (#2178) 2022-10-18 11:52:15 +08:00
README.md refactor(core,schemas): rename migration to alteration (#2002) 2022-09-26 16:38:27 +08:00

Database Alteration

The folder for all alteration files.

Format

The alteration files are named in the format of <version>-<timestamp>-name.js where <timestamp> is the unix timestamp of when the alteration was created and name is the name of the alteration, 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 alteration files after they are created. If you need to change the alteration, you should create a new alteration file with the new content.

Typing

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

When the alteration 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";
  `);
};