schmema
This commit is contained in:
@@ -3503,6 +3503,170 @@ ALTER TABLE ONLY public.user_warnings
|
|||||||
ADD CONSTRAINT user_warnings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE;
|
ADD CONSTRAINT user_warnings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."user"(id) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- ============================================================
|
||||||
|
-- Migrations not present in the original pg_dump
|
||||||
|
-- ============================================================
|
||||||
|
|
||||||
|
-- Migration: anon_identities
|
||||||
|
CREATE TABLE IF NOT EXISTS public.anon_identities (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES public."user"(id) ON DELETE CASCADE,
|
||||||
|
pubkey TEXT UNIQUE,
|
||||||
|
fingerprint TEXT UNIQUE,
|
||||||
|
credential_id TEXT UNIQUE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
last_seen TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
created_ip VARCHAR(128),
|
||||||
|
last_ip VARCHAR(128),
|
||||||
|
hw_fingerprint VARCHAR(128)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_identities_pubkey ON public.anon_identities(pubkey);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_identities_fingerprint ON public.anon_identities(fingerprint);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_identities_user_id ON public.anon_identities(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_identities_credential_id ON public.anon_identities(credential_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_identities_hw ON public.anon_identities(hw_fingerprint);
|
||||||
|
|
||||||
|
-- Migration: passkey_credentials
|
||||||
|
CREATE TABLE IF NOT EXISTS public.passkey_credentials (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES public."user"(id) ON DELETE CASCADE,
|
||||||
|
credential_id TEXT NOT NULL UNIQUE,
|
||||||
|
public_key_spki TEXT NOT NULL,
|
||||||
|
sign_count BIGINT NOT NULL DEFAULT 0,
|
||||||
|
aaguid TEXT,
|
||||||
|
name TEXT,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
last_used TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_passkey_credential_id ON public.passkey_credentials(credential_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_passkey_user_id ON public.passkey_credentials(user_id);
|
||||||
|
|
||||||
|
-- Migration: anon_activity_log and ban tables
|
||||||
|
CREATE TABLE IF NOT EXISTS anon_activity_log (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INT NOT NULL,
|
||||||
|
fingerprint VARCHAR(128),
|
||||||
|
hw_fingerprint VARCHAR(128),
|
||||||
|
action VARCHAR(64) NOT NULL,
|
||||||
|
target_id INT,
|
||||||
|
ip VARCHAR(128) NOT NULL,
|
||||||
|
user_agent TEXT,
|
||||||
|
details JSONB,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_act_user_id ON anon_activity_log (user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_act_action ON anon_activity_log (action);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_act_ip ON anon_activity_log (ip);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_act_created ON anon_activity_log (created_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_anon_activity_hw ON anon_activity_log(hw_fingerprint);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS banned_ips (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
ip VARCHAR(128) NOT NULL UNIQUE,
|
||||||
|
ip_hash VARCHAR(128),
|
||||||
|
reason TEXT DEFAULT 'Banned by administrator',
|
||||||
|
banned_by INT,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
expires_at TIMESTAMP WITH TIME ZONE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_banned_ips_ip ON banned_ips (ip);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_banned_ips_hash ON banned_ips (ip_hash);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS banned_fingerprints (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
fingerprint VARCHAR(128) NOT NULL UNIQUE,
|
||||||
|
pubkey TEXT,
|
||||||
|
reason TEXT DEFAULT 'Banned by administrator',
|
||||||
|
banned_by INT,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
expires_at TIMESTAMP WITH TIME ZONE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_banned_fp_fp ON banned_fingerprints (fingerprint);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS banned_hardware_fingerprints (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
hw_fingerprint VARCHAR(128) UNIQUE NOT NULL,
|
||||||
|
banned_by INT REFERENCES "user"(id) ON DELETE SET NULL,
|
||||||
|
reason TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
expires_at TIMESTAMPTZ
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_banned_hw_fp ON banned_hardware_fingerprints(hw_fingerprint);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_banned_hw_expires ON banned_hardware_fingerprints(expires_at);
|
||||||
|
|
||||||
|
-- Add IP columns to comments/items if missing
|
||||||
|
ALTER TABLE comments ADD COLUMN IF NOT EXISTS ip VARCHAR(128);
|
||||||
|
ALTER TABLE items ADD COLUMN IF NOT EXISTS uploader_ip VARCHAR(128);
|
||||||
|
|
||||||
|
-- Migration: album support
|
||||||
|
ALTER TABLE public.items ADD COLUMN IF NOT EXISTS is_album boolean DEFAULT false;
|
||||||
|
ALTER TABLE public.items ADD COLUMN IF NOT EXISTS album_count integer DEFAULT 0;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.album_items (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
item_id INTEGER NOT NULL REFERENCES public.items(id) ON DELETE CASCADE,
|
||||||
|
dest CHARACTER VARYING(60) NOT NULL,
|
||||||
|
mime CHARACTER VARYING(100) NOT NULL,
|
||||||
|
size INTEGER NOT NULL,
|
||||||
|
checksum CHARACTER VARYING(255) NOT NULL,
|
||||||
|
phash TEXT,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
order_index INTEGER NOT NULL DEFAULT 0,
|
||||||
|
slug CHARACTER VARYING(60) DEFAULT NULL,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_album_items_item_id ON public.album_items(item_id, order_index ASC);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_album_items_slug ON public.album_items(slug);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.album_items_tags_assign (
|
||||||
|
album_item_id INTEGER NOT NULL REFERENCES public.album_items(id) ON DELETE CASCADE,
|
||||||
|
tag_id INTEGER NOT NULL REFERENCES public.tags(id) ON DELETE CASCADE,
|
||||||
|
user_id INTEGER REFERENCES public."user"(id) ON DELETE SET DEFAULT,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||||
|
PRIMARY KEY (album_item_id, tag_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_album_items_tags_assign_tag_id ON public.album_items_tags_assign(tag_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_album_items_tags_assign_album_item_id ON public.album_items_tags_assign(album_item_id);
|
||||||
|
|
||||||
|
-- Migration: user recommendation affinity
|
||||||
|
CREATE TABLE IF NOT EXISTS public.user_tag_affinity (
|
||||||
|
user_id integer NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||||
|
tag_id integer NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
|
||||||
|
score real DEFAULT 0.0,
|
||||||
|
interaction_count integer DEFAULT 1,
|
||||||
|
last_interacted timestamp with time zone DEFAULT now(),
|
||||||
|
PRIMARY KEY (user_id, tag_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_tag_affinity_user_score
|
||||||
|
ON public.user_tag_affinity(user_id, score DESC);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.user_creator_affinity (
|
||||||
|
user_id integer NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||||
|
creator_username text NOT NULL,
|
||||||
|
score real DEFAULT 0.0,
|
||||||
|
interaction_count integer DEFAULT 1,
|
||||||
|
last_interacted timestamp with time zone DEFAULT now(),
|
||||||
|
PRIMARY KEY (user_id, creator_username)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_creator_affinity_user_score
|
||||||
|
ON public.user_creator_affinity(user_id, score DESC);
|
||||||
|
|
||||||
|
-- ============================================================
|
||||||
|
-- End of consolidated migrations
|
||||||
|
-- ============================================================
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: alltables; Type: PUBLICATION; Schema: -; Owner: -
|
-- Name: alltables; Type: PUBLICATION; Schema: -; Owner: -
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user