Skip to content

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

Tenancy: add label_key table to bytebase database. (#82)

spinningbotece5f95ce5b0
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index ce1afcf43d..c8eee4b75b 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -1265,3 +1265,37 @@ WHERE
rowid = old.rowid;
END;
+
+-- Label
+-- label_key stores available label keys at workspace level.
+CREATE TABLE label_key (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED')
+ ) 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')),
+ key TEXT NOT NULL UNIQUE
+);
+
+CREATE UNIQUE INDEX idx_label_key_key ON label_key(key);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('label_key', 100);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_label_key_modification_time`
+AFTER
+UPDATE
+ ON `label_key` FOR EACH ROW BEGIN
+UPDATE
+ `label_key`
+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 48c6a2f077..c55259179b 100644
--- a/store/seed/test/10000__reset.sql
+++ b/store/seed/test/10000__reset.sql
@@ -86,6 +86,9 @@ DELETE FROM
DELETE FROM
project_member;
+DELETE FROM
+ label_key;
+
-- Project 1 refers to DEFAULT project which is considered as part of schema
DELETE FROM
project
diff --git a/store/seed/test/10200__label.sql b/store/seed/test/10200__label.sql
new file mode 100644
index 0000000000..2833377dd7
--- /dev/null
+++ b/store/seed/test/10200__label.sql
@@ -0,0 +1,31 @@
+-- Label key for `bb.location`.
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 20001,
+ 1,
+ 1,
+ 'bb.location'
+ );
+
+-- Label key for `bb.tenant`.
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 20002,
+ 1,
+ 1,
+ 'bb.tenant'
+ );