import { MigrationInterface, QueryRunner } from 'typeorm'

export class AddTableTokenEntity1700145521797 implements MigrationInterface {
	name = 'AddTableTokenEntity1700145521797'

	public async up(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(
			`CREATE TABLE "table_token" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "tenantId" uuid, "token" text NOT NULL DEFAULT substr(md5(''||now()::text||random()::text), 0, 16), "tableId" uuid NOT NULL, CONSTRAINT "UQ_4a86f31a1c87cbed8b50f08e681" UNIQUE ("token"), CONSTRAINT "UQ_913b239ba68337f22566416274e" UNIQUE ("tableId"), CONSTRAINT "PK_b509b374adc87ebee64c3177fe7" PRIMARY KEY ("id"))`,
		)
	}

	public async down(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(`DROP TABLE "table_token"`)
	}
}
