44 lines
1.5 KiB
SQL
44 lines
1.5 KiB
SQL
DROP INDEX idx_show_share_sessions_share;
|
|
DROP INDEX idx_show_shares_show;
|
|
|
|
ALTER TABLE show_share_sessions RENAME TO show_share_sessions_v15;
|
|
ALTER TABLE show_shares RENAME TO show_shares_v15;
|
|
|
|
CREATE TABLE show_shares (
|
|
id TEXT PRIMARY KEY,
|
|
show_id TEXT NOT NULL REFERENCES shows(id) ON DELETE CASCADE,
|
|
token_hash TEXT NOT NULL UNIQUE,
|
|
scope TEXT NOT NULL CHECK (scope IN ('rundown', 'moderation', 'research')),
|
|
password_hash TEXT,
|
|
expires_at_utc TEXT,
|
|
revoked_at_utc TEXT,
|
|
created_by_user_id TEXT NOT NULL REFERENCES users(id) ON DELETE RESTRICT,
|
|
created_at_utc TEXT NOT NULL
|
|
);
|
|
|
|
CREATE INDEX idx_show_shares_show ON show_shares(show_id, created_at_utc DESC);
|
|
|
|
CREATE TABLE show_share_sessions (
|
|
token_hash TEXT PRIMARY KEY,
|
|
share_id TEXT NOT NULL REFERENCES show_shares(id) ON DELETE CASCADE,
|
|
created_at_utc TEXT NOT NULL,
|
|
expires_at_utc TEXT NOT NULL
|
|
);
|
|
|
|
CREATE INDEX idx_show_share_sessions_share ON show_share_sessions(share_id, expires_at_utc);
|
|
|
|
INSERT INTO show_shares (
|
|
id, show_id, token_hash, scope, password_hash, expires_at_utc, revoked_at_utc,
|
|
created_by_user_id, created_at_utc
|
|
)
|
|
SELECT id, show_id, token_hash, scope, password_hash, expires_at_utc, revoked_at_utc,
|
|
created_by_user_id, created_at_utc
|
|
FROM show_shares_v15;
|
|
|
|
INSERT INTO show_share_sessions (token_hash, share_id, created_at_utc, expires_at_utc)
|
|
SELECT token_hash, share_id, created_at_utc, expires_at_utc
|
|
FROM show_share_sessions_v15;
|
|
|
|
DROP TABLE show_share_sessions_v15;
|
|
DROP TABLE show_shares_v15;
|