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,25 @@
CREATE TABLE user_editor_preferences (
user_id BIGINT NOT NULL,
pad_id BIGINT NULL,
note_id BIGINT NULL,
authorship_mode VARCHAR(16) 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 VARCHAR(16) NOT NULL DEFAULT 'mono',
font_size BIGINT NOT NULL DEFAULT 14,
updated_at VARCHAR(64) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
CONSTRAINT fk_user_editor_preferences_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_user_editor_preferences_pad FOREIGN KEY (pad_id) REFERENCES pads(id) ON DELETE CASCADE,
CONSTRAINT fk_user_editor_preferences_note FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE,
CONSTRAINT chk_user_editor_preferences_resource CHECK ((pad_id IS NOT NULL AND note_id IS NULL) OR (pad_id IS NULL AND note_id IS NOT NULL)),
UNIQUE KEY uq_user_editor_preferences_pad (user_id, pad_id),
UNIQUE KEY uq_user_editor_preferences_note (user_id, note_id),
INDEX idx_user_editor_preferences_user (user_id),
INDEX idx_user_editor_preferences_pad (pad_id),
INDEX idx_user_editor_preferences_note (note_id)
) ENGINE=InnoDB;
DROP TABLE resource_editor_settings;
@@ -0,0 +1,40 @@
CREATE TABLE resource_editor_settings (
resource_kind VARCHAR(32) NOT NULL,
resource_slug VARCHAR(512) NOT NULL,
authorship_mode VARCHAR(16) NOT NULL DEFAULT 'simple',
colors_enabled BOOLEAN NOT NULL DEFAULT TRUE,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
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,
CURRENT_TIMESTAMP
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 DUPLICATE KEY UPDATE resource_slug = VALUES(resource_slug);
INSERT INTO resource_editor_settings (
resource_kind, resource_slug, authorship_mode, colors_enabled, updated_at
)
SELECT 'note', CONCAT(workspace.slug, '/', note.slug),
preferences.authorship_mode, preferences.colors_enabled,
CURRENT_TIMESTAMP
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 DUPLICATE KEY UPDATE resource_slug = VALUES(resource_slug);
ALTER TABLE user_editor_preferences
DROP COLUMN authorship_mode,
DROP COLUMN colors_enabled;