business: add privacy-aware user projection
(cherry picked from commit a636192ef22ee69d792b0ca7db1c6be963be9cb2)
This commit is contained in:
parent
14d220c971
commit
8ff3343ae0
29 changed files with 2239 additions and 112 deletions
|
|
@ -0,0 +1,26 @@
|
|||
DROP INDEX IF EXISTS contacts_personal_photo_idx;
|
||||
|
||||
ALTER TABLE contacts
|
||||
DROP COLUMN IF EXISTS personal_photo_date,
|
||||
DROP COLUMN IF EXISTS personal_photo_id;
|
||||
|
||||
DROP INDEX IF EXISTS profile_photos_current_idx;
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
DROP CONSTRAINT IF EXISTS profile_photos_kind_check;
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
DROP CONSTRAINT IF EXISTS profile_photos_pkey;
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
ADD CONSTRAINT profile_photos_pkey PRIMARY KEY (owner_peer_type, owner_peer_id, photo_id);
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
DROP COLUMN IF EXISTS kind;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS profile_photos_current_idx
|
||||
ON profile_photos (owner_peer_type, owner_peer_id, sort_order DESC)
|
||||
WHERE active;
|
||||
|
||||
DROP TABLE IF EXISTS account_privacy_rules;
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
-- 0069_privacy_and_profile_photo_kinds: account privacy rules, fallback photos,
|
||||
-- and viewer-private contact profile photos.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS account_privacy_rules (
|
||||
owner_user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
privacy_key TEXT NOT NULL,
|
||||
rules JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (owner_user_id, privacy_key)
|
||||
);
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL DEFAULT 'profile';
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
DROP CONSTRAINT IF EXISTS profile_photos_pkey;
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
ADD CONSTRAINT profile_photos_pkey PRIMARY KEY (owner_peer_type, owner_peer_id, kind, photo_id);
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
DROP CONSTRAINT IF EXISTS profile_photos_kind_check;
|
||||
|
||||
ALTER TABLE profile_photos
|
||||
ADD CONSTRAINT profile_photos_kind_check CHECK (kind IN ('profile', 'fallback'));
|
||||
|
||||
DROP INDEX IF EXISTS profile_photos_current_idx;
|
||||
CREATE INDEX IF NOT EXISTS profile_photos_current_idx
|
||||
ON profile_photos (owner_peer_type, owner_peer_id, kind, sort_order DESC)
|
||||
WHERE active;
|
||||
|
||||
ALTER TABLE contacts
|
||||
ADD COLUMN IF NOT EXISTS personal_photo_id BIGINT NOT NULL DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS personal_photo_date INT NOT NULL DEFAULT 0;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS contacts_personal_photo_idx
|
||||
ON contacts (user_id, contact_user_id)
|
||||
WHERE personal_photo_id <> 0;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue