1CREATE TABLE servers (
2 id SERIAL PRIMARY KEY,
3 environment VARCHAR NOT NULL
4);
5
6DROP TABLE worktree_extensions;
7DROP TABLE project_activity_periods;
8DELETE from projects;
9ALTER TABLE projects
10 DROP COLUMN host_connection_epoch,
11 ADD COLUMN host_connection_server_id INTEGER REFERENCES servers (id) ON DELETE CASCADE;
12CREATE INDEX "index_projects_on_host_connection_server_id" ON "projects" ("host_connection_server_id");
13CREATE INDEX "index_projects_on_host_connection_id_and_host_connection_server_id" ON "projects" ("host_connection_id", "host_connection_server_id");
14
15DELETE FROM project_collaborators;
16ALTER TABLE project_collaborators
17 DROP COLUMN connection_epoch,
18 ADD COLUMN connection_server_id INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE;
19CREATE INDEX "index_project_collaborators_on_connection_server_id" ON "project_collaborators" ("connection_server_id");
20CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_connection_id_and_server_id" ON "project_collaborators" ("project_id", "connection_id", "connection_server_id");
21
22DELETE FROM room_participants;
23ALTER TABLE room_participants
24 DROP COLUMN answering_connection_epoch,
25 DROP COLUMN calling_connection_epoch,
26 ADD COLUMN answering_connection_server_id INTEGER REFERENCES servers (id) ON DELETE CASCADE,
27 ADD COLUMN calling_connection_server_id INTEGER REFERENCES servers (id) ON DELETE SET NULL;
28CREATE INDEX "index_room_participants_on_answering_connection_server_id" ON "room_participants" ("answering_connection_server_id");
29CREATE INDEX "index_room_participants_on_calling_connection_server_id" ON "room_participants" ("calling_connection_server_id");
30CREATE UNIQUE INDEX "index_room_participants_on_answering_connection_id_and_answering_connection_server_id" ON "room_participants" ("answering_connection_id", "answering_connection_server_id");