| 1 | #!/usr/bin/env -S node |
| 2 | import type { Contract as End } from '../../snapshots/7de60ab4aee8baa42480f8a2d3559ff4027deae801de73c6a93c9eeb4170f558/contract'; |
| 3 | import endContract from '../../snapshots/7de60ab4aee8baa42480f8a2d3559ff4027deae801de73c6a93c9eeb4170f558/contract.json' with { type: 'json' }; |
| 4 | import { Migration, MigrationCLI, col, fn, primaryKey } from '@internal/postgres/migration'; |
| 5 | |
| 6 | export default class M extends Migration<never, End> { |
| 7 | override readonly endContractJson = endContract; |
| 8 | |
| 9 | override get operations() { |
| 10 | return [ |
| 11 | this.createSchema({ schema: 'public' }), |
| 12 | this.createTable({ |
| 13 | schema: 'public', |
| 14 | table: 'Post', |
| 15 | columns: [ |
| 16 | col('authorId', 'uuid', { notNull: true, codecRef: { codecId: 'pg/uuid@1' } }), |
| 17 | col('id', 'uuid', { notNull: true, codecRef: { codecId: 'pg/uuid@1' } }), |
| 18 | col('title', 'text', { notNull: true, codecRef: { codecId: 'pg/text@1' } }), |
| 19 | ], |
| 20 | constraints: [primaryKey(['id'])], |
| 21 | }), |
| 22 | this.createTable({ |
| 23 | schema: 'public', |
| 24 | table: 'User', |
| 25 | columns: [ |
| 26 | col('createdAt', 'timestamptz', { |
| 27 | notNull: true, |
| 28 | default: fn('now()'), |
| 29 | codecRef: { codecId: 'pg/timestamptz-string@1' }, |
| 30 | }), |
| 31 | col('email', 'text', { notNull: true, codecRef: { codecId: 'pg/text@1' } }), |
| 32 | col('id', 'uuid', { notNull: true, codecRef: { codecId: 'pg/uuid@1' } }), |
| 33 | col('name', 'text', { notNull: true, codecRef: { codecId: 'pg/text@1' } }), |
| 34 | ], |
| 35 | constraints: [primaryKey(['id'])], |
| 36 | }), |
| 37 | this.addUnique({ |
| 38 | schema: 'public', |
| 39 | table: 'User', |
| 40 | constraint: 'User_email_key', |
| 41 | columns: ['email'], |
| 42 | }), |
| 43 | ]; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | MigrationCLI.run(import.meta.url, M); |