1682587956616-initial-boilerplate.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { MigrationInterface, QueryRunner } from 'typeorm'
  2. export class initialBoilerplate1682587956616 implements MigrationInterface {
  3. name = 'initialBoilerplate1682587956616'
  4. public async up(queryRunner: QueryRunner): Promise<void> {
  5. await queryRunner.query(
  6. 'CREATE TABLE "items" ("uuid" varchar PRIMARY KEY NOT NULL, "duplicate_of" varchar(36), "items_key_id" varchar(255), "content" text, "content_type" varchar(255), "content_size" integer, "enc_item_key" text, "auth_hash" varchar(255), "user_uuid" varchar(36) NOT NULL, "deleted" tinyint(1) DEFAULT (0), "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, "created_at_timestamp" bigint NOT NULL, "updated_at_timestamp" bigint NOT NULL, "updated_with_session" varchar(36))',
  7. )
  8. await queryRunner.query('CREATE INDEX "index_items_on_content_type" ON "items" ("content_type") ')
  9. await queryRunner.query('CREATE INDEX "index_items_on_user_uuid" ON "items" ("user_uuid") ')
  10. await queryRunner.query('CREATE INDEX "index_items_on_deleted" ON "items" ("deleted") ')
  11. await queryRunner.query('CREATE INDEX "updated_at_timestamp" ON "items" ("updated_at_timestamp") ')
  12. await queryRunner.query('CREATE INDEX "user_uuid_and_deleted" ON "items" ("user_uuid", "deleted") ')
  13. await queryRunner.query(
  14. 'CREATE INDEX "user_uuid_and_updated_at_timestamp_and_created_at_timestamp" ON "items" ("user_uuid", "updated_at_timestamp", "created_at_timestamp") ',
  15. )
  16. await queryRunner.query(
  17. 'CREATE INDEX "index_items_on_user_uuid_and_content_type" ON "items" ("user_uuid", "content_type") ',
  18. )
  19. }
  20. public async down(queryRunner: QueryRunner): Promise<void> {
  21. await queryRunner.query('DROP INDEX "index_items_on_user_uuid_and_content_type"')
  22. await queryRunner.query('DROP INDEX "user_uuid_and_updated_at_timestamp_and_created_at_timestamp"')
  23. await queryRunner.query('DROP INDEX "user_uuid_and_deleted"')
  24. await queryRunner.query('DROP INDEX "updated_at_timestamp"')
  25. await queryRunner.query('DROP INDEX "index_items_on_deleted"')
  26. await queryRunner.query('DROP INDEX "index_items_on_user_uuid"')
  27. await queryRunner.query('DROP INDEX "index_items_on_content_type"')
  28. await queryRunner.query('DROP TABLE "items"')
  29. }
  30. }