metropolis/migration/1625694002469-initialize.ts

43 lines
1.2 KiB
TypeScript

import { MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm';
export class initialize1625694002469 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE SEQUENCE items_serial
AS bigint
MINVALUE 140000000000
START WITH 140000000000;
`);
const items = new Table();
items.name = 'item';
const iid = new TableColumn();
iid.name = 'id';
iid.type = 'bigint';
iid.default = "nextval('items_serial')";
iid.isPrimary = true;
iid.isUnique = true;
iid.isNullable = false;
items.addColumn(iid);
const iname = new TableColumn();
iname.name = 'name';
iname.type = 'varchar(40)';
iname.isNullable = false;
items.addColumn(iname);
const inotes = new TableColumn();
inotes.name = 'notes';
inotes.type = 'varchar(255)';
inotes.isNullable = true;
items.addColumn(inotes);
await queryRunner.createTable(items);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('items');
await queryRunner.query(`
DROP SEQUENCE items_serial;
`);
}
}