Skip to content

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

fix: fix existing demo data and share commont reset.sql (#4421)

Tianzhou (天舟)3ef9e3710cfd
diff --git a/backend/store/demo/default/10090##pipeline.sql b/backend/store/demo/default/10090##pipeline.sql
index 1cab63b163..59844919fe 100644
--- a/backend/store/demo/default/10090##pipeline.sql
+++ b/backend/store/demo/default/10090##pipeline.sql
@@ -4,16 +4,14 @@ INSERT INTO
id,
creator_id,
updater_id,
- name,
- status
+ name
)
VALUES
(
9001,
101,
101,
- 'Pipeline - Hello world',
- 'OPEN'
+ 'Pipeline - Hello world'
);
-- A multiple stage Pipeline for simulating webhook push event to create table for shop project database.
@@ -24,8 +22,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -34,8 +31,7 @@ VALUES
1624873710,
1,
1624873710,
- 'Pipeline - Create product table',
- 'OPEN'
+ 'Pipeline - Create product table'
);
-- A two stage, each containing a single create table task, the 1st task has a failed task run
@@ -44,16 +40,14 @@ INSERT INTO
id,
creator_id,
updater_id,
- name,
- status
+ name
)
VALUES
(
9003,
103,
103,
- 'Pipeline - Create table ''tbl1''',
- 'CANCELED'
+ 'Pipeline - Create table ''tbl1'''
);
-- Pipeline for simulating webhook push event to create table for blog project dev database.
@@ -64,8 +58,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -74,8 +67,7 @@ VALUES
1624865387,
1,
1624865387,
- 'Pipeline - Create user, post, comment table for dev environment',
- 'DONE'
+ 'Pipeline - Create user, post, comment table for dev environment'
);
-- Pipeline for simulating webhook push event to create table for blog project integration database.
@@ -86,8 +78,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -96,8 +87,7 @@ VALUES
1624866790,
1,
1624866790,
- 'Pipeline - Create user, post, comment table for integration environment',
- 'DONE'
+ 'Pipeline - Create user, post, comment table for integration environment'
);
-- Pipeline for simulating webhook push event to create table for blog project staging database.
@@ -108,8 +98,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -118,8 +107,7 @@ VALUES
1624868407,
1,
1624868407,
- 'Pipeline - Create user, post, comment table for staging environment',
- 'DONE'
+ 'Pipeline - Create user, post, comment table for staging environment'
);
-- Pipeline for simulating webhook push event to create table for blog project prod database.
@@ -130,8 +118,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -140,8 +127,7 @@ VALUES
1624868680,
1,
1624868680,
- 'Pipeline - Create user, post, comment table for prod environment',
- 'DONE'
+ 'Pipeline - Create user, post, comment table for prod environment'
);
-- Pipeline for simulating webhook push event to alter table for blog project dev database.
@@ -152,8 +138,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -162,8 +147,7 @@ VALUES
1624869944,
1,
1624869944,
- 'Pipeline - Add created_at column to user,post,comment table for dev environment',
- 'OPEN'
+ 'Pipeline - Add created_at column to user,post,comment table for dev environment'
);
-- Pipeline for multi-stage create table UI workflow
@@ -174,8 +158,7 @@ INSERT INTO
created_ts,
updater_id,
updated_ts,
- name,
- status
+ name
)
VALUES
(
@@ -184,8 +167,7 @@ VALUES
1624879944,
103,
1624879944,
- 'Pipeline - Create a new table tbl2',
- 'OPEN'
+ 'Pipeline - Create a new table tbl2'
);
ALTER SEQUENCE pipeline_id_seq RESTART WITH 9010;
diff --git a/backend/store/demo/default/10000##reset.sql b/backend/store/demo/reset.sql
similarity index 99%
rename from backend/store/demo/default/10000##reset.sql
rename to backend/store/demo/reset.sql
index 8da14801c0..99480d64f1 100644
--- a/backend/store/demo/default/10000##reset.sql
+++ b/backend/store/demo/reset.sql
@@ -5,6 +5,7 @@ DELETE FROM
setting
WHERE
name != 'bb.auth.secret' AND name != 'bb.enterprise.license';
+
-- We have to change the creator and updater to system robot, otherwise, we will get foreign key check errors on
-- resetting principal table.
UPDATE setting SET creator_id = 1, updater_id = 1 WHERE name = 'bb.enterprise.license';
diff --git a/backend/store/demo/schema-migration-history/10000##reset.sql b/backend/store/demo/schema-migration-history/10000##reset.sql
deleted file mode 100644
index 1a4f52a91e..0000000000
--- a/backend/store/demo/schema-migration-history/10000##reset.sql
+++ /dev/null
@@ -1,115 +0,0 @@
--- delete all table records
-DELETE FROM
- setting;
-
-DELETE FROM
- anomaly;
-
-DELETE FROM
- repository;
-
-DELETE FROM
- vcs;
-
-DELETE FROM
- bookmark;
-
-DELETE FROM
- inbox;
-
-DELETE FROM
- activity;
-
-DELETE FROM
- sheet_organizer;
-
-DELETE FROM
- sheet;
-
-DELETE FROM
- issue_subscriber;
-
-DELETE FROM
- issue;
-
-DELETE FROM
- task_check_run;
-
-DELETE FROM
- task_run;
-
-DELETE FROM
- task_dag;
-
-DELETE FROM
- task;
-
-DELETE FROM
- stage;
-
-DELETE FROM
- pipeline;
-
-DELETE FROM
- data_source;
-
-DELETE FROM
- vw;
-
-DELETE FROM
- idx;
-
-DELETE FROM
- col;
-
-DELETE FROM
- tbl;
-
-DELETE FROM
- backup;
-
-DELETE FROM
- backup_setting;
-
--- Delete in this order following foreign constraints.
-DELETE FROM
- db_label;
-
-DELETE FROM
- label_value;
-
-DELETE FROM
- label_key;
-
-DELETE FROM
- db;
-
-DELETE FROM
- instance_user;
-
-DELETE FROM
- instance;
-
-DELETE FROM
- policy;
-
-DELETE FROM
- environment;
-
-DELETE FROM
- project_webhook;
-
-DELETE FROM
- project_member;
-
-DELETE FROM
- deployment_config;
-
-DELETE FROM
- project;
-
-DELETE FROM
- member;
-
-DELETE FROM
- principal;
diff --git a/backend/store/demo/schema-migration-history/10001##data.sql b/backend/store/demo/schema-migration-history/10001##data.sql
index 62f56884b3..52b9b69f64 100644
--- a/backend/store/demo/schema-migration-history/10001##data.sql
+++ b/backend/store/demo/schema-migration-history/10001##data.sql
@@ -1,40 +1,38 @@
-- schema migration seeding data
INSERT INTO "public"."principal" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "type", "name", "email", "password_hash") VALUES
-(1, 'NORMAL', 1, 1657272778, 1, 1657272778, 'SYSTEM_BOT', 'Bytebase', '[email protected]', ''),
(101, 'NORMAL', 1, 1657272815, 1, 1657272815, 'END_USER', 'Demo', '[email protected]', '$2a$10$/65QFlHOmDzXshEMt/qYuunbJrXtRLcaYDcRODbyOPa/9/N0N8Zc2');
INSERT INTO "public"."member" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "status", "role", "principal_id") VALUES
(101, 'NORMAL', 1, 1657272815, 1, 1657272815, 'ACTIVE', 'OWNER', 101);
-INSERT INTO "public"."project" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "key", "workflow_type", "visibility", "tenant_mode", "db_name_template") VALUES
-(1, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Default', 'DEFAULT', 'UI', 'PUBLIC', 'DISABLED', ''),
-(101, 'NORMAL', 101, 1657272873, 101, 1657272873, 'DEMO', 'Z77', 'UI', 'PUBLIC', 'DISABLED', '');
+INSERT INTO "public"."project" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "key", "workflow_type", "visibility", "tenant_mode", "db_name_template", "resource_id") VALUES
+(101, 'NORMAL', 101, 1657272873, 101, 1657272873, 'DEMO', 'Z77', 'UI', 'PUBLIC', 'DISABLED', '', 'demo');
INSERT INTO "public"."project_member" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "project_id", "role", "principal_id", "payload") VALUES
(101, 'NORMAL', 101, 1657272873, 101, 1657272873, 101, 'OWNER', 101, '{}');
-INSERT INTO "public"."environment" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "order") VALUES
-(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Test', 0),
-(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Prod', 1);
+INSERT INTO "public"."environment" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "order", "resource_id") VALUES
+(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Test', 0, 'test'),
+(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Prod', 1, 'prod');
INSERT INTO "public"."policy" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "resource_type", "resource_id", "type", "payload") VALUES
(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 101, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_NEVER"}'),
(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 102, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_ALWAYS"}'),
(103, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 102, 'bb.policy.backup-plan', '{"schedule": "WEEKLY"}');
-INSERT INTO "public"."instance" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "environment_id", "name", "engine", "engine_version", "host", "port", "external_link") VALUES
-(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 'Sample Test instance', 'POSTGRES', '14.3', 'host.docker.internal', '5432', ''),
-(102, 'NORMAL', 101, 1657272848, 1, 1657272850, 101, 'DEMO', 'MYSQL', '8.0.28', 'demo.cfxzcrq5mf2d.us-west-1.rds.amazonaws.com', '', '');
+INSERT INTO "public"."instance" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "environment_id", "name", "engine", "engine_version", "external_link", "resource_id") VALUES
+(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 'Sample Test instance', 'POSTGRES', '14.3', '', 'sample-test-mysql'),
+(102, 'NORMAL', 101, 1657272848, 1, 1657272850, 101, 'DEMO', 'MYSQL', '8.0.28', '', 'demo-test-mysql');
INSERT INTO "public"."instance_user" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "instance_id", "name", "grant") VALUES
(101, 'NORMAL', 1, 1657272852, 1, 1657274591, 102, '''admin''@''%''', 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO `admin`@`%` WITH GRANT OPTION'),
(102, 'NORMAL', 1, 1657272852, 1, 1657274591, 102, '''rdsadmin''@''localhost''', 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `rdsadmin`@`localhost` WITH GRANT OPTION
GRANT SERVICE_CONNECTION_ADMIN,SET_USER_ID,SYSTEM_USER ON *.* TO `rdsadmin`@`localhost` WITH GRANT OPTION');
-INSERT INTO "public"."db" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "instance_id", "project_id", "source_backup_id", "sync_status", "last_successful_sync_ts", "schema_version", "name", "character_set", "collation") VALUES
-(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 1, NULL, 'OK', 0, '', '*', 'utf8mb4', 'utf8mb4_general_ci'),
-(102, 'NORMAL', 101, 1657272848, 101, 1657272848, 102, 1, NULL, 'OK', 1657272848, '', '*', 'utf8mb4', 'utf8mb4_general_ci'),
-(103, 'NORMAL', 1, 1657272853, 1, 1657274591, 102, 101, NULL, 'OK', 1657274591, '20220708094434', 'employee', 'utf8mb4', 'utf8mb4_general_ci');
+INSERT INTO "public"."db" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "instance_id", "project_id", "source_backup_id", "sync_status", "last_successful_sync_ts", "schema_version", "name") VALUES
+(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 1, NULL, 'OK', 0, '', '*'),
+(102, 'NORMAL', 101, 1657272848, 101, 1657272848, 102, 1, NULL, 'OK', 1657272848, '', '*'),
+(103, 'NORMAL', 1, 1657272853, 1, 1657274591, 102, 101, NULL, 'OK', 1657274591, '20220708094434', 'employee');
INSERT INTO "public"."tbl" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "database_id", "name", "type", "engine", "collation", "row_count", "data_size", "index_size", "data_free", "create_options", "comment") VALUES
(126, 'NORMAL', 1, 1657190787, 1, 0, 103, 'department', 'BASE TABLE', 'InnoDB', 'utf8mb4_0900_ai_ci', 0, 16384, 16384, 0, '', ''),
@@ -102,11 +100,11 @@ INSERT INTO "public"."data_source" ("id", "row_status", "creator_id", "created_t
(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 101, 'Admin data source', 'ADMIN', 'root', '', '', '', ''),
(102, 'NORMAL', 101, 1657272848, 101, 1657272848, 102, 102, 'Admin data source', 'ADMIN', 'admin', 'Bytebase12345', '', '', '');
-INSERT INTO "public"."pipeline" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "status") VALUES
-(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Pipeline - Hello world', 'OPEN'),
-(102, 'NORMAL', 101, 1657272890, 101, 1657272890, 'Establish database baseline pipeline', 'OPEN'),
-(103, 'NORMAL', 101, 1657272927, 101, 1657272945, 'Update database schema pipeline', 'DONE'),
-(104, 'NORMAL', 101, 1657273475, 101, 1657273475, 'Update database schema pipeline', 'OPEN');
+INSERT INTO "public"."pipeline" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name") VALUES
+(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Pipeline - Hello world'),
+(102, 'NORMAL', 101, 1657272890, 101, 1657272890, 'Establish database baseline pipeline'),
+(103, 'NORMAL', 101, 1657272927, 101, 1657272945, 'Update database schema pipeline'),
+(104, 'NORMAL', 101, 1657273475, 101, 1657273475, 'Update database schema pipeline');
INSERT INTO "public"."stage" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "pipeline_id", "environment_id", "name") VALUES
(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 101, 'Test'),
@@ -187,10 +185,3 @@ INSERT INTO "public"."anomaly" ("id", "row_status", "creator_id", "created_ts",
INSERT INTO "public"."label_key" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "key") VALUES
(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'bb.location'),
(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'bb.tenant');
-
-INSERT INTO "public"."setting" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "name", "value", "description") VALUES
-(101, 'NORMAL', 1, 1657272785, 1, 1657272785, 'bb.branding.logo', '', 'The branding logo image in base64 string format.'),
-(102, 'NORMAL', 1, 1657272785, 1, 1657272785, 'bb.auth.secret', 'qOfnyO0qpMdqThSRdsDvLgQcL8me45EC', 'Random string used to sign the JWT auth token.'),
-(103, 'NORMAL', 1, 1657272785, 1, 1657272785, 'bb.workspace.id', 'cd0d7ce7-e7a6-4bbd-b922-d6716829f032', 'The workspace identifier'),
-(104, 'NORMAL', 1, 1657272785, 101, 1657272865, 'bb.enterprise.license', 'eyJhbGciOiJSUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJpbnN0YW5jZUNvdW50Ijo5OTksInRyaWFsaW5nIjpmYWxzZSwicGxhbiI6IlRFQU0iLCJhdWQiOiJiYi5saWNlbnNlIiwiZXhwIjo0ODExMTA3NTg0LCJpYXQiOjE2NTUzNjQ5NTQsImlzcyI6ImJ5dGViYXNlIiwic3ViIjoiNjc2MjA4NTMuNDI0Mjk4MTQifQ.tQHbKBkcG6DEvTnSbd4HK9ysyk4nCUiiCUhRXXOxBTa0aesJW8if35FKS-x6Aw7bOyQ8EEw8o_18qYidWmiWzSss_jKrgwnDLBsHMFdpdTYdnh9nJfiS-52UBbGC1x8fy7k_owmAnnQ7mta4Vc8u8rIa022iCIzb6xiAszvZ0NJD4lGl3MlX5T7R7kFV3nuDy4BZW8m2N_X6Hj4bLFdBSJbrVx_z831tPaymkE2o2NHCNYghDgQgAhYGp9ligOT2w9lg3hB9wCVWItFiGbx2kqVmkEwrvH6OfSgfAORsNbM6oXjtnJd0fd5PzTYy3woLHyVGvyX2pVNKTmOEIt7Abw', 'Enterprise license');
-
diff --git a/backend/store/pg_engine.go b/backend/store/pg_engine.go
index 85a58e50e8..d5e631dde1 100644
--- a/backend/store/pg_engine.go
+++ b/backend/store/pg_engine.go
@@ -238,6 +238,12 @@ func (db *DB) setupDemoData() error {
}
log.Info(fmt.Sprintf("Setting up demo %q...", db.demoName))
+
+ // Reset existing demo data.
+ if err := db.applyDataFile("demo/reset.sql"); err != nil {
+ return errors.Wrapf(err, "Failed to reset demo data")
+ }
+
names, err := fs.Glob(demoFS, fmt.Sprintf("demo/%s/*.sql", db.demoName))
if err != nil {
return err
@@ -252,7 +258,7 @@ func (db *DB) setupDemoData() error {
// Loop over all data files and execute them in order.
for _, name := range names {
if err := db.applyDataFile(name); err != nil {
- return errors.Wrapf(err, "applyDataFile error: name=%q", name)
+ return errors.Wrapf(err, "Failed to load demo data: %q", name)
}
}
log.Info("Completed demo data setup.")