36 lines
1.9 KiB
SQL
36 lines
1.9 KiB
SQL
-- Migration: Add anonymize_names, expires_at, access_password_hash to share_links
|
|
-- Run this on existing database
|
|
|
|
-- 1. Add anonymize_names column (default false = show names)
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS anonymize_names BOOLEAN DEFAULT false;
|
|
|
|
-- 2. Add expires_at column (default 7 days from creation, nullable for backward compat)
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS expires_at TIMESTAMPTZ;
|
|
|
|
-- 3. Add access_password_hash column for bcrypt password protection
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS access_password_hash VARCHAR(255);
|
|
|
|
-- 4. Update existing links to have expires_at = created_at + 7 days (optional, for existing links)
|
|
-- UPDATE share_links SET expires_at = created_at + interval '7 days' WHERE expires_at IS NULL;
|
|
|
|
-- 5. Add index for cleanup of expired links
|
|
CREATE INDEX IF NOT EXISTS idx_share_links_expires_at ON share_links(expires_at);
|
|
|
|
-- 6. Add public message and external link shown on the share page
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS message TEXT;
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS link_url VARCHAR(500);
|
|
|
|
-- 7. Per-link visibility overrides (NULL = fall back to global settings)
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS show_student_message BOOLEAN;
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS show_entry_date BOOLEAN;
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS show_group_photos BOOLEAN;
|
|
|
|
-- 8. Replace anonymize_names with positive show_student_names (NULL = inherit global setting)
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'share_links' AND column_name = 'anonymize_names') THEN
|
|
ALTER TABLE share_links ADD COLUMN IF NOT EXISTS show_student_names BOOLEAN;
|
|
UPDATE share_links SET show_student_names = (NOT anonymize_names) WHERE anonymize_names IS NOT NULL;
|
|
ALTER TABLE share_links DROP COLUMN anonymize_names;
|
|
END IF;
|
|
END $$; |