Skip to content

Commit 6ad0879

Browse files
committed
Refactor last migrations in server
1 parent 081932d commit 6ad0879

9 files changed

+135
-1246
lines changed

server/drizzle/0017_add_replying_to_message.sql

-1
This file was deleted.

server/drizzle/0018_add_reaction.sql renamed to server/drizzle/0017_reply_and_reactions.sql

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS "reactions" (
88
CONSTRAINT "unique_reaction_per_emoji" UNIQUE("chat_id","message_id","user_id","emoji")
99
);
1010
--> statement-breakpoint
11+
ALTER TABLE "messages" ADD COLUMN "reply_to_msg_id" integer;--> statement-breakpoint
1112
DO $$ BEGIN
1213
ALTER TABLE "reactions" ADD CONSTRAINT "reactions_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;
1314
EXCEPTION
@@ -19,3 +20,9 @@ DO $$ BEGIN
1920
EXCEPTION
2021
WHEN duplicate_object THEN null;
2122
END $$;
23+
--> statement-breakpoint
24+
DO $$ BEGIN
25+
ALTER TABLE "reactions" ADD CONSTRAINT "message_id_fk" FOREIGN KEY ("chat_id","message_id") REFERENCES "public"."messages"("chat_id","message_id") ON DELETE cascade ON UPDATE no action;
26+
EXCEPTION
27+
WHEN duplicate_object THEN null;
28+
END $$;

server/drizzle/meta/0017_snapshot.json

