Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove combine latest data (#15137)
Danny Xuf8e306bef3f4
diff --git a/backend/legacyapi/principal.go b/backend/legacyapi/principal.goindex e8c5054b78..c204fa85cf 100644--- a/backend/legacyapi/principal.go+++ b/backend/legacyapi/principal.go@@ -6,9 +6,6 @@ const SystemBotID = 1// SystemBotEmail is the email of the system robot.const SystemBotEmail = "[email protected]"-// AllUsersID is the ID of the allUsers robot.-const AllUsersID = 2-// AllUsers is the email of the pseudo allUsers account.const AllUsers = "allUsers"diff --git a/backend/legacyapi/project.go b/backend/legacyapi/project.goindex 3eee8a8aaf..2153c2325a 100644--- a/backend/legacyapi/project.go+++ b/backend/legacyapi/project.go@@ -3,14 +3,10 @@ package apiconst (// DefaultProjectID is the resource ID for the default project.DefaultProjectID = "default"-- // Below are defined in LATEST_DATA.sql.-// DefaultTestEnvironmentID is the initial resource ID for the test environment.// This can be mutated by the user. But for now this is only used by onboarding flow to create// a test instance after first signup, so it's safe to refer it.DefaultTestEnvironmentID = "test"-// DefaultProdEnvironmentID is the initial resource ID for the prod environment.// This can be mutated by the user. But for now this is only used by onboarding flow to create// a prod instance after first signup, so it's safe to refer it.diff --git a/backend/migrator/migration/3.4/0001##cleanup.sql b/backend/migrator/migration/3.4/0001##cleanup.sqlnew file mode 100644index 0000000000..ec4d7ad274--- /dev/null+++ b/backend/migrator/migration/3.4/0001##cleanup.sql@@ -0,0 +1 @@+DROP TABLE branch;\ No newline at end of filediff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sqlindex ba6b4e1c0d..c417f65769 100644--- a/backend/migrator/migration/LATEST.sql+++ b/backend/migrator/migration/LATEST.sql@@ -36,52 +36,6 @@ CREATE TABLE principal (profile JSONB NOT NULL DEFAULT '{}');--- 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',- '[email protected]',- ''- );---- Pseudo allUsers account id is 2.-INSERT INTO- principal (- id,- creator_id,- updater_id,- type,- name,- email,- password_hash- )-VALUES- (- 2,- 2,- 2,- 'SYSTEM_BOT',- 'All Users',- 'allUsers',- ''- );--ALTER SEQUENCE principal_id_seq RESTART WITH 101;--- SettingCREATE TABLE setting (id SERIAL PRIMARY KEY,@@ -177,27 +131,6 @@ CREATE UNIQUE INDEX idx_project_unique_key ON project(key);CREATE UNIQUE INDEX idx_project_unique_resource_id ON project(resource_id);-INSERT INTO- project (- id,- creator_id,- updater_id,- name,- key,- resource_id- )-VALUES- (- 1,- 1,- 1,- 'Default',- 'DEFAULT',- 'default'- );--ALTER SEQUENCE project_id_seq RESTART WITH 101;--- Project HookCREATE TABLE project_webhook (id SERIAL PRIMARY KEY,@@ -900,30 +833,6 @@ CREATE UNIQUE INDEX idx_changelist_project_id_name ON changelist(project_id, namALTER SEQUENCE changelist_id_seq RESTART WITH 101;-CREATE TABLE branch (- 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,- engine TEXT NOT NULL,- base JSONB NOT NULL DEFAULT '{}',- head JSONB NOT NULL DEFAULT '{}',- base_schema TEXT NOT NULL DEFAULT '',- head_schema TEXT NOT NULL DEFAULT '',- reconcile_state TEXT NOT NULL DEFAULT '',- config JSONB NOT NULL DEFAULT '{}'-);--CREATE UNIQUE INDEX idx_branch_unique_project_id_name ON branch(project_id, name);--CREATE INDEX idx_branch_reconcile_state ON branch(reconcile_state);--ALTER SEQUENCE branch_id_seq RESTART WITH 101;-CREATE TABLE export_archive (id SERIAL PRIMARY KEY,created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),@@ -1021,3 +930,20 @@ CREATE TABLE IF NOT EXISTS release (ALTER SEQUENCE release_id_seq RESTART WITH 101;CREATE INDEX idx_release_project_id ON release (project_id);+++-- 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', '[email protected]', '');++ALTER SEQUENCE principal_id_seq RESTART WITH 101;++-- Default project.+INSERT INTO project (id, creator_id, updater_id, name, key, resource_id) VALUES (1, 1, 1, 'Default', 'DEFAULT', 'default');++ALTER SEQUENCE project_id_seq RESTART WITH 101;++-- Create "test" and "prod" environments+INSERT INTO environment (id, creator_id, updater_id, name, "order", resource_id) VALUES (101, 1, 1, 'Test', 0, 'test');+INSERT INTO environment (id, creator_id, updater_id, name, "order", resource_id) VALUES (102, 1, 1, 'Prod', 1, 'prod');++ALTER SEQUENCE environment_id_seq RESTART WITH 103;diff --git a/backend/migrator/migration/LATEST_DATA.sql b/backend/migrator/migration/LATEST_DATA.sqldeleted file mode 100644index 7fc9f29aac..0000000000--- a/backend/migrator/migration/LATEST_DATA.sql+++ /dev/null@@ -1,40 +0,0 @@--- Create "test" and "prod" environments-INSERT INTO- environment (- id,- creator_id,- updater_id,- name,- "order",- resource_id- )-VALUES- (- 101,- 1,- 1,- 'Test',- 0,- 'test'- );--INSERT INTO- environment (- id,- creator_id,- updater_id,- name,- "order",- resource_id- )-VALUES- (- 102,- 1,- 1,- 'Prod',- 1,- 'prod'- );--ALTER SEQUENCE environment_id_seq RESTART WITH 103;diff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.goindex 83a8ccb277..a872060c66 100644--- a/backend/migrator/migrator.go+++ b/backend/migrator/migrator.go@@ -101,14 +101,7 @@ func initializeSchema(ctx context.Context, storeInstance *store.Store, metadataDif err != nil {return errors.Wrapf(err, "failed to read latest schema %q", latestSchemaPath)}- latestDataPath := fmt.Sprintf("migration/%s", latestDataFile)- dataBuf, err := migrationFS.ReadFile(latestDataPath)- if err != nil {- return errors.Wrapf(err, "failed to read latest data %q", latestSchemaPath)- }-- // We will create the database together with initial schema and data migration.- stmt := fmt.Sprintf("%s\n%s", buf, dataBuf)+ stmt := string(buf)version := model.Version{Semantic: true, Version: cutoffSchemaVersion.String(), Suffix: time.Now().Format("20060102150405")}// Set role to database owner so that the schema owner and database owner are consistent.@@ -243,7 +236,6 @@ func getLatestVersion(ctx context.Context, storeInstance *store.Store) (semver.Vconst (latestSchemaFile = "LATEST.sql"- latestDataFile = "LATEST_DATA.sql")// migrate sets up migration tracking and executes pending migration files.@@ -415,7 +407,7 @@ func getMinorVersions(names []string) ([]semver.Version, error) {var versions []semver.Versionfor _, name := range names {baseName := filepath.Base(name)- if baseName == latestSchemaFile || baseName == latestDataFile {+ if baseName == latestSchemaFile {continue}// Convert minor version to semantic version format, e.g. "1.12" will be "1.12.0".diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex e6c5697805..b9930e986d 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -19,7 +19,7 @@ import ()func TestGetMinorMigrationVersions(t *testing.T) {- names := []string{latestDataFile, latestSchemaFile, "1.0", "1.1", "1.2", "1.3", "1.4"}+ names := []string{latestSchemaFile, "1.0", "1.1", "1.2", "1.3", "1.4"}tests := []struct {names []string@@ -60,11 +60,11 @@ func TestGetMinorVersions(t *testing.T) {want []semver.Version}{{- names: []string{fmt.Sprintf("migration/release/%s", latestDataFile), fmt.Sprintf("migration/dev/%s", latestSchemaFile), "migration/release/1.1", "migration/release/1.0"},+ names: []string{fmt.Sprintf("migration/dev/%s", latestSchemaFile), "migration/release/1.1", "migration/release/1.0"},want: []semver.Version{semver.MustParse("1.0.0"), semver.MustParse("1.1.0")},},{- names: []string{fmt.Sprintf("migration/release/%s", latestDataFile), fmt.Sprintf("migration/dev/%s", latestSchemaFile)},+ names: []string{fmt.Sprintf("migration/dev/%s", latestSchemaFile)},want: nil,},}@@ -217,5 +217,5 @@ func TestMigrationCompatibility(t *testing.T) {func TestGetCutoffVersion(t *testing.T) {releaseVersion, err := getProdCutoffVersion()require.NoError(t, err)- require.Equal(t, semver.MustParse("3.4.0"), releaseVersion)+ require.Equal(t, semver.MustParse("3.4.1"), releaseVersion)}diff --git a/docs/schema-update-guide.md b/docs/schema-update-guide.mddeleted file mode 100644index 446df6f1dc..0000000000--- a/docs/schema-update-guide.md+++ /dev/null@@ -1,42 +0,0 @@-# Schema Update Guide--This document goes over the scheme update process during development and production release.--All schemas are located at [store/migration](https://github.com/bytebase/bytebase/tree/main/store/migration). Bytebase schema release follows semantic versioning.--Prod--- [prod](https://github.com/bytebase/bytebase/tree/main/backend/migrator/migration/prod) schema.-- `LATEST.sql` and `LATEST_DATA.sql` will be the schema and data to initialize a new database.-- The version directory such as `1.1` contains all the DDL statements used to migrate from previous version of schema such as `1.0`. When a prod release binary starts, it will apply all the schema migrations from current version up to the latest schema release version.--Dev--- [dev](https://github.com/bytebase/bytebase/tree/main/backend/migrator/migration/dev) schema.-- `LATEST.sql` and `LATEST_DATA.sql` will only be used to view the latest schema and data. This is different from the Prod.-- When a dev release binary starts, it will use the `LATEST.sql` in the release directory to initialize the database and then apply all the DDLs in the dev directory if not yet applied.--Demo Data--- When the binary starts in Demo mode, we will seed [demo data](https://github.com/bytebase/bytebase/tree/main/backend/migrator/demo) to provide a better onboarding experience.--## Development--1. Add a DDL SQL file such as `dev/20220408000000##schema_version_type.sql`. The prefix numbers should be the date time format when the PR is sent.-2. Update `LATEST.sql` and `LATEST_DATA.sql` w.r.t. the DDL changes. (TODO: auto-generate the latest schema)-3. Update Dev Demo data if needed.-4. Since we use the same code for both dev and release schemas, we should add if-else branching to read storage differently based on schema version, such as [this example](https://github.com/bytebase/bytebase/pull/1039).--## Release-Releaser should take the following steps for schema update release, about once a month. A DDL file should only be moved forward to release only if the feature is completed and well tested.--1. Create a new version directory in the release directory, such as `release/1.6`.-1. Move DDLs to be released from `dev` to `release/1.6`. Rename DDL SQL file prefixes in sure the prefixes are in consecutively increasing order starting from `0000`.-2. Update `prod/LATEST.sql` and `prod/LATEST_DATA.sql` w.r.t. DDLs to be released. (TODO: auto-generate the latest schema)-3. Copy over Dev Demo data to Prod Demo directory for the changes to be released.--### DML Change--> **Note** Changing the structure of a JSON field is considered to be a schema change and should follow the DDL change practice. See [this example](https://github.com/bytebase/bytebase/pull/4232/files#diff-199bfe21ce52a70858acbc212c5463c8bd7853c09b077c4da53cd73ccee38e8b)--For DML file release, we don't need to bump up the minor version because the database schema does not change. We can move the file to the current schema release directory and rename it by following the format above. See [this example](https://github.com/bytebase/bytebase/pull/2439).\ No newline at end of file