Skip to content

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

Add principal and workspace schema and seed testing data

天舟704cab533be9
diff --git a/backend/sqlite/migration/0001_init_schema.down.sql b/backend/sqlite/migration/0001_init_schema.down.sql
index 471f45925c..af74080369 100644
--- a/backend/sqlite/migration/0001_init_schema.down.sql
+++ b/backend/sqlite/migration/0001_init_schema.down.sql
@@ -1 +1,4 @@
-DROP TABLE principal;
\ No newline at end of file
+DROP TABLE workspace;
+
+DROP TABLE principal;
+
diff --git a/backend/sqlite/migration/0001_init_schema.up.sql b/backend/sqlite/migration/0001_init_schema.up.sql
index 658feaaa4b..f8da5634e7 100644
--- a/backend/sqlite/migration/0001_init_schema.up.sql
+++ b/backend/sqlite/migration/0001_init_schema.up.sql
@@ -1,11 +1,68 @@
CREATE TABLE principal (
id INTEGER PRIMARY KEY AUTOINCREMENT,
- creatorId INTEGER NOT NULL,
- createdTs INTEGER NOT NULL,
- updaterId INTEGER NOT NULL,
- updatedTs INTEGER NOT NULL,
- status TEXT NOT NULL,
- type TEXT NOT NULL,
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ -- "INVITED" | "ACTIVE"
+ `status` TEXT NOT NULL,
+ -- "END_USER" | "SYSTEM_BOT"
+ `type` TEXT NOT NULL,
name TEXT NOT NULL,
- email TEXT NOT NULL
-);
\ No newline at end of file
+ email TEXT NOT NULL,
+ password_hash TEXT NOT NULL
+);
+
+-- Default bytebase system account id is 1
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'SYSTEM_BOT',
+ 'Bytebase',
+ ''
+ );
+
+-- We only allow a single workspace for on-premise deployment.
+-- So theoretically speaking, we don't need to create a workspace table.
+-- But we create this table mostly for preparing a future cloud version
+-- where we need to support many workspaces and it would be painful to
+-- introduce workspace table at that time.
+CREATE TABLE workspace (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ -- "NORMAL" | "ARCHIVED" | "PENDING_DELETE"
+ row_status TEXT NOT NULL,
+ slug TEXT NOT NULL UNIQUE,
+ name TEXT NOT NULL
+);
+
+-- Default workspace for on-premise deployment, id is 1
+INSERT INTO
+ workspace (
+ id,
+ creator_id,
+ updater_id,
+ row_status,
+ slug,
+ name
+ )
+VALUES
+ (1, 1, 1, 'NORMAL', '', 'Default workspace');
\ No newline at end of file
diff --git a/backend/sqlite/seed/001_principal.sql b/backend/sqlite/seed/001_principal.sql
new file mode 100644
index 0000000000..c764a3df9b
--- /dev/null
+++ b/backend/sqlite/seed/001_principal.sql
@@ -0,0 +1,139 @@
+-- End user id starts at 1001, we reserve the range between 1 ~ 1000 for internal use.
+-- Setting the id explicitly changes the next id value to be +1
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1001,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'END_USER',
+ 'Demo Owner',
+ ''
+ );
+
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1002,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'END_USER',
+ 'Jerry DBA',
+ ''
+ );
+
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1003,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'END_USER',
+ 'Tom Dev',
+ ''
+ );
+
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1004,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'END_USER',
+ 'Alice DBA',
+ ''
+ );
+
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1005,
+ 1,
+ 1,
+ 'ACTIVE',
+ 'END_USER',
+ 'Jane Dev',
+ ''
+ );
+
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ `status`,
+ `type`,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1006,
+ 1,
+ 1,
+ 'INVITED',
+ 'END_USER',
+ 'Bob Invited',
+ ''
+ );
\ No newline at end of file
diff --git a/backend/sqlite/seed/010_workspace.sql b/backend/sqlite/seed/010_workspace.sql
new file mode 100644
index 0000000000..e75043d37c
--- /dev/null
+++ b/backend/sqlite/seed/010_workspace.sql
@@ -0,0 +1,13 @@
+-- Insert a second workspace for testing purpose to make sure we don't
+-- advertently return data from a different workspace.
+INSERT INTO
+ workspace (
+ id,
+ creator_id,
+ updater_id,
+ row_status,
+ slug,
+ name
+ )
+VALUES
+ (2, 1, 1, 'NORMAL', 'ws2', 'Workspace2');
\ No newline at end of file