added history option field to db

This commit is contained in:
Sergey Kurdin 2024-06-29 00:09:59 -04:00
parent 1115b5a73e
commit 07860c0662
7 changed files with 144 additions and 9 deletions

View File

@ -1,4 +1,4 @@
-- Creating a temporary table without the new columns for link_metadata
-- Rollback for link_metadata table
CREATE TEMPORARY TABLE link_metadata_backup(
metadata_id VARCHAR(50) PRIMARY KEY,
history_id VARCHAR(50) UNIQUE,
@ -11,17 +11,93 @@ CREATE TEMPORARY TABLE link_metadata_backup(
link_favicon TEXT
);
-- Inserting data from the original table to the temporary table
INSERT INTO link_metadata_backup SELECT metadata_id, history_id, item_id, link_url, link_title, link_description, link_image, link_domain, link_favicon FROM link_metadata;
INSERT INTO link_metadata_backup SELECT
metadata_id, history_id, item_id, link_url, link_title,
link_description, link_image, link_domain, link_favicon
FROM link_metadata;
-- Dropping the original table
DROP TABLE link_metadata;
-- Renaming the backup table to the original name
ALTER TABLE link_metadata_backup RENAME TO link_metadata;
-- Handling the items table similarly
CREATE TEMPORARY TABLE items_backup AS SELECT * FROM items;
ALTER TABLE items_backup DROP COLUMN item_options;
-- Rollback for items table
CREATE TEMPORARY TABLE items_backup(
item_id VARCHAR(50) PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
value VARCHAR(255),
color VARCHAR(50),
border_width INT DEFAULT 0,
is_image BOOLEAN DEFAULT FALSE,
image_path_full_res VARCHAR(255),
image_preview_height INT DEFAULT 0,
image_height INT DEFAULT 0,
image_width INT DEFAULT 0,
image_data_url VARCHAR(255),
image_type VARCHAR(255),
image_hash VARCHAR(255),
image_scale INT DEFAULT 1,
is_image_data BOOLEAN DEFAULT FALSE,
is_masked BOOLEAN DEFAULT FALSE,
is_text BOOLEAN DEFAULT FALSE,
is_form BOOLEAN DEFAULT FALSE,
is_template BOOLEAN DEFAULT FALSE,
is_code BOOLEAN DEFAULT FALSE,
is_link BOOLEAN DEFAULT FALSE,
is_path BOOLEAN DEFAULT FALSE,
is_file BOOLEAN DEFAULT FALSE,
is_pinned BOOLEAN DEFAULT FALSE,
is_favorite BOOLEAN DEFAULT FALSE,
is_protected BOOLEAN DEFAULT FALSE,
is_command BOOLEAN DEFAULT FALSE,
is_web_request BOOLEAN DEFAULT FALSE,
is_web_scraping BOOLEAN DEFAULT FALSE,
is_video BOOLEAN DEFAULT FALSE,
has_emoji BOOLEAN DEFAULT FALSE,
has_masked_words BOOLEAN DEFAULT FALSE,
path_type VARCHAR(20),
icon VARCHAR(20),
icon_visibility VARCHAR(20),
command_request_output TEXT,
command_request_last_run_at BIGINT,
request_options TEXT,
form_template_options TEXT,
links TEXT,
detected_language VARCHAR(20),
is_active BOOLEAN NOT NULL DEFAULT TRUE,
is_disabled BOOLEAN NOT NULL DEFAULT FALSE,
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
is_folder BOOLEAN NOT NULL DEFAULT FALSE,
is_separator BOOLEAN NOT NULL DEFAULT FALSE,
is_board BOOLEAN NOT NULL DEFAULT FALSE,
is_menu BOOLEAN NOT NULL DEFAULT FALSE,
is_clip BOOLEAN NOT NULL DEFAULT FALSE,
size VARCHAR(10),
layout VARCHAR(10),
layout_items_max_width VARCHAR(10),
layout_split INT NOT NULL DEFAULT 1,
show_description BOOLEAN DEFAULT TRUE,
pinned_order_number INT DEFAULT 0,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
created_date TIMESTAMP NOT NULL,
updated_date TIMESTAMP NOT NULL
);
INSERT INTO items_backup SELECT
item_id, name, description, value, color, border_width, is_image,
image_path_full_res, image_preview_height, image_height, image_width,
image_data_url, image_type, image_hash, image_scale, is_image_data,
is_masked, is_text, is_form, is_template, is_code, is_link, is_path,
is_file, is_pinned, is_favorite, is_protected, is_command,
is_web_request, is_web_scraping, is_video, has_emoji, has_masked_words,
path_type, icon, icon_visibility, command_request_output,
command_request_last_run_at, request_options, form_template_options,
links, detected_language, is_active, is_disabled, is_deleted,
is_folder, is_separator, is_board, is_menu, is_clip, size, layout,
layout_items_max_width, layout_split, show_description,
pinned_order_number, created_at, updated_at, created_date, updated_date
FROM items;
DROP TABLE items;
ALTER TABLE items_backup RENAME TO items;
ALTER TABLE items_backup RENAME TO items;

View File

@ -0,0 +1,48 @@
-- Rollback for clipboard_history table
CREATE TABLE clipboard_history_new (
history_id VARCHAR(50) PRIMARY KEY NOT NULL,
title VARCHAR(255),
value VARCHAR(255),
value_preview VARCHAR(150),
value_more_preview_lines INT DEFAULT 0,
value_more_preview_chars INT DEFAULT 0,
value_hash VARCHAR(255),
is_image BOOLEAN DEFAULT FALSE,
image_path_full_res VARCHAR(255),
image_data_low_res BLOB,
image_preview_height INT DEFAULT 0,
image_height INT DEFAULT 0,
image_width INT DEFAULT 0,
image_data_url VARCHAR(255),
image_hash VARCHAR(255),
is_image_data BOOLEAN DEFAULT FALSE,
is_masked BOOLEAN DEFAULT FALSE,
is_text BOOLEAN DEFAULT FALSE,
is_code BOOLEAN DEFAULT FALSE,
is_link BOOLEAN DEFAULT FALSE,
is_video BOOLEAN DEFAULT FALSE,
has_emoji BOOLEAN DEFAULT FALSE,
has_masked_words BOOLEAN DEFAULT FALSE,
is_pinned BOOLEAN DEFAULT FALSE,
is_favorite BOOLEAN DEFAULT FALSE,
links TEXT,
detected_language VARCHAR(20),
pinned_order_number INT DEFAULT 0,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
created_date TIMESTAMP NOT NULL,
updated_date TIMESTAMP NOT NULL
);
INSERT INTO clipboard_history_new SELECT
history_id, title, value, value_preview, value_more_preview_lines,
value_more_preview_chars, value_hash, is_image, image_path_full_res,
image_data_low_res, image_preview_height, image_height, image_width,
image_data_url, image_hash, is_image_data, is_masked, is_text, is_code,
is_link, is_video, has_emoji, has_masked_words, is_pinned, is_favorite,
links, detected_language, pinned_order_number, created_at, updated_at,
created_date, updated_date
FROM clipboard_history;
DROP TABLE clipboard_history;
ALTER TABLE clipboard_history_new RENAME TO clipboard_history;

View File

@ -0,0 +1,2 @@
-- Adding new column to items table
ALTER TABLE clipboard_history ADD COLUMN history_options TEXT;

View File

@ -100,6 +100,7 @@ pub struct UpdatedItemData {
pub icon: Option<String>,
pub icon_visibility: Option<String>,
pub detected_language: Option<String>,
pub pinned_order_number: Option<i32>,
pub command_request_output: Option<String>,
pub command_request_last_run_at: Option<i64>,
@ -113,6 +114,7 @@ pub struct UpdatedItemData {
#[diesel(table_name = clipboard_history)]
pub struct UpdatedHistoryData {
pub history_id: Option<String>,
pub history_options: Option<String>,
pub title: Option<String>,
pub value: Option<String>,
pub is_text: Option<bool>,
@ -271,6 +273,7 @@ pub struct ClipboardHistory {
pub updated_at: i64,
pub created_date: NaiveDateTime,
pub updated_date: NaiveDateTime,
pub history_options: Option<String>,
}
#[derive(

View File

@ -34,6 +34,7 @@ diesel::table! {
updated_at -> BigInt,
created_date -> Timestamp,
updated_date -> Timestamp,
history_options -> Nullable<Text>,
}
}

View File

@ -100,6 +100,7 @@ pub struct RecentClipboardHistoryData {
#[serde(rename_all = "camelCase")]
pub struct ClipboardHistoryWithMetaData {
pub history_id: String,
pub history_options: Option<String>,
pub title: Option<String>,
pub value: Option<String>,
pub value_preview: Option<String>,
@ -174,6 +175,7 @@ impl ClipboardHistoryWithMetaData {
updated_at: history.updated_at,
created_date: history.created_date,
updated_date: history.updated_date,
history_options: history.history_options,
link_metadata,
};
@ -320,6 +322,7 @@ fn create_new_history(
) -> ClipboardHistory {
ClipboardHistory {
history_id: _history_id,
history_options: None,
title: None,
value: None,
value_preview: None,
@ -493,6 +496,7 @@ pub fn add_clipboard_history_from_text(
let new_history = ClipboardHistory {
history_id: new_history_id,
history_options: None,
title: None,
value: if !_text_as_json.is_empty() {
Some(_text_as_json)

View File

@ -36,6 +36,7 @@ use super::utils::delete_file_and_maybe_parent;
#[serde(rename_all = "camelCase")]
pub struct CreateItem {
pub history_id: Option<String>,
pub history_options: Option<String>,
pub item_options: Option<String>,
pub name: String,
pub description: Option<String>,