From bf5247066db9291f2a52496ee974f8424da5c5a6 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 11 Jun 2022 17:13:52 +0800 Subject: [PATCH] refactor: sqlite schema --- .../down.sql | 0 .../up.sql | 0 .../down.sql | 0 .../up.sql | 0 .../migrations/2021-07-22-234458_flowy-editor/down.sql | 2 -- .../migrations/2021-07-22-234458_flowy-editor/up.sql | 7 ------- .../down.sql | 0 .../up.sql | 0 .../migrations/2022-03-04-101530_flowy-grid/down.sql | 2 -- .../migrations/2022-03-04-101530_flowy-grid/up.sql | 5 ----- .../down.sql | 1 + .../up.sql | 4 ++++ .../down.sql | 0 .../up.sql | 0 .../migrations/2022-06-11-090029_view-add-col/down.sql | 1 + .../migrations/2022-06-11-090029_view-add-col/up.sql | 2 ++ frontend/rust-lib/flowy-database/src/schema.rs | 10 +--------- .../src/services/persistence/version_1/view_sql.rs | 3 ++- 18 files changed, 11 insertions(+), 26 deletions(-) rename frontend/rust-lib/flowy-database/migrations/{2021-07-09-063045_flowy-user => 2021-07-09-063045_user}/down.sql (100%) rename frontend/rust-lib/flowy-database/migrations/{2021-07-09-063045_flowy-user => 2021-07-09-063045_user}/up.sql (100%) rename frontend/rust-lib/flowy-database/migrations/{2021-07-14-022241_flowy-user => 2021-07-14-022241_user-add-col}/down.sql (100%) rename frontend/rust-lib/flowy-database/migrations/{2021-07-14-022241_flowy-user => 2021-07-14-022241_user-add-col}/up.sql (100%) delete mode 100644 frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql delete mode 100644 frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql rename frontend/rust-lib/flowy-database/migrations/{2021-09-22-074638_flowy-doc-op => 2021-09-22-074638_revision}/down.sql (100%) rename frontend/rust-lib/flowy-database/migrations/{2021-09-22-074638_flowy-doc-op => 2021-09-22-074638_revision}/up.sql (100%) delete mode 100644 frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/down.sql delete mode 100644 frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/up.sql rename frontend/rust-lib/flowy-database/migrations/{2022-03-11-025536_flowy-grid => 2022-03-11-025536_grid}/down.sql (58%) rename frontend/rust-lib/flowy-database/migrations/{2022-03-11-025536_flowy-grid => 2022-03-11-025536_grid}/up.sql (85%) rename frontend/rust-lib/flowy-database/migrations/{2022-04-05-015536_flowy-grid-block-index => 2022-04-05-015536_grid-block-index}/down.sql (100%) rename frontend/rust-lib/flowy-database/migrations/{2022-04-05-015536_flowy-grid-block-index => 2022-04-05-015536_grid-block-index}/up.sql (100%) create mode 100644 frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/down.sql create mode 100644 frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/up.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/down.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_user/down.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/down.sql rename to frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_user/down.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_user/up.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql rename to frontend/rust-lib/flowy-database/migrations/2021-07-09-063045_user/up.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_user-add-col/down.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql rename to frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_user-add-col/down.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_user-add-col/up.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql rename to frontend/rust-lib/flowy-database/migrations/2021-07-14-022241_user-add-col/up.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql deleted file mode 100644 index 41dd39b71f..0000000000 --- a/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE doc_table; \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql b/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql deleted file mode 100644 index c5b88ab96f..0000000000 --- a/frontend/rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Your SQL goes here -CREATE TABLE doc_table ( - id TEXT NOT NULL PRIMARY KEY, --- data BLOB NOT NULL DEFAULT (x''), - data TEXT NOT NULL DEFAULT '', - rev_id BIGINT NOT NULL DEFAULT 0 -); \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_flowy-doc-op/down.sql b/frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_revision/down.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_flowy-doc-op/down.sql rename to frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_revision/down.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_flowy-doc-op/up.sql b/frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_revision/up.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_flowy-doc-op/up.sql rename to frontend/rust-lib/flowy-database/migrations/2021-09-22-074638_revision/up.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/down.sql b/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/down.sql deleted file mode 100644 index 96473ec177..0000000000 --- a/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE kv_table; \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/up.sql b/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/up.sql deleted file mode 100644 index edde5d7dfa..0000000000 --- a/frontend/rust-lib/flowy-database/migrations/2022-03-04-101530_flowy-grid/up.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Your SQL goes here -CREATE TABLE kv_table ( - key TEXT NOT NULL PRIMARY KEY, - value BLOB NOT NULL DEFAULT (x'') -); \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/down.sql b/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/down.sql similarity index 58% rename from frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/down.sql rename to frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/down.sql index 9d48f0fb8a..54ad291ac7 100644 --- a/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/down.sql +++ b/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/down.sql @@ -1,3 +1,4 @@ -- This file should undo anything in `up.sql` +DROP TABLE kv_table; DROP TABLE grid_rev_table; DROP TABLE grid_meta_rev_table; \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/up.sql b/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/up.sql similarity index 85% rename from frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/up.sql rename to frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/up.sql index 4ce278ec8f..655533fc93 100644 --- a/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_flowy-grid/up.sql +++ b/frontend/rust-lib/flowy-database/migrations/2022-03-11-025536_grid/up.sql @@ -1,4 +1,8 @@ -- Your SQL goes here +CREATE TABLE kv_table ( + key TEXT NOT NULL PRIMARY KEY, + value BLOB NOT NULL DEFAULT (x'') +); CREATE TABLE grid_rev_table ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, object_id TEXT NOT NULL DEFAULT '', diff --git a/frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_flowy-grid-block-index/down.sql b/frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_grid-block-index/down.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_flowy-grid-block-index/down.sql rename to frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_grid-block-index/down.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_flowy-grid-block-index/up.sql b/frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_grid-block-index/up.sql similarity index 100% rename from frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_flowy-grid-block-index/up.sql rename to frontend/rust-lib/flowy-database/migrations/2022-04-05-015536_grid-block-index/up.sql diff --git a/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/down.sql b/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/down.sql new file mode 100644 index 0000000000..291a97c5ce --- /dev/null +++ b/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/up.sql b/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/up.sql new file mode 100644 index 0000000000..c4545a457c --- /dev/null +++ b/frontend/rust-lib/flowy-database/migrations/2022-06-11-090029_view-add-col/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE view_table ADD COLUMN ext_data TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/frontend/rust-lib/flowy-database/src/schema.rs b/frontend/rust-lib/flowy-database/src/schema.rs index 8fddd037e0..b131adf05f 100644 --- a/frontend/rust-lib/flowy-database/src/schema.rs +++ b/frontend/rust-lib/flowy-database/src/schema.rs @@ -13,14 +13,6 @@ table! { } } -table! { - doc_table (id) { - id -> Text, - data -> Text, - rev_id -> BigInt, - } -} - table! { grid_block_index_table (row_id) { row_id -> Text, @@ -102,6 +94,7 @@ table! { view_type -> Integer, version -> BigInt, is_trash -> Bool, + ext_data -> Text, } } @@ -119,7 +112,6 @@ table! { allow_tables_to_appear_in_same_query!( app_table, - doc_table, grid_block_index_table, grid_meta_rev_table, grid_rev_table, diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs index bda73dd71d..cbbcf48bfb 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs @@ -79,6 +79,7 @@ pub(crate) struct ViewTable { pub view_type: SqlViewDataType, pub version: i64, pub is_trash: bool, + pub ext_data: String, } impl ViewTable { @@ -120,7 +121,7 @@ impl std::convert::From for View { modified_time: table.modified_time, version: table.version, create_time: table.create_time, - ext_data: "".to_string(), + ext_data: table.ext_data, thumbnail: table.thumbnail, // Store the view in ViewTable was deprecated since v0.0.2. // No need worry about plugin_type.