mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-11 22:31:32 +00:00
74 lines
3.5 KiB
SQL
74 lines
3.5 KiB
SQL
-- session-sharing 0001: adopt_session_sharing
|
|
-- Generated by termix-plugin migrations. Review before committing.
|
|
-- Hand-edited: keeps the legacy foreign keys the SDK cannot declare
|
|
-- (nullable or set-null user and host links, and links between these tables).
|
|
|
|
CREATE TABLE IF NOT EXISTS "session_shares" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"host_id" integer NOT NULL,
|
|
"owner_user_id" text NOT NULL,
|
|
"protocol" text NOT NULL,
|
|
"session_id" text NOT NULL,
|
|
"tab_instance_id" text,
|
|
"share_type" text NOT NULL,
|
|
"target_user_id" text,
|
|
"link_token" text UNIQUE,
|
|
"permission_level" text NOT NULL DEFAULT 'read-only',
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"expires_at" text NOT NULL,
|
|
"revoked_at" text,
|
|
"last_joined_at" text,
|
|
"join_count" integer NOT NULL DEFAULT 0,
|
|
FOREIGN KEY ("host_id") REFERENCES "ssh_data" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("owner_user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_session_shares_session_id" ON "session_shares" ("session_id");
|
|
CREATE INDEX IF NOT EXISTS "idx_session_shares_host_id" ON "session_shares" ("host_id");
|
|
ALTER TABLE "session_shares" RENAME TO "p_session_sharing_shares";
|
|
CREATE TABLE IF NOT EXISTS "session_share_participants" (
|
|
"id" integer PRIMARY KEY AUTOINCREMENT,
|
|
"share_id" text NOT NULL,
|
|
"user_id" text,
|
|
"guest_label" text,
|
|
"joined_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"left_at" text,
|
|
FOREIGN KEY ("share_id") REFERENCES "p_session_sharing_shares" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
ALTER TABLE "session_share_participants" RENAME TO "p_session_sharing_share_participants";
|
|
CREATE TABLE IF NOT EXISTS "collab_rooms" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"owner_user_id" text NOT NULL,
|
|
"persistent" integer NOT NULL DEFAULT 0,
|
|
"presenter_user_id" text,
|
|
"stage_protocol" text,
|
|
"stage_host_id" integer,
|
|
"stage_share_id" text,
|
|
"guest_link_token" text,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"ended_at" text,
|
|
FOREIGN KEY ("owner_user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("presenter_user_id") REFERENCES "users" ("id") ON DELETE SET NULL,
|
|
FOREIGN KEY ("stage_host_id") REFERENCES "ssh_data" ("id") ON DELETE SET NULL,
|
|
FOREIGN KEY ("stage_share_id") REFERENCES "p_session_sharing_shares" ("id") ON DELETE SET NULL
|
|
);
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "idx_collab_rooms_guest_token" ON "collab_rooms" ("guest_link_token");
|
|
CREATE INDEX IF NOT EXISTS "idx_collab_rooms_owner" ON "collab_rooms" ("owner_user_id");
|
|
ALTER TABLE "collab_rooms" RENAME TO "p_session_sharing_rooms";
|
|
CREATE TABLE IF NOT EXISTS "collab_room_members" (
|
|
"id" integer PRIMARY KEY AUTOINCREMENT,
|
|
"room_id" text NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"room_role" text NOT NULL DEFAULT 'member',
|
|
"added_by" text,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("room_id") REFERENCES "p_session_sharing_rooms" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("added_by") REFERENCES "users" ("id") ON DELETE SET NULL
|
|
);
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "idx_collab_room_members_room_user" ON "collab_room_members" ("room_id", "user_id");
|
|
CREATE INDEX IF NOT EXISTS "idx_collab_room_members_user" ON "collab_room_members" ("user_id");
|
|
ALTER TABLE "collab_room_members" RENAME TO "p_session_sharing_room_members";
|