Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(sql-editor): create a new table named sheet (#474)

Yunwei Xiao532e3621a17d
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 5b49fdcdcb..9ab4185a9b 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -1416,3 +1416,44 @@ WHERE
rowid = old.rowid;
END;
+
+-- sheet table stores the query for the user
+CREATE TABLE sheet (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ -- allowed row status are 'NORMAL', 'ARCHIVED'.
+ row_status TEXT NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ database_id INTEGER NULL REFERENCES db (id),
+ name TEXT NOT NULL,
+ statement TEXT NOT NULL,
+ -- allowed visibilities are 'PRIVATE', 'PROJECT', 'PUBLIC'.
+ visibility TEXT NOT NULL DEFAULT 'PRIVATE'
+);
+
+CREATE INDEX idx_sheet_creator_id ON sheet(creator_id);
+
+CREATE INDEX idx_sheet_instance_id_row_status ON sheet(instance_id, row_status);
+
+CREATE INDEX idx_sheet_database_id_row_status ON sheet(database_id, row_status);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('sheet', 100);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_sheet_modification_time`
+AFTER
+UPDATE
+ ON `sheet` FOR EACH ROW BEGIN
+UPDATE
+ `sheet`
+SET
+ updated_ts = (strftime('%s', 'now'))
+WHERE
+ rowid = old.rowid;
+
+END;
diff --git a/store/seed/test/10000__reset.sql b/store/seed/test/10000__reset.sql
index 8d521e1db0..2b1dcef87c 100644
--- a/store/seed/test/10000__reset.sql
+++ b/store/seed/test/10000__reset.sql
@@ -102,6 +102,9 @@ DELETE FROM
DELETE FROM
saved_query;
+DELETE FROM
+ sheet;
+
-- Project 1 refers to DEFAULT project which is considered as part of schema
DELETE FROM
project