Skip to content

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

Add row_status column to every table

天舟cca72cdf5e3d
diff --git a/backend/store/environment.go b/backend/store/environment.go
index 1d40fb3437..8dd0b6d12a 100644
--- a/backend/store/environment.go
+++ b/backend/store/environment.go
@@ -130,14 +130,13 @@ func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *Tx, crea
// Insert row into database.
row2, err2 := tx.QueryContext(ctx, `
INSERT INTO environment (
- row_status,
workspace_id,
creator_id,
updater_id,
name,
`+"`order`"+`
)
- VALUES ('NORMAL', ?, ?, ?, ?, ?)
+ VALUES (?, ?, ?, ?, ?)
RETURNING id, row_status, workspace_id, creator_id, created_ts, updater_id, updated_ts, name, `+"`order`"+`
`,
create.WorkspaceId,
diff --git a/backend/store/instance.go b/backend/store/instance.go
index c8999711f7..da73641c8a 100644
--- a/backend/store/instance.go
+++ b/backend/store/instance.go
@@ -107,7 +107,6 @@ func createInstance(ctx context.Context, tx *Tx, create *api.InstanceCreate) (*a
// Insert row into database.
row, err := tx.QueryContext(ctx, `
INSERT INTO instance (
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -117,10 +116,9 @@ func createInstance(ctx context.Context, tx *Tx, create *api.InstanceCreate) (*a
host,
port
)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, workspace_id, environment_id, name, external_link, host, port
`,
- "NORMAL",
create.CreatorId,
create.CreatorId,
create.WorkspaceId,
@@ -284,19 +282,3 @@ func patchInstance(ctx context.Context, tx *Tx, patch *api.InstancePatch) (*api.
return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance ID not found: %d", patch.ID)}
}
-
-// deleteInstance permanently deletes a instance by ID.
-func deleteInstance(ctx context.Context, tx *Tx, delete *api.InstanceDelete) error {
- // Remove row from database.
- result, err := tx.ExecContext(ctx, `DELETE FROM instance WHERE id = ?`, delete.ID)
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance ID not found: %d", delete.ID)}
- }
-
- return nil
-}
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 427e85da40..d03c2c6e1b 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -1,6 +1,9 @@
-- principal
CREATE TABLE principal (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ) DEFAULT 'NORMAL',
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
@@ -62,13 +65,13 @@ VALUES
-- introduce workspace table at that time.
CREATE TABLE workspace (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ) DEFAULT 'NORMAL',
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- row_status TEXT NOT NULL CHECK (
- `row_status` IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
- ),
slug TEXT NOT NULL UNIQUE,
name TEXT NOT NULL
);
@@ -97,16 +100,18 @@ INSERT INTO
id,
creator_id,
updater_id,
- row_status,
slug,
name
)
VALUES
- (1, 1, 1, 'NORMAL', '', 'Default workspace');
+ (1, 1, 1, '', 'Default workspace');
-- Member table stores the workspace membership
CREATE TABLE member (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ) DEFAULT 'NORMAL',
workspace_id INTEGER NOT NULL REFERENCES workspace (id),
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
@@ -142,7 +147,7 @@ CREATE TABLE environment (
id INTEGER PRIMARY KEY AUTOINCREMENT,
row_status TEXT NOT NULL CHECK (
row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
- ),
+ ) DEFAULT 'NORMAL',
workspace_id INTEGER NOT NULL REFERENCES workspace (id),
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
@@ -175,7 +180,7 @@ CREATE TABLE instance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
row_status TEXT NOT NULL CHECK (
row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
- ),
+ ) DEFAULT 'NORMAL',
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updater_id INTEGER NOT NULL REFERENCES principal (id),
diff --git a/backend/store/seed/0030_environment.sql b/backend/store/seed/0030_environment.sql
index ad0833b631..23b41aa55f 100644
--- a/backend/store/seed/0030_environment.sql
+++ b/backend/store/seed/0030_environment.sql
@@ -1,7 +1,6 @@
INSERT INTO
environment (
id,
- row_status,
workspace_id,
creator_id,
updater_id,
@@ -9,12 +8,11 @@ INSERT INTO
`order`
)
VALUES
- (2001, 'NORMAL', 1, 1001, 1001, 'Sandbox A', 0);
+ (2001, 1, 1001, 1001, 'Sandbox A', 0);
INSERT INTO
environment (
id,
- row_status,
workspace_id,
creator_id,
updater_id,
@@ -22,12 +20,11 @@ INSERT INTO
`order`
)
VALUES
- (2002, 'NORMAL', 1, 1001, 1001, 'Integration', 1);
+ (2002, 1, 1001, 1001, 'Integration', 1);
INSERT INTO
environment (
id,
- row_status,
workspace_id,
creator_id,
updater_id,
@@ -35,12 +32,11 @@ INSERT INTO
`order`
)
VALUES
- (2003, 'NORMAL', 1, 1001, 1001, 'Staging', 2);
+ (2003, 1, 1001, 1001, 'Staging', 2);
INSERT INTO
environment (
id,
- row_status,
workspace_id,
creator_id,
updater_id,
@@ -48,7 +44,7 @@ INSERT INTO
`order`
)
VALUES
- (2004, 'NORMAL', 1, 1001, 1001, 'Prod', 3);
+ (2004, 1, 1001, 1001, 'Prod', 3);
INSERT INTO
environment (
diff --git a/backend/store/seed/0040_instance.sql b/backend/store/seed/0040_instance.sql
index fdc81a5449..ca641ba77d 100644
--- a/backend/store/seed/0040_instance.sql
+++ b/backend/store/seed/0040_instance.sql
@@ -1,7 +1,6 @@
INSERT INTO
instance (
id,
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -14,7 +13,6 @@ INSERT INTO
VALUES
(
3001,
- 'NORMAL',
1001,
1001,
1,
@@ -28,7 +26,6 @@ VALUES
INSERT INTO
instance (
id,
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -41,7 +38,6 @@ INSERT INTO
VALUES
(
3002,
- 'NORMAL',
1001,
1001,
1,
@@ -55,7 +51,6 @@ VALUES
INSERT INTO
instance (
id,
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -68,7 +63,6 @@ INSERT INTO
VALUES
(
3003,
- 'NORMAL',
1001,
1001,
1,
@@ -82,7 +76,6 @@ VALUES
INSERT INTO
instance (
id,
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -95,7 +88,6 @@ INSERT INTO
VALUES
(
3004,
- 'NORMAL',
1001,
1001,
1,
@@ -109,7 +101,6 @@ VALUES
INSERT INTO
instance (
id,
- row_status,
creator_id,
updater_id,
workspace_id,
@@ -122,7 +113,6 @@ INSERT INTO
VALUES
(
3005,
- 'NORMAL',
1001,
1001,
1,