1#!/usr/bin/env -S bun
2import type { Contract as End } from "../../snapshots/55b9b6715d228453c726947eaa87ebbd9ca24c38185277c672b1096c6e8effde/contract";
3import endContract from "../../snapshots/55b9b6715d228453c726947eaa87ebbd9ca24c38185277c672b1096c6e8effde/contract.json" with { type: "json" };
4import {
5 Migration,
6 MigrationCLI,
7 col,
8 fn,
9 primaryKey,
10} from "@prisma/orm-postgres/migration";
11
12export default class M extends Migration<never, End> {
13 override readonly endContractJson = endContract;
14
15 override get operations() {
16 return [
17 this.createSchema({ schema: "public" }),
18 this.createTable({
19 schema: "public",
20 table: "post",
21 columns: [
22 col("authorId", "uuid", {
23 notNull: true,
24 codecRef: { codecId: "pg/uuid@1" },
25 }),
26 col("id", "uuid", {
27 notNull: true,
28 codecRef: { codecId: "pg/uuid@1" },
29 }),
30 col("title", "text", {
31 notNull: true,
32 codecRef: { codecId: "pg/text@1" },
33 }),
34 ],
35 constraints: [primaryKey(["id"])],
36 }),
37 this.createTable({
38 schema: "public",
39 table: "user",
40 columns: [
41 col("createdAt", "timestamptz", {
42 notNull: true,
43 default: fn("now()"),
44 codecRef: { codecId: "pg/timestamptz-string@1" },
45 }),
46 col("email", "text", {
47 notNull: true,
48 codecRef: { codecId: "pg/text@1" },
49 }),
50 col("id", "uuid", {
51 notNull: true,
52 codecRef: { codecId: "pg/uuid@1" },
53 }),
54 col("name", "text", {
55 notNull: true,
56 codecRef: { codecId: "pg/text@1" },
57 }),
58 ],
59 constraints: [primaryKey(["id"])],
60 }),
61 this.addUnique({
62 schema: "public",
63 table: "user",
64 constraint: "user_email_key",
65 columns: ["email"],
66 }),
67 this.createIndex({
68 schema: "public",
69 table: "post",
70 index: "post_authorId_idx_e47547ed",
71 columns: ["authorId"],
72 }),
73 this.addForeignKey({
74 schema: "public",
75 table: "post",
76 foreignKey: {
77 name: "post_authorId_fkey",
78 columns: ["authorId"],
79 references: { schema: "public", table: "user", columns: ["id"] },
80 },
81 }),
82 ];
83 }
84}
85
86MigrationCLI.run(import.meta.url, M);