new finctions and fixes

This commit is contained in:
Mateusz Gruszczyński
2026-07-30 00:12:48 +02:00
parent 9ca055de5f
commit 2274cf57c9
31 changed files with 1348 additions and 505 deletions
@@ -0,0 +1,23 @@
CREATE TABLE user_editor_preferences (
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
pad_id BIGINT REFERENCES pads(id) ON DELETE CASCADE,
note_id BIGINT REFERENCES notes(id) ON DELETE CASCADE,
authorship_mode TEXT NOT NULL DEFAULT 'simple',
colors_enabled BOOLEAN NOT NULL DEFAULT TRUE,
compact_view BOOLEAN NOT NULL DEFAULT TRUE,
editor_line_numbers BOOLEAN NOT NULL DEFAULT TRUE,
preview_line_numbers BOOLEAN NOT NULL DEFAULT FALSE,
line_links BOOLEAN NOT NULL DEFAULT FALSE,
font_family TEXT NOT NULL DEFAULT 'mono',
font_size BIGINT NOT NULL DEFAULT 14,
updated_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP::text),
CHECK ((pad_id IS NOT NULL AND note_id IS NULL) OR (pad_id IS NULL AND note_id IS NOT NULL)),
UNIQUE (user_id, pad_id),
UNIQUE (user_id, note_id)
);
CREATE INDEX idx_user_editor_preferences_user ON user_editor_preferences(user_id);
CREATE INDEX idx_user_editor_preferences_pad ON user_editor_preferences(pad_id);
CREATE INDEX idx_user_editor_preferences_note ON user_editor_preferences(note_id);
DROP TABLE resource_editor_settings;
@@ -0,0 +1,40 @@
CREATE TABLE resource_editor_settings (
resource_kind TEXT NOT NULL,
resource_slug TEXT NOT NULL,
authorship_mode TEXT NOT NULL DEFAULT 'simple',
colors_enabled BOOLEAN NOT NULL DEFAULT TRUE,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (resource_kind, resource_slug)
);
INSERT INTO resource_editor_settings (
resource_kind, resource_slug, authorship_mode, colors_enabled, updated_at
)
SELECT 'pad', p.slug, preferences.authorship_mode, preferences.colors_enabled,
preferences.updated_at::timestamptz
FROM user_editor_preferences preferences
JOIN pads p ON p.id = preferences.pad_id
JOIN user_pads ownership
ON ownership.pad_id = p.id
AND ownership.user_id = preferences.user_id
WHERE preferences.pad_id IS NOT NULL
ON CONFLICT (resource_kind, resource_slug) DO NOTHING;
INSERT INTO resource_editor_settings (
resource_kind, resource_slug, authorship_mode, colors_enabled, updated_at
)
SELECT 'note', workspace.slug || '/' || note.slug,
preferences.authorship_mode, preferences.colors_enabled,
preferences.updated_at::timestamptz
FROM user_editor_preferences preferences
JOIN notes note ON note.id = preferences.note_id
JOIN workspaces workspace ON workspace.id = note.workspace_id
JOIN user_workspaces ownership
ON ownership.workspace_id = workspace.id
AND ownership.user_id = preferences.user_id
WHERE preferences.note_id IS NOT NULL
ON CONFLICT (resource_kind, resource_slug) DO NOTHING;
ALTER TABLE user_editor_preferences
DROP COLUMN authorship_mode,
DROP COLUMN colors_enabled;