nix: set up project-wide formatter
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I4806c58aa0a17f504c9312723ad770166a6a6964
This commit is contained in:
parent
aa9c55277c
commit
9e5eb41d39
78 changed files with 7406 additions and 2504 deletions
|
|
@ -1,68 +1,85 @@
|
|||
-- V17: Enhanced Sharing System
|
||||
-- Replaces simple share_links with comprehensive sharing capabilities
|
||||
|
||||
-- Enhanced shares table
|
||||
CREATE TABLE shares (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
target_type TEXT NOT NULL CHECK (target_type IN ('media', 'collection', 'tag', 'saved_search')),
|
||||
target_id TEXT NOT NULL,
|
||||
owner_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
recipient_type TEXT NOT NULL CHECK (recipient_type IN ('public_link', 'user', 'group', 'federated')),
|
||||
recipient_user_id TEXT REFERENCES users(id) ON DELETE CASCADE,
|
||||
recipient_group_id TEXT,
|
||||
recipient_federated_handle TEXT,
|
||||
recipient_federated_server TEXT,
|
||||
public_token TEXT UNIQUE,
|
||||
public_password_hash TEXT,
|
||||
perm_view BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
perm_download BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_edit BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_delete BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_reshare BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_add BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
note TEXT,
|
||||
expires_at TIMESTAMPTZ,
|
||||
access_count BIGINT NOT NULL DEFAULT 0,
|
||||
last_accessed TIMESTAMPTZ,
|
||||
inherit_to_children BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
parent_share_id TEXT REFERENCES shares(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
UNIQUE(owner_id, target_type, target_id, recipient_type, recipient_user_id)
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
target_type TEXT NOT NULL CHECK (
|
||||
target_type IN ('media', 'collection', 'tag', 'saved_search')
|
||||
),
|
||||
target_id TEXT NOT NULL,
|
||||
owner_id TEXT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
recipient_type TEXT NOT NULL CHECK (
|
||||
recipient_type IN ('public_link', 'user', 'group', 'federated')
|
||||
),
|
||||
recipient_user_id TEXT REFERENCES users (id) ON DELETE CASCADE,
|
||||
recipient_group_id TEXT,
|
||||
recipient_federated_handle TEXT,
|
||||
recipient_federated_server TEXT,
|
||||
public_token TEXT UNIQUE,
|
||||
public_password_hash TEXT,
|
||||
perm_view BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
perm_download BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_edit BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_delete BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_reshare BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
perm_add BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
note TEXT,
|
||||
expires_at TIMESTAMPTZ,
|
||||
access_count BIGINT NOT NULL DEFAULT 0,
|
||||
last_accessed TIMESTAMPTZ,
|
||||
inherit_to_children BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
parent_share_id TEXT REFERENCES shares (id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
UNIQUE (
|
||||
owner_id,
|
||||
target_type,
|
||||
target_id,
|
||||
recipient_type,
|
||||
recipient_user_id
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_shares_owner ON shares(owner_id);
|
||||
CREATE INDEX idx_shares_recipient_user ON shares(recipient_user_id);
|
||||
CREATE INDEX idx_shares_target ON shares(target_type, target_id);
|
||||
CREATE INDEX idx_shares_token ON shares(public_token);
|
||||
CREATE INDEX idx_shares_expires ON shares(expires_at);
|
||||
CREATE INDEX idx_shares_owner ON shares (owner_id);
|
||||
|
||||
CREATE INDEX idx_shares_recipient_user ON shares (recipient_user_id);
|
||||
|
||||
CREATE INDEX idx_shares_target ON shares (target_type, target_id);
|
||||
|
||||
CREATE INDEX idx_shares_token ON shares (public_token);
|
||||
|
||||
CREATE INDEX idx_shares_expires ON shares (expires_at);
|
||||
|
||||
-- Share activity log
|
||||
CREATE TABLE share_activity (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
share_id TEXT NOT NULL REFERENCES shares(id) ON DELETE CASCADE,
|
||||
actor_id TEXT REFERENCES users(id) ON DELETE SET NULL,
|
||||
actor_ip TEXT,
|
||||
action TEXT NOT NULL,
|
||||
details TEXT,
|
||||
timestamp TIMESTAMPTZ NOT NULL
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
share_id TEXT NOT NULL REFERENCES shares (id) ON DELETE CASCADE,
|
||||
actor_id TEXT REFERENCES users (id) ON DELETE SET NULL,
|
||||
actor_ip TEXT,
|
||||
action TEXT NOT NULL,
|
||||
details TEXT,
|
||||
timestamp TIMESTAMPTZ NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_share_activity_share ON share_activity(share_id);
|
||||
CREATE INDEX idx_share_activity_timestamp ON share_activity(timestamp);
|
||||
CREATE INDEX idx_share_activity_share ON share_activity (share_id);
|
||||
|
||||
CREATE INDEX idx_share_activity_timestamp ON share_activity (timestamp);
|
||||
|
||||
-- Share notifications
|
||||
CREATE TABLE share_notifications (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
share_id TEXT NOT NULL REFERENCES shares(id) ON DELETE CASCADE,
|
||||
notification_type TEXT NOT NULL,
|
||||
is_read BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
user_id TEXT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
share_id TEXT NOT NULL REFERENCES shares (id) ON DELETE CASCADE,
|
||||
notification_type TEXT NOT NULL,
|
||||
is_read BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_share_notifications_user ON share_notifications(user_id);
|
||||
CREATE INDEX idx_share_notifications_unread ON share_notifications(user_id) WHERE is_read = FALSE;
|
||||
CREATE INDEX idx_share_notifications_user ON share_notifications (user_id);
|
||||
|
||||
CREATE INDEX idx_share_notifications_unread ON share_notifications (user_id)
|
||||
WHERE
|
||||
is_read = FALSE;
|
||||
|
||||
-- Migrate existing share_links to new shares table
|
||||
DO $$
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue