Skip to content

Commit

Permalink
Refactor last migrations in server
Browse files Browse the repository at this point in the history
  • Loading branch information
morajabi committed Dec 29, 2024
1 parent 081932d commit 6ad0879
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 1,246 deletions.
1 change: 0 additions & 1 deletion server/drizzle/0017_add_replying_to_message.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS "reactions" (
CONSTRAINT "unique_reaction_per_emoji" UNIQUE("chat_id","message_id","user_id","emoji")
);
--> statement-breakpoint
ALTER TABLE "messages" ADD COLUMN "reply_to_msg_id" integer;--> statement-breakpoint
DO $$ BEGIN
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;
EXCEPTION
Expand All @@ -19,3 +20,9 @@ DO $$ BEGIN
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
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;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
149 changes: 114 additions & 35 deletions server/drizzle/meta/0017_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "aa1d865a-e96e-43c1-92d7-6536096e654f",
"id": "f2dbd406-adc5-4a0d-86e8-1ea6f04961d0",
"prevId": "77d439c3-9c69-455f-9c0d-66f09afd16ed",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -65,9 +65,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.there_users": {
"name": "there_users",
Expand Down Expand Up @@ -117,9 +115,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.users": {
"name": "users",
Expand Down Expand Up @@ -236,9 +232,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.sessions": {
"name": "sessions",
Expand Down Expand Up @@ -367,9 +361,7 @@
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.login_codes": {
"name": "login_codes",
Expand Down Expand Up @@ -439,9 +431,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.spaces": {
"name": "spaces",
Expand Down Expand Up @@ -511,9 +501,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.members": {
"name": "members",
Expand Down Expand Up @@ -593,9 +581,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.chats": {
"name": "chats",
Expand Down Expand Up @@ -763,14 +749,12 @@
]
}
},
"policies": {},
"checkConstraints": {
"user_ids_check": {
"name": "user_ids_check",
"value": "\"chats\".\"min_user_id\" <= \"chats\".\"max_user_id\""
}
},
"isRLSEnabled": false
}
},
"public.messages": {
"name": "messages",
Expand Down Expand Up @@ -843,8 +827,8 @@
"notNull": true,
"default": "now()"
},
"replied_to_message_id": {
"name": "replied_to_message_id",
"reply_to_msg_id": {
"name": "reply_to_msg_id",
"type": "integer",
"primaryKey": false,
"notNull": false
Expand Down Expand Up @@ -920,9 +904,7 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.dialogs": {
"name": "dialogs",
Expand Down Expand Up @@ -1050,9 +1032,108 @@
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
"checkConstraints": {}
},
"public.reactions": {
"name": "reactions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"message_id": {
"name": "message_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"chat_id": {
"name": "chat_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"emoji": {
"name": "emoji",
"type": "text",
"primaryKey": false,
"notNull": true
},
"date": {
"name": "date",
"type": "timestamp (3)",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"reactions_chat_id_chats_id_fk": {
"name": "reactions_chat_id_chats_id_fk",
"tableFrom": "reactions",
"tableTo": "chats",
"columnsFrom": [
"chat_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"reactions_user_id_users_id_fk": {
"name": "reactions_user_id_users_id_fk",
"tableFrom": "reactions",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"message_id_fk": {
"name": "message_id_fk",
"tableFrom": "reactions",
"tableTo": "messages",
"columnsFrom": [
"chat_id",
"message_id"
],
"columnsTo": [
"chat_id",
"message_id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"unique_reaction_per_emoji": {
"name": "unique_reaction_per_emoji",
"nullsNotDistinct": false,
"columns": [
"chat_id",
"message_id",
"user_id",
"emoji"
]
}
},
"checkConstraints": {}
}
},
"enums": {
Expand Down Expand Up @@ -1096,8 +1177,6 @@
"cycle": false
}
},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
Expand Down
Loading

0 comments on commit 6ad0879

Please sign in to comment.