|
| 1 | +import { MigrationInterface, QueryRunner, Table } from 'typeorm'; |
| 2 | +import { BaseColumns } from './base-columns'; |
| 3 | + |
| 4 | +async function createShareTypeEnum(queryRunner: QueryRunner): Promise<void> { |
| 5 | + await queryRunner.query(` |
| 6 | + CREATE TYPE share_type AS ENUM ( |
| 7 | + 'doc_only', |
| 8 | + 'chat_only', |
| 9 | + 'all' |
| 10 | + ); |
| 11 | + `); |
| 12 | +} |
| 13 | + |
| 14 | +async function createSharesTable(queryRunner: QueryRunner): Promise<void> { |
| 15 | + const table = new Table({ |
| 16 | + name: 'shares', |
| 17 | + columns: [ |
| 18 | + { |
| 19 | + name: 'id', |
| 20 | + type: 'character varying', |
| 21 | + isPrimary: true, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: 'namespace_id', |
| 25 | + type: 'character varying', |
| 26 | + isNullable: false, |
| 27 | + }, |
| 28 | + { |
| 29 | + name: 'resource_id', |
| 30 | + type: 'character varying', |
| 31 | + isNullable: false, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'enabled', |
| 35 | + type: 'boolean', |
| 36 | + isNullable: false, |
| 37 | + }, |
| 38 | + { |
| 39 | + name: 'require_login', |
| 40 | + type: 'boolean', |
| 41 | + isNullable: false, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: 'share_type', |
| 45 | + type: 'share_type', |
| 46 | + isNullable: false, |
| 47 | + }, |
| 48 | + { |
| 49 | + name: 'password', |
| 50 | + type: 'character varying', |
| 51 | + isNullable: true, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: 'expires_at', |
| 55 | + type: 'timestamp with time zone', |
| 56 | + isNullable: true, |
| 57 | + }, |
| 58 | + ...BaseColumns(), |
| 59 | + ], |
| 60 | + indices: [ |
| 61 | + { |
| 62 | + columnNames: ['namespace_id', 'resource_id'], |
| 63 | + isUnique: true, |
| 64 | + where: 'deleted_at IS NULL', |
| 65 | + }, |
| 66 | + ], |
| 67 | + foreignKeys: [ |
| 68 | + { |
| 69 | + columnNames: ['namespace_id'], |
| 70 | + referencedTableName: 'namespaces', |
| 71 | + referencedColumnNames: ['id'], |
| 72 | + }, |
| 73 | + { |
| 74 | + columnNames: ['resource_id'], |
| 75 | + referencedTableName: 'resources', |
| 76 | + referencedColumnNames: ['id'], |
| 77 | + }, |
| 78 | + ], |
| 79 | + }); |
| 80 | + await queryRunner.createTable(table, true, true, true); |
| 81 | +} |
| 82 | + |
| 83 | +export class Shares1753866547335 implements MigrationInterface { |
| 84 | + public async up(queryRunner: QueryRunner): Promise<void> { |
| 85 | + await createShareTypeEnum(queryRunner); |
| 86 | + await createSharesTable(queryRunner); |
| 87 | + } |
| 88 | + |
| 89 | + public down(): Promise<void> { |
| 90 | + throw new Error('Not supported.'); |
| 91 | + } |
| 92 | +} |
0 commit comments