69
This commit is contained in:
38
migrations/add_private_unlisted_uploads.sql
Normal file
38
migrations/add_private_unlisted_uploads.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
-- Add visibility and slug columns to items table
|
||||
ALTER TABLE items ADD COLUMN IF NOT EXISTS visibility smallint DEFAULT 0;
|
||||
ALTER TABLE items ADD COLUMN IF NOT EXISTS slug varchar(16) UNIQUE;
|
||||
ALTER TABLE user_options ADD COLUMN IF NOT EXISTS default_upload_visibility smallint DEFAULT 0;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_items_slug ON items(slug);
|
||||
|
||||
COMMENT ON COLUMN items.visibility IS '0=public, 1=unlisted, 2=private';
|
||||
COMMENT ON COLUMN items.slug IS 'Unique unguessable 11-character URL slug for direct access';
|
||||
COMMENT ON COLUMN user_options.default_upload_visibility IS 'Default upload visibility preference for user (0=public, 1=unlisted, 2=private)';
|
||||
|
||||
-- Populate missing slugs for existing items
|
||||
DO $$
|
||||
DECLARE
|
||||
r RECORD;
|
||||
chars text := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||
new_slug text;
|
||||
i integer;
|
||||
BEGIN
|
||||
FOR r IN SELECT id FROM items WHERE slug IS NULL LOOP
|
||||
LOOP
|
||||
new_slug := '';
|
||||
FOR i IN 1..11 LOOP
|
||||
new_slug := new_slug || substr(chars, floor(random() * 64 + 1)::integer, 1);
|
||||
END LOOP;
|
||||
BEGIN
|
||||
UPDATE items SET slug = new_slug WHERE id = r.id;
|
||||
EXIT;
|
||||
EXCEPTION WHEN unique_violation THEN
|
||||
END;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
END $$;
|
||||
|
||||
-- Fix any items with NULL visibility (should default to 0 = public)
|
||||
UPDATE items SET visibility = 0 WHERE visibility IS NULL;
|
||||
ALTER TABLE items ALTER COLUMN visibility SET NOT NULL;
|
||||
ALTER TABLE items ALTER COLUMN visibility SET DEFAULT 0;
|
||||
@@ -114,6 +114,7 @@ DROP INDEX IF EXISTS public.idx_items_username;
|
||||
DROP INDEX IF EXISTS public.idx_items_pinned_id;
|
||||
DROP INDEX IF EXISTS public.idx_items_is_purged;
|
||||
DROP INDEX IF EXISTS public.idx_items_is_deleted;
|
||||
DROP INDEX IF EXISTS public.idx_items_slug;
|
||||
DROP INDEX IF EXISTS public.idx_items_active_id;
|
||||
DROP INDEX IF EXISTS public.idx_global_chat_created_at;
|
||||
DROP INDEX IF EXISTS public.idx_discord_queue_sent;
|
||||
@@ -910,12 +911,18 @@ CREATE TABLE public.items (
|
||||
original_filename text,
|
||||
title text,
|
||||
width integer,
|
||||
height integer
|
||||
height integer,
|
||||
visibility smallint DEFAULT 0 NOT NULL,
|
||||
slug character varying(16)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.items OWNER TO f0ckm;
|
||||
|
||||
COMMENT ON COLUMN public.items.visibility IS '0=public, 1=unlisted, 2=private';
|
||||
COMMENT ON COLUMN public.items.slug IS 'Unique unguessable 11-character URL slug for direct access';
|
||||
|
||||
|
||||
--
|
||||
-- Name: COLUMN items.src; Type: COMMENT; Schema: public; Owner: f0ckm
|
||||
--
|
||||
@@ -1500,12 +1507,16 @@ CREATE TABLE public.user_options (
|
||||
comment_display_mode integer DEFAULT 1,
|
||||
force_comment_display_mode integer DEFAULT 0,
|
||||
favorites_private boolean DEFAULT false,
|
||||
hide_fav_badge boolean DEFAULT false
|
||||
hide_fav_badge boolean DEFAULT false,
|
||||
default_upload_visibility smallint DEFAULT 0
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.user_options OWNER TO f0ckm;
|
||||
|
||||
COMMENT ON COLUMN public.user_options.default_upload_visibility IS 'Default upload visibility preference for user (0=public, 1=unlisted, 2=private)';
|
||||
|
||||
|
||||
--
|
||||
-- Name: COLUMN user_options.avatar_file; Type: COMMENT; Schema: public; Owner: f0ckm
|
||||
--
|
||||
@@ -2164,6 +2175,13 @@ CREATE INDEX idx_global_chat_created_at ON public.global_chat USING btree (creat
|
||||
CREATE INDEX idx_items_active_id ON public.items USING btree (id) WHERE (active = true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_items_slug; Type: INDEX; Schema: public; Owner: f0ckm
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_items_slug ON public.items USING btree (slug);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_items_is_deleted; Type: INDEX; Schema: public; Owner: f0ckm
|
||||
--
|
||||
|
||||
2
migrations/fix_null_visibility.sql
Normal file
2
migrations/fix_null_visibility.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- Fix items with NULL visibility (should default to 0 = public)
|
||||
UPDATE items SET visibility = 0 WHERE visibility IS NULL;
|
||||
Reference in New Issue
Block a user