Skip to content

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

feat(semantic): switch bytebase schema management to semantic versioning (#970)

Danny Xu5118c6bc0bfc
diff --git a/Dockerfile.render b/Dockerfile.render-preview
similarity index 98%
rename from Dockerfile.render
rename to Dockerfile.render-preview
index 0c602c9d58..45f50fca3c 100644
--- a/Dockerfile.render
+++ b/Dockerfile.render-preview
@@ -41,7 +41,7 @@ COPY ./scripts .
# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
# go-sqlite3 requires CGO_ENABLED
RUN STAGING_VERSION=`cat ./VERSION`-${RENDER_GIT_COMMIT:0:5} && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
- --tags "release alpine" \
+ --tags "alpine" \
-ldflags="-w -s -X 'github.com/bytebase/bytebase/bin/server/cmd.version=${STAGING_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=${GO_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=${RENDER_GIT_COMMIT}' -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=${BUILD_TIME}' -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=${BUILD_USER}'" \
-o bytebase \
./bin/server/main.go;
diff --git a/bin/server/cmd/profile_dev.go b/bin/server/cmd/profile_dev.go
index 223f76a853..26d4e53795 100644
--- a/bin/server/cmd/profile_dev.go
+++ b/bin/server/cmd/profile_dev.go
@@ -4,26 +4,21 @@
package cmd
import (
- "fmt"
"time"
+
+ "github.com/blang/semver/v4"
)
func activeProfile(dataDir string, port, datastorePort int, isDemo bool) Profile {
- dsn := fmt.Sprintf("file:%s/bytebase_dev.db", dataDir)
- if isDemo {
- dsn = fmt.Sprintf("file:%s/bytebase_demo.db", dataDir)
- }
return Profile{
mode: "dev",
port: port,
datastorePort: datastorePort,
pgUser: "bbdev",
dataDir: dataDir,
- dsn: dsn,
- seedDir: "seed/test",
- forceResetSeed: true,
+ demoDataDir: "demo/test",
backupRunnerInterval: 10 * time.Second,
- schemaVersion: 10002,
+ schemaVersion: semver.MustParse("1.1.0"),
}
}
@@ -35,10 +30,8 @@ func GetTestProfile(dataDir string, port, datastorePort int) Profile {
datastorePort: datastorePort,
pgUser: "bbtest",
dataDir: dataDir,
- dsn: fmt.Sprintf("file:%s/bytebase_test.db", dataDir),
- seedDir: "seed/test",
- forceResetSeed: true,
+ demoDataDir: "demo/test",
backupRunnerInterval: 10 * time.Second,
- schemaVersion: 10002,
+ schemaVersion: semver.MustParse("1.1.0"),
}
}
diff --git a/bin/server/cmd/profile_release.go b/bin/server/cmd/profile_release.go
index e55bf51cdd..86cc868c4d 100644
--- a/bin/server/cmd/profile_release.go
+++ b/bin/server/cmd/profile_release.go
@@ -4,18 +4,15 @@
package cmd
import (
- "fmt"
"time"
+
+ "github.com/blang/semver/v4"
)
func activeProfile(dataDir string, port, datastorePort int, isDemo bool) Profile {
- dsn := fmt.Sprintf("file:%s/bytebase.db", dataDir)
- seedDir := "seed/release"
- forceResetSeed := false
+ demoDataDir := ""
if isDemo {
- dsn = fmt.Sprintf("file:%s/bytebase_demo.db", dataDir)
- seedDir = "seed/test"
- forceResetSeed = true
+ demoDataDir = "demo/release"
}
return Profile{
mode: "release",
@@ -23,10 +20,8 @@ func activeProfile(dataDir string, port, datastorePort int, isDemo bool) Profile
datastorePort: datastorePort,
pgUser: "bb",
dataDir: dataDir,
- dsn: dsn,
- seedDir: seedDir,
- forceResetSeed: forceResetSeed,
+ demoDataDir: demoDataDir,
backupRunnerInterval: 10 * time.Minute,
- schemaVersion: 10001,
+ schemaVersion: semver.MustParse("1.0.0"),
}
}
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index 9ebb5d7ea4..991559c569 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -12,6 +12,7 @@ import (
"syscall"
"time"
+ "github.com/blang/semver/v4"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
enterprise "github.com/bytebase/bytebase/enterprise/service"
@@ -148,16 +149,12 @@ type Profile struct {
pgUser string
// dataDir is the directory stores the data including Bytebase's own database, backups, etc.
dataDir string
- // dsn points to where Bytebase stores its own data
- dsn string
- // seedDir points to where to populate the initial data.
- seedDir string
- // force reset seed, true for testing and demo
- forceResetSeed bool
+ // demoDataDir points to where to populate the initial data.
+ demoDataDir string
// backupRunnerInterval is the interval for backup runner.
backupRunnerInterval time.Duration
// schemaVersion is the version of schema applied to.
- schemaVersion int
+ schemaVersion semver.Version
}
// retrieved via the SettingService upon startup
@@ -284,10 +281,9 @@ func NewMain(activeProfile Profile, logger *zap.Logger) (*Main, error) {
fmt.Printf("server=%s:%d\n", host, activeProfile.port)
fmt.Printf("datastore=%s:%d\n", host, activeProfile.datastorePort)
fmt.Printf("frontend=%s:%d\n", frontendHost, frontendPort)
- fmt.Printf("dsn=%s\n", activeProfile.dsn)
fmt.Printf("resourceDir=%s\n", resourceDir)
fmt.Printf("pgdataDir=%s\n", pgDataDir)
- fmt.Printf("seedDir=%s\n", activeProfile.seedDir)
+ fmt.Printf("demoDataDir=%s\n", activeProfile.demoDataDir)
fmt.Printf("readonly=%t\n", readonly)
fmt.Printf("demo=%t\n", demo)
fmt.Printf("debug=%t\n", debug)
@@ -356,7 +352,7 @@ func (m *Main) Run(ctx context.Context) error {
Host: common.GetPostgresSocketDir(),
Port: fmt.Sprintf("%d", m.profile.datastorePort),
}
- db := store.NewDB(m.l, m.profile.dsn, connCfg, m.profile.seedDir, m.profile.forceResetSeed, readonly, version, m.profile.schemaVersion)
+ db := store.NewDB(m.l, connCfg, m.profile.demoDataDir, readonly, version, m.profile.schemaVersion)
if err := db.Open(ctx); err != nil {
return fmt.Errorf("cannot open db: %w", err)
}
diff --git a/store/demo/release/10000__reset.sql b/store/demo/release/10000__reset.sql
new file mode 100644
index 0000000000..6e74825595
--- /dev/null
+++ b/store/demo/release/10000__reset.sql
@@ -0,0 +1,118 @@
+-- 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
+DELETE FROM
+ setting
+WHERE
+ name != 'bb.auth.secret';
+
+DELETE FROM
+ anomaly;
+
+DELETE FROM
+ repository;
+
+DELETE FROM
+ vcs;
+
+DELETE FROM
+ bookmark;
+
+DELETE FROM
+ inbox;
+
+DELETE FROM
+ activity;
+
+DELETE FROM
+ sheet;
+
+DELETE FROM
+ issue_subscriber;
+
+DELETE FROM
+ issue;
+
+DELETE FROM
+ task_check_run;
+
+DELETE FROM
+ task_run;
+
+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/seed/test/10001__principal.sql b/store/demo/release/10001__principal.sql
similarity index 100%
rename from store/seed/test/10001__principal.sql
rename to store/demo/release/10001__principal.sql
diff --git a/store/seed/test/10010__workspace.sql b/store/demo/release/10010__workspace.sql
similarity index 100%
rename from store/seed/test/10010__workspace.sql
rename to store/demo/release/10010__workspace.sql
diff --git a/store/seed/test/10020__member.sql b/store/demo/release/10020__member.sql
similarity index 100%
rename from store/seed/test/10020__member.sql
rename to store/demo/release/10020__member.sql
diff --git a/store/seed/test/10030__project.sql b/store/demo/release/10030__project.sql
similarity index 100%
rename from store/seed/test/10030__project.sql
rename to store/demo/release/10030__project.sql
diff --git a/store/seed/test/10040__project_member.sql b/store/demo/release/10040__project_member.sql
similarity index 100%
rename from store/seed/test/10040__project_member.sql
rename to store/demo/release/10040__project_member.sql
diff --git a/store/seed/test/10041__project_webhook.sql b/store/demo/release/10041__project_webhook.sql
similarity index 100%
rename from store/seed/test/10041__project_webhook.sql
rename to store/demo/release/10041__project_webhook.sql
diff --git a/store/seed/test/10050__environment.sql b/store/demo/release/10050__environment.sql
similarity index 100%
rename from store/seed/test/10050__environment.sql
rename to store/demo/release/10050__environment.sql
diff --git a/store/seed/test/10051__policy.sql b/store/demo/release/10051__policy.sql
similarity index 100%
rename from store/seed/test/10051__policy.sql
rename to store/demo/release/10051__policy.sql
diff --git a/store/seed/test/10060__instance.sql b/store/demo/release/10060__instance.sql
similarity index 100%
rename from store/seed/test/10060__instance.sql
rename to store/demo/release/10060__instance.sql
diff --git a/store/seed/test/10061__instance_user.sql b/store/demo/release/10061__instance_user.sql
similarity index 100%
rename from store/seed/test/10061__instance_user.sql
rename to store/demo/release/10061__instance_user.sql
diff --git a/store/seed/test/10070__db.sql b/store/demo/release/10070__db.sql
similarity index 100%
rename from store/seed/test/10070__db.sql
rename to store/demo/release/10070__db.sql
diff --git a/store/seed/test/10071__tbl.sql b/store/demo/release/10071__tbl.sql
similarity index 100%
rename from store/seed/test/10071__tbl.sql
rename to store/demo/release/10071__tbl.sql
diff --git a/store/seed/test/10072__col.sql b/store/demo/release/10072__col.sql
similarity index 100%
rename from store/seed/test/10072__col.sql
rename to store/demo/release/10072__col.sql
diff --git a/store/seed/test/10073__idx.sql b/store/demo/release/10073__idx.sql
similarity index 100%
rename from store/seed/test/10073__idx.sql
rename to store/demo/release/10073__idx.sql
diff --git a/store/seed/test/10074__backup.sql b/store/demo/release/10074__backup.sql
similarity index 100%
rename from store/seed/test/10074__backup.sql
rename to store/demo/release/10074__backup.sql
diff --git a/store/seed/test/10080__data_source.sql b/store/demo/release/10080__data_source.sql
similarity index 100%
rename from store/seed/test/10080__data_source.sql
rename to store/demo/release/10080__data_source.sql
diff --git a/store/seed/test/10090__pipeline.sql b/store/demo/release/10090__pipeline.sql
similarity index 100%
rename from store/seed/test/10090__pipeline.sql
rename to store/demo/release/10090__pipeline.sql
diff --git a/store/seed/test/10100__stage.sql b/store/demo/release/10100__stage.sql
similarity index 100%
rename from store/seed/test/10100__stage.sql
rename to store/demo/release/10100__stage.sql
diff --git a/store/seed/test/10110__task.sql b/store/demo/release/10110__task.sql
similarity index 100%
rename from store/seed/test/10110__task.sql
rename to store/demo/release/10110__task.sql
diff --git a/store/seed/test/10120__task_run.sql b/store/demo/release/10120__task_run.sql
similarity index 100%
rename from store/seed/test/10120__task_run.sql
rename to store/demo/release/10120__task_run.sql
diff --git a/store/seed/test/10121__task_check_run.sql b/store/demo/release/10121__task_check_run.sql
similarity index 100%
rename from store/seed/test/10121__task_check_run.sql
rename to store/demo/release/10121__task_check_run.sql
diff --git a/store/seed/test/10130__issue.sql b/store/demo/release/10130__issue.sql
similarity index 100%
rename from store/seed/test/10130__issue.sql
rename to store/demo/release/10130__issue.sql
diff --git a/store/seed/test/10131__issue_subscriber.sql b/store/demo/release/10131__issue_subscriber.sql
similarity index 100%
rename from store/seed/test/10131__issue_subscriber.sql
rename to store/demo/release/10131__issue_subscriber.sql
diff --git a/store/seed/test/10140__activity.sql b/store/demo/release/10140__activity.sql
similarity index 100%
rename from store/seed/test/10140__activity.sql
rename to store/demo/release/10140__activity.sql
diff --git a/store/seed/test/10150__inbox.sql b/store/demo/release/10150__inbox.sql
similarity index 100%
rename from store/seed/test/10150__inbox.sql
rename to store/demo/release/10150__inbox.sql
diff --git a/store/seed/test/10160__bookmark.sql b/store/demo/release/10160__bookmark.sql
similarity index 100%
rename from store/seed/test/10160__bookmark.sql
rename to store/demo/release/10160__bookmark.sql
diff --git a/store/seed/test/10170__vcs.sql b/store/demo/release/10170__vcs.sql
similarity index 100%
rename from store/seed/test/10170__vcs.sql
rename to store/demo/release/10170__vcs.sql
diff --git a/store/seed/test/10180__repository.sql b/store/demo/release/10180__repository.sql
similarity index 100%
rename from store/seed/test/10180__repository.sql
rename to store/demo/release/10180__repository.sql
diff --git a/store/seed/test/10190__anomaly.sql b/store/demo/release/10190__anomaly.sql
similarity index 100%
rename from store/seed/test/10190__anomaly.sql
rename to store/demo/release/10190__anomaly.sql
diff --git a/store/seed/test/10200__label.sql b/store/demo/release/10200__label.sql
similarity index 100%
rename from store/seed/test/10200__label.sql
rename to store/demo/release/10200__label.sql
diff --git a/store/seed/test/10210__deployment_config.sql b/store/demo/release/10210__deployment_config.sql
similarity index 100%
rename from store/seed/test/10210__deployment_config.sql
rename to store/demo/release/10210__deployment_config.sql
diff --git a/store/demo/release/10220__sheet.sql b/store/demo/release/10220__sheet.sql
new file mode 100644
index 0000000000..fcd1af89b7
--- /dev/null
+++ b/store/demo/release/10220__sheet.sql
@@ -0,0 +1,23 @@
+-- Sheet for principal 101 "Demo Owner"
+INSERT INTO
+ sheet (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ database_id,
+ name,
+ statement
+ )
+VALUES
+ (
+ 22001,
+ 101,
+ 101,
+ 3001,
+ 7019,
+ 'my-sheet',
+ 'SELECT * FROM demo'
+ );
+
+ALTER SEQUENCE sheet_id_seq RESTART WITH 22002;
diff --git a/store/demo/release/README.md b/store/demo/release/README.md
new file mode 100644
index 0000000000..31ae78aed9
--- /dev/null
+++ b/store/demo/release/README.md
@@ -0,0 +1,3 @@
+This is used for release demo when building with "release" tag (demo.bytebase.com and staging.bytebase.com).
+
+The seed data file name has the format of {{number}}\_\_{{description}}, where {{number}} corresponds to the order of SQL files being applied.
diff --git a/store/seed/test/10000__reset.sql b/store/demo/test/10000__reset.sql
similarity index 100%
rename from store/seed/test/10000__reset.sql
rename to store/demo/test/10000__reset.sql
diff --git a/store/demo/test/10001__principal.sql b/store/demo/test/10001__principal.sql
new file mode 100644
index 0000000000..e15388e635
--- /dev/null
+++ b/store/demo/test/10001__principal.sql
@@ -0,0 +1,95 @@
+-- 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'
+ );
+
+-- 104
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ type,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 104,
+ 1,
+ 1,
+ 'END_USER',
+ 'Jane Dev',
+ -- 8192
+ '$2a$10$2QTgsuKDTGYe68lpeqRqouw1dQTRhssrYSnwQVzQUctQvhnVIccRa'
+ );
+
+ALTER SEQUENCE principal_id_seq RESTART WITH 105;
diff --git a/store/demo/test/10010__workspace.sql b/store/demo/test/10010__workspace.sql
new file mode 100644
index 0000000000..026f1d2de6
--- /dev/null
+++ b/store/demo/test/10010__workspace.sql
@@ -0,0 +1 @@
+-- 0010 is reserved for workspace, but is not implemented yet.
diff --git a/store/demo/test/10020__member.sql b/store/demo/test/10020__member.sql
new file mode 100644
index 0000000000..53e43b2e59
--- /dev/null
+++ b/store/demo/test/10020__member.sql
@@ -0,0 +1,49 @@
+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);
+
+INSERT INTO
+ member (
+ id,
+ creator_id,
+ updater_id,
+ status,
+ role,
+ principal_id
+ )
+VALUES
+ (2004, 101, 101, 'ACTIVE', 'DEVELOPER', 104);
+
+ALTER SEQUENCE member_id_seq RESTART WITH 2005;
diff --git a/store/demo/test/10030__project.sql b/store/demo/test/10030__project.sql
new file mode 100644
index 0000000000..aaa1250f09
--- /dev/null
+++ b/store/demo/test/10030__project.sql
@@ -0,0 +1,178 @@
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3001,
+ 101,
+ 101,
+ 'Test (UI)',
+ 'TEST',
+ 'UI',
+ 'PUBLIC',
+ 'DISABLED',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3002,
+ 101,
+ 101,
+ 'Shop (Git)',
+ 'SHP',
+ 'VCS',
+ 'PUBLIC',
+ 'DISABLED',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3003,
+ 101,
+ 101,
+ 'Blog (Git)',
+ 'BLG',
+ 'VCS',
+ 'PUBLIC',
+ 'DISABLED',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3004,
+ 'ARCHIVED',
+ 101,
+ 101,
+ 'Retired Project',
+ 'RTR',
+ 'UI',
+ 'PUBLIC',
+ 'DISABLED',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3005,
+ 101,
+ 101,
+ 'Tenant (Git)',
+ 'TNTG',
+ 'VCS',
+ 'PUBLIC',
+ 'TENANT',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3006,
+ 101,
+ 101,
+ 'Tenant (UI)',
+ 'TNTU',
+ 'UI',
+ 'PUBLIC',
+ 'TENANT',
+ ''
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 3007,
+ 101,
+ 101,
+ 'A Game',
+ 'GAME',
+ 'UI',
+ 'PUBLIC',
+ 'TENANT',
+ '{{DB_NAME}}_{{TENANT}}'
+ );
+
+ALTER SEQUENCE project_id_seq RESTART WITH 3008;
diff --git a/store/demo/test/10040__project_member.sql b/store/demo/test/10040__project_member.sql
new file mode 100644
index 0000000000..d982b84b77
--- /dev/null
+++ b/store/demo/test/10040__project_member.sql
@@ -0,0 +1,351 @@
+-- Project 3001 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4001,
+ 101,
+ 101,
+ 3001,
+ 'DEVELOPER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4002,
+ 101,
+ 101,
+ 3001,
+ 'OWNER',
+ 102
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4003,
+ 101,
+ 101,
+ 3001,
+ 'DEVELOPER',
+ 103
+ );
+
+-- Project 3002 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4004,
+ 101,
+ 101,
+ 3002,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4005,
+ 101,
+ 101,
+ 3002,
+ 'DEVELOPER',
+ 102
+ );
+
+-- Project 3003 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4006,
+ 101,
+ 101,
+ 3003,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4007,
+ 101,
+ 101,
+ 3003,
+ 'DEVELOPER',
+ 103
+ );
+
+-- Project 3004 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4008,
+ 101,
+ 101,
+ 3004,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4009,
+ 101,
+ 101,
+ 3004,
+ 'OWNER',
+ 102
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4010,
+ 101,
+ 101,
+ 3004,
+ 'DEVELOPER',
+ 103
+ );
+
+-- Project 3005 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4011,
+ 101,
+ 101,
+ 3005,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4012,
+ 101,
+ 101,
+ 3005,
+ 'DEVELOPER',
+ 102
+ );
+
+-- Project 3006 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4013,
+ 101,
+ 101,
+ 3006,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4014,
+ 101,
+ 101,
+ 3006,
+ 'DEVELOPER',
+ 102
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4015,
+ 101,
+ 101,
+ 3006,
+ 'DEVELOPER',
+ 103
+ );
+
+
+-- Project 3007 membership
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4016,
+ 101,
+ 101,
+ 3007,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4017,
+ 101,
+ 101,
+ 3007,
+ 'DEVELOPER',
+ 102
+ );
+
+INSERT INTO
+ project_member (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ role,
+ principal_id
+ )
+VALUES
+ (
+ 4018,
+ 101,
+ 101,
+ 3007,
+ 'DEVELOPER',
+ 103
+ );
+
+ALTER SEQUENCE project_member_id_seq RESTART WITH 4019;
diff --git a/store/demo/test/10041__project_webhook.sql b/store/demo/test/10041__project_webhook.sql
new file mode 100644
index 0000000000..a679f3c7da
--- /dev/null
+++ b/store/demo/test/10041__project_webhook.sql
@@ -0,0 +1,142 @@
+-- Project 3001 hook
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4101,
+ 101,
+ 101,
+ 3001,
+ 'bb.plugin.webhook.wecom',
+ 'WeCom',
+ 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4102,
+ 101,
+ 101,
+ 3001,
+ 'bb.plugin.webhook.dingtalk',
+ 'DingTalk',
+ 'https://oapi.dingtalk.com/robot/send?access_token=12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+-- Project 3002 hook
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4103,
+ 101,
+ 101,
+ 3002,
+ 'bb.plugin.webhook.feishu',
+ 'Feishu',
+ 'https://open.feishu.cn/open-apis/bot/v2/hook/12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4104,
+ 101,
+ 101,
+ 3002,
+ 'bb.plugin.webhook.slack',
+ 'Slack',
+ 'https://hooks.slack.com/services/12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+-- Project 3003 hook
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4105,
+ 101,
+ 101,
+ 3003,
+ 'bb.plugin.webhook.discord',
+ 'Discord',
+ 'https://discord.com/api/webhooks/12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+INSERT INTO
+ project_webhook (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ type,
+ name,
+ url,
+ activity_list
+ )
+VALUES
+ (
+ 4106,
+ 101,
+ 101,
+ 3003,
+ 'bb.plugin.webhook.teams',
+ 'Teams',
+ 'https://foo.webhook.office.com/webhookb2/12345',
+ '{"bb.issue.create", "bb.issue.status.update", "bb.pipeline.task.status.update", "bb.issue.field.update", "bb.issue.comment.create"}'
+ );
+
+ALTER SEQUENCE project_webhook_id_seq RESTART WITH 4107;
diff --git a/store/demo/test/10050__environment.sql b/store/demo/test/10050__environment.sql
new file mode 100644
index 0000000000..205d93b330
--- /dev/null
+++ b/store/demo/test/10050__environment.sql
@@ -0,0 +1,88 @@
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 5001,
+ 101,
+ 101,
+ 'Dev',
+ 0
+ );
+
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 5002,
+ 101,
+ 101,
+ 'Integration',
+ 1
+ );
+
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 5003,
+ 101,
+ 101,
+ 'Staging',
+ 2
+ );
+
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 5004,
+ 101,
+ 101,
+ 'Prod',
+ 3
+ );
+
+INSERT INTO
+ environment (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 5005,
+ 'ARCHIVED',
+ 101,
+ 101,
+ 'Archived Env 1',
+ 4
+ );
+
+ALTER SEQUENCE environment_id_seq RESTART WITH 5006;
diff --git a/store/demo/test/10051__policy.sql b/store/demo/test/10051__policy.sql
new file mode 100644
index 0000000000..69ddc01aed
--- /dev/null
+++ b/store/demo/test/10051__policy.sql
@@ -0,0 +1,156 @@
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5101,
+ 101,
+ 101,
+ 5001,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_NEVER"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5102,
+ 101,
+ 101,
+ 5002,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_NEVER"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5103,
+ 101,
+ 101,
+ 5003,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_ALWAYS"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5104,
+ 101,
+ 101,
+ 5004,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_NEVER"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5105,
+ 101,
+ 101,
+ 5005,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_NEVER"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5106,
+ 101,
+ 101,
+ 5003,
+ 'bb.policy.backup-plan',
+ '{"schedule":"WEEKLY"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5107,
+ 101,
+ 101,
+ 5004,
+ 'bb.policy.backup-plan',
+ '{"schedule":"DAILY"}'
+ );
+
+-- Test upsert.
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 5108,
+ 101,
+ 101,
+ 5004,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_ALWAYS"}'
+ )
+ ON CONFLICT(environment_id, type) DO UPDATE SET
+ payload = excluded.payload;
+
+ALTER SEQUENCE policy_id_seq RESTART WITH 5109;
diff --git a/store/demo/test/10060__instance.sql b/store/demo/test/10060__instance.sql
new file mode 100644
index 0000000000..1026a8d7ca
--- /dev/null
+++ b/store/demo/test/10060__instance.sql
@@ -0,0 +1,273 @@
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6001,
+ 101,
+ 101,
+ 5001,
+ 'Localhost Dev MySQL',
+ 'MYSQL',
+ '8.0.19',
+ '127.0.0.1',
+ '3306',
+ 'bytebase.com/database/mysql'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6002,
+ 101,
+ 101,
+ 5002,
+ 'On-premises Integration MySQL',
+ 'MYSQL',
+ '8.0.19',
+ 'mysql.integration.example.com',
+ '3306',
+ 'bytebase.com/database/mysql'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6003,
+ 101,
+ 101,
+ 5003,
+ 'On-premises Staging MySQL',
+ 'MYSQL',
+ '8.0.19',
+ 'mysql.staging.example.com',
+ '3306',
+ 'bytebase.com/database/mysql'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6004,
+ 101,
+ 101,
+ 5004,
+ 'On-premises Prod MySQL',
+ 'MYSQL',
+ '8.0.19',
+ 'mysql.prod.example.com',
+ '3306',
+ 'bytebase.com/database/mysql'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6005,
+ 101,
+ 101,
+ 5001,
+ 'Localhost Dev PostgreSQL',
+ 'POSTGRES',
+ '13.0',
+ '127.0.0.1',
+ '5432',
+ 'bytebase.com/database/postgres'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6006,
+ 101,
+ 101,
+ 5001,
+ 'Demo PostgreSQL on Render',
+ 'POSTGRES',
+ '13.0',
+ 'dpg-c8a7pcd0mal7gtod05p0',
+ '5432',
+ 'postgres://postgre_demo_user:3QixNmRMGhklX6B1lmCZ3ZsHFPIE5EgG@dpg-c8a7pcd0mal7gtod05p0/postgre_demo'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6007,
+ 101,
+ 101,
+ 5001,
+ 'Localhost Dev TiDB',
+ 'TIDB',
+ '5.7.25-TiDB-v5.2.1',
+ '127.0.0.1',
+ '4000',
+ 'bytebase.com/database/tidb'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6008,
+ 101,
+ 101,
+ 5001,
+ 'Localhost Dev ClickHouse',
+ 'CLICKHOUSE',
+ '21.10.2.15',
+ '127.0.0.1',
+ '9000',
+ 'bytebase.com/database/clickhouse'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6009,
+ 101,
+ 101,
+ 5001,
+ 'Localhost Dev Snowflake',
+ 'SNOWFLAKE',
+ '21.10.2.15',
+ '127.0.0.1',
+ '',
+ 'bytebase.com/database/snowflake'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 6010,
+ 'ARCHIVED',
+ 101,
+ 101,
+ 5004,
+ 'Retired Prod MySQL',
+ 'MYSQL',
+ '5.7.25',
+ 'mysql.retired.example.com',
+ '3306',
+ 'bytebase.com/database/mysql'
+ );
+
+ALTER SEQUENCE instance_id_seq RESTART WITH 6011;
diff --git a/store/demo/test/10061__instance_user.sql b/store/demo/test/10061__instance_user.sql
new file mode 100644
index 0000000000..951c36776c
--- /dev/null
+++ b/store/demo/test/10061__instance_user.sql
@@ -0,0 +1,115 @@
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6101,
+ 1,
+ 1,
+ 6001,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6102,
+ 1,
+ 1,
+ 6002,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6103,
+ 1,
+ 1,
+ 6003,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6104,
+ 1,
+ 1,
+ 6004,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6105,
+ 1,
+ 1,
+ 6005,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+INSERT INTO
+ instance_user (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ name,
+ "grant"
+ )
+VALUES
+ (
+ 6106,
+ 1,
+ 1,
+ 6006,
+ '`root`@`%`',
+ '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 `root`@`localhost` WITH GRANT OPTION'
+ );
+
+ALTER SEQUENCE instance_user_id_seq RESTART WITH 6107;
diff --git a/store/demo/test/10070__db.sql b/store/demo/test/10070__db.sql
new file mode 100644
index 0000000000..522ac50010
--- /dev/null
+++ b/store/demo/test/10070__db.sql
@@ -0,0 +1,905 @@
+-- Database for sandbox environment instance 6001
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7001,
+ 101,
+ 101,
+ 6001,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7002,
+ 101,
+ 101,
+ 6001,
+ 3001,
+ 'testdb_dev',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7003,
+ 101,
+ 101,
+ 6001,
+ 3002,
+ 'shop',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7004,
+ 101,
+ 101,
+ 6001,
+ 3003,
+ 'blog',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for integration environment instance 6002
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7005,
+ 101,
+ 101,
+ 6002,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7006,
+ 101,
+ 101,
+ 6002,
+ 3001,
+ 'testdb_integration',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7007,
+ 101,
+ 101,
+ 6002,
+ 3002,
+ 'shop',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7008,
+ 101,
+ 101,
+ 6002,
+ 3003,
+ 'blog',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for staging environment instance 6003
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7009,
+ 101,
+ 101,
+ 6003,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7010,
+ 101,
+ 101,
+ 6003,
+ 3001,
+ 'testdb_staging',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7011,
+ 101,
+ 101,
+ 6003,
+ 3002,
+ 'shop',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7012,
+ 101,
+ 101,
+ 6003,
+ 3003,
+ 'blog',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for prod environment instance 6004
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7013,
+ 101,
+ 101,
+ 6004,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7014,
+ 101,
+ 101,
+ 6004,
+ 3001,
+ 'testdb_prod',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7015,
+ 101,
+ 101,
+ 6004,
+ 3002,
+ 'shop',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7016,
+ 101,
+ 101,
+ 6004,
+ 3003,
+ 'blog',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for dev environment PostgreSQL instance 6005
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7017,
+ 101,
+ 101,
+ 6005,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Wildcard database for dev environment PostgreSQL instance 6006
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7018,
+ 101,
+ 101,
+ 6006,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for dev environment PostgreSQL instance 6006
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7019,
+ 101,
+ 101,
+ 6006,
+ 3001,
+ 'postgre_demo',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for dev environment TiDB instance 6007
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7020,
+ 101,
+ 101,
+ 6007,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for dev environment ClickHouse instance 6008
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7021,
+ 101,
+ 101,
+ 6008,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Database for dev environment Snowflake instance 6009
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7022,
+ 101,
+ 101,
+ 6009,
+ 1,
+ '*',
+ '',
+ '',
+ 'OK',
+ 0,
+ ''
+ );
+
+-- Databases for tenant mode project.
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7023,
+ 101,
+ 101,
+ 6001,
+ 3005,
+ 'tenant_db1',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ 'v1'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7024,
+ 101,
+ 101,
+ 6002,
+ 3005,
+ 'tenant_db1',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ 'v1'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7025,
+ 101,
+ 101,
+ 6001,
+ 3006,
+ 'tenant_db2',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ '2021v1'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7026,
+ 101,
+ 101,
+ 6002,
+ 3006,
+ 'tenant_db2',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ '2021v1'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7027,
+ 101,
+ 101,
+ 6001,
+ 3007,
+ 'game_dev',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ '2022v0'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7028,
+ 101,
+ 101,
+ 6003,
+ 3007,
+ 'game_public_test',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ '2022v0'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7029,
+ 101,
+ 101,
+ 6004,
+ 3007,
+ 'game_turtle_rock',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 1624558090,
+ '2022v0'
+ );
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7030,
+ 101,
+ 101,
+ 6004,
+ 3007,
+ 'game_echo_island',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'NOT_FOUND',
+ 1624558090,
+ '2022v0'
+ );
+
+-- Database for prod environment archived mysql instance 6010
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 7031,
+ 101,
+ 101,
+ 6010,
+ 3001,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+ALTER SEQUENCE db_id_seq RESTART WITH 7032;
diff --git a/store/demo/test/10071__tbl.sql b/store/demo/test/10071__tbl.sql
new file mode 100644
index 0000000000..5111e69d73
--- /dev/null
+++ b/store/demo/test/10071__tbl.sql
@@ -0,0 +1,677 @@
+-- Table for database 7002 testdb_dev
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7101,
+ 101,
+ 101,
+ 7002,
+ 'tbl1',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1234,
+ 16384,
+ 0,
+ 0,
+ '',
+ ''
+ );
+
+-- Table for database 7006 testdb_integration
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7102,
+ 101,
+ 101,
+ 7006,
+ 'tbl1',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1234,
+ 16384,
+ 16384,
+ 65536,
+ '',
+ ''
+ );
+
+-- Table for database 7010 testdb_staging
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7103,
+ 101,
+ 101,
+ 7010,
+ 'tbl1',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 12234,
+ 65536,
+ 16384,
+ 655360,
+ '',
+ ''
+ );
+
+-- Table for database 7014 testdb_prod
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7104,
+ 101,
+ 101,
+ 7014,
+ 'tbl1',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1234,
+ 32768,
+ 4096,
+ 327680,
+ '',
+ ''
+ );
+
+-- Table for database 7003 shop
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7105,
+ 101,
+ 101,
+ 7003,
+ 'product',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1000,
+ 4096,
+ 0,
+ 409600,
+ '',
+ ''
+ );
+
+-- Table for database 7007 shop
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7106,
+ 101,
+ 101,
+ 7007,
+ 'product',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1000,
+ 4096,
+ 1024,
+ 0,
+ '',
+ ''
+ );
+
+-- Table for database 7004 blog
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7107,
+ 101,
+ 101,
+ 7004,
+ 'user',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1000,
+ 4096,
+ 1024,
+ 204800,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7108,
+ 101,
+ 101,
+ 7004,
+ 'post',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 1000,
+ 8192,
+ 1024,
+ 204800,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7109,
+ 101,
+ 101,
+ 7004,
+ 'comment',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 30000,
+ 65536,
+ 4096,
+ 102400,
+ '',
+ ''
+ );
+
+-- Table for database 7008 blog
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7110,
+ 101,
+ 101,
+ 7008,
+ 'user',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 100,
+ 4096,
+ 0,
+ 204800,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7111,
+ 101,
+ 101,
+ 7008,
+ 'post',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 300,
+ 4096,
+ 1024,
+ 102400,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7112,
+ 101,
+ 101,
+ 7008,
+ 'comment',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 2000,
+ 65536,
+ 2048,
+ 40960,
+ '',
+ ''
+ );
+
+-- Table for database 7012 blog
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7113,
+ 101,
+ 101,
+ 7012,
+ 'user',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 200,
+ 4096,
+ 1024,
+ 81920,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7114,
+ 101,
+ 101,
+ 7012,
+ 'post',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 500,
+ 4096,
+ 1024,
+ 8192,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7115,
+ 101,
+ 101,
+ 7012,
+ 'comment',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 4000,
+ 65536,
+ 65536,
+ 20480,
+ '',
+ ''
+ );
+
+-- Table for database 7016 blog
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7116,
+ 101,
+ 101,
+ 7016,
+ 'user',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 200,
+ 4096,
+ 1024,
+ 0,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7117,
+ 101,
+ 101,
+ 7016,
+ 'post',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 500,
+ 4096,
+ 1024,
+ 2048,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7118,
+ 101,
+ 101,
+ 7016,
+ 'comment',
+ 'BASE TABLE',
+ 'InnoDB',
+ 'utf8mb4_general_ci',
+ 7000,
+ 8192,
+ 0,
+ 8192,
+ '',
+ ''
+ );
+
+INSERT INTO
+ tbl (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ name,
+ type,
+ ENGINE,
+ "collation",
+ row_count,
+ data_size,
+ index_size,
+ data_free,
+ create_options,
+ comment
+ )
+VALUES
+ (
+ 7119,
+ 101,
+ 101,
+ 7019,
+ 'blog',
+ 'BASE TABLE',
+ -- PostgreSQL doesn't use pluggable engines.
+ 'ACID',
+ 'utf8mb4_general_ci',
+ 7000,
+ 8192,
+ 0,
+ 8192,
+ '',
+ ''
+ );
+
+ALTER SEQUENCE tbl_id_seq RESTART WITH 7120;
diff --git a/store/demo/test/10072__col.sql b/store/demo/test/10072__col.sql
new file mode 100644
index 0000000000..b75f8821cb
--- /dev/null
+++ b/store/demo/test/10072__col.sql
@@ -0,0 +1,1801 @@
+-- Column for database 7002 testdb_dev, table 7101 tbl1
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7201,
+ 101,
+ 101,
+ 7002,
+ 7101,
+ 'col1',
+ 1,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7006 testdb_integration, table 7102 tbl1
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7202,
+ 101,
+ 101,
+ 7006,
+ 7102,
+ 'col1',
+ 1,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7010 testdb_staging, table 7103 tbl1
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7203,
+ 101,
+ 101,
+ 7010,
+ 7103,
+ 'col1',
+ 1,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7014 testdb_prod, table 7104 tbl1
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7204,
+ 101,
+ 101,
+ 7014,
+ 7104,
+ 'col1',
+ 1,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ 'I am a comment'
+ );
+
+-- Column for database 7003 shop, table 7105 product
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7205,
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7206,
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7207,
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'description',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7007 shop, table 7106 product
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7208,
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7209,
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7210,
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'description',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7107 user
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7211,
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7212,
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7213,
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'email',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7108 post
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7214,
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7215,
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7216,
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'content',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7217,
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7004 blog, table 7109 comment
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7218,
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7219,
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'content',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7220,
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'post_id',
+ 3,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7221,
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7110 user
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7222,
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7223,
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7224,
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'email',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7111 post
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7225,
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7226,
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7227,
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'content',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7228,
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7112 comment
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7229,
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7230,
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'content',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7231,
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'post_id',
+ 3,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7232,
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7012 blog, table 7113 user
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7233,
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7234,
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7235,
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'email',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7012 blog, table 7114 post
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7236,
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7237,
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7238,
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'content',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7239,
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7012 blog, table 7115 comment
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7240,
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7241,
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'content',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7242,
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'post_id',
+ 3,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7243,
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7016 blog, table 7116 user
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7244,
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7245,
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7246,
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'email',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+-- Column for database 7008 blog, table 7117 post
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7247,
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7248,
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'name',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7249,
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'content',
+ 3,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7250,
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+-- Column for database 7016 blog, table 7118 comment
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7251,
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'id',
+ 1,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7252,
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'content',
+ 2,
+ NULL,
+ false,
+ 'text',
+ 'utf8mb4',
+ 'utf8mb4_0900_ai_ci',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7253,
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'post_id',
+ 3,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+INSERT INTO
+ col (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ position,
+ "default",
+ nullable,
+ type,
+ character_set,
+ "collation",
+ comment
+ )
+VALUES
+ (
+ 7254,
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'author_id',
+ 4,
+ NULL,
+ false,
+ 'int',
+ '',
+ '',
+ ''
+ );
+
+ALTER SEQUENCE col_id_seq RESTART WITH 7255;
diff --git a/store/demo/test/10073__idx.sql b/store/demo/test/10073__idx.sql
new file mode 100644
index 0000000000..a0b91046fe
--- /dev/null
+++ b/store/demo/test/10073__idx.sql
@@ -0,0 +1,577 @@
+-- Index for database 7002 testdb_dev, table 7101 tbl1
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7301,
+ 101,
+ 101,
+ 7002,
+ 7101,
+ 'idx_col1',
+ 'col1',
+ 1,
+ 'BTREE',
+ false,
+ true,
+ ''
+ );
+
+-- Index for database 7006 testdb_dev, table 7102 tbl1
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7302,
+ 101,
+ 101,
+ 7006,
+ 7102,
+ 'idx_col1',
+ 'col1',
+ 1,
+ 'BTREE',
+ false,
+ true,
+ ''
+ );
+
+-- Index for database 7010 testdb_dev, table 7103 tbl1
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7303,
+ 101,
+ 101,
+ 7010,
+ 7103,
+ 'idx_col1',
+ 'col1',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7014 testdb_dev, table 7104 tbl1
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7304,
+ 101,
+ 101,
+ 7014,
+ 7104,
+ 'idx_col1',
+ 'col1',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7003 shop, table 7105 product
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7305,
+ 101,
+ 101,
+ 7003,
+ 7105,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7007 shop, table 7106 product
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7306,
+ 101,
+ 101,
+ 7007,
+ 7106,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7004 blog, table 7107 user
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7307,
+ 101,
+ 101,
+ 7004,
+ 7107,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7004 blog, table 7108 post
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7308,
+ 101,
+ 101,
+ 7004,
+ 7108,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7004 blog, table 7109 comment
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7309,
+ 101,
+ 101,
+ 7004,
+ 7109,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7008 blog, table 7110 user
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7310,
+ 101,
+ 101,
+ 7008,
+ 7110,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7008 blog, table 7111 post
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7311,
+ 101,
+ 101,
+ 7008,
+ 7111,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7008 blog, table 7112 comment
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7312,
+ 101,
+ 101,
+ 7008,
+ 7112,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7012 blog, table 7113 user
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7313,
+ 101,
+ 101,
+ 7012,
+ 7113,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7012 blog, table 7114 post
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7314,
+ 101,
+ 101,
+ 7012,
+ 7114,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7012 blog, table 7115 comment
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7315,
+ 101,
+ 101,
+ 7012,
+ 7115,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7016 blog, table 7116 user
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7316,
+ 101,
+ 101,
+ 7016,
+ 7116,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7016 blog, table 7117 post
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7317,
+ 101,
+ 101,
+ 7016,
+ 7117,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+-- Index for database 7016 blog, table 7118 comment
+INSERT INTO
+ idx (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ table_id,
+ name,
+ expression,
+ position,
+ type,
+ "unique",
+ visible,
+ comment
+ )
+VALUES
+ (
+ 7318,
+ 101,
+ 101,
+ 7016,
+ 7118,
+ 'PRIMARY',
+ 'id',
+ 1,
+ 'BTREE',
+ true,
+ true,
+ ''
+ );
+
+ALTER SEQUENCE idx_id_seq RESTART WITH 7319;
diff --git a/store/demo/test/10074__backup.sql b/store/demo/test/10074__backup.sql
new file mode 100644
index 0000000000..177ee05213
--- /dev/null
+++ b/store/demo/test/10074__backup.sql
@@ -0,0 +1,267 @@
+-- Backup for database 7015 (shop database in prod environment)
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7401,
+ 101,
+ 1629136800,
+ 101,
+ 1629136800,
+ 7015,
+ 'shop-prod-20210817T094000',
+ 'DONE',
+ 'MANUAL',
+ 'LOCAL',
+ 'v1_20210817094000',
+ 'data/backup/db/7015/shop-prod-20210817T094000.sql',
+ ''
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7402,
+ 101,
+ 1629250800,
+ 101,
+ 1629250800,
+ 7015,
+ 'shop-prod-20210818T140000',
+ 'DONE',
+ 'MANUAL',
+ 'LOCAL',
+ 'v2_20210818140000',
+ 'data/backup/db/7015/shop-prod-20210818T140000.sql',
+ ''
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7403,
+ 101,
+ 1627754400,
+ 101,
+ 1627754400,
+ 7015,
+ 'shop-prod-20210801T020000-autobackup',
+ 'FAILED',
+ 'AUTOMATIC',
+ 'LOCAL',
+ 'v3_20210801020000',
+ 'data/backup/db/7015/shop-prod-20210801T020000-autobackup.sql',
+ 'Something unfortunate happened. Here is a long long long long long long long long long long long long long long long long long long long long long long long long error message.'
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7404,
+ 101,
+ 1628359200,
+ 101,
+ 1628359200,
+ 7015,
+ 'shop-prod-20210808T020000-autobackup',
+ 'DONE',
+ 'AUTOMATIC',
+ 'LOCAL',
+ 'v3_20210808020000',
+ 'data/backup/db/7015/shop-prod-20210808T020000-autobackup.sql',
+ ''
+ );
+
+-- Backup for database 7016 (blog database in prod environment)
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7405,
+ 101,
+ 1629250800,
+ 101,
+ 1629250800,
+ 7016,
+ 'blog-prod-20210818T094000',
+ 'DONE',
+ 'MANUAL',
+ 'LOCAL',
+ 'v1_20210818094000',
+ 'data/backup/db/7016/blog-prod-20210818T094000.sql',
+ ''
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7406,
+ 101,
+ 1629337200,
+ 101,
+ 1629337200,
+ 7016,
+ 'blog-prod-20210819T140000',
+ 'DONE',
+ 'MANUAL',
+ 'LOCAL',
+ 'v2_20210819140000',
+ 'data/backup/db/7016/blog-prod-20210819T140000.sql',
+ ''
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7407,
+ 101,
+ 1627754400,
+ 101,
+ 1627754400,
+ 7016,
+ 'blog-prod-20210801T020000-autobackup',
+ 'FAILED',
+ 'AUTOMATIC',
+ 'LOCAL',
+ 'v3_20210801020000',
+ 'data/backup/db/7016/blog-prod-20210801T020000-autobackup.sql',
+ 'Something unfortunate happened. Here is a long long long long long long long long long long long long long long long long long long long long long long long long error message.'
+ );
+
+INSERT INTO
+ backup (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ database_id,
+ name,
+ status,
+ type,
+ storage_backend,
+ migration_history_version,
+ path,
+ comment
+ )
+VALUES
+ (
+ 7408,
+ 101,
+ 1628359200,
+ 101,
+ 1628359200,
+ 7016,
+ 'blog-prod-20210808T020000-autobackup',
+ 'DONE',
+ 'AUTOMATIC',
+ 'LOCAL',
+ 'v3_20210808020000',
+ 'data/backup/db/7016/blog-prod-20210808T020000-autobackup.sql',
+ ''
+ );
+
+ALTER SEQUENCE backup_id_seq RESTART WITH 7409;
diff --git a/store/demo/test/10080__data_source.sql b/store/demo/test/10080__data_source.sql
new file mode 100644
index 0000000000..b01490769f
--- /dev/null
+++ b/store/demo/test/10080__data_source.sql
@@ -0,0 +1,251 @@
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8001,
+ 1,
+ 1,
+ 6001,
+ 7001,
+ 'Admin data source',
+ 'ADMIN',
+ 'root',
+ 'testpwd1'
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8002,
+ 1,
+ 1,
+ 6002,
+ 7005,
+ 'Admin data source',
+ 'ADMIN',
+ 'admin',
+ 'Integration12345'
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8003,
+ 1,
+ 1,
+ 6003,
+ 7009,
+ 'Admin data source',
+ 'ADMIN',
+ 'admin',
+ 'Staging12345'
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8004,
+ 1,
+ 1,
+ 6004,
+ 7013,
+ 'Admin data source',
+ 'ADMIN',
+ 'root',
+ 'testpwd1'
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8005,
+ 1,
+ 1,
+ 6005,
+ 7017,
+ 'Admin data source',
+ 'ADMIN',
+ 'postgres',
+ ''
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8006,
+ 1,
+ 1,
+ 6006,
+ 7018,
+ 'Admin data source',
+ 'ADMIN',
+ 'postgre_demo_user',
+ '3QixNmRMGhklX6B1lmCZ3ZsHFPIE5EgG'
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8007,
+ 1,
+ 1,
+ 6007,
+ 7020,
+ 'Admin data source',
+ 'ADMIN',
+ 'root',
+ ''
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8008,
+ 1,
+ 1,
+ 6008,
+ 7021,
+ 'Admin data source',
+ 'ADMIN',
+ '',
+ ''
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8009,
+ 1,
+ 1,
+ 6009,
+ 7022,
+ 'Admin data source',
+ 'ADMIN',
+ '',
+ ''
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ PASSWORD
+ )
+VALUES
+ (
+ 8010,
+ 1,
+ 1,
+ 6010,
+ 7031,
+ 'Admin data source',
+ 'ADMIN',
+ 'admin',
+ 'Prod12345'
+ );
+
+ALTER SEQUENCE data_source_id_seq RESTART WITH 8011;
diff --git a/store/demo/test/10090__pipeline.sql b/store/demo/test/10090__pipeline.sql
new file mode 100644
index 0000000000..1cab63b163
--- /dev/null
+++ b/store/demo/test/10090__pipeline.sql
@@ -0,0 +1,191 @@
+-- A single stage, single task "hello world"
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ status
+ )
+VALUES
+ (
+ 9001,
+ 101,
+ 101,
+ 'Pipeline - Hello world',
+ 'OPEN'
+ );
+
+-- A multiple stage Pipeline for simulating webhook push event to create table for shop project database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9002,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 'Pipeline - Create product table',
+ 'OPEN'
+ );
+
+-- A two stage, each containing a single create table task, the 1st task has a failed task run
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ status
+ )
+VALUES
+ (
+ 9003,
+ 103,
+ 103,
+ 'Pipeline - Create table ''tbl1''',
+ 'CANCELED'
+ );
+
+-- Pipeline for simulating webhook push event to create table for blog project dev database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9004,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 'Pipeline - Create user, post, comment table for dev environment',
+ 'DONE'
+ );
+
+-- Pipeline for simulating webhook push event to create table for blog project integration database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9005,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 'Pipeline - Create user, post, comment table for integration environment',
+ 'DONE'
+ );
+
+-- Pipeline for simulating webhook push event to create table for blog project staging database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9006,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 'Pipeline - Create user, post, comment table for staging environment',
+ 'DONE'
+ );
+
+-- Pipeline for simulating webhook push event to create table for blog project prod database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9007,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 'Pipeline - Create user, post, comment table for prod environment',
+ 'DONE'
+ );
+
+-- Pipeline for simulating webhook push event to alter table for blog project dev database.
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9008,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 'Pipeline - Add created_at column to user,post,comment table for dev environment',
+ 'OPEN'
+ );
+
+-- Pipeline for multi-stage create table UI workflow
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
+ )
+VALUES
+ (
+ 9009,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 'Pipeline - Create a new table tbl2',
+ 'OPEN'
+ );
+
+ALTER SEQUENCE pipeline_id_seq RESTART WITH 9010;
diff --git a/store/demo/test/10100__stage.sql b/store/demo/test/10100__stage.sql
new file mode 100644
index 0000000000..7cb971f27a
--- /dev/null
+++ b/store/demo/test/10100__stage.sql
@@ -0,0 +1,366 @@
+-- Stage for Pipeline 9001 "Hello world"
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10001,
+ 101,
+ 101,
+ 9001,
+ 5004,
+ 'Prod'
+ );
+
+-- Stage for Pipeline 9002 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10002,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 5001,
+ 'Dev'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10003,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 5002,
+ 'Integration'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10004,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 5003,
+ 'Staging'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10005,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 5004,
+ 'Prod'
+ );
+
+-- Stage for Pipeline 9003 create table
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10006,
+ 103,
+ 103,
+ 9003,
+ 5001,
+ 'Dev'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10007,
+ 103,
+ 103,
+ 9003,
+ 5002,
+ 'Integration'
+ );
+
+-- Stage for Pipeline 9004 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10008,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 9004,
+ 5001,
+ 'Dev'
+ );
+
+-- Stage for Pipeline 9005 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10009,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 9005,
+ 5002,
+ 'Integration'
+ );
+
+-- Stage for Pipeline 9006 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10010,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 9006,
+ 5003,
+ 'Staging'
+ );
+
+-- Stage for Pipeline 9007 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10011,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 9007,
+ 5004,
+ 'Prod'
+ );
+
+-- Stage for Pipeline 9008 simulating webhook push event
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10012,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 9008,
+ 5001,
+ 'Dev'
+ );
+
+-- Stage for Pipeline 9009 multi-stage create table UI workflow
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10013,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 9009,
+ 5001,
+ 'Dev'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10014,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 9009,
+ 5002,
+ 'Integration'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10015,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 9009,
+ 5003,
+ 'Staging'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 10016,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 9009,
+ 5004,
+ 'Prod'
+ );
+
+ALTER SEQUENCE stage_id_seq RESTART WITH 10017;
diff --git a/store/demo/test/10110__task.sql b/store/demo/test/10110__task.sql
new file mode 100644
index 0000000000..c0dde9ca79
--- /dev/null
+++ b/store/demo/test/10110__task.sql
@@ -0,0 +1,521 @@
+-- Task for Pipeline 9001 "Hello world", Stage 10001 "Prod" to update database 7014 "testdb_prod"
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11001,
+ 101,
+ 101,
+ 9001,
+ 10001,
+ 6004,
+ 7014,
+ 'Welcome',
+ 'bb.task.general',
+ 'PENDING_APPROVAL',
+ '{"statement":"SELECT ''Welcome Tech Lead, DBA, Developer'';"}'
+ );
+
+-- Task for Pipeline 9002
+-- Task for stage 10002 "Dev" to update database 7003 'shop'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11002,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 10002,
+ 6001,
+ 7003,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10003 "Integration" to update database 7007 'shop'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11003,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 10003,
+ 6001,
+ 7007,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10004 "Staging" to update database 7011 'shop'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11004,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 10004,
+ 6003,
+ 7011,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'PENDING_APPROVAL',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10005 "Prod" to update database 7015 'proddb1'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11005,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 9002,
+ 10005,
+ 6004,
+ 7015,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'PENDING_APPROVAL',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for Pipeline 9003 create table
+-- Task for stage 10006 "Dev" to craete table in database 7002 'testdb_dev'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11006,
+ 103,
+ 103,
+ 9003,
+ 10006,
+ 6001,
+ 7002,
+ 'Update testdb_dev',
+ 'bb.task.database.schema.update',
+ 'FAILED',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl1 (name TEXT);"}'
+ );
+
+-- Task for stage 10003 "Integration" to update database 7006 'testdb_integration'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11007,
+ 103,
+ 103,
+ 9003,
+ 10007,
+ 6001,
+ 7006,
+ 'Update testdb_integration',
+ 'bb.task.database.schema.update',
+ 'PENDING',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl1 (name TEXT);"}'
+ );
+
+-- Task for stage 10008 simulating webhook push event
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11008,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 9004,
+ 10008,
+ 6001,
+ 7004,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10009 simulating webhook push event
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11009,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 9005,
+ 10009,
+ 6002,
+ 7008,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"0765950c28c50dd07217aa0a133e8239e64f0ea1","title":"Create user, post, comment table for integration environment","message":"Create user, post, comment table for integration environment","createdTs":1624866787,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/0765950c28c50dd07217aa0a133e8239e64f0ea1","authorName":"tianzhou","added":"bytebase/integration/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10010 simulating webhook push event
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11010,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 9006,
+ 10010,
+ 6003,
+ 7012,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"149f18b8d94805be4b92e256ef1dc9f4a27d5157","title":"Create user, post, comment table for staging environment","message":"Create user, post, comment table for staging environment","createdTs":1624868403,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/149f18b8d94805be4b92e256ef1dc9f4a27d5157","authorName":"tianzhou","added":"bytebase/bytebase/staging/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10011 simulating webhook push event
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11011,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 9007,
+ 10011,
+ 6004,
+ 7016,
+ 'Add initial schema',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"ec17d38d6581015feb49b341cc3da56cb0e354fb","title":"Create user, post, comment table for prod environment","message":"Create user, post, comment table for prod environment","createdTs":1624868676,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/ec17d38d6581015feb49b341cc3da56cb0e354fb","authorName":"tianzhou","added":"bytebase/prod/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task for stage 10012 simulating webhook push event
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11012,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 9008,
+ 10012,
+ 6001,
+ 7004,
+ 'Add created at column',
+ 'bb.task.database.schema.update',
+ 'FAILED',
+ '{"migrationType":"MIGRATE","statement":"ALTER TABLE `user` ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE post ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE comment ADD COLUMN `created_at` DATETIME NOT NULL;\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1624869938,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}}}'
+ );
+
+-- Task for Pipeline 9009 multi-stage create table UI workflow
+-- Task for stage 10013 "Dev" to create table in database 7002 'testdb_dev'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11013,
+ 103,
+ 103,
+ 9009,
+ 10013,
+ 6001,
+ 7002,
+ 'Update testdb_dev',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT);"}'
+ );
+
+-- Task for stage 10014 "Integration" to create table in database 7006 'testdb_integration'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11014,
+ 103,
+ 103,
+ 9009,
+ 10014,
+ 6002,
+ 7006,
+ 'Update testdb_integration',
+ 'bb.task.database.schema.update',
+ 'DONE',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl2 (name TEXT);"}'
+ );
+
+
+-- Task for stage 10015 "Integration" to create table in database 7010 'testdb_staging'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11015,
+ 103,
+ 103,
+ 9009,
+ 10015,
+ 6003,
+ 7010,
+ 'Update testdb_staging',
+ 'bb.task.database.schema.update',
+ 'FAILED',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT);"}'
+ );
+
+-- Task for stage 10016 "prod" to create table in database 7014 'testdb_prod'
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 11016,
+ 103,
+ 103,
+ 9009,
+ 10016,
+ 6004,
+ 7014,
+ 'Update testdb_prod',
+ 'bb.task.database.schema.update',
+ 'PENDING_APPROVAL',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_prod.tbl2 (name TEXT);"}'
+ );
+
+ALTER SEQUENCE task_id_seq RESTART WITH 11017;
diff --git a/store/demo/test/10120__task_run.sql b/store/demo/test/10120__task_run.sql
new file mode 100644
index 0000000000..4aebd9236a
--- /dev/null
+++ b/store/demo/test/10120__task_run.sql
@@ -0,0 +1,345 @@
+-- Task run for task 11002
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12001,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 11002,
+ 'Add initial schema 1624873710',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task run for task 11003
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12002,
+ 1,
+ 1624883710,
+ 1,
+ 1624883710,
+ 11003,
+ 'Add initial schema 1624883710',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Failed task run for task 11006 create table
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ updater_id,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result
+ )
+VALUES
+ (
+ 12003,
+ 101,
+ 101,
+ 11006,
+ 'Update testdb_dev task run',
+ 'FAILED',
+ 'bb.task.database.schema.update',
+ 103,
+ '{"detail":"table \"tbl1\" already exists"}'
+ );
+
+-- Task run for task 11008
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12004,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 11008,
+ 'Add initial schema 1624865387',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task run for task 11009
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12005,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 11009,
+ 'Add initial schema 1624866790',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task run for task 11010
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12006,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 11010,
+ 'Add initial schema 1624868407',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Task run for task 11011
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12007,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 11011,
+ 'Add initial schema 1624868680',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
+ '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
+ );
+
+-- Failed task run for task 11012 create table
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12008,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 11012,
+ 'Add created at column 1624869944',
+ 'FAILED',
+ 'bb.task.database.schema.update',
+ 201,
+ '{"detail":"database ''blog'' has already applied version 202106280100"}',
+ '{"migrationType":"MIGRATE","statement":"ALTER TABLE `user` ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE post ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE comment ADD COLUMN `created_at` DATETIME NOT NULL;\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1624869938,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}}}'
+ );
+
+-- Successful task run for task 10013 create table
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12009,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 11013,
+ 'Update testdb_dev task run',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ 0,
+ '{"detail":"Applied migration version 20210830011437.11013 to database \"testdb_dev\"","migrationId":1,"version":"20210830011437.11013"}',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT)"}'
+ );
+
+-- Successful task run for task 10014 create table
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12010,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 11014,
+ 'Update testdb_integration task run',
+ 'DONE',
+ 'bb.task.database.schema.update',
+ '{"detail":"Applied migration version 20210830011437.11014 to database \"testdb_integration\"","migrationId":1,"version":"20210830011437.11014"}',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl2 (name TEXT)"}'
+ );
+
+-- Failed task run for task 10015 create table
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ task_id,
+ name,
+ status,
+ type,
+ code,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12011,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 11015,
+ 'Update testdb_staging task run',
+ 'FAILED',
+ 'bb.task.database.schema.update',
+ 103,
+ '{"detail":"table \"tbl2\" already exists"}',
+ '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT)"}'
+ );
+
+ALTER SEQUENCE task_run_id_seq RESTART WITH 12012;
diff --git a/store/demo/test/10121__task_check_run.sql b/store/demo/test/10121__task_check_run.sql
new file mode 100644
index 0000000000..5799101847
--- /dev/null
+++ b/store/demo/test/10121__task_check_run.sql
@@ -0,0 +1,56 @@
+-- Task run for task 11004
+INSERT INTO
+ task_check_run (
+ id,
+ creator_id,
+ updater_id,
+ task_id,
+ status,
+ type,
+ code,
+ comment,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12101,
+ 1,
+ 1,
+ 11004,
+ 'FAILED',
+ 'bb.task-check.database.connect',
+ 101,
+ 'failed to connect database "shop": failed to connect database On-premises Staging MySQL/shop at "mysql.staging.example.com":"3306" with user "admin": dial tcp: lookup mysql.staging.example.com: no such host',
+ '{}',
+ '{}'
+ );
+
+INSERT INTO
+ task_check_run (
+ id,
+ creator_id,
+ updater_id,
+ task_id,
+ status,
+ type,
+ code,
+ comment,
+ result,
+ payload
+ )
+VALUES
+ (
+ 12102,
+ 1,
+ 1,
+ 11004,
+ 'DONE',
+ 'bb.task-check.database.statement.syntax',
+ 0,
+ '',
+ '{"resultList":[{"status":"SUCCESS","code":0,"title":"Syntax OK","content":"OK"}]}',
+ '{"statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","dbType":"MYSQL","charset":"utf8mb4","collation":"utf8mb4_general_ci"}'
+ );
+
+ALTER SEQUENCE task_check_run_id_seq RESTART WITH 12103;
diff --git a/store/demo/test/10130__issue.sql b/store/demo/test/10130__issue.sql
new file mode 100644
index 0000000000..adfe2a4360
--- /dev/null
+++ b/store/demo/test/10130__issue.sql
@@ -0,0 +1,277 @@
+-- Issue for the single stage, single step "Hello world" pipeline
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 3001,
+ 9001,
+ 'Hello world!',
+ 'OPEN',
+ 'bb.issue.general',
+ 'Welcome to Bytebase, this is the issue interface where developers and DBAs collaborate on database schema management issues such as: \n - Creating a new database\n - Creating a table\n - Creating an index\n - Adding/Altering a column\n - Troubleshooting performance issue\nLet''s try some simple tasks:\n1. Bookmark this issue by clicking the star icon on the top of this page\n2. Leave a comment below to greet future comers',
+ 101
+ );
+
+-- Issue for simulating webhook push event to create table in multi-stage for shop project.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13002,
+ 103,
+ 1624873710,
+ 103,
+ 1624873710,
+ 3002,
+ 9002,
+ 'Create product table using multi-stage VCS workflow',
+ 'OPEN',
+ 'bb.issue.database.schema.update',
+ 'Create product table using multi-stage VCS workflow',
+ 101
+ );
+
+-- Issue for the multi stage create table pipeline, first stage has a failed task run
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13003,
+ 103,
+ 103,
+ 3001,
+ 9003,
+ 'Create a new table ''tbl1''',
+ 'CANCELED',
+ 'bb.issue.database.schema.update',
+ 'Create tbl1.',
+ 102
+ );
+
+-- Issue for simulating webhook push event to create table for blog project dev database.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13004,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 3003,
+ 9004,
+ 'Create user, post, comment table for dev environment',
+ 'DONE',
+ 'bb.issue.database.schema.update',
+ 'Create user, post, comment table for dev environment',
+ 1
+ );
+
+-- Issue for simulating webhook push event to create table for blog project integration database.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13005,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 3003,
+ 9005,
+ 'Create user, post, comment table for integration environment',
+ 'DONE',
+ 'bb.issue.database.schema.update',
+ 'Create user, post, comment table for integration environment',
+ 1
+ );
+
+-- Issue for simulating webhook push event to create table for blog project staging database.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13006,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 3003,
+ 9006,
+ 'Create user, post, comment table for staging environment',
+ 'DONE',
+ 'bb.issue.database.schema.update',
+ 'Create user, post, comment table for staging environment',
+ 1
+ );
+
+-- Issue for simulating webhook push event to create table for blog project prod database.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13007,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 3003,
+ 9007,
+ 'Create user, post, comment table for prod environment',
+ 'DONE',
+ 'bb.issue.database.schema.update',
+ 'Create user, post, comment table for prod environment',
+ 1
+ );
+
+-- Issue for simulating webhook push event to alter table for blog project dev database.
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13008,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 3003,
+ 9008,
+ 'Add created_at column to user,post,comment table for dev environment',
+ 'OPEN',
+ 'bb.issue.database.schema.update',
+ 'Add created_at column to user,post,comment table for dev environment',
+ 1
+ );
+
+-- Issue for multi-stage create table UI workflow
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 13009,
+ 103,
+ 103,
+ 3001,
+ 9009,
+ 'Create a new table ''tbl2'' using multi-stage SQL review workflow',
+ 'CANCELED',
+ 'bb.issue.database.schema.update',
+ 'Create tbl2 using multi-stage SQL review workflow',
+ 102
+ );
+
+ALTER SEQUENCE issue_id_seq RESTART WITH 13010;
diff --git a/store/demo/test/10131__issue_subscriber.sql b/store/demo/test/10131__issue_subscriber.sql
new file mode 100644
index 0000000000..ba0f8bbd16
--- /dev/null
+++ b/store/demo/test/10131__issue_subscriber.sql
@@ -0,0 +1,123 @@
+-- Subscriber for issue 101
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (101, 102);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (101, 103);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (101, 104);
+
+-- Subscriber for issue 13002
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13002, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13002, 102);
+
+-- Subscriber for issue 13003
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13003, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13003, 102);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13003, 103);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13003, 104);
+
+-- Subscriber for issue 13004
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13004, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13004, 102);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13004, 103);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13004, 104);
+
+-- Subscriber for issue 13005
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13005, 101);
+
+-- Subscriber for issue 13006
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13006, 103);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13006, 104);
+
+-- Subscriber for issue 13007
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13007, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13007, 102);
+
+-- Subscriber for issue 13008
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13008, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13007, 103);
+
+-- Subscriber for issue 13009
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13009, 101);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13009, 102);
+
+INSERT INTO
+ issue_subscriber (issue_id, subscriber_id)
+VALUES
+ (13009, 103);
diff --git a/store/demo/test/10140__activity.sql b/store/demo/test/10140__activity.sql
new file mode 100644
index 0000000000..ee112d285a
--- /dev/null
+++ b/store/demo/test/10140__activity.sql
@@ -0,0 +1,1276 @@
+-- Activity for issue 101
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ payload
+ )
+VALUES
+ (
+ 14001,
+ 1,
+ 1,
+ 101,
+ 'bb.issue.create',
+ 'INFO',
+ '{"issueName":"Hello world!"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ comment,
+ payload
+ )
+VALUES
+ (
+ 14002,
+ 101,
+ 101,
+ 101,
+ 'bb.issue.comment.create',
+ 'INFO',
+ 'Welcome!',
+ '{"issueName":"Hello world!"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ comment,
+ payload
+ )
+VALUES
+ (
+ 14003,
+ 102,
+ 102,
+ 101,
+ 'bb.issue.comment.create',
+ 'INFO',
+ 'Let''s rock!',
+ '{"issueName":"Hello world!"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ comment,
+ payload
+ )
+VALUES
+ (
+ 14004,
+ 103,
+ 103,
+ 101,
+ 'bb.issue.comment.create',
+ 'INFO',
+ 'Go fish!',
+ '{"issueName":"Hello world!"}'
+ );
+
+-- Activity for issue 13002
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ payload
+ )
+VALUES
+ (
+ 14005,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.issue.create',
+ 'INFO',
+ '{"issueName":"Create product table"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14006,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11002,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create product table","taskName":"Add initial schema"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14007,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''shop''',
+ '{"taskId":11002,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14008,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11003,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14009,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''shop''',
+ '{"taskId":11003,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ payload
+ )
+VALUES
+ (
+ 14010,
+ 1,
+ 1624873710,
+ 1,
+ 1624873710,
+ 13002,
+ 'bb.issue.field.update',
+ 'INFO',
+ '{"fieldId":"3","oldValue":"1","newValue":"101","issueName":"Create product table"}'
+ );
+
+-- Activity for issue 13003
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ payload
+ )
+VALUES
+ (
+ 14011,
+ 103,
+ 1624873710,
+ 103,
+ 1624873710,
+ 13003,
+ 'bb.issue.create',
+ 'INFO',
+ '{"issueName":"CREATE a new TABLE ''tbl1''"}'
+ );
+
+-- Activity for failed task_run 12001
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14012,
+ 1,
+ 1,
+ 13003,
+ 'bb.pipeline.task.status.update',
+ 'ERROR',
+ 'table "tbl1" already exists',
+ '{"taskId":11006,"oldStatus":"RUNNING","newStatus":"FAILED","issueName":"Create a new table ''tbl1''","taskName":"Update testdb_dev"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ payload
+ )
+VALUES
+ (
+ 14013,
+ 102,
+ 102,
+ 13003,
+ 'bb.issue.status.update',
+ 'INFO',
+ '{"oldStatus":"OPEN","newStatus":"CANCELED","issueName":"Create a new table ''tbl1''"}'
+ );
+
+-- Activity for issue 13004
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14014,
+ 1,
+ 1624865387,
+ 1,
+ 1624865387,
+ 13004,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Create user, post, comment table for dev environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14015,
+ 1,
+ 1624865388,
+ 1,
+ 1624865388,
+ 13004,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11008,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14016,
+ 1,
+ 1624865388,
+ 1,
+ 1624865388,
+ 13004,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''blog''',
+ '{"taskId":11008,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14017,
+ 1,
+ 1624865388,
+ 1,
+ 1624865388,
+ 13004,
+ 'bb.issue.status.update',
+ 'INFO',
+ '',
+ '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for dev environment"}'
+ );
+
+-- Activity for issue 13005
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14018,
+ 1,
+ 1624866790,
+ 1,
+ 1624866790,
+ 13005,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Create user, post, comment table for integration environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14019,
+ 1,
+ 1624866791,
+ 1,
+ 1624866791,
+ 13005,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11009,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14020,
+ 1,
+ 1624866791,
+ 1,
+ 1624866791,
+ 13005,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''blog''',
+ '{"taskId":11009,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14021,
+ 1,
+ 1624866791,
+ 1,
+ 1624866791,
+ 13005,
+ 'bb.issue.status.update',
+ 'INFO',
+ '',
+ '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for integration environment"}'
+ );
+
+-- Activity for issue 13006
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14022,
+ 1,
+ 1624868407,
+ 1,
+ 1624868407,
+ 13006,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Create user, post, comment table for staging environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14023,
+ 1,
+ 1624868408,
+ 1,
+ 1624868408,
+ 13006,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11010,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14024,
+ 1,
+ 1624868408,
+ 1,
+ 1624868408,
+ 13006,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''blog''',
+ '{"taskId":11010,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14025,
+ 1,
+ 1624868408,
+ 1,
+ 1624868408,
+ 13006,
+ 'bb.issue.status.update',
+ 'INFO',
+ '',
+ '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for staging environment"}'
+ );
+
+-- Activity for issue 13007
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14026,
+ 1,
+ 1624868680,
+ 1,
+ 1624868680,
+ 13007,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Create user, post, comment table for prod environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14027,
+ 1,
+ 1624868681,
+ 1,
+ 1624868681,
+ 13007,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11011,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14028,
+ 1,
+ 1624868681,
+ 1,
+ 1624868681,
+ 13007,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Established baseline version 202106280000 for database ''blog''',
+ '{"taskId":11011,"oldStatus":"RUNNING","newStatus":"DONE"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14029,
+ 1,
+ 1624868681,
+ 1,
+ 1624868681,
+ 13007,
+ 'bb.issue.status.update',
+ 'INFO',
+ '',
+ '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for prod environment"}'
+ );
+
+-- Activity for issue 13008
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14030,
+ 1,
+ 1624869944,
+ 1,
+ 1624869944,
+ 13008,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Add created_at column to user,post,comment table for dev environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14031,
+ 1,
+ 1624869945,
+ 1,
+ 1624869945,
+ 13008,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11012,"oldStatus":"PENDING","newStatus":"RUNNING"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14032,
+ 1,
+ 1624869945,
+ 1,
+ 1624869945,
+ 13008,
+ 'bb.pipeline.task.status.update',
+ 'ERROR',
+ 'database ''blog'' has already applied version 202106280100',
+ '{"taskId":11012,"oldStatus":"RUNNING","newStatus":"FAILED"}'
+ );
+
+-- Activity for issue 13009
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14033,
+ 103,
+ 1624879944,
+ 103,
+ 1624879944,
+ 13009,
+ 'bb.issue.create',
+ 'INFO',
+ '',
+ '{"issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14034,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11015,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_dev"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14035,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Applied migration version 20210830011437.11013 to database "testdb_dev"',
+ '{"taskId":11013,"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_dev"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14036,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11014,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_integration"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14037,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ 'Applied migration version 20210830011437.11014 to database "testdb_integration"',
+ '{"taskId":11014,"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_integration"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14038,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'INFO',
+ '',
+ '{"taskId":11015,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_staging"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14039,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 13009,
+ 'bb.pipeline.task.status.update',
+ 'ERROR',
+ 'table "tbl2" already exists',
+ '{"taskId":11015,"oldStatus":"RUNNING","newStatus":"FAILED","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_staging"}'
+ );
+
+-- Project activity for 3001
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14040,
+ 102,
+ 1624879944,
+ 102,
+ 1624879944,
+ 3001,
+ 'bb.project.member.role.update',
+ 'INFO',
+ 'Changed Demo Owner ([email protected]) from OWNER to DEVELOPER.',
+ '{}'
+ );
+
+-- Project activity for 3002
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14041,
+ 101,
+ 1624879944,
+ 101,
+ 1624879944,
+ 3002,
+ 'bb.project.member.create',
+ 'INFO',
+ 'Granted Jerry DBA to [email protected] (DEVELOPER).',
+ '{}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14042,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3002,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Create product table using multi-stage VCS workflow".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs": 1630940811,"url":"https://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}},"issueId":13002,"issueName":"Create product table using multi-stage VCS workflow"}'
+ );
+
+-- Project activity for 3003
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14043,
+ 101,
+ 1624879944,
+ 101,
+ 1624879944,
+ 3003,
+ 'bb.project.member.create',
+ 'INFO',
+ 'Granted Tom Dev to [email protected] (DEVELOPER).',
+ '{}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14044,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3003,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Add created_at column to user,post,comment table for dev environment".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1630943211,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}},"issueId":13008,"issueName":"Add created_at column to user,post,comment table for dev environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14045,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3003,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Create user, post, comment table for dev environment".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13004,"issueName":"Create user, post, comment table for dev environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14046,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3003,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Create user, post, comment table for integration environment".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"0765950c28c50dd07217aa0a133e8239e64f0ea1","title":"Create user, post, comment table for integration environment","message":"Create user, post, comment table for integration environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/0765950c28c50dd07217aa0a133e8239e64f0ea1","authorName":"tianzhou","added":"bytebase/integration/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13005,"issueName":"Create user, post, comment table for integration environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14047,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3003,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Create user, post, comment table for staging environment".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"149f18b8d94805be4b92e256ef1dc9f4a27d5157","title":"Create user, post, comment table for staging environment","message":"Create user, post, comment table for staging environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/149f18b8d94805be4b92e256ef1dc9f4a27d5157","authorName":"tianzhou","added":"bytebase/staging/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13006,"issueName":"Create user, post, comment table for staging environment"}'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ container_id,
+ type,
+ level,
+ COMMENT,
+ payload
+ )
+VALUES
+ (
+ 14048,
+ 1,
+ 1624879944,
+ 1,
+ 1624879944,
+ 3003,
+ 'bb.project.repository.push',
+ 'INFO',
+ 'Created issue "Create user, post, comment table for prod environment".',
+ '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"ec17d38d6581015feb49b341cc3da56cb0e354fb","title":"Create user, post, comment table for prod environment","message":"Create user, post, comment table for prod environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/ec17d38d6581015feb49b341cc3da56cb0e354fb","authorName":"tianzhou","added":"bytebase/prod/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13006,"issueName":"Create user, post, comment table for prod environment"}'
+ );
+
+ALTER SEQUENCE activity_id_seq RESTART WITH 14049;
diff --git a/store/demo/test/10150__inbox.sql b/store/demo/test/10150__inbox.sql
new file mode 100644
index 0000000000..3b10323ccc
--- /dev/null
+++ b/store/demo/test/10150__inbox.sql
@@ -0,0 +1,289 @@
+-- Inbox for receiver 101
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15001,
+ 101,
+ 14001,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15002,
+ 101,
+ 14003,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15003,
+ 101,
+ 14004,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15004,
+ 101,
+ 14005,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15005,
+ 101,
+ 14010,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15006,
+ 101,
+ 14012,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15007,
+ 101,
+ 14013,
+ 'UNREAD'
+ );
+
+-- Inbox for receiver 102
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15008,
+ 102,
+ 14001,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15009,
+ 102,
+ 14002,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15010,
+ 102,
+ 14004,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15011,
+ 102,
+ 14005,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15012,
+ 102,
+ 14006,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15013,
+ 102,
+ 14013,
+ 'UNREAD'
+ );
+
+-- Inbox for receiver 103
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15014,
+ 103,
+ 14001,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15015,
+ 103,
+ 14002,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15016,
+ 103,
+ 14003,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15017,
+ 103,
+ 14005,
+ 'READ'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15018,
+ 103,
+ 14006,
+ 'UNREAD'
+ );
+
+INSERT INTO
+ inbox (
+ id,
+ receiver_id,
+ activity_id,
+ status
+ )
+VALUES
+ (
+ 15019,
+ 103,
+ 14013,
+ 'UNREAD'
+ );
+
+ALTER SEQUENCE inbox_id_seq RESTART WITH 15020;
diff --git a/store/demo/test/10160__bookmark.sql b/store/demo/test/10160__bookmark.sql
new file mode 100644
index 0000000000..9024a2a879
--- /dev/null
+++ b/store/demo/test/10160__bookmark.sql
@@ -0,0 +1,19 @@
+-- Bookmark for issue 101 "Hello world"
+INSERT INTO
+ bookmark (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ link
+ )
+VALUES
+ (
+ 16001,
+ 101,
+ 101,
+ 'Hello world!',
+ '/issue/hello-world-101'
+ );
+
+ALTER SEQUENCE bookmark_id_seq RESTART WITH 16002;
diff --git a/store/demo/test/10170__vcs.sql b/store/demo/test/10170__vcs.sql
new file mode 100644
index 0000000000..7122ce7c18
--- /dev/null
+++ b/store/demo/test/10170__vcs.sql
@@ -0,0 +1,27 @@
+-- This is for demo purpose and the applciation_id has alraedy been deleted
+INSERT INTO
+ vcs (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ type,
+ instance_url,
+ api_url,
+ application_id,
+ secret
+ )
+VALUES
+ (
+ 17001,
+ 101,
+ 101,
+ 'bytebase.gitlab.com',
+ 'GITLAB_SELF_HOST',
+ 'https://gitlab.bytebase.com',
+ 'https://gitlab.bytebase.com/api/v4',
+ 'fda62e44b5388b1ca6e72d5a7028a3c2c47157fc13fd98328e2bd446fae98fd8',
+ '4ac5cf6f2e400398e34f753a5222432838e84349e8d5120c4adaa6a65278b765'
+ );
+
+ALTER SEQUENCE vcs_id_seq RESTART WITH 17002;
diff --git a/store/demo/test/10180__repository.sql b/store/demo/test/10180__repository.sql
new file mode 100644
index 0000000000..0daf1bec99
--- /dev/null
+++ b/store/demo/test/10180__repository.sql
@@ -0,0 +1,150 @@
+-- This is for demo purpose and the webhook has already been deleted
+INSERT INTO
+ repository (
+ id,
+ creator_id,
+ updater_id,
+ vcs_id,
+ project_id,
+ name,
+ full_path,
+ web_url,
+ branch_filter,
+ base_directory,
+ file_path_template,
+ schema_path_template,
+ external_id,
+ external_webhook_id,
+ webhook_url_host,
+ webhook_endpoint_id,
+ webhook_secret_token,
+ access_token,
+ expires_ts,
+ refresh_token
+ )
+VALUES
+ (
+ 18001,
+ 101,
+ 101,
+ 17001,
+ 3003,
+ 'Blog',
+ 'bytebase-demo/blog',
+ 'http://gitlab.bytebase.com/bytebase-demo/blog',
+ 'master',
+ 'bytebase',
+ '{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql',
+ '{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql',
+ -- Refers to the bytebase-demo/blog
+ '13',
+ -- Refers to the webhook in bytebase-demo/blog
+ '60',
+ 'https://demo.bytebase.com',
+ 'e99bf622-7f58-4d6b-a5be-b97af313d7ea',
+ 'xxxxxxxxxxxxxxxx',
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+ 0,
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+ );
+
+INSERT INTO
+ repository (
+ id,
+ creator_id,
+ updater_id,
+ vcs_id,
+ project_id,
+ name,
+ full_path,
+ web_url,
+ branch_filter,
+ base_directory,
+ file_path_template,
+ schema_path_template,
+ external_id,
+ external_webhook_id,
+ webhook_url_host,
+ webhook_endpoint_id,
+ webhook_secret_token,
+ access_token,
+ expires_ts,
+ refresh_token
+ )
+VALUES
+ (
+ 18002,
+ 101,
+ 101,
+ 17001,
+ 3002,
+ 'Shop',
+ 'bytebase-demo/shop',
+ 'http://gitlab.bytebase.com/bytebase-demo/shop',
+ 'master',
+ 'bytebase',
+ '{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql',
+ '{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql',
+ -- Refers to the bytebase-demo/shop
+ '14',
+ -- Refers to the webhook in bytebase-demo/shop
+ '61',
+ 'https://demo.bytebase.com',
+ 'c5e30130-7322-4f84-953a-d08168c047d1',
+ 'xxxxxxxxxxxxxxxx',
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+ 0,
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+ );
+
+-- This is for demo purpose and the webhook has already been deleted
+INSERT INTO
+ repository (
+ id,
+ creator_id,
+ updater_id,
+ vcs_id,
+ project_id,
+ name,
+ full_path,
+ web_url,
+ branch_filter,
+ base_directory,
+ file_path_template,
+ schema_path_template,
+ external_id,
+ external_webhook_id,
+ webhook_url_host,
+ webhook_endpoint_id,
+ webhook_secret_token,
+ access_token,
+ expires_ts,
+ refresh_token
+ )
+VALUES
+ (
+ 18003,
+ 101,
+ 101,
+ 17001,
+ 3005,
+ 'Tenant',
+ 'bytebase-demo/tenant',
+ 'http://gitlab.bytebase.com/bytebase-demo/tenant',
+ 'master',
+ 'bytebase',
+ '{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql',
+ '.{{DB_NAME}}__LATEST.sql',
+ -- Refers to the bytebase-demo/tenant
+ '15',
+ -- Refers to the webhook in bytebase-demo/tenant
+ '62',
+ 'https://demo.bytebase.com',
+ 'e48bf625-7f58-4d6b-a5be-b97af313d7ea',
+ 'xxxxxxxxxxxxxxxx',
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+ 0,
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+ );
+
+ALTER SEQUENCE repository_id_seq RESTART WITH 18004;
diff --git a/store/demo/test/10190__anomaly.sql b/store/demo/test/10190__anomaly.sql
new file mode 100644
index 0000000000..829eb23330
--- /dev/null
+++ b/store/demo/test/10190__anomaly.sql
@@ -0,0 +1,125 @@
+-- Database anomalies
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19001,
+ 1,
+ 1,
+ 6004,
+ 7014,
+ 'bb.anomaly.database.connection',
+ '{"detail":"failed to connect database at mysql.prod.example.com:3306 with user \"root\": dial tcp: lookup mysql.prod.example.com: no such host"}'
+ );
+
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19002,
+ 1,
+ 1,
+ 6004,
+ 7014,
+ 'bb.anomaly.database.backup.policy-violation',
+ '{"environmentId":5004,"expectedSchedule":"DAILY","actualSchedule":"UNSET"}'
+ );
+
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19003,
+ 1,
+ 1,
+ 6003,
+ 7012,
+ 'bb.anomaly.database.connection',
+ '{"detail":"failed to connect database at mysql.staging.example.com:3306 with user \"root\": dial tcp: lookup mysql.staging.example.com: no such host"}'
+ );
+
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19004,
+ 1,
+ 1,
+ 6003,
+ 7012,
+ 'bb.anomaly.database.backup.policy-violation',
+ '{"environmentId":5003,"expectedSchedule":"WEEKLY","actualSchedule":"UNSET"}'
+ );
+
+-- Instance anomalies
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19005,
+ 1,
+ 1,
+ 6004,
+ 'bb.anomaly.instance.connection',
+ '{"detail":"failed to connect database at mysql.prod.example.com:3306 with user \"root\": dial tcp: lookup mysql.prod.example.com: no such host"}'
+ );
+
+INSERT INTO
+ anomaly (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 19006,
+ 1,
+ 1,
+ 6003,
+ 'bb.anomaly.instance.connection',
+ '{"detail":"failed to connect database at mysql.staging.example.com:3306 with user \"admin\": dial tcp: lookup mysql.staging.example.com: no such host"}'
+ );
+
+ALTER SEQUENCE anomaly_id_seq RESTART WITH 19007;
diff --git a/store/demo/test/10200__label.sql b/store/demo/test/10200__label.sql
new file mode 100644
index 0000000000..1c04b729da
--- /dev/null
+++ b/store/demo/test/10200__label.sql
@@ -0,0 +1,401 @@
+-- Label keys.
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 20001,
+ 1,
+ 1,
+ 'bb.location'
+ );
+
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 20002,
+ 1,
+ 1,
+ 'bb.tenant'
+ );
+
+ALTER SEQUENCE label_key_id_seq RESTART WITH 20003;
+
+-- Label values.
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20010,
+ 1,
+ 1,
+ 'bb.location',
+ 'earth'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20011,
+ 1,
+ 1,
+ 'bb.tenant',
+ 'bytebase'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20012,
+ 1,
+ 1,
+ 'bb.location',
+ 'east'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20013,
+ 1,
+ 1,
+ 'bb.location',
+ 'west'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20014,
+ 1,
+ 1,
+ 'bb.tenant',
+ 'turtle_rock'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20015,
+ 1,
+ 1,
+ 'bb.tenant',
+ 'echo_island'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20016,
+ 1,
+ 1,
+ 'bb.tenant',
+ 'public_test'
+ );
+
+INSERT INTO
+ label_value (
+ id,
+ creator_id,
+ updater_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20017,
+ 1,
+ 1,
+ 'bb.tenant',
+ 'dev'
+ );
+
+ALTER SEQUENCE label_value_id_seq RESTART WITH 20018;
+
+-- Database labels for database in tenant mode disabled project.
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20021,
+ 1,
+ 1,
+ 7002,
+ 'bb.location',
+ 'earth'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20022,
+ 1,
+ 1,
+ 7002,
+ 'bb.tenant',
+ 'bytebase'
+ );
+
+-- Database labels for database in tenant mode project.
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20023,
+ 1,
+ 1,
+ 7021,
+ 'bb.location',
+ 'earth'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20024,
+ 1,
+ 1,
+ 7022,
+ 'bb.tenant',
+ 'bytebase'
+ );
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20025,
+ 1,
+ 1,
+ 7023,
+ 'bb.location',
+ 'earth'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20026,
+ 1,
+ 1,
+ 7024,
+ 'bb.tenant',
+ 'bytebase'
+ );
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20027,
+ 1,
+ 1,
+ 7027,
+ 'bb.tenant',
+ 'dev'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20028,
+ 1,
+ 1,
+ 7028,
+ 'bb.tenant',
+ 'public_test'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20029,
+ 1,
+ 1,
+ 7029,
+ 'bb.tenant',
+ 'turtle_rock'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20030,
+ 1,
+ 1,
+ 7029,
+ 'bb.location',
+ 'east'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20031,
+ 1,
+ 1,
+ 7030,
+ 'bb.tenant',
+ 'echo_island'
+ );
+
+INSERT INTO
+ db_label (
+ id,
+ creator_id,
+ updater_id,
+ database_id,
+ key,
+ value
+ )
+VALUES
+ (
+ 20032,
+ 1,
+ 1,
+ 7030,
+ 'bb.location',
+ 'west'
+ );
+
+ALTER SEQUENCE db_label_id_seq RESTART WITH 20033;
diff --git a/store/demo/test/10210__deployment_config.sql b/store/demo/test/10210__deployment_config.sql
new file mode 100644
index 0000000000..0731459e9f
--- /dev/null
+++ b/store/demo/test/10210__deployment_config.sql
@@ -0,0 +1,60 @@
+-- Deployment config with regional deployments for tenant mode project.
+INSERT INTO
+ deployment_config (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ name,
+ config
+ )
+VALUES
+ (
+ 21001,
+ 101,
+ 101,
+ 3005,
+ 'regional-1',
+ '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
+ );
+
+INSERT INTO
+ deployment_config (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ name,
+ config
+ )
+VALUES
+ (
+ 21002,
+ 101,
+ 101,
+ 3006,
+ 'regional-2',
+ '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
+ );
+
+
+INSERT INTO
+ deployment_config (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ name,
+ config
+ )
+VALUES
+ (
+ 21003,
+ 101,
+ 101,
+ 3007,
+ 'db-pattern',
+ '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.tenant","operator":"In","values":["dev"]}]}}},{"name":"PTR Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Staging"]},{"key":"bb.tenant","operator":"Exists"}]}}},{"name":"Release Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Prod"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
+ );
+
+ALTER SEQUENCE deployment_config_id_seq RESTART WITH 21004;
diff --git a/store/seed/test/10220__sheet.sql b/store/demo/test/10220__sheet.sql
similarity index 100%
rename from store/seed/test/10220__sheet.sql
rename to store/demo/test/10220__sheet.sql
diff --git a/store/demo/test/README.md b/store/demo/test/README.md
new file mode 100644
index 0000000000..4645522915
--- /dev/null
+++ b/store/demo/test/README.md
@@ -0,0 +1,3 @@
+This is used for local development when building without "release" tag.
+
+The seed data file name has the format of {{number}}\_\_{{description}}, where {{number}} corresponds to the order of SQL files being applied..
\ No newline at end of file
diff --git a/store/migration/10001__init_schema.sql b/store/migration/1.0.0/latest.sql
similarity index 100%
rename from store/migration/10001__init_schema.sql
rename to store/migration/1.0.0/latest.sql
diff --git a/store/seed/release/10001__init_seed.sql b/store/migration/1.0.0/latest_data.sql
similarity index 100%
rename from store/seed/release/10001__init_seed.sql
rename to store/migration/1.0.0/latest_data.sql
diff --git a/store/migration/1.1.0/github_com.sql b/store/migration/1.1.0/github_com.sql
new file mode 100644
index 0000000000..86900272d8
--- /dev/null
+++ b/store/migration/1.1.0/github_com.sql
@@ -0,0 +1,8 @@
+ALTER TABLE project DROP CONSTRAINT project_role_provider_check;
+ALTER TABLE project ADD CONSTRAINT project_role_provider_check CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM'));
+
+ALTER TABLE project_member DROP CONSTRAINT project_member_role_provider_check;
+ALTER TABLE project_member ADD CONSTRAINT project_member_role_provider_check CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM'));
+
+ALTER TABLE vcs DROP CONSTRAINT vcs_type_check;
+ALTER TABLE vcs ADD CONSTRAINT vcs_type_check CHECK (type IN ('GITLAB_SELF_HOST', 'GITHUB_COM'));
diff --git a/store/migration/1.1.0/latest.sql b/store/migration/1.1.0/latest.sql
new file mode 100644
index 0000000000..cb181b11d8
--- /dev/null
+++ b/store/migration/1.1.0/latest.sql
@@ -0,0 +1,1078 @@
+-- Type
+CREATE TYPE row_status AS ENUM ('NORMAL', 'ARCHIVED');
+
+-- updated_ts trigger.
+CREATE OR REPLACE FUNCTION trigger_update_updated_ts()
+RETURNS TRIGGER AS $$
+BEGIN
+ NEW.updated_ts = extract(epoch from now());
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql;
+
+-- principal
+CREATE TABLE principal (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ type TEXT NOT NULL CHECK (type IN ('END_USER', 'SYSTEM_BOT')),
+ name TEXT NOT NULL,
+ email TEXT NOT NULL,
+ password_hash TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX idx_principal_unique_email ON principal(email);
+
+CREATE TRIGGER update_principal_updated_ts
+BEFORE
+UPDATE
+ ON principal FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Default bytebase system account id is 1
+INSERT INTO
+ principal (
+ id,
+ creator_id,
+ updater_id,
+ type,
+ name,
+ email,
+ password_hash
+ )
+VALUES
+ (
+ 1,
+ 1,
+ 1,
+ 'SYSTEM_BOT',
+ 'Bytebase',
+ ''
+ );
+
+ALTER SEQUENCE principal_id_seq RESTART WITH 101;
+
+-- Setting
+CREATE TABLE setting (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ value TEXT NOT NULL,
+ description TEXT NOT NULL DEFAULT ''
+);
+
+CREATE UNIQUE INDEX idx_setting_unique_name ON setting(name);
+
+ALTER SEQUENCE setting_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_setting_updated_ts
+BEFORE
+UPDATE
+ ON setting FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Member
+-- We separate the concept from Principal because if we support multiple workspace in the future, each workspace can have different member for the same principal
+CREATE TABLE member (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ status TEXT NOT NULL CHECK (status IN ('INVITED', 'ACTIVE')),
+ role TEXT NOT NULL CHECK (role IN ('OWNER', 'DBA', 'DEVELOPER')),
+ principal_id INTEGER NOT NULL REFERENCES principal (id)
+);
+
+CREATE UNIQUE INDEX idx_member_unique_principal_id ON member(principal_id);
+
+ALTER SEQUENCE member_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_member_updated_ts
+BEFORE
+UPDATE
+ ON member FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Environment
+CREATE TABLE environment (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ "order" INTEGER NOT NULL CHECK ("order" >= 0)
+);
+
+CREATE UNIQUE INDEX idx_environment_unique_name ON environment(name);
+
+ALTER SEQUENCE environment_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_environment_updated_ts
+BEFORE
+UPDATE
+ ON environment FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Policy
+-- policy stores the policies for each environment.
+-- Policies are associated with environments. Since we may have policies not associated with environment later, we name the table policy.
+CREATE TABLE policy (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ environment_id INTEGER NOT NULL REFERENCES environment (id),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.policy.%'),
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_policy_environment_id ON policy(environment_id);
+
+CREATE UNIQUE INDEX idx_policy_unique_environment_id_type ON policy(environment_id, type);
+
+ALTER SEQUENCE policy_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_policy_updated_ts
+BEFORE
+UPDATE
+ ON policy FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Project
+CREATE TABLE project (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ key TEXT NOT NULL,
+ workflow_type TEXT NOT NULL CHECK (workflow_type IN ('UI', 'VCS')),
+ visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PRIVATE')),
+ tenant_mode TEXT NOT NULL CHECK (tenant_mode IN ('DISABLED', 'TENANT')) DEFAULT 'DISABLED',
+ -- db_name_template is only used when a project is in tenant mode.
+ -- Empty value means {{DB_NAME}}.
+ db_name_template TEXT NOT NULL,
+ role_provider TEXT NOT NULL CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM')) DEFAULT 'BYTEBASE'
+);
+
+CREATE UNIQUE INDEX idx_project_unique_key ON project(key);
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ key,
+ workflow_type,
+ visibility,
+ tenant_mode,
+ db_name_template
+ )
+VALUES
+ (
+ 1,
+ 1,
+ 1,
+ 'Default',
+ 'DEFAULT',
+ 'UI',
+ 'PUBLIC',
+ 'DISABLED',
+ ''
+ );
+
+ALTER SEQUENCE project_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_project_updated_ts
+BEFORE
+UPDATE
+ ON project FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Project member
+CREATE TABLE project_member (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ role TEXT NOT NULL CHECK (role IN ('OWNER', 'DEVELOPER')),
+ principal_id INTEGER NOT NULL REFERENCES principal (id),
+ role_provider TEXT NOT NULL CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM')) DEFAULT 'BYTEBASE',
+ -- payload is determined by the type of role_provider
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE UNIQUE INDEX idx_project_member_unique_project_id_role_provider_principal_id ON project_member(project_id, role_provider, principal_id);
+
+ALTER SEQUENCE project_member_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_project_member_updated_ts
+BEFORE
+UPDATE
+ ON project_member FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Project Hook
+CREATE TABLE project_webhook (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.plugin.webhook.%'),
+ name TEXT NOT NULL,
+ url TEXT NOT NULL,
+ activity_list TEXT ARRAY NOT NULL
+);
+
+CREATE INDEX idx_project_webhook_project_id ON project_webhook(project_id);
+
+CREATE UNIQUE INDEX idx_project_webhook_unique_project_id_url ON project_webhook(project_id, url);
+
+ALTER SEQUENCE project_webhook_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_project_webhook_updated_ts
+BEFORE
+UPDATE
+ ON project_webhook FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Instance
+CREATE TABLE instance (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ environment_id INTEGER NOT NULL REFERENCES environment (id),
+ name TEXT NOT NULL,
+ engine TEXT NOT NULL CHECK (engine IN ('MYSQL', 'POSTGRES', 'TIDB', 'CLICKHOUSE', 'SNOWFLAKE', 'SQLITE')),
+ engine_version TEXT NOT NULL DEFAULT '',
+ host TEXT NOT NULL,
+ port TEXT NOT NULL,
+ external_link TEXT NOT NULL DEFAULT ''
+);
+
+ALTER SEQUENCE instance_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_instance_updated_ts
+BEFORE
+UPDATE
+ ON instance FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Instance user stores the users for a particular instance
+CREATE TABLE instance_user (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ name TEXT NOT NULL,
+ "grant" TEXT NOT NULL
+);
+
+ALTER SEQUENCE instance_user_id_seq RESTART WITH 101;
+
+CREATE UNIQUE INDEX idx_instance_user_unique_instance_id_name ON instance_user(instance_id, name);
+
+CREATE TRIGGER update_instance_user_updated_ts
+BEFORE
+UPDATE
+ ON instance_user FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- db stores the databases for a particular instance
+-- data is synced periodically from the instance
+CREATE TABLE db (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ -- If db is restored from a backup, then we will record that backup id. We can thus trace up to the original db.
+ source_backup_id INTEGER,
+ sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
+ last_successful_sync_ts BIGINT NOT NULL,
+ schema_version TEXT NOT NULL,
+ name TEXT NOT NULL,
+ character_set TEXT NOT NULL,
+ "collation" TEXT NOT NULL
+);
+
+CREATE INDEX idx_db_instance_id ON db(instance_id);
+
+CREATE UNIQUE INDEX idx_db_unique_instance_id_name ON db(instance_id, name);
+
+ALTER SEQUENCE db_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_db_updated_ts
+BEFORE
+UPDATE
+ ON db FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- tbl stores the table for a particular database
+-- data is synced periodically from the instance
+CREATE TABLE tbl (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ type TEXT NOT NULL,
+ engine TEXT NOT NULL,
+ "collation" TEXT NOT NULL,
+ row_count BIGINT NOT NULL,
+ data_size BIGINT NOT NULL,
+ index_size BIGINT NOT NULL,
+ data_free BIGINT NOT NULL,
+ create_options TEXT NOT NULL,
+ comment TEXT NOT NULL
+);
+
+CREATE INDEX idx_tbl_database_id ON tbl(database_id);
+
+CREATE UNIQUE INDEX idx_tbl_unique_database_id_name ON tbl(database_id, name);
+
+ALTER SEQUENCE tbl_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_tbl_updated_ts
+BEFORE
+UPDATE
+ ON tbl FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- col stores the column for a particular table from a particular database
+-- data is synced periodically from the instance
+CREATE TABLE col (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ position INTEGER NOT NULL,
+ "default" TEXT,
+ nullable BOOLEAN NOT NULL,
+ type TEXT NOT NULL,
+ character_set TEXT NOT NULL,
+ "collation" TEXT NOT NULL,
+ comment TEXT NOT NULL
+);
+
+CREATE INDEX idx_col_database_id_table_id ON col(database_id, table_id);
+
+CREATE UNIQUE INDEX idx_col_unique_database_id_table_id_name ON col(database_id, table_id, name);
+
+ALTER SEQUENCE col_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_col_updated_ts
+BEFORE
+UPDATE
+ ON col FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- idx stores the index for a particular table from a particular database
+-- data is synced periodically from the instance
+CREATE TABLE idx (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ expression TEXT NOT NULL,
+ position INTEGER NOT NULL,
+ type TEXT NOT NULL,
+ "unique" BOOLEAN NOT NULL,
+ visible BOOLEAN NOT NULL,
+ comment TEXT NOT NULL
+);
+
+CREATE INDEX idx_idx_database_id_table_id ON idx(database_id, table_id);
+
+CREATE UNIQUE INDEX idx_idx_unique_database_id_table_id_name_expression ON idx(database_id, table_id, name, expression);
+
+ALTER SEQUENCE idx_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_idx_updated_ts
+BEFORE
+UPDATE
+ ON idx FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- vw stores the view for a particular database
+-- data is synced periodically from the instance
+CREATE TABLE vw (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ definition TEXT NOT NULL,
+ comment TEXT NOT NULL
+);
+
+CREATE INDEX idx_vw_database_id ON vw(database_id);
+
+CREATE UNIQUE INDEX idx_vw_unique_database_id_name ON vw(database_id, name);
+
+ALTER SEQUENCE vw_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_vw_updated_ts
+BEFORE
+UPDATE
+ ON vw FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- data_source table stores the data source for a particular database
+CREATE TABLE data_source (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ name TEXT NOT NULL,
+ type TEXT NOT NULL CHECK (type IN ('ADMIN', 'RW', 'RO')),
+ username TEXT NOT NULL,
+ password TEXT NOT NULL,
+ ssl_key TEXT NOT NULL DEFAULT '',
+ ssl_cert TEXT NOT NULL DEFAULT '',
+ ssl_ca TEXT NOT NULL DEFAULT ''
+);
+
+CREATE INDEX idx_data_source_instance_id ON data_source(instance_id);
+
+CREATE UNIQUE INDEX idx_data_source_unique_database_id_name ON data_source(database_id, name);
+
+ALTER SEQUENCE data_source_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_data_source_updated_ts
+BEFORE
+UPDATE
+ ON data_source FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- backup stores the backups for a particular database.
+CREATE TABLE backup (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ name TEXT NOT NULL,
+ status TEXT NOT NULL CHECK (status IN ('PENDING_CREATE', 'DONE', 'FAILED')),
+ type TEXT NOT NULL CHECK (type IN ('MANUAL', 'AUTOMATIC')),
+ storage_backend TEXT NOT NULL CHECK (storage_backend IN ('LOCAL', 'S3', 'GCS', 'OSS')),
+ migration_history_version TEXT NOT NULL,
+ path TEXT NOT NULL,
+ comment TEXT NOT NULL DEFAULT ''
+);
+
+CREATE INDEX idx_backup_database_id ON backup(database_id);
+
+CREATE UNIQUE INDEX idx_backup_unique_database_id_name ON backup(database_id, name);
+
+ALTER SEQUENCE backup_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_backup_updated_ts
+BEFORE
+UPDATE
+ ON backup FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- backup_setting stores the backup settings for a particular database.
+-- This is a strict version of cron expression using UTC timezone uniformly.
+CREATE TABLE backup_setting (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ enabled BOOLEAN NOT NULL,
+ hour INTEGER NOT NULL CHECK (hour >= 0 AND hour <= 23),
+ -- day_of_week can be -1 which is wildcard (daily automatic backup).
+ day_of_week INTEGER NOT NULL CHECK (day_of_week >= -1 AND day_of_week <= 6),
+ -- hook_url is the callback url to be requested after a successful backup.
+ hook_url TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX idx_backup_setting_unique_database_id ON backup_setting(database_id);
+
+ALTER SEQUENCE backup_setting_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_backup_setting_updated_ts
+BEFORE
+UPDATE
+ ON backup_setting FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-----------------------
+-- Pipeline related BEGIN
+-- pipeline table
+CREATE TABLE pipeline (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ status TEXT NOT NULL CHECK (status IN ('OPEN', 'DONE', 'CANCELED'))
+);
+
+CREATE INDEX idx_pipeline_status ON pipeline(status);
+
+ALTER SEQUENCE pipeline_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_pipeline_updated_ts
+BEFORE
+UPDATE
+ ON pipeline FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- stage table stores the stage for the pipeline
+CREATE TABLE stage (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),
+ environment_id INTEGER NOT NULL REFERENCES environment (id),
+ name TEXT NOT NULL
+);
+
+CREATE INDEX idx_stage_pipeline_id ON stage(pipeline_id);
+
+ALTER SEQUENCE stage_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_stage_updated_ts
+BEFORE
+UPDATE
+ ON stage FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- task table stores the task for the stage
+CREATE TABLE task (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),
+ stage_id INTEGER NOT NULL REFERENCES stage (id),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ -- Could be empty for creating database task when the task isn't yet completed successfully.
+ database_id INTEGER REFERENCES db (id),
+ name TEXT NOT NULL,
+ status TEXT NOT NULL CHECK (status IN ('PENDING', 'PENDING_APPROVAL', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.task.%'),
+ payload JSONB NOT NULL DEFAULT '{}',
+ earliest_allowed_ts BIGINT NOT NULL DEFAULT 0
+);
+
+CREATE INDEX idx_task_pipeline_id_stage_id ON task(pipeline_id, stage_id);
+
+CREATE INDEX idx_task_status ON task(status);
+
+CREATE INDEX idx_task_earliest_allowed_ts ON task(earliest_allowed_ts);
+
+ALTER SEQUENCE task_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_task_updated_ts
+BEFORE
+UPDATE
+ ON task FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- task_dag describes task dependency relationship
+-- from_task_id is blocked by to_task_id
+CREATE TABLE task_dag (
+ id SERIAL PRIMARY KEY,
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ from_task_id INTEGER NOT NULL REFERENCES task (id),
+ to_task_id INTEGER NOT NULL REFERENCES task (id),
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_task_dag_from_task_id ON task_dag(from_task_id);
+
+CREATE INDEX idx_task_dag_to_task_id ON task_dag(to_task_id);
+
+ALTER SEQUENCE task_dag_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_task_dag_updated_ts
+BEFORE
+UPDATE
+ ON task_dag FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- task run table stores the task run
+CREATE TABLE task_run (
+ id SERIAL PRIMARY KEY,
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ task_id INTEGER NOT NULL REFERENCES task (id),
+ name TEXT NOT NULL,
+ status TEXT NOT NULL CHECK (status IN ('RUNNING', 'DONE', 'FAILED', 'CANCELED')),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.task.%'),
+ code INTEGER NOT NULL DEFAULT 0,
+ comment TEXT NOT NULL DEFAULT '',
+ -- result saves the task run result in json format
+ result JSONB NOT NULL DEFAULT '{}',
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_task_run_task_id ON task_run(task_id);
+
+ALTER SEQUENCE task_run_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_task_run_updated_ts
+BEFORE
+UPDATE
+ ON task_run FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- task check run table stores the task check run
+CREATE TABLE task_check_run (
+ id SERIAL PRIMARY KEY,
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ task_id INTEGER NOT NULL REFERENCES task (id),
+ status TEXT NOT NULL CHECK (status IN ('RUNNING', 'DONE', 'FAILED', 'CANCELED')),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.task-check.%'),
+ code INTEGER NOT NULL DEFAULT 0,
+ comment TEXT NOT NULL DEFAULT '',
+ -- result saves the task check run result in json format
+ result JSONB NOT NULL DEFAULT '{}',
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_task_check_run_task_id ON task_check_run(task_id);
+
+ALTER SEQUENCE task_check_run_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_task_check_run_updated_ts
+BEFORE
+UPDATE
+ ON task_check_run FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Pipeline related END
+-----------------------
+-- issue
+-- Each issue links a pipeline driving the resolution.
+CREATE TABLE issue (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),
+ name TEXT NOT NULL,
+ status TEXT NOT NULL CHECK (status IN ('OPEN', 'DONE', 'CANCELED')),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.issue.%'),
+ description TEXT NOT NULL DEFAULT '',
+ -- While changing assignee_id, one should only change it to a non-robot DBA/owner.
+ assignee_id INTEGER NOT NULL REFERENCES principal (id),
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_issue_project_id ON issue(project_id);
+
+CREATE INDEX idx_issue_pipeline_id ON issue(pipeline_id);
+
+CREATE INDEX idx_issue_creator_id ON issue(creator_id);
+
+CREATE INDEX idx_issue_assignee_id ON issue(assignee_id);
+
+CREATE INDEX idx_issue_created_ts ON issue(created_ts);
+
+ALTER SEQUENCE issue_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_issue_updated_ts
+BEFORE
+UPDATE
+ ON issue FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- stores the issue subscribers. Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.
+-- We use a separate table mainly because we can't leverage indexed query if the subscriber id is stored
+-- as a comma separated id list in the issue table.
+CREATE TABLE issue_subscriber (
+ issue_id INTEGER NOT NULL REFERENCES issue (id),
+ subscriber_id INTEGER NOT NULL REFERENCES principal (id),
+ PRIMARY KEY (issue_id, subscriber_id)
+);
+
+CREATE INDEX idx_issue_subscriber_subscriber_id ON issue_subscriber(subscriber_id);
+
+-- activity table stores the activity for the container such as issue
+CREATE TABLE activity (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ container_id INTEGER NOT NULL CHECK (container_id > 0),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.%'),
+ level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')),
+ comment TEXT NOT NULL DEFAULT '',
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_activity_container_id ON activity(container_id);
+
+CREATE INDEX idx_activity_created_ts ON activity(created_ts);
+
+ALTER SEQUENCE activity_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_activity_updated_ts
+BEFORE
+UPDATE
+ ON activity FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- inbox table stores the inbox entry for the corresponding activity.
+-- Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.
+-- We design in this way because:
+-- 1. The table may potentially contain a lot of rows (an issue activity will generate one inbox record per issue subscriber)
+-- 2. Does not provide much value besides what's contained in the related activity record.
+CREATE TABLE inbox (
+ id SERIAL PRIMARY KEY,
+ receiver_id INTEGER NOT NULL REFERENCES principal (id),
+ activity_id INTEGER NOT NULL REFERENCES activity (id),
+ status TEXT NOT NULL CHECK (status IN ('UNREAD', 'READ'))
+);
+
+CREATE INDEX idx_inbox_receiver_id_activity_id ON inbox(receiver_id, activity_id);
+
+CREATE INDEX idx_inbox_receiver_id_status ON inbox(receiver_id, status);
+
+ALTER SEQUENCE inbox_id_seq RESTART WITH 101;
+
+-- bookmark table stores the bookmark for the user
+CREATE TABLE bookmark (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ link TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX idx_bookmark_unique_creator_id_link ON bookmark(creator_id, link);
+
+ALTER SEQUENCE bookmark_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_bookmark_updated_ts
+BEFORE
+UPDATE
+ ON bookmark FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- vcs table stores the version control provider config
+CREATE TABLE vcs (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ name TEXT NOT NULL,
+ type TEXT NOT NULL CHECK (type IN ('GITLAB_SELF_HOST', 'GITHUB_COM')),
+ instance_url TEXT NOT NULL CHECK ((instance_url LIKE 'http://%' OR instance_url LIKE 'https://%') AND instance_url = rtrim(instance_url, '/')),
+ api_url TEXT NOT NULL CHECK ((api_url LIKE 'http://%' OR api_url LIKE 'https://%') AND api_url = rtrim(api_url, '/')),
+ application_id TEXT NOT NULL,
+ secret TEXT NOT NULL
+);
+
+ALTER SEQUENCE vcs_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_vcs_updated_ts
+BEFORE
+UPDATE
+ ON vcs FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- repository table stores the repository setting for a project
+-- A vcs is associated with many repositories.
+-- A project can only link one repository (at least for now).
+CREATE TABLE repository (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ vcs_id INTEGER NOT NULL REFERENCES vcs (id),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ -- Name from the corresponding VCS provider.
+ -- For GitLab, this is the project name. e.g. project 1
+ name TEXT NOT NULL,
+ -- Full path from the corresponding VCS provider.
+ -- For GitLab, this is the project full path. e.g. group1/project-1
+ full_path TEXT NOT NULL,
+ -- Web url from the corresponding VCS provider.
+ -- For GitLab, this is the project web url. e.g. https://gitlab.example.com/group1/project-1
+ web_url TEXT NOT NULL,
+ -- Branch we are interested.
+ -- For GitLab, this corresponds to webhook's push_events_branch_filter. Wildcard is supported
+ branch_filter TEXT NOT NULL DEFAULT '',
+ -- Base working directory we are interested.
+ base_directory TEXT NOT NULL DEFAULT '',
+ -- The file path template for matching the commited migration script.
+ file_path_template TEXT NOT NULL DEFAULT '',
+ -- The file path template for storing the latest schema auto-generated by Bytebase after migration.
+ -- If empty, then Bytebase won't auto generate it.
+ schema_path_template TEXT NOT NULL DEFAULT '',
+ -- Repository id from the corresponding VCS provider.
+ -- For GitLab, this is the project id. e.g. 123
+ external_id TEXT NOT NULL,
+ -- Push webhook id from the corresponding VCS provider.
+ -- For GitLab, this is the project webhook id. e.g. 123
+ external_webhook_id TEXT NOT NULL,
+ -- Identify the host of the webhook url where the webhook event sends. We store this to identify stale webhook url whose url doesn't match the current bytebase --host.
+ webhook_url_host TEXT NOT NULL,
+ -- Identify the target repository receiving the webhook event. This is a random string.
+ webhook_endpoint_id TEXT NOT NULL,
+ -- For GitLab, webhook request contains this in the 'X-Gitlab-Token" header and we compare it with the one stored in db to validate it sends to the expected endpoint.
+ webhook_secret_token TEXT NOT NULL,
+ -- access_token, expires_ts, refresh_token belongs to the user linking the project to the VCS repository.
+ access_token TEXT NOT NULL,
+ expires_ts BIGINT NOT NULL,
+ refresh_token TEXT NOT NULL,
+ sheet_path_template TEXT NOT NULL DEFAULT ''
+);
+
+CREATE UNIQUE INDEX idx_repository_unique_project_id ON repository(project_id);
+
+CREATE UNIQUE INDEX idx_repository_unique_webhook_endpoint_id ON repository(webhook_endpoint_id);
+
+ALTER SEQUENCE repository_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_repository_updated_ts
+BEFORE
+UPDATE
+ ON repository FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Anomaly
+-- anomaly stores various anomalies found by the scanner.
+-- For now, anomaly can be associated with a particular instance or database.
+CREATE TABLE anomaly (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ instance_id INTEGER NOT NULL REFERENCES instance (id),
+ -- NULL if it's an instance anomaly
+ database_id INTEGER NULL REFERENCES db (id),
+ type TEXT NOT NULL CHECK (type LIKE 'bb.anomaly.%'),
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_anomaly_instance_id_row_status_type ON anomaly(instance_id, row_status, type);
+CREATE INDEX idx_anomaly_database_id_row_status_type ON anomaly(database_id, row_status, type);
+
+ALTER SEQUENCE anomaly_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_anomaly_updated_ts
+BEFORE
+UPDATE
+ ON anomaly FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Label
+-- label_key stores available label keys at workspace level.
+CREATE TABLE label_key (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ key TEXT NOT NULL
+);
+
+-- key's are unique within the label_key table.
+CREATE UNIQUE INDEX idx_label_key_unique_key ON label_key(key);
+
+ALTER SEQUENCE label_key_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_label_key_updated_ts
+BEFORE
+UPDATE
+ ON label_key FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- label_value stores available label key values at workspace level.
+CREATE TABLE label_value (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ key TEXT NOT NULL REFERENCES label_key(key),
+ value TEXT NOT NULL
+);
+
+-- key/value's are unique within the label_value table.
+CREATE UNIQUE INDEX idx_label_value_unique_key_value ON label_value(key, value);
+
+ALTER SEQUENCE label_value_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_label_value_updated_ts
+BEFORE
+UPDATE
+ ON label_value FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- db_label stores labels asscociated with databases.
+CREATE TABLE db_label (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ database_id INTEGER NOT NULL REFERENCES db (id),
+ key TEXT NOT NULL,
+ value TEXT NOT NULL,
+ FOREIGN KEY(key, value) REFERENCES label_value(key, value)
+);
+
+-- database_id/key's are unique within the db_label table.
+CREATE UNIQUE INDEX idx_db_label_unique_database_id_key ON db_label(database_id, key);
+
+ALTER SEQUENCE db_label_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_db_label_updated_ts
+BEFORE
+UPDATE
+ ON db_label FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- Deployment Configuration.
+-- deployment_config stores deployment configurations at project level.
+CREATE TABLE deployment_config (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ name TEXT NOT NULL,
+ config JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE UNIQUE INDEX idx_deployment_config_unique_project_id ON deployment_config(project_id);
+
+ALTER SEQUENCE deployment_config_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_deployment_config_updated_ts
+BEFORE
+UPDATE
+ ON deployment_config FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
+
+-- sheet table stores general statements.
+CREATE TABLE sheet (
+ id SERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ project_id INTEGER NOT NULL REFERENCES project (id),
+ database_id INTEGER NULL REFERENCES db (id),
+ name TEXT NOT NULL,
+ statement TEXT NOT NULL,
+ visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'PROJECT', 'PUBLIC')) DEFAULT 'PRIVATE',
+ source TEXT NOT NULL CHECK (source IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM')) DEFAULT 'BYTEBASE',
+ type TEXT NOT NULL CHECK (type IN ('SQL')) DEFAULT 'SQL',
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_sheet_creator_id ON sheet(creator_id);
+
+CREATE INDEX idx_sheet_project_id_row_status ON sheet(project_id, row_status);
+
+CREATE INDEX idx_sheet_database_id_row_status ON sheet(database_id, row_status);
+
+CREATE INDEX idx_sheet_project_id ON sheet(project_id);
+
+CREATE INDEX idx_sheet_name ON sheet(name);
+
+ALTER SEQUENCE sheet_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_sheet_updated_ts
+BEFORE
+UPDATE
+ ON sheet FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
diff --git a/store/migration/1.1.0/latest_data.sql b/store/migration/1.1.0/latest_data.sql
new file mode 100644
index 0000000000..b5cc1d7708
--- /dev/null
+++ b/store/migration/1.1.0/latest_data.sql
@@ -0,0 +1,553 @@
+-- Create "test" and "prod" environments
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 'Test',
+ 0
+ );
+
+INSERT INTO
+ environment (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ "order"
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 'Prod',
+ 1
+ );
+
+ALTER SEQUENCE environment_id_seq RESTART WITH 103;
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_NEVER"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 102,
+ 'bb.policy.pipeline-approval',
+ '{"value":"MANUAL_APPROVAL_ALWAYS"}'
+ );
+
+INSERT INTO
+ policy (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ type,
+ payload
+ )
+VALUES
+ (
+ 103,
+ 1,
+ 1,
+ 102,
+ 'bb.policy.backup-plan',
+ '{"schedule":"WEEKLY"}'
+ );
+
+ALTER SEQUENCE policy_id_seq RESTART WITH 104;
+
+-- Create label keys for `bb.location` and `bb.tenant`.
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 'bb.location'
+ );
+
+INSERT INTO
+ label_key (
+ id,
+ creator_id,
+ updater_id,
+ key
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 'bb.tenant'
+ );
+
+ALTER SEQUENCE label_key_id_seq RESTART WITH 103;
+
+-- Create 1 "test", 1 "prod" instance (including * database and admin data source)
+-- Both instances contains the connection info we expect user to setup according to https://bytebase.com/docs/install/install-with-docker#start-a-local-mysql-server-for-testing
+-- Set host to 172.17.0.1 which is the default docker gateway ip.
+-- Our quickstart guide suggests to run both Bytebase and MySQL using docker, and in such case, bytebase access the mysqld container via 172.17.0.1
+-- "test" instance
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 'Sample Test instance (Follow the "External Link" field to bring up the MySQL server)',
+ 'MYSQL',
+ '8.0.19',
+ 'host.docker.internal',
+ '3306',
+ 'https://bytebase.com/docs/install/install-with-docker#start-a-local-mysql-server-for-testing'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ creator_id,
+ updater_id,
+ environment_id,
+ name,
+ engine,
+ engine_version,
+ host,
+ port,
+ external_link
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 102,
+ 'Sample Prod instance (Follow the "External Link" field to bring up the MySQL server)',
+ 'MYSQL',
+ '8.0.19',
+ 'host.docker.internal',
+ '3306',
+ 'https://bytebase.com/docs/install/install-with-docker#start-a-local-mysql-server-for-testing'
+ );
+
+ALTER SEQUENCE instance_id_seq RESTART WITH 103;
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+INSERT INTO
+ db (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ project_id,
+ name,
+ character_set,
+ "collation",
+ sync_status,
+ last_successful_sync_ts,
+ schema_version
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 102,
+ 1,
+ '*',
+ 'utf8mb4',
+ 'utf8mb4_general_ci',
+ 'OK',
+ 0,
+ ''
+ );
+
+ALTER SEQUENCE db_id_seq RESTART WITH 103;
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ password
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 101,
+ 'Admin data source',
+ 'ADMIN',
+ 'root',
+ ''
+ );
+
+INSERT INTO
+ data_source (
+ id,
+ creator_id,
+ updater_id,
+ instance_id,
+ database_id,
+ name,
+ TYPE,
+ username,
+ password
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 102,
+ 102,
+ 'Admin data source',
+ 'ADMIN',
+ 'root',
+ ''
+ );
+
+ALTER SEQUENCE data_source_id_seq RESTART WITH 103;
+
+-- Create pipeline/stage/task/issue for onboarding
+-- Create pipeline 101 "Hello world"
+INSERT INTO
+ pipeline (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ status
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 'Pipeline - Hello world',
+ 'OPEN'
+ );
+
+ALTER SEQUENCE pipeline_id_seq RESTART WITH 102;
+
+-- Create stage 101, 102 for pipeline 101
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 101,
+ 'Test'
+ );
+
+INSERT INTO
+ stage (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ environment_id,
+ name
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 101,
+ 102,
+ 'Prod'
+ );
+
+ALTER SEQUENCE stage_id_seq RESTART WITH 103;
+
+-- Create task 101 for stage 101
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 101,
+ 101,
+ NULL,
+ 'Welcome',
+ 'bb.task.general',
+ 'RUNNING',
+ '{"statement":"SELECT ''Welcome Builders'';"}'
+ );
+
+-- Create task 102 for stage 102
+INSERT INTO
+ task (
+ id,
+ creator_id,
+ updater_id,
+ pipeline_id,
+ stage_id,
+ instance_id,
+ database_id,
+ name,
+ type,
+ status,
+ payload
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 101,
+ 102,
+ 102,
+ NULL,
+ 'Let''s go',
+ 'bb.task.general',
+ 'PENDING_APPROVAL',
+ '{"statement":"SELECT ''Let''s go'';"}'
+ );
+
+ALTER SEQUENCE task_id_seq RESTART WITH 103;
+
+-- Create task_run for task 101
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ updater_id,
+ task_id,
+ name,
+ status,
+ type,
+ comment,
+ result,
+ payload
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 'Welcome',
+ 'FAILED',
+ 'bb.task.general',
+ '',
+ '{"detail":"Something is not right..."}',
+ '{}'
+ );
+
+INSERT INTO
+ task_run (
+ id,
+ creator_id,
+ updater_id,
+ task_id,
+ name,
+ status,
+ type,
+ comment,
+ payload
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 101,
+ 'Welcome',
+ 'RUNNING',
+ 'bb.task.general',
+ 'Let''s give another try',
+ '{}'
+ );
+
+ALTER SEQUENCE task_run_id_seq RESTART WITH 103;
+
+-- Create issue 101 "Hello world"
+INSERT INTO
+ issue (
+ id,
+ creator_id,
+ updater_id,
+ project_id,
+ pipeline_id,
+ name,
+ status,
+ type,
+ description,
+ assignee_id
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 1,
+ 101,
+ 'Hello world!',
+ 'OPEN',
+ 'bb.issue.general',
+ 'Welcome to Bytebase, this is the issue interface where developers and DBAs collaborate on database schema management issues such as: \n - Creating a new database\n - Creating a table\n - Creating an index\n - Adding/altering a column\n - Troubleshooting performance issue\nLet''s try some simple tasks:\n1. Bookmark this issue by clicking the star icon on the top of this page\n2. Leave a comment below to greet future comers\n3. Follow the Quickstart on the bottom left to get familiar with other features',
+ 1
+ );
+
+ALTER SEQUENCE issue_id_seq RESTART WITH 102;
+
+-- Create activity 101
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level
+ )
+VALUES
+ (
+ 101,
+ 1,
+ 1,
+ 101,
+ 'bb.issue.create',
+ 'INFO'
+ );
+
+INSERT INTO
+ activity (
+ id,
+ creator_id,
+ updater_id,
+ container_id,
+ type,
+ level,
+ comment
+ )
+VALUES
+ (
+ 102,
+ 1,
+ 1,
+ 101,
+ 'bb.issue.comment.create',
+ 'INFO',
+ 'Go fish!'
+ );
+
+ALTER SEQUENCE activity_id_seq RESTART WITH 103;
diff --git a/store/migration/1.1.0/sheet_vcs.sql b/store/migration/1.1.0/sheet_vcs.sql
new file mode 100644
index 0000000000..a950a71b61
--- /dev/null
+++ b/store/migration/1.1.0/sheet_vcs.sql
@@ -0,0 +1,9 @@
+ALTER TABLE sheet ADD source TEXT NOT NULL CHECK (source IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM')) DEFAULT 'BYTEBASE';
+ALTER TABLE sheet ADD type TEXT NOT NULL CHECK (type IN ('SQL')) DEFAULT 'SQL';
+ALTER TABLE sheet ADD payload JSONB NOT NULL DEFAULT '{}';
+
+CREATE INDEX idx_sheet_project_id ON sheet(project_id);
+
+CREATE INDEX idx_sheet_name ON sheet(name);
+
+ALTER TABLE repository ADD sheet_path_template TEXT NOT NULL DEFAULT '';
diff --git a/store/migration/1.1.0/task_dag.sql b/store/migration/1.1.0/task_dag.sql
new file mode 100644
index 0000000000..b00f439580
--- /dev/null
+++ b/store/migration/1.1.0/task_dag.sql
@@ -0,0 +1,22 @@
+-- task_dag describes task dependency relationship
+-- from_task_id is blocked by to_task_id
+CREATE TABLE task_dag (
+ id SERIAL PRIMARY KEY,
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ from_task_id INTEGER NOT NULL REFERENCES task (id),
+ to_task_id INTEGER NOT NULL REFERENCES task (id),
+ payload JSONB NOT NULL DEFAULT '{}'
+);
+
+CREATE INDEX idx_task_dag_from_task_id ON task_dag(from_task_id);
+
+CREATE INDEX idx_task_dag_to_task_id ON task_dag(to_task_id);
+
+ALTER SEQUENCE task_dag_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_task_dag_updated_ts
+BEFORE
+UPDATE
+ ON task_dag FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
diff --git a/store/migration/10002__1.1.0.sql b/store/migration/10002__1.1.0.sql
deleted file mode 100644
index 0b2672050b..0000000000
--- a/store/migration/10002__1.1.0.sql
+++ /dev/null
@@ -1,41 +0,0 @@
-ALTER TABLE project DROP CONSTRAINT project_role_provider_check;
-ALTER TABLE project ADD CONSTRAINT project_role_provider_check CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM'));
-
-ALTER TABLE project_member DROP CONSTRAINT project_member_role_provider_check;
-ALTER TABLE project_member ADD CONSTRAINT project_member_role_provider_check CHECK (role_provider IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM'));
-
-ALTER TABLE vcs DROP CONSTRAINT vcs_type_check;
-ALTER TABLE vcs ADD CONSTRAINT vcs_type_check CHECK (type IN ('GITLAB_SELF_HOST', 'GITHUB_COM'));
-
-ALTER TABLE sheet ADD source TEXT NOT NULL CHECK (source IN ('BYTEBASE', 'GITLAB_SELF_HOST', 'GITHUB_COM')) DEFAULT 'BYTEBASE';
-ALTER TABLE sheet ADD type TEXT NOT NULL CHECK (type IN ('SQL')) DEFAULT 'SQL';
-ALTER TABLE sheet ADD payload JSONB NOT NULL DEFAULT '{}';
-
-CREATE INDEX idx_sheet_project_id ON sheet(project_id);
-
-CREATE INDEX idx_sheet_name ON sheet(name);
-
-ALTER TABLE repository ADD sheet_path_template TEXT NOT NULL DEFAULT '';
-
--- task_dag describes task dependency relationship
--- from_task_id is blocked by to_task_id
-CREATE TABLE task_dag (
- id SERIAL PRIMARY KEY,
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- from_task_id INTEGER NOT NULL REFERENCES task (id),
- to_task_id INTEGER NOT NULL REFERENCES task (id),
- payload JSONB NOT NULL DEFAULT '{}'
-);
-
-CREATE INDEX idx_task_dag_from_task_id ON task_dag(from_task_id);
-
-CREATE INDEX idx_task_dag_to_task_id ON task_dag(to_task_id);
-
-ALTER SEQUENCE task_dag_id_seq RESTART WITH 101;
-
-CREATE TRIGGER update_task_dag_updated_ts
-BEFORE
-UPDATE
- ON task_dag FOR EACH ROW
-EXECUTE FUNCTION trigger_update_updated_ts();
diff --git a/store/pg_engine.go b/store/pg_engine.go
index b3bd60690c..c67f07da34 100644
--- a/store/pg_engine.go
+++ b/store/pg_engine.go
@@ -1,6 +1,7 @@
package store
import (
+ "bytes"
"context"
"database/sql"
"embed"
@@ -8,10 +9,10 @@ import (
"io/fs"
"path/filepath"
"sort"
- "strconv"
"strings"
"time"
+ "github.com/blang/semver/v4"
dbdriver "github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/common"
@@ -38,15 +39,14 @@ const (
// will require a separate process to upgrade the schema.
// If the new release requires a higher MINOR version than the schema file, then it will apply the migration upon
// startup.
- majorSchemaVervion = 1
- createDatabaseSchemaVersion = "10000"
+ majorSchemaVervion = 1
)
//go:embed migration
var migrationFS embed.FS
-//go:embed seed
-var seedFS embed.FS
+//go:embed demo
+var demoFS embed.FS
// DB represents the database connection.
type DB struct {
@@ -58,11 +58,8 @@ type DB struct {
// The user has superuser privilege to the database.
connCfg dbdriver.ConnectionConfig
- // Dir to load seed data
- seedDir string
-
- // Force reset seed, true for testing and demo
- forceResetSeed bool
+ // Dir to load demo data
+ demoDataDir string
// If true, database will be opened in readonly mode
readonly bool
@@ -71,7 +68,7 @@ type DB struct {
serverVersion string
// schemaVersion is the version of Bytebase schema.
- schemaVersion int
+ schemaVersion semver.Version
// Returns the current time. Defaults to time.Now().
// Can be mocked for tests.
@@ -79,16 +76,15 @@ type DB struct {
}
// NewDB returns a new instance of DB associated with the given datasource name.
-func NewDB(logger *zap.Logger, dsn string, connCfg dbdriver.ConnectionConfig, seedDir string, forceResetSeed bool, readonly bool, serverVersion string, schemaVersion int) *DB {
+func NewDB(logger *zap.Logger, connCfg dbdriver.ConnectionConfig, demoDataDir string, readonly bool, serverVersion string, schemaVersion semver.Version) *DB {
db := &DB{
- l: logger,
- connCfg: connCfg,
- seedDir: seedDir,
- forceResetSeed: forceResetSeed,
- readonly: readonly,
- Now: time.Now,
- serverVersion: serverVersion,
- schemaVersion: schemaVersion,
+ l: logger,
+ connCfg: connCfg,
+ demoDataDir: demoDataDir,
+ readonly: readonly,
+ Now: time.Now,
+ serverVersion: serverVersion,
+ schemaVersion: schemaVersion,
}
return db
}
@@ -108,7 +104,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
databaseName := db.connCfg.Username
if db.readonly {
- db.l.Info("Database is opened in readonly mode. Skip migration and seeding.")
+ db.l.Info("Database is opened in readonly mode. Skip migration and demo data setup.")
// The database storing metadata is the same as user name.
db.db, err = d.GetDbConnection(ctx, databaseName)
if err != nil {
@@ -140,8 +136,8 @@ func (db *DB) Open(ctx context.Context) (err error) {
return fmt.Errorf("failed to connect to database %q, error: %v", db.connCfg.Username, err)
}
- if err := db.seed(verBefore, verAfter); err != nil {
- return fmt.Errorf("failed to seed: %w."+
+ if err := db.setupDemoData(); err != nil {
+ return fmt.Errorf("failed to setup demo data: %w."+
" It could be Bytebase is running against an old Bytebase schema. If you are developing Bytebase, you can remove pgdata"+
" directory under the same directory where the bytebase binary resides. and restart again to let"+
" Bytebase create the latest schema. If you are running in production and don't want to reset the data, you can contact [email protected] for help",
@@ -151,66 +147,60 @@ func (db *DB) Open(ctx context.Context) (err error) {
return nil
}
-func getLatestVersion(ctx context.Context, d dbdriver.Driver, database string) (ver version, err error) {
- // TODO(d): support semantic versioning.
+// getLatestVersion returns the latest schema version in semantic versioning format.
+// If there's no migration history, version will be nil.
+func getLatestVersion(ctx context.Context, d dbdriver.Driver, database string) (*semver.Version, error) {
limit := 1
history, err := d.FindMigrationHistoryList(ctx, &dbdriver.MigrationHistoryFind{
Database: &database,
Limit: &limit,
})
if err != nil {
- return version{}, fmt.Errorf("failed to get migration history, error: %v", err)
+ return nil, fmt.Errorf("failed to get migration history, error: %v", err)
}
if len(history) == 0 {
- return version{major: 0, minor: 0}, nil
+ return nil, nil
}
- v, err := strconv.Atoi(history[0].Version)
+ v, err := semver.Make(history[0].Version)
if err != nil {
- return version{}, fmt.Errorf("invalid version %q, error: %v", history[0].Version, err)
+ return nil, fmt.Errorf("invalid version %q, error: %v", history[0].Version, err)
}
- return versionFromInt(v), nil
+ return &v, nil
}
-// seed loads the seed data for testing
-func (db *DB) seed(verBefore, verAfter version) error {
- db.l.Info(fmt.Sprintf("Seeding database from %s, force: %t ...", db.seedDir, db.forceResetSeed))
- names, err := fs.Glob(seedFS, fmt.Sprintf("%s/*.sql", db.seedDir))
+// setupDemoData loads the setupDemoData data for testing
+func (db *DB) setupDemoData() error {
+ if db.demoDataDir == "" {
+ db.l.Debug("Skip setting up demo data. Demo data directory not specified.")
+ return nil
+ }
+ db.l.Info(fmt.Sprintf("Setting up demo data from %q...", db.demoDataDir))
+ names, err := fs.Glob(demoFS, fmt.Sprintf("%s/*.sql", db.demoDataDir))
if err != nil {
return err
}
- // We separate seed data for each table into their own seed file.
+ // We separate demo data for each table into their own demo data file.
// And there exists foreign key dependency among tables, so we
- // name the seed file as 10001_xxx.sql, 10002_xxx.sql. Here we sort
+ // name the data file as 10001_xxx.sql, 10002_xxx.sql. Here we sort
// the file name so they are loaded accordingly.
sort.Strings(names)
- // Loop over all seed files and execute them in order.
+ // Loop over all data files and execute them in order.
for _, name := range names {
- versionPrefix := strings.Split(filepath.Base(name), "__")[0]
- version, err := strconv.Atoi(versionPrefix)
- if err != nil {
- return fmt.Errorf("invalid seed file format %s, expected number prefix", filepath.Base(name))
- }
- ver := versionFromInt(version)
- if db.forceResetSeed || ver.biggerThan(verBefore) && !ver.biggerThan(verAfter) {
- if err := db.seedFile(name); err != nil {
- return fmt.Errorf("seed error: name=%q err=%w", name, err)
- }
- } else {
- db.l.Info(fmt.Sprintf("Skip this seed file: %s. The corresponding seed version %s is not in the applicable range (%s, %s].",
- name, ver, verBefore, verAfter))
+ if err := db.applyDataFile(name); err != nil {
+ return fmt.Errorf("applyDataFile error: name=%q err=%w", name, err)
}
}
- db.l.Info("Completed database seeding.")
+ db.l.Info("Completed demo data setup.")
return nil
}
-// seedFile runs a single seed file within a transaction.
-func (db *DB) seedFile(name string) error {
- db.l.Info(fmt.Sprintf("Seeding %s...", name))
+// applyDataFile runs a single demo data file within a transaction.
+func (db *DB) applyDataFile(name string) error {
+ db.l.Info(fmt.Sprintf("Applying data file %s...", name))
tx, err := db.db.Begin()
if err != nil {
return err
@@ -218,7 +208,7 @@ func (db *DB) seedFile(name string) error {
defer tx.Rollback()
// Read and execute migration file.
- if buf, err := fs.ReadFile(seedFS, name); err != nil {
+ if buf, err := fs.ReadFile(demoFS, name); err != nil {
return err
} else if _, err := tx.Exec(string(buf)); err != nil {
return err
@@ -227,6 +217,11 @@ func (db *DB) seedFile(name string) error {
return tx.Commit()
}
+const (
+ latestSchemaFile = "latest.sql"
+ latestDataFile = "latest_data.sql"
+)
+
// migrate sets up migration tracking and executes pending migration files.
//
// Migration files are embedded in the migration folder and are executed
@@ -234,88 +229,152 @@ func (db *DB) seedFile(name string) error {
//
// We prepend each migration file with version = xxx; Each migration
// file run in a transaction to prevent partial migrations.
-func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, databaseName string) error {
+func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer *semver.Version, databaseName string) error {
db.l.Info("Apply database migration if needed...")
- db.l.Info(fmt.Sprintf("Current schema version before migration: %s", curVer))
-
- // major version is 0 when the store isn't yet setup for the first time.
- if curVer.major != 0 && curVer.major != majorSchemaVervion {
- return fmt.Errorf("current major schema version %d is different from the major schema version %d this release %s expects", curVer.major, majorSchemaVervion, db.serverVersion)
+ db.l.Info(fmt.Sprintf("The release cutoff schema version: %s", db.schemaVersion))
+ if curVer == nil {
+ db.l.Info("The database schema has not been setup.")
+ } else {
+ db.l.Info(fmt.Sprintf("Current schema version before migration: %s", curVer))
+ major := (*curVer).Major
+ if major != majorSchemaVervion {
+ return fmt.Errorf("current major schema version %d is different from the major schema version %d this release %s expects", major, majorSchemaVervion, db.serverVersion)
+ }
}
- if curVer.major == 0 && curVer.minor == 0 {
- createDatabaseStatement := fmt.Sprintf("CREATE DATABASE %s", databaseName)
- // TODO(d): support semantic versioning.
+ // Initial schema setup.
+ if curVer == nil {
+ latestSchemaPath := fmt.Sprintf("migration/%s/%s", db.schemaVersion.String(), latestSchemaFile)
+ buf, err := migrationFS.ReadFile(latestSchemaPath)
+ if err != nil {
+ return fmt.Errorf("failed to read latest schema %q, error %w", latestSchemaPath, err)
+ }
+ latestDataPath := fmt.Sprintf("migration/%s/%s", db.schemaVersion.String(), latestDataFile)
+ dataBuf, err := migrationFS.ReadFile(latestDataPath)
+ if err != nil {
+ return fmt.Errorf("failed to read latest data %q, error %w", latestSchemaPath, err)
+ }
+ // We will create the database together with initial schema and data migration.
+ stmt := fmt.Sprintf("CREATE DATABASE %s;\n\\connect \"%s\";\n%s\n%s", databaseName, databaseName, buf, dataBuf)
if _, _, err := d.ExecuteMigration(
ctx,
&dbdriver.MigrationInfo{
- ReleaseVersion: db.serverVersion,
- Version: createDatabaseSchemaVersion,
- Namespace: databaseName,
- Database: databaseName,
- Environment: "", /* unused in execute migration */
- Source: dbdriver.LIBRARY,
- Type: dbdriver.Baseline,
- Description: fmt.Sprintf("Create database %s.", databaseName),
- CreateDatabase: true,
+ ReleaseVersion: db.serverVersion,
+ UseSemanticVersion: true,
+ Version: db.schemaVersion.String(),
+ SemanticVersionSuffix: time.Now().Format("20060102150405"),
+ Namespace: databaseName,
+ Database: databaseName,
+ Environment: "", /* unused in execute migration */
+ Source: dbdriver.LIBRARY,
+ Type: dbdriver.Migrate,
+ Description: fmt.Sprintf("Initial migration version %s server version %s with file %s.", db.schemaVersion, db.serverVersion, latestSchemaPath),
+ CreateDatabase: true,
},
- createDatabaseStatement,
+ stmt,
); err != nil {
- return fmt.Errorf("failed to migrate create database schema, error: %v", err)
+ return fmt.Errorf("failed to migrate initial schema version %q, error: %v", latestSchemaPath, err)
}
+ db.l.Info("Completed database initial migration.")
+ return nil
}
// Apply migrations
- names, err := fs.Glob(migrationFS, "migration/*.sql")
+ versionNames, err := fs.Glob(migrationFS, "migration/*")
if err != nil {
return err
}
- // Sort the migration up file in ascending order.
- sort.Strings(names)
+ var versions []semver.Version
+ for _, name := range versionNames {
+ v, err := semver.Make(strings.TrimPrefix(name, "migration/"))
+ if err != nil {
+ return fmt.Errorf("invalid migration file path %q, error %w", name, err)
+ }
+ versions = append(versions, v)
+ }
+ // Sort the migration semantic version in ascending order.
+ sort.Slice(versions, func(i, j int) bool {
+ return versions[i].LT(versions[j])
+ })
- maxVer := versionFromInt(db.schemaVersion)
- for _, name := range names {
- versionPrefix := strings.Split(filepath.Base(name), "__")[0]
- version, err := strconv.Atoi(versionPrefix)
+ migrateVersions, messages := getMigrationVersions(versions, db.schemaVersion, *curVer)
+ for _, message := range messages {
+ db.l.Info(message)
+ }
+
+ for _, version := range migrateVersions {
+ // Migrate migration files.
+ db.l.Info(fmt.Sprintf("Migrating %s...", version))
+ names, err := fs.Glob(migrationFS, fmt.Sprintf("migration/%s/*.sql", version))
if err != nil {
- return fmt.Errorf("invalid migration file format %s, expected number prefix", filepath.Base(name))
+ return err
}
- v := versionFromInt(version)
- if v.biggerThan(maxVer) {
- db.l.Debug(fmt.Sprintf("Skip this migration file: %s. The corresponding migration version %s is bigger than maximum schema version %s.", name, v, maxVer))
- } else if v.biggerThan(curVer) {
- // Migrate migration files.
- db.l.Info(fmt.Sprintf("Migrating %s...", name))
+ var stmtBuf bytes.Buffer
+ var baseNames []string
+ for _, name := range names {
+ // Skip the latest sql file.
+ baseName := filepath.Base(name)
+ if baseName == latestSchemaFile {
+ continue
+ }
+ if baseName == latestDataFile {
+ continue
+ }
+ baseNames = append(baseNames, baseName)
buf, err := fs.ReadFile(migrationFS, name)
if err != nil {
- return err
+ return fmt.Errorf("failed to read migration file %q, error %w", name, err)
+ }
+ if _, err := stmtBuf.Write(buf); err != nil {
+ return fmt.Errorf("failed to write buffer for migration file %q, error %w", name, err)
}
- // TODO(d): support semantic versioning.
- if _, _, err := d.ExecuteMigration(
- ctx,
- &dbdriver.MigrationInfo{
- ReleaseVersion: db.serverVersion,
- Version: fmt.Sprintf("%d", version),
- Namespace: databaseName,
- Database: databaseName,
- Environment: "", /* unused in execute migration */
- Source: dbdriver.LIBRARY,
- Type: dbdriver.Migrate,
- Description: fmt.Sprintf("Migrate %s.", filepath.Base(name)),
- },
- string(buf),
- ); err != nil {
- return fmt.Errorf("failed to migrate schema version %q, error: %v", filepath.Base(name), err)
+ if _, err := stmtBuf.WriteString("\n\n"); err != nil {
+ return fmt.Errorf("failed to write newline buffer for migration file %q, error %w", name, err)
}
- } else {
- db.l.Info(fmt.Sprintf("Skip this migration file: %s. The corresponding migration version %s has already been applied.", name, v))
+ db.l.Debug(fmt.Sprintf("Reading migration file %q.", name))
+ }
+ if _, _, err := d.ExecuteMigration(
+ ctx,
+ &dbdriver.MigrationInfo{
+ ReleaseVersion: db.serverVersion,
+ UseSemanticVersion: true,
+ Version: version.String(),
+ SemanticVersionSuffix: time.Now().Format("20060102150405"),
+ Namespace: databaseName,
+ Database: databaseName,
+ Environment: "", /* unused in execute migration */
+ Source: dbdriver.LIBRARY,
+ Type: dbdriver.Migrate,
+ Description: fmt.Sprintf("Migrate version %s server version %s with files %s.", version, db.serverVersion, strings.Join(baseNames, ", ")),
+ },
+ stmtBuf.String(),
+ ); err != nil {
+ return fmt.Errorf("failed to migrate schema version %q, error: %v", version, err)
}
}
-
db.l.Info("Completed database migration.")
return nil
}
+func getMigrationVersions(versions []semver.Version, releaseCutSchemaVersion, currentVersion semver.Version) ([]semver.Version, []string) {
+ var migrateVersions []semver.Version
+ var messages []string
+ for _, version := range versions {
+ // If the migration version is greater than the schema version this build expects, we will skip the migration.
+ if version.GT(releaseCutSchemaVersion) {
+ messages = append(messages, fmt.Sprintf("Skip this migration: %s; the corresponding migration version %s is bigger than maximum schema version %s.", version, version, releaseCutSchemaVersion))
+ continue
+ }
+ // If the migration version is less than or equal to the current version, we will skip the migration since it's already applied.
+ if version.LE(currentVersion) {
+ messages = append(messages, fmt.Sprintf("Skip this migration: %s; the current schema version %s is higher.", version, currentVersion))
+ continue
+ }
+ migrateVersions = append(migrateVersions, version)
+ }
+ return migrateVersions, messages
+}
+
// Close closes the database connection.
func (db *DB) Close() error {
// Close database.
diff --git a/store/pg_engine_test.go b/store/pg_engine_test.go
new file mode 100644
index 0000000000..2552c41ac9
--- /dev/null
+++ b/store/pg_engine_test.go
@@ -0,0 +1,49 @@
+package store
+
+import (
+ "testing"
+
+ "github.com/blang/semver/v4"
+ "github.com/stretchr/testify/require"
+)
+
+func TestGetMigrationVersions(t *testing.T) {
+ versions := []semver.Version{semver.MustParse("1.0.0"), semver.MustParse("1.1.0"), semver.MustParse("1.1.1"), semver.MustParse("1.2.0"), semver.MustParse("1.3.0")}
+
+ tests := []struct {
+ versions []semver.Version
+ releaseCutSchemaVersion semver.Version
+ currentVersion semver.Version
+ want []semver.Version
+ }{
+ {
+ versions,
+ semver.MustParse("1.0.0"),
+ semver.MustParse("1.0.0"),
+ nil,
+ },
+ {
+ versions,
+ semver.MustParse("1.1.1"),
+ semver.MustParse("1.1.1"),
+ nil,
+ },
+ {
+ versions,
+ semver.MustParse("1.1.1"),
+ semver.MustParse("1.0.0"),
+ []semver.Version{semver.MustParse("1.1.0"), semver.MustParse("1.1.1")},
+ },
+ {
+ versions,
+ semver.MustParse("1.3.0"),
+ semver.MustParse("1.0.0"),
+ []semver.Version{semver.MustParse("1.1.0"), semver.MustParse("1.1.1"), semver.MustParse("1.2.0"), semver.MustParse("1.3.0")},
+ },
+ }
+
+ for _, test := range tests {
+ migrateVersions, _ := getMigrationVersions(test.versions, test.releaseCutSchemaVersion, test.currentVersion)
+ require.Equal(t, test.want, migrateVersions)
+ }
+}
diff --git a/store/seed/README.md b/store/seed/README.md
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/store/seed/release/README.md b/store/seed/release/README.md
deleted file mode 100644
index f888101b79..0000000000
--- a/store/seed/release/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-This folder contains the seed data for release. The release seed data is used when building with "release" tag or running with --demo.
-
-The seed data file name follows the same naming convention as the migration file like {{version_number}}\_\_{{description}}, where {{version_number}}
-corresponds to the migration file having the same {{version_number}}. The particular release seed data file is ONLY loaded when the corresponding migration file has been applied, which means it should only be loaded once together with running the migration file.
diff --git a/store/seed/test/README.md b/store/seed/test/README.md
deleted file mode 100644
index c30cb3d170..0000000000
--- a/store/seed/test/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-This folder contains the seed data for test. The test seed data is used when NOT building with "release" tag or running with --demo. Test seed data is
-reloaded everytime we start the application (by setting forceResetSeed in the dev profile from the code)
-
-Each file represents the data for a particular table. The file name is something like YXXXX, where Y is the major version number and XXXX is the id
-start sequence number for that table, reasons for doing this:
-
-- Y (majar version number) corresponds to the major schema version the seed file applies to
-
-- Code loads the seed data in lexical file order, thus we maintain an explict order about how seed data is loaded since there exists order dependency between tables.
-
-- Because XXXX corresponds to the id prefix for the record, so we can identify the resource type by just looking the id, and catch errors that our code accidentally passes an ID for a different resource type.
diff --git a/store/version.go b/store/version.go
deleted file mode 100644
index d36cb6e3c7..0000000000
--- a/store/version.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package store
-
-import "fmt"
-
-type version struct {
- major, minor int
-}
-
-func newVersion(major, minor int) version {
- return version{
- major: major,
- minor: minor,
- }
-}
-
-func versionFromInt(v int) version {
- return newVersion(v/10000, v%10000)
-}
-
-func (v version) biggerThan(other version) bool {
- if v.major > other.major {
- return true
- }
- return v.major == other.major && v.minor > other.minor
-}
-
-func (v version) String() string {
- return fmt.Sprintf("%d.%d", v.major, v.minor)
-}
diff --git a/store/version_test.go b/store/version_test.go
deleted file mode 100644
index 7b628d70d1..0000000000
--- a/store/version_test.go
+++ /dev/null
@@ -1,107 +0,0 @@
-package store
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func Test_versionFromInt(t *testing.T) {
- t.Run("should parse major and minor correctly", func(t *testing.T) {
- tests := []struct {
- num, major, minor int
- }{
- {10031, 1, 31},
- {131, 0, 131},
- {20009, 2, 9},
- }
- for _, tt := range tests {
- v := versionFromInt(tt.num)
- assert.Equal(t, v.major, tt.major)
- assert.Equal(t, v.minor, tt.minor)
- }
- })
-}
-
-func Test_version_biggerThan(t *testing.T) {
- type fields struct {
- major int
- minor int
- }
- type args struct {
- other version
- }
- tests := []struct {
- name string
- fields fields
- args args
- want bool
- }{
- {
- name: "should return true if major is bigger",
- fields: fields{
- major: 1,
- minor: 0,
- },
- args: args{
- other: version{
- major: 0,
- minor: 0,
- },
- },
- want: true,
- },
- {
- name: "should return true if major and minor are bigger",
- fields: fields{
- major: 1,
- minor: 1,
- },
- args: args{
- other: version{
- major: 1,
- minor: 0,
- },
- },
- want: true,
- },
- {
- name: "should return false if major is smaller",
- fields: fields{
- major: 0,
- minor: 0,
- },
- args: args{
- other: version{
- major: 1,
- minor: 0,
- },
- },
- want: false,
- },
- {
- name: "should return false if major and minor are smaller",
- fields: fields{
- major: 0,
- minor: 0,
- },
- args: args{
- other: version{
- major: 1,
- minor: 1,
- },
- },
- want: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- v := version{
- major: tt.fields.major,
- minor: tt.fields.minor,
- }
- got := v.biggerThan(tt.args.other)
- assert.Equal(t, got, tt.want)
- })
- }
-}