Skip to content

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

feat: add `demo-name` to args (#1745)

boojack69cd5a48f41d
diff --git a/bin/server/cmd/profile_dev.go b/bin/server/cmd/profile_dev.go
index d3ed447fd8..c1e68e1b26 100644
--- a/bin/server/cmd/profile_dev.go
+++ b/bin/server/cmd/profile_dev.go
@@ -12,8 +12,15 @@ import (
)
func activeProfile(dataDir string) server.Profile {
+ // `flags.demo` always be true in dev mode
+ demoName := string(common.ReleaseModeDev)
+ if flags.demoName != "" {
+ demoName = flags.demoName
+ }
+ demoDataDir := fmt.Sprintf("demo/%s", demoName)
// Using flags.port + 1 as our datastore port
datastorePort := flags.port + 1
+
return server.Profile{
Mode: common.ReleaseModeDev,
BackendHost: flags.host,
@@ -26,7 +33,7 @@ func activeProfile(dataDir string) server.Profile {
Debug: flags.debug,
Demo: flags.demo,
DataDir: dataDir,
- DemoDataDir: fmt.Sprintf("demo/%s", common.ReleaseModeDev),
+ DemoDataDir: demoDataDir,
BackupRunnerInterval: 10 * time.Second,
Version: version,
GitCommit: gitcommit,
diff --git a/bin/server/cmd/profile_release.go b/bin/server/cmd/profile_release.go
index 3331c802cc..d030af3b39 100644
--- a/bin/server/cmd/profile_release.go
+++ b/bin/server/cmd/profile_release.go
@@ -14,10 +14,15 @@ import (
func activeProfile(dataDir string) server.Profile {
demoDataDir := ""
if flags.demo {
- demoDataDir = fmt.Sprintf("demo/%s", common.ReleaseModeProd)
+ demoName := string(common.ReleaseModeProd)
+ if flags.demoName != "" {
+ demoName = flags.demoName
+ }
+ demoDataDir = fmt.Sprintf("demo/%s", demoName)
}
// Using flags.port + 1 as our datastore port
datastorePort := flags.port + 1
+
return server.Profile{
Mode: common.ReleaseModeProd,
BackendHost: flags.host,
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index 8d6c5d9de7..3509ca4aaa 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -86,7 +86,11 @@ var (
// - Requests other than GET will be rejected
// - Any operations involving mutation will not start (e.g. Background schema syncer, task scheduler)
readonly bool
- demo bool
+ // demo is a flag to seed the database with demo data.
+ demo bool
+ // demoName is the name of the demo. It is only used when --demo is set,
+ // and should be one of the subpath name in the ./store/demo/ directory.
+ demoName string
debug bool
// pgURL must follow PostgreSQL connection URIs pattern.
// https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
@@ -123,6 +127,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&flags.dataDir, "data", ".", "directory where Bytebase stores data. If relative path is supplied, then the path is relative to the directory where Bytebase is under")
rootCmd.PersistentFlags().BoolVar(&flags.readonly, "readonly", false, "whether to run in read-only mode")
rootCmd.PersistentFlags().BoolVar(&flags.demo, "demo", false, "whether to run using demo data")
+ rootCmd.PersistentFlags().StringVar(&flags.demoName, "demo-name", "", "name of the demo to use when running in demo mode")
rootCmd.PersistentFlags().BoolVar(&flags.debug, "debug", false, "whether to enable debug level logging")
// TODO(tianzhou): this needs more bake time. There are couple blocking issues:
// 1. Currently, we will create a separate database "bytebase" to store the migration_history table, we need to put it inside the specified database here.
diff --git a/scripts/demo.sh b/scripts/demo.sh
index 6073d41de6..69212a78fb 100644
--- a/scripts/demo.sh
+++ b/scripts/demo.sh
@@ -7,6 +7,8 @@
# ./demo.sh
# ./demo.sh https://example.com
# ./demo.sh https://example.com:8080
+# ./demo.sh https://example.com:8080 schema-migration
+# ./demo.sh https://schema-migration.demo.bytebase.com schema-migration
# If no parameter is passed, use https://demo.bytebase.com as host and 443 as port by default
ONLINE_DEMO_HOST='https://demo.bytebase.com'
@@ -23,10 +25,15 @@ if [ $1 ]; then
fi
fi
+DEMO_NAME=''
+if [ $2 ]; then
+ DEMO_NAME=$2
+fi
+
seedDemoData() {
echo 'Seeding data for online demo'
- bytebase --host ${ONLINE_DEMO_HOST} --port ${ONLINE_DEMO_PORT} --demo --data /var/opt/bytebase &
+ bytebase --host ${ONLINE_DEMO_HOST} --port ${ONLINE_DEMO_PORT} --demo --demo-name ${DEMO_NAME} --data /var/opt/bytebase &
until [ -f /var/opt/bytebase/pgdata/PG_VERSION ]; do
echo "waiting..."
diff --git a/store/demo/schema-migration/10000__reset.sql b/store/demo/schema-migration/10000__reset.sql
new file mode 100644
index 0000000000..8da14801c0
--- /dev/null
+++ b/store/demo/schema-migration/10000__reset.sql
@@ -0,0 +1,128 @@
+-- For testing, we reset data on each run
+-- Do not reset bb.auth.secret so that we don't need to re-login after restart.
+-- Do not reset bb.enterprise.license so that the dev license is preserved after restart.
+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';
+
+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;
+
+-- Project 1 refers to DEFAULT project which is considered as part of schema
+DELETE FROM
+ project
+WHERE
+ id != 1;
+
+DELETE FROM
+ member;
+
+-- Principal 1 refers to bytebase system account which is considered as part of schema
+DELETE FROM
+ principal
+WHERE
+ id != 1;
diff --git a/store/demo/schema-migration/10001__principal.sql b/store/demo/schema-migration/10001__principal.sql
new file mode 100644
index 0000000000..e8552e5af9
--- /dev/null
+++ b/store/demo/schema-migration/10001__principal.sql
@@ -0,0 +1,72 @@
+-- End user id starts at 101, we reserve the range between 1 ~ 100 for internal use.
+-- Setting the id explicitly changes the next id value to be +1
+-- 101
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ type,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 'END_USER',
+ 'Demo Owner',
+ -- 1024
+ '$2a$10$/65QFlHOmDzXshEMt/qYuunbJrXtRLcaYDcRODbyOPa/9/N0N8Zc2'
+ );
+
+-- 102
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ type,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 'END_USER',
+ 'Jerry DBA',
+ -- 2048
+ '$2a$10$Q2NJib9bRvDkap1N1RDP2O3HyxjCldwfvGoxAzZL5gbbBgKAFD4cq'
+ );
+
+-- 103
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ type,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 103,
+ 1,
+ 1,
+ 'END_USER',
+ 'Tom Dev',
+ -- 4096
+ '$2a$10$X5bvIWk4BKhEaZqlNLGjgOUB09i97olKBfjTQT49zMtNGnhoy6GIW'
+ );
+
+ALTER SEQUENCE principal_id_seq RESTART WITH 104;
diff --git a/store/demo/schema-migration/10010__workspace.sql b/store/demo/schema-migration/10010__workspace.sql
new file mode 100644
index 0000000000..026f1d2de6
--- /dev/null
+++ b/store/demo/schema-migration/10010__workspace.sql
@@ -0,0 +1 @@
+-- 0010 is reserved for workspace, but is not implemented yet.
diff --git a/store/demo/schema-migration/10020__member.sql b/store/demo/schema-migration/10020__member.sql
new file mode 100644
index 0000000000..91c0ddf683
--- /dev/null
+++ b/store/demo/schema-migration/10020__member.sql
@@ -0,0 +1,37 @@
+INSERT INTO
+ member (
+ id,
+ creator_id,
+ updater_id,
+ status,
+ role,
+ principal_id
+ )
+VALUES
+ (2001, 101, 101, 'ACTIVE', 'OWNER', 101);
+
+INSERT INTO
+ member (
+ id,
+ creator_id,
+ updater_id,
+ status,
+ role,
+ principal_id
+ )
+VALUES
+ (2002, 101, 101, 'ACTIVE', 'DBA', 102);
+
+INSERT INTO
+ member (
+ id,
+ creator_id,
+ updater_id,
+ status,
+ role,
+ principal_id
+ )
+VALUES
+ (2003, 101, 101, 'ACTIVE', 'DEVELOPER', 103);
+
+ALTER SEQUENCE member_id_seq RESTART WITH 2004;