+114-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "aa1d865a-e96e-43c1-92d7-6536096e654f",
2+
"id": "f2dbd406-adc5-4a0d-86e8-1ea6f04961d0",
33
"prevId": "77d439c3-9c69-455f-9c0d-66f09afd16ed",
44
"version": "7",
55
"dialect": "postgresql",
@@ -65,9 +65,7 @@
6565
]
6666
}
6767
},
68-
"policies": {},
69-
"checkConstraints": {},
70-
"isRLSEnabled": false
68+
"checkConstraints": {}
7169
},
7270
"public.there_users": {
7371
"name": "there_users",
@@ -117,9 +115,7 @@
117115
]
118116
}
119117
},
120-
"policies": {},
121-
"checkConstraints": {},
122-
"isRLSEnabled": false
118+
"checkConstraints": {}
123119
},
124120
"public.users": {
125121
"name": "users",
@@ -236,9 +232,7 @@
236232
]
237233
}
238234
},
239-
"policies": {},
240-
"checkConstraints": {},
241-
"isRLSEnabled": false
235+
"checkConstraints": {}
242236
},
243237
"public.sessions": {
244238
"name": "sessions",
@@ -367,9 +361,7 @@
367361
},
368362
"compositePrimaryKeys": {},
369363
"uniqueConstraints": {},
370-
"policies": {},
371-
"checkConstraints": {},
372-
"isRLSEnabled": false
364+
"checkConstraints": {}
373365
},
374366
"public.login_codes": {
375367
"name": "login_codes",
@@ -439,9 +431,7 @@
439431
]
440432
}
441433
},
442-
"policies": {},
443-
"checkConstraints": {},
444-
"isRLSEnabled": false
434+
"checkConstraints": {}
445435
},
446436
"public.spaces": {
447437
"name": "spaces",
@@ -511,9 +501,7 @@
511501
]
512502
}
513503
},
514-
"policies": {},
515-
"checkConstraints": {},
516-
"isRLSEnabled": false
504+
"checkConstraints": {}
517505
},
518506
"public.members": {
519507
"name": "members",
@@ -593,9 +581,7 @@
593581
]
594582
}
595583
},
596-
"policies": {},
597-
"checkConstraints": {},
598-
"isRLSEnabled": false
584+
"checkConstraints": {}
599585
},
600586
"public.chats": {
601587
"name": "chats",
@@ -763,14 +749,12 @@
763749
]
764750
}
765751
},
766-
"policies": {},
767752
"checkConstraints": {
768753
"user_ids_check": {
769754
"name": "user_ids_check",
770755
"value": "\"chats\".\"min_user_id\" <= \"chats\".\"max_user_id\""
771756
}
772-
},
773-
"isRLSEnabled": false
757+
}
774758
},
775759
"public.messages": {
776760
"name": "messages",
@@ -843,8 +827,8 @@
843827
"notNull": true,
844828
"default": "now()"
845829
},
846-
"replied_to_message_id": {
847-
"name": "replied_to_message_id",
830+
"reply_to_msg_id": {
831+
"name": "reply_to_msg_id",
848832
"type": "integer",
849833
"primaryKey": false,
850834
"notNull": false
@@ -920,9 +904,7 @@
920904
]
921905
}
922906
},
923-
"policies": {},
924-
"checkConstraints": {},
925-
"isRLSEnabled": false
907+
"checkConstraints": {}
926908
},
927909
"public.dialogs": {
928910
"name": "dialogs",
@@ -1050,9 +1032,108 @@
10501032
]
10511033
}
10521034
},
1053-
"policies": {},
1054-
"checkConstraints": {},
1055-
"isRLSEnabled": false
1035+
"checkConstraints": {}
1036+
},
1037+
"public.reactions": {
1038+
"name": "reactions",
1039+
"schema": "",
1040+
"columns": {
1041+
"id": {
1042+
"name": "id",
1043+
"type": "serial",
1044+
"primaryKey": true,
1045+
"notNull": true
1046+
},
1047+
"message_id": {
1048+
"name": "message_id",
1049+
"type": "integer",
1050+
"primaryKey": false,
1051+
"notNull": true
1052+
},
1053+
"chat_id": {
1054+
"name": "chat_id",
1055+
"type": "integer",
1056+
"primaryKey": false,
1057+
"notNull": true
1058+
},
1059+
"user_id": {
1060+
"name": "user_id",
1061+
"type": "integer",
1062+
"primaryKey": false,
1063+
"notNull": true
1064+
},
1065+
"emoji": {
1066+
"name": "emoji",
1067+
"type": "text",
1068+
"primaryKey": false,
1069+
"notNull": true
1070+
},
1071+
"date": {
1072+
"name": "date",
1073+
"type": "timestamp (3)",
1074+
"primaryKey": false,
1075+
"notNull": true,
1076+
"default": "now()"
1077+
}
1078+
},
1079+
"indexes": {},
1080+
"foreignKeys": {
1081+
"reactions_chat_id_chats_id_fk": {
1082+
"name": "reactions_chat_id_chats_id_fk",
1083+
"tableFrom": "reactions",
1084+
"tableTo": "chats",
1085+
"columnsFrom": [
1086+
"chat_id"
1087+
],
1088+
"columnsTo": [
1089+
"id"
1090+
],
1091+
"onDelete": "cascade",
1092+
"onUpdate": "no action"
1093+
},
1094+
"reactions_user_id_users_id_fk": {
1095+
"name": "reactions_user_id_users_id_fk",
1096+
"tableFrom": "reactions",
1097+
"tableTo": "users",
1098+
"columnsFrom": [
1099+
"user_id"
1100+
],
1101+
"columnsTo": [
1102+
"id"
1103+
],
1104+
"onDelete": "cascade",
1105+
"onUpdate": "no action"
1106+
},
1107+
"message_id_fk": {
1108+
"name": "message_id_fk",
1109+
"tableFrom": "reactions",
1110+
"tableTo": "messages",
1111+
"columnsFrom": [
1112+
"chat_id",
1113+
"message_id"
1114+
],
1115+
"columnsTo": [
1116+
"chat_id",
1117+
"message_id"
1118+
],
1119+
"onDelete": "cascade",
1120+
"onUpdate": "no action"
1121+
}
1122+
},
1123+
"compositePrimaryKeys": {},
1124+
"uniqueConstraints": {
1125+
"unique_reaction_per_emoji": {
1126+
"name": "unique_reaction_per_emoji",
1127+
"nullsNotDistinct": false,
1128+
"columns": [
1129+
"chat_id",
1130+
"message_id",
1131+
"user_id",
1132+
"emoji"
1133+
]
1134+
}
1135+
},
1136+
"checkConstraints": {}
10561137
}
10571138
},
10581139
"enums": {
@@ -1096,8 +1177,6 @@
10961177
"cycle": false
10971178
}
10981179
},
1099-
"roles": {},
1100-
"policies": {},
11011180
"views": {},
11021181
"_meta": {
11031182
"columns": {},

0 commit comments

Comments
 (0)