Skip to content

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

Implement /api/environment

天舟7e7add84ebe7
diff --git a/backend/api/common.go b/backend/api/common.go
new file mode 100644
index 0000000000..454942e40e
--- /dev/null
+++ b/backend/api/common.go
@@ -0,0 +1,21 @@
+package api
+
+type RowStatus string
+
+const (
+ Normal RowStatus = "NORMAL"
+ Archived RowStatus = "ARCHIVED"
+ PendingDelete RowStatus = "PENDING_DELETE"
+)
+
+func (e RowStatus) String() string {
+ switch e {
+ case Normal:
+ return "NORMAL"
+ case Archived:
+ return "ARCHIVED"
+ case PendingDelete:
+ return "PENDING_DELETE"
+ }
+ return ""
+}
diff --git a/backend/api/environment.go b/backend/api/environment.go
index 776dd98ad2..07f69fcaed 100644
--- a/backend/api/environment.go
+++ b/backend/api/environment.go
@@ -1,10 +1,60 @@
package api
+import "context"
+
type Environment struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Order uint `json:"order"`
+ ID string `jsonapi:"primary,principal"`
+
+ // Standard fields
+ RowStatus RowStatus `jsonapi:"attr,rowStatus"`
+ WorkspaceId int
+ CreatorId int `jsonapi:"attr,creatorId"`
+ CreatedTs int64 `jsonapi:"attr,createdTs"`
+ UpdaterId int `jsonapi:"attr,updaterId"`
+ UpdatedTs int64 `jsonapi:"attr,updatedTs"`
+
+ // Domain specific fields
+ Name string `jsonapi:"attr,name"`
+ Order uint `jsonapi:"attr,order"`
+}
+
+type EnvironmentCreate struct {
+ // Standard fields
+ WorkspaceId int
+ // Value is assigned from the jwt subject field passed by the client.
+ CreatorId int
+
+ // Domain specific fields
+ Name string `jsonapi:"attr,name"`
+}
+
+type EnvironmentFind struct {
+ // Standard fields
+ WorkspaceId *int
+}
+
+type EnvironmentPatch struct {
+ // Standard fields
+ ID int
+ RowStatus *string `jsonapi:"attr,rowStatus"`
+ WorkspaceId int
+ // Value is assigned from the jwt subject field passed by the client.
+ UpdaterId int
+
+ // Domain specific fields
+ Name *string `jsonapi:"attr,name"`
+}
+
+type EnvironmentDelete struct {
+ // Standard fields
+ ID int
+ // Value is assigned from the jwt subject field passed by the client.
+ DeleterId int
}
type EnvironmentService interface {
+ CreateEnvironment(ctx context.Context, create *EnvironmentCreate) (*Environment, error)
+ FindEnvironmentList(ctx context.Context, find *EnvironmentFind) ([]*Environment, error)
+ PatchEnvironmentByID(ctx context.Context, patch *EnvironmentPatch) (*Environment, error)
+ DeleteEnvironmentByID(ctx context.Context, delete *EnvironmentDelete) error
}
diff --git a/backend/cmd/echo/main.go b/backend/cmd/echo/main.go
index c386cac388..ecbb7b8ddd 100644
--- a/backend/cmd/echo/main.go
+++ b/backend/cmd/echo/main.go
@@ -41,6 +41,7 @@ func (m *Main) Run() error {
server := server.NewServer(m.l)
server.PrincipalService = store.NewPrincipalService(m.l, db)
server.MemberService = store.NewMemberService(m.l, db)
+ server.EnvironmentService = store.NewEnvironmentService(m.l, db)
m.server = server
if err := server.Run(); err != nil {
diff --git a/backend/server/acl_casbin_policy_dba.csv b/backend/server/acl_casbin_policy_dba.csv
index 8e039fe02c..a68a58e0a5 100644
--- a/backend/server/acl_casbin_policy_dba.csv
+++ b/backend/server/acl_casbin_policy_dba.csv
@@ -1,4 +1,8 @@
p, DBA, /principal, GET
p, DBA, /principal/{id}, GET
p, DBA, /principal/{id}, PATCH_SELF
-p, DBA, /member, GET
\ No newline at end of file
+p, DBA, /member, GET
+p, OWNER, /environment, POST
+p, OWNER, /environment, GET
+p, OWNER, /environment/{id}, PATCH
+p, OWNER, /environment/{id}, DELETE
\ No newline at end of file
diff --git a/backend/server/acl_casbin_policy_developer.csv b/backend/server/acl_casbin_policy_developer.csv
index 3ee5edb997..b3a6ae98ae 100644
--- a/backend/server/acl_casbin_policy_developer.csv
+++ b/backend/server/acl_casbin_policy_developer.csv
@@ -1,4 +1,5 @@
p, DEVELOPER, /principal, GET
p, DEVELOPER, /principal/{id}, GET
p, DEVELOPER, /principal/{id}, PATCH_SELF
-p, DEVELOPER, /member, GET
\ No newline at end of file
+p, DEVELOPER, /member, GET
+p, OWNER, /environment, GET
\ No newline at end of file
diff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csv
index 80f59f468e..5d4414c085 100644
--- a/backend/server/acl_casbin_policy_owner.csv
+++ b/backend/server/acl_casbin_policy_owner.csv
@@ -6,4 +6,8 @@ p, OWNER, /principal/{id}, PATCH_SELF
p, OWNER, /member, POST
p, OWNER, /member, GET
p, OWNER, /member/{id}, PATCH
-p, OWNER, /member/{id}, DELETE
\ No newline at end of file
+p, OWNER, /member/{id}, DELETE
+p, OWNER, /environment, POST
+p, OWNER, /environment, GET
+p, OWNER, /environment/{id}, PATCH
+p, OWNER, /environment/{id}, DELETE
\ No newline at end of file
diff --git a/backend/server/environment.go b/backend/server/environment.go
index 1a395c7b4a..44eb2325bf 100644
--- a/backend/server/environment.go
+++ b/backend/server/environment.go
@@ -1,8 +1,108 @@
package server
import (
+ "context"
+ "fmt"
+ "net/http"
+ "strconv"
+
+ "github.com/bytebase/bytebase"
+ "github.com/bytebase/bytebase/api"
+ "github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
func (s *Server) registerEnvironmentRoutes(g *echo.Group) {
+ g.POST("/environment", func(c echo.Context) error {
+ environmentCreate := &api.EnvironmentCreate{WorkspaceId: api.DEFAULT_WORKPSACE_ID}
+ if err := jsonapi.UnmarshalPayload(c.Request().Body, environmentCreate); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformatted create environment request").SetInternal(err)
+ }
+
+ environmentCreate.CreatorId = c.Get(GetPrincipalIdContextKey()).(int)
+
+ environment, err := s.EnvironmentService.CreateEnvironment(context.Background(), environmentCreate)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Environment name already exists: %s", environmentCreate.Name))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create environment").SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, environment); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create environment response").SetInternal(err)
+ }
+ return nil
+ })
+
+ g.GET("/environment", func(c echo.Context) error {
+ wsId := api.DEFAULT_WORKPSACE_ID
+ environmentFind := &api.EnvironmentFind{
+ WorkspaceId: &wsId,
+ }
+ list, err := s.EnvironmentService.FindEnvironmentList(context.Background(), environmentFind)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environment list").SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, list); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal environment list response").SetInternal(err)
+ }
+ return nil
+ })
+
+ g.PATCH("/environment/:id", func(c echo.Context) error {
+ id, err := strconv.Atoi(c.Param("id"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
+ }
+
+ environmentPatch := &api.EnvironmentPatch{
+ ID: id,
+ WorkspaceId: api.DEFAULT_WORKPSACE_ID,
+ UpdaterId: c.Get(GetPrincipalIdContextKey()).(int),
+ }
+ if err := jsonapi.UnmarshalPayload(c.Request().Body, environmentPatch); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch environment request").SetInternal(err)
+ }
+
+ environment, err := s.EnvironmentService.PatchEnvironmentByID(context.Background(), environmentPatch)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", id))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch environment ID: %v", id)).SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, environment); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal environment ID response: %v", id)).SetInternal(err)
+ }
+ return nil
+ })
+
+ g.DELETE("/environment/:id", func(c echo.Context) error {
+ id, err := strconv.Atoi(c.Param("id"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
+ }
+
+ environmentDelete := &api.EnvironmentDelete{
+ ID: id,
+ DeleterId: c.Get(GetPrincipalIdContextKey()).(int),
+ }
+ err = s.EnvironmentService.DeleteEnvironmentByID(context.Background(), environmentDelete)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", id))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete environment ID: %v", id)).SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ c.Response().WriteHeader(http.StatusOK)
+ return nil
+ })
}
diff --git a/backend/store/environment.go b/backend/store/environment.go
new file mode 100644
index 0000000000..044296c84a
--- /dev/null
+++ b/backend/store/environment.go
@@ -0,0 +1,291 @@
+package store
+
+import (
+ "context"
+ "fmt"
+ "strings"
+
+ "github.com/bytebase/bytebase"
+ "github.com/bytebase/bytebase/api"
+)
+
+var (
+ _ api.EnvironmentService = (*EnvironmentService)(nil)
+)
+
+// EnvironmentService represents a service for managing environment.
+type EnvironmentService struct {
+ l *bytebase.Logger
+ db *DB
+}
+
+// NewEnvironmentService returns a new instance of EnvironmentService.
+func NewEnvironmentService(logger *bytebase.Logger, db *DB) *EnvironmentService {
+ return &EnvironmentService{l: logger, db: db}
+}
+
+// CreateEnvironment creates a new environment.
+func (s *EnvironmentService) CreateEnvironment(ctx context.Context, create *api.EnvironmentCreate) (*api.Environment, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ environment, err := createEnvironment(ctx, tx, create)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return environment, nil
+}
+
+// FindEnvironmentList retrieves a list of environments based on find.
+func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.EnvironmentFind) ([]*api.Environment, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ list, err := findEnvironmentList(ctx, tx, find)
+ if err != nil {
+ return []*api.Environment{}, err
+ }
+
+ return list, nil
+}
+
+// PatchEnvironmentByID updates an existing environment by ID.
+// Returns ENOTFOUND if environment does not exist.
+func (s *EnvironmentService) PatchEnvironmentByID(ctx context.Context, patch *api.EnvironmentPatch) (*api.Environment, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ environment, err := patchEnvironment(ctx, tx, patch)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return environment, nil
+}
+
+// DeleteEnvironmentByID deletes an existing environment by ID.
+// Returns ENOTFOUND if environment does not exist.
+func (s *EnvironmentService) DeleteEnvironmentByID(ctx context.Context, delete *api.EnvironmentDelete) error {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return FormatError(err)
+ }
+ defer tx.Rollback()
+
+ err = deleteEnvironment(ctx, tx, delete)
+ if err != nil {
+ return FormatError(err)
+ }
+
+ if err := tx.Commit(); err != nil {
+ return FormatError(err)
+ }
+
+ return nil
+}
+
+// createEnvironment creates a new environment.
+func createEnvironment(ctx context.Context, tx *Tx, create *api.EnvironmentCreate) (*api.Environment, error) {
+ // The order is the MAX(order) + 1
+ row1, err1 := tx.QueryContext(ctx, `
+ SELECT `+"`order`"+`
+ FROM environment
+ WHERE workspace_id = ?
+ ORDER BY `+"`order`"+` DESC
+ LIMIT 1
+ `,
+ create.WorkspaceId)
+
+ if err1 != nil {
+ return nil, FormatError(err1)
+ }
+ defer row1.Close()
+
+ row1.Next()
+ var order int
+ if err1 := row1.Scan(
+ &order,
+ ); err1 != nil {
+ return nil, FormatError(err1)
+ }
+
+ // Insert row into database.
+ row2, err2 := tx.QueryContext(ctx, `
+ INSERT INTO environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `+"`order`"+`
+ )
+ VALUES ('NORMAL', ?, ?, ?, ?, ?)
+ RETURNING id, row_status, workspace_id, creator_id, created_ts, updater_id, updated_ts, name, `+"`order`"+`
+ `,
+ create.WorkspaceId,
+ create.CreatorId,
+ create.CreatorId,
+ create.Name,
+ order+1,
+ )
+
+ if err2 != nil {
+ return nil, FormatError(err2)
+ }
+ defer row2.Close()
+
+ row2.Next()
+ var environment api.Environment
+ if err := row2.Scan(
+ &environment.ID,
+ &environment.RowStatus,
+ &environment.WorkspaceId,
+ &environment.CreatorId,
+ &environment.CreatedTs,
+ &environment.UpdaterId,
+ &environment.UpdatedTs,
+ &environment.Name,
+ &environment.Order,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return &environment, nil
+}
+
+func findEnvironmentList(ctx context.Context, tx *Tx, find *api.EnvironmentFind) (_ []*api.Environment, err error) {
+ // Build WHERE clause.
+ where, args := []string{"1 = 1"}, []interface{}{}
+ if v := find.WorkspaceId; v != nil {
+ where, args = append(where, "workspace_id = ?"), append(args, *v)
+ }
+
+ rows, err := tx.QueryContext(ctx, `
+ SELECT
+ id,
+ row_status,
+ workspace_id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ `+"`order`"+`
+ FROM environment
+ WHERE `+strings.Join(where, " AND "),
+ args...,
+ )
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer rows.Close()
+
+ // Iterate over result set and deserialize rows into list.
+ list := make([]*api.Environment, 0)
+ for rows.Next() {
+ var environment api.Environment
+ if err := rows.Scan(
+ &environment.ID,
+ &environment.RowStatus,
+ &environment.WorkspaceId,
+ &environment.CreatorId,
+ &environment.CreatedTs,
+ &environment.UpdaterId,
+ &environment.UpdatedTs,
+ &environment.Name,
+ &environment.Order,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ list = append(list, &environment)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return list, nil
+}
+
+// patchEnvironment updates a environment by ID. Returns the new state of the environment after update.
+func patchEnvironment(ctx context.Context, tx *Tx, patch *api.EnvironmentPatch) (*api.Environment, error) {
+ // Build UPDATE clause.
+ set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
+ if v := patch.RowStatus; v != nil {
+ set, args = append(set, "row_status = ?"), append(args, api.RowStatus(*v))
+ }
+ if v := patch.Name; v != nil {
+ set, args = append(set, "name = ?"), append(args, *v)
+ }
+
+ args = append(args, patch.ID)
+
+ // Execute update query with RETURNING.
+ row, err := tx.QueryContext(ctx, `
+ UPDATE environment
+ SET `+strings.Join(set, ", ")+`
+ WHERE id = ?
+ RETURNING id, row_status, workspace_id, creator_id, created_ts, updater_id, updated_ts, name, `+"`order`"+`
+ `,
+ args...,
+ )
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer row.Close()
+
+ if row.Next() {
+ var environment api.Environment
+ if err := row.Scan(
+ &environment.ID,
+ &environment.RowStatus,
+ &environment.WorkspaceId,
+ &environment.CreatorId,
+ &environment.CreatedTs,
+ &environment.UpdaterId,
+ &environment.UpdatedTs,
+ &environment.Name,
+ &environment.Order,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return &environment, nil
+ }
+
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment ID not found: %d", patch.ID)}
+}
+
+// deleteEnvironment permanently deletes a environment by ID.
+func deleteEnvironment(ctx context.Context, tx *Tx, delete *api.EnvironmentDelete) error {
+ // Remove row from database.
+ result, err := tx.ExecContext(ctx, `DELETE FROM environment 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("environment ID not found: %d", delete.ID)}
+ }
+
+ return nil
+}
diff --git a/backend/store/migration/0001_init_schema.down.sql b/backend/store/migration/0001_init_schema.down.sql
index 9089eb1603..b03cbafdf5 100644
--- a/backend/store/migration/0001_init_schema.down.sql
+++ b/backend/store/migration/0001_init_schema.down.sql
@@ -1,3 +1,5 @@
+DROP TABLE IF EXISTS environment;
+
DROP TABLE member;
DROP TABLE workspace;
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 1e24b2aa41..ddecf9468e 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -135,4 +135,38 @@ SET
WHERE
rowid = old.rowid;
+END;
+
+-- Environment table stores the workspace environment
+CREATE TABLE environment (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ),
+ 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')),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ name TEXT NOT NULL UNIQUE,
+ `order` INTEGER NOT NULL,
+ UNIQUE(workspace_id, `order`)
+);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('environment', 1000);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_environment_modification_time`
+AFTER
+UPDATE
+ ON `environment` FOR EACH ROW BEGIN
+UPDATE
+ `environment`
+SET
+ updated_ts = (strftime('%s', 'now'))
+WHERE
+ rowid = old.rowid;
+
END;
\ No newline at end of file
diff --git a/backend/store/seed/0030_environment.sql b/backend/store/seed/0030_environment.sql
new file mode 100644
index 0000000000..96fd386fe6
--- /dev/null
+++ b/backend/store/seed/0030_environment.sql
@@ -0,0 +1,59 @@
+INSERT INTO
+ environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `order`
+ )
+VALUES
+ ('NORMAL', 1, 1001, 1001, 'Sandbox A', 1);
+
+INSERT INTO
+ environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `order`
+ )
+VALUES
+ ('NORMAL', 1, 1001, 1001, 'Integration', 2);
+
+INSERT INTO
+ environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `order`
+ )
+VALUES
+ ('NORMAL', 1, 1001, 1001, 'Staging', 3);
+
+INSERT INTO
+ environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `order`
+ )
+VALUES
+ ('NORMAL', 1, 1001, 1001, 'Prod', 4);
+
+INSERT INTO
+ environment (
+ row_status,
+ workspace_id,
+ creator_id,
+ updater_id,
+ name,
+ `order`
+ )
+VALUES
+ ('ARCHIVED', 1, 1001, 1001, 'Archived Env 1', 5);
\ No newline at end of file
diff --git a/backend/store/sqlite.go b/backend/store/sqlite.go
index 9845131714..f93228428b 100644
--- a/backend/store/sqlite.go
+++ b/backend/store/sqlite.go
@@ -247,6 +247,8 @@ func FormatError(err error) error {
switch err.Error() {
case "UNIQUE constraint failed: principal.email":
return bytebase.Errorf(bytebase.ECONFLICT, "email already exists")
+ case "UNIQUE constraint failed: environment.name":
+ return bytebase.Errorf(bytebase.ECONFLICT, "name already exists")
default:
return err
}
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 3f6814fedf..f9469a0b30 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -98,7 +98,8 @@ axios.interceptors.request.use((request) => {
!request.url!.startsWith("/api/auth/login") &&
!request.url!.startsWith("/api/auth/signup") &&
!request.url!.startsWith("/api/principal") &&
- !request.url!.startsWith("/api/member"))
+ !request.url!.startsWith("/api/member") &&
+ !request.url!.startsWith("/api/environment"))
) {
request.url = request.url!.replace("/api", "/mock");
}
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index 7b4f0c3934..2358732bcb 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -41,6 +41,7 @@ const workspacesSeeder = (server: any) => {
for (let i = 0; i < 5; i++) {
environmentList1.push(
server.create("environment", {
+ id: 1001 + i,
workspace: workspace1,
creatorId: ws1Owner.id,
updaterId: ws1Owner.id,
@@ -53,6 +54,7 @@ const workspacesSeeder = (server: any) => {
for (let i = 0; i < 5; i++) {
environmentList2.push(
server.create("environment", {
+ id: 2001 + i,
workspace: workspace2,
creatorId: ws2DBA.id,
updaterId: ws2DBA.id,
@@ -183,8 +185,7 @@ const workspacesSeeder = (server: any) => {
name: "Hello, World!",
description:
"Welcome to Bytebase, this is the issue interface where DBAs and developers collaborate on database management issues such as: \n\n - Requesting a new database\n - Creating a table\n - Creating an index\n - Adding a column\n - Troubleshooting performance issue\n\nLet's bookmark this issue by clicking the star icon on the top of this page.",
- sql:
- "SELECT 'Welcome'\nFROM engineering\nWHERE role IN ('DBA', 'Developer') AND taste = 'Good';",
+ sql: "SELECT 'Welcome'\nFROM engineering\nWHERE role IN ('DBA', 'Developer') AND taste = 'Good';",
creatorId: ws1Dev1.id,
updaterId: ws1Dev1.id,
assigneeId: ws1Owner.id,
diff --git a/frontend/src/types/environment.ts b/frontend/src/types/environment.ts
index f7a2cdde6c..026a2cc4e7 100644
--- a/frontend/src/types/environment.ts
+++ b/frontend/src/types/environment.ts
@@ -27,6 +27,7 @@ export type EnvironmentCreate = {
};
export type EnvironmentPatch = {
+ // Standard fields
updaterId: PrincipalId;
rowStatus?: RowStatus;