Skip to content

Commit c9539f7

Browse files
committed
feat: add media, messages, sessions, and users tables with foreign key constraints
1 parent 54f5e01 commit c9539f7

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

server/migrations/0000_abnormal_namor.sql renamed to server/migrations/0000_closed_scalphunter.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ CREATE TABLE IF NOT EXISTS "media" (
44
"created_at" timestamp DEFAULT now() NOT NULL,
55
"url" text NOT NULL,
66
"type" text NOT NULL,
7-
"thumbnail" text
7+
"thumbnail" text,
8+
"message_id" uuid
89
);
910
--> statement-breakpoint
1011
CREATE TABLE IF NOT EXISTS "messages" (
1112
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
1213
"text" text NOT NULL,
1314
"created_at" timestamp DEFAULT now(),
1415
"from_id" uuid NOT NULL,
15-
"to_id" uuid NOT NULL,
16-
"media_id" uuid[] DEFAULT '{}'::uuid[]
16+
"to_id" uuid NOT NULL
1717
);
1818
--> statement-breakpoint
1919
CREATE TABLE IF NOT EXISTS "sessions" (
@@ -45,6 +45,12 @@ EXCEPTION
4545
WHEN duplicate_object THEN null;
4646
END $$;
4747
--> statement-breakpoint
48+
DO $$ BEGIN
49+
ALTER TABLE "media" ADD CONSTRAINT "media_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;
50+
EXCEPTION
51+
WHEN duplicate_object THEN null;
52+
END $$;
53+
--> statement-breakpoint
4854
DO $$ BEGIN
4955
ALTER TABLE "messages" ADD CONSTRAINT "messages_from_id_users_id_fk" FOREIGN KEY ("from_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
5056
EXCEPTION

server/migrations/meta/0000_snapshot.json

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "b2e054d2-5939-4859-a21f-afaca890bc7e",
2+
"id": "cd1f2ba6-97e0-46ce-8b0e-716235448ded",
33
"prevId": "00000000-0000-0000-0000-000000000000",
44
"version": "7",
55
"dialect": "postgresql",
@@ -45,6 +45,12 @@
4545
"type": "text",
4646
"primaryKey": false,
4747
"notNull": false
48+
},
49+
"message_id": {
50+
"name": "message_id",
51+
"type": "uuid",
52+
"primaryKey": false,
53+
"notNull": false
4854
}
4955
},
5056
"indexes": {},
@@ -61,6 +67,19 @@
6167
],
6268
"onDelete": "cascade",
6369
"onUpdate": "no action"
70+
},
71+
"media_message_id_messages_id_fk": {
72+
"name": "media_message_id_messages_id_fk",
73+
"tableFrom": "media",
74+
"tableTo": "messages",
75+
"columnsFrom": [
76+
"message_id"
77+
],
78+
"columnsTo": [
79+
"id"
80+
],
81+
"onDelete": "cascade",
82+
"onUpdate": "no action"
6483
}
6584
},
6685
"compositePrimaryKeys": {},
@@ -101,13 +120,6 @@
101120
"type": "uuid",
102121
"primaryKey": false,
103122
"notNull": true
104-
},
105-
"media_id": {
106-
"name": "media_id",
107-
"type": "uuid[]",
108-
"primaryKey": false,
109-
"notNull": false,
110-
"default": "'{}'::uuid[]"
111123
}
112124
},
113125
"indexes": {},

server/migrations/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{
66
"idx": 0,
77
"version": "7",
8-
"when": 1747754410999,
9-
"tag": "0000_abnormal_namor",
8+
"when": 1751782883721,
9+
"tag": "0000_closed_scalphunter",
1010
"breakpoints": true
1111
}
1212
]

0 commit comments

Comments
 (0)