ALTER TABLE workspaces ADD COLUMN is_private BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE pads ADD COLUMN is_private BOOLEAN NOT NULL DEFAULT FALSE;
CREATE TABLE resource_permissions (
 resource_kind VARCHAR(16) NOT NULL,
 resource_slug VARCHAR(255) NOT NULL,
 user_id BIGINT NOT NULL,
 permission VARCHAR(2) NOT NULL,
 created_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 PRIMARY KEY(resource_kind, resource_slug, user_id),
 CONSTRAINT fk_resource_permissions_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX idx_resource_permissions_user ON resource_permissions(user_id);
CREATE TABLE resource_share_links (
 token_hash VARCHAR(64) PRIMARY KEY,
 resource_kind VARCHAR(16) NOT NULL,
 resource_slug VARCHAR(255) NOT NULL,
 permission VARCHAR(2) NOT NULL,
 expires_at TEXT NULL,
 created_by BIGINT NOT NULL,
 created_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 revoked_at TEXT NULL,
 CONSTRAINT fk_resource_share_links_user FOREIGN KEY(created_by) REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX idx_resource_share_links_resource ON resource_share_links(resource_kind, resource_slug);
