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;
