Skip to content

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

chore: schema change for adding environment to database (#7184)

Danny Xu8bb6c0139c4e
diff --git a/backend/migrator/migration/dev/LATEST.sql b/backend/migrator/migration/dev/LATEST.sql
index aa00a9dfaa..58545bf9ef 100644
--- a/backend/migrator/migration/dev/LATEST.sql
+++ b/backend/migrator/migration/dev/LATEST.sql
@@ -325,7 +325,7 @@ CREATE TABLE instance (
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),
+ environment_id INTEGER REFERENCES environment (id),
name TEXT NOT NULL,
engine TEXT NOT NULL,
engine_version TEXT NOT NULL DEFAULT '',
@@ -380,6 +380,7 @@ CREATE TABLE db (
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),
+ environment_id INTEGER REFERENCES environment (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')),
diff --git a/backend/migrator/migration/prod/2.5/0003##db_env.sql b/backend/migrator/migration/prod/2.5/0003##db_env.sql
new file mode 100644
index 0000000000..a1066a6c8c
--- /dev/null
+++ b/backend/migrator/migration/prod/2.5/0003##db_env.sql
@@ -0,0 +1,2 @@
+ALTER TABLE db ADD COLUMN environment_id INTEGER REFERENCES environment (id);
+ALTER TABLE instance ALTER COLUMN environment_id DROP NOT NULL;
diff --git a/backend/migrator/migration/prod/LATEST.sql b/backend/migrator/migration/prod/LATEST.sql
index 68f2c21fdf..b217cffa56 100644
--- a/backend/migrator/migration/prod/LATEST.sql
+++ b/backend/migrator/migration/prod/LATEST.sql
@@ -324,7 +324,7 @@ CREATE TABLE instance (
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),
+ environment_id INTEGER REFERENCES environment (id),
name TEXT NOT NULL,
engine TEXT NOT NULL,
engine_version TEXT NOT NULL DEFAULT '',
@@ -379,6 +379,7 @@ CREATE TABLE db (
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),
+ environment_id INTEGER REFERENCES environment (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')),
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index b1c2069610..281f697942 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -241,5 +241,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("2.5.2"), releaseVersion)
+ require.Equal(t, semver.MustParse("2.5.3"), releaseVersion)
}