Skip to content

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

Implement /api/instance endpoint

天舟1bebbcf81333
diff --git a/backend/api/instance.go b/backend/api/instance.go
new file mode 100644
index 0000000000..702ef3f67e
--- /dev/null
+++ b/backend/api/instance.go
@@ -0,0 +1,81 @@
+package api
+
+import "context"
+
+type Instance struct {
+ ID string `jsonapi:"primary,instance"`
+
+ // Related fields
+ Environment *ResourceObject `jsonapi:"relation,environment"`
+
+ // 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"`
+ ExternalLink string `jsonapi:"attr,externalLink"`
+ Host string `jsonapi:"attr,host"`
+ Port string `jsonapi:"attr,port"`
+ Username string `jsonapi:"attr,username"`
+ Password string `jsonapi:"attr,password"`
+}
+
+type InstanceCreate struct {
+ // Related fields
+ EnvironmentId string `jsonapi:"attr,environmentId"`
+
+ // 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"`
+ ExternalLink string `jsonapi:"attr,externalLink"`
+ Host string `jsonapi:"attr,host"`
+ Port string `jsonapi:"attr,port"`
+ Username string `jsonapi:"attr,username"`
+ Password string `jsonapi:"attr,password"`
+}
+
+type InstanceFind struct {
+ // Standard fields
+ ID *int
+ WorkspaceId *int
+}
+
+type InstancePatch struct {
+ // Standard fields
+ ID int `jsonapi:"primary,instancepatch"`
+ 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"`
+ ExternalLink *string `jsonapi:"attr,externalLink"`
+ Host *string `jsonapi:"attr,host"`
+ Port *string `jsonapi:"attr,port"`
+ Username *string `jsonapi:"attr,username"`
+ Password *string `jsonapi:"attr,password"`
+}
+
+type InstanceDelete struct {
+ // Standard fields
+ ID int
+ // Value is assigned from the jwt subject field passed by the client.
+ DeleterId int
+}
+
+type InstanceService interface {
+ CreateInstance(ctx context.Context, create *InstanceCreate) (*Instance, error)
+ FindInstanceList(ctx context.Context, find *InstanceFind) ([]*Instance, error)
+ FindInstance(ctx context.Context, find *InstanceFind) (*Instance, error)
+ PatchInstanceByID(ctx context.Context, patch *InstancePatch) (*Instance, error)
+}
diff --git a/backend/cmd/echo/main.go b/backend/cmd/echo/main.go
index ecbb7b8ddd..0e451922f7 100644
--- a/backend/cmd/echo/main.go
+++ b/backend/cmd/echo/main.go
@@ -42,6 +42,7 @@ func (m *Main) Run() error {
server.PrincipalService = store.NewPrincipalService(m.l, db)
server.MemberService = store.NewMemberService(m.l, db)
server.EnvironmentService = store.NewEnvironmentService(m.l, db)
+ server.InstanceService = store.NewInstanceService(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 1f2432607e..a5b60f4f04 100644
--- a/backend/server/acl_casbin_policy_dba.csv
+++ b/backend/server/acl_casbin_policy_dba.csv
@@ -5,4 +5,8 @@ p, DBA, /member, GET
p, DBA, /environment, POST
p, DBA, /environment, GET
p, DBA, /environment/{id}, PATCH
-p, DBA, /environment/{id}, DELETE
\ No newline at end of file
+p, DBA, /environment/{id}, DELETE
+p, OWNER, /instance, POST
+p, OWNER, /instance, GET
+p, OWNER, /instance/{id}, GET
+p, OWNER, /instance/{id}, PATCH
\ 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 e3938d7ee4..ec30d32148 100644
--- a/backend/server/acl_casbin_policy_developer.csv
+++ b/backend/server/acl_casbin_policy_developer.csv
@@ -2,4 +2,6 @@ p, DEVELOPER, /principal, GET
p, DEVELOPER, /principal/{id}, GET
p, DEVELOPER, /principal/{id}, PATCH_SELF
p, DEVELOPER, /member, GET
-p, DEVELOPER, /environment, GET
\ No newline at end of file
+p, DEVELOPER, /environment, GET
+p, OWNER, /instance, GET
+p, OWNER, /instance/{id}, 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 5d4414c085..ecc72a125c 100644
--- a/backend/server/acl_casbin_policy_owner.csv
+++ b/backend/server/acl_casbin_policy_owner.csv
@@ -10,4 +10,8 @@ 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
+p, OWNER, /environment/{id}, DELETE
+p, OWNER, /instance, POST
+p, OWNER, /instance, GET
+p, OWNER, /instance/{id}, GET
+p, OWNER, /instance/{id}, PATCH
\ No newline at end of file
diff --git a/backend/server/instance.go b/backend/server/instance.go
new file mode 100644
index 0000000000..ae8a759645
--- /dev/null
+++ b/backend/server/instance.go
@@ -0,0 +1,109 @@
+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) registerInstanceRoutes(g *echo.Group) {
+ g.POST("/instance", func(c echo.Context) error {
+ instanceCreate := &api.InstanceCreate{WorkspaceId: api.DEFAULT_WORKPSACE_ID}
+ if err := jsonapi.UnmarshalPayload(c.Request().Body, instanceCreate); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformatted create instance request").SetInternal(err)
+ }
+
+ instanceCreate.CreatorId = c.Get(GetPrincipalIdContextKey()).(int)
+
+ instance, err := s.InstanceService.CreateInstance(context.Background(), instanceCreate)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Instance name already exists: %s", instanceCreate.Name))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create instance").SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, instance); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create instance response").SetInternal(err)
+ }
+ return nil
+ })
+
+ g.GET("/instance", func(c echo.Context) error {
+ wsId := api.DEFAULT_WORKPSACE_ID
+ instanceFind := &api.InstanceFind{
+ WorkspaceId: &wsId,
+ }
+ list, err := s.InstanceService.FindInstanceList(context.Background(), instanceFind)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch instance 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 instance list response").SetInternal(err)
+ }
+ return nil
+ })
+
+ g.GET("/instance/:instanceId", func(c echo.Context) error {
+ id, err := strconv.Atoi(c.Param("instanceId"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
+ }
+
+ instanceFind := &api.InstanceFind{
+ ID: &id,
+ }
+ instance, err := s.InstanceService.FindInstance(context.Background(), instanceFind)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, instance); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal instance ID response: %v", id)).SetInternal(err)
+ }
+ return nil
+ })
+
+ g.PATCH("/instance/:instanceId", func(c echo.Context) error {
+ id, err := strconv.Atoi(c.Param("instanceId"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
+ }
+
+ instancePatch := &api.InstancePatch{
+ ID: id,
+ WorkspaceId: api.DEFAULT_WORKPSACE_ID,
+ UpdaterId: c.Get(GetPrincipalIdContextKey()).(int),
+ }
+ if err := jsonapi.UnmarshalPayload(c.Request().Body, instancePatch); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch instance request").SetInternal(err)
+ }
+
+ instance, err := s.InstanceService.PatchInstanceByID(context.Background(), instancePatch)
+ if err != nil {
+ if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch instance ID: %v", id)).SetInternal(err)
+ }
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ if err := jsonapi.MarshalPayload(c.Response().Writer, instance); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal instance ID response: %v", id)).SetInternal(err)
+ }
+ return nil
+ })
+}
diff --git a/backend/server/server.go b/backend/server/server.go
index e594bb1c85..be37fd9910 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -22,6 +22,7 @@ type Server struct {
PrincipalService api.PrincipalService
MemberService api.MemberService
EnvironmentService api.EnvironmentService
+ InstanceService api.InstanceService
e *echo.Echo
}
@@ -103,14 +104,11 @@ func NewServer(logger *bytebase.Logger) *Server {
})
s.registerDebugRoutes(g)
-
s.registerAuthRoutes(g)
-
s.registerPrincipalRoutes(g)
-
s.registerMemberRoutes(g)
-
s.registerEnvironmentRoutes(g)
+ s.registerInstanceRoutes(g)
return s
}
diff --git a/backend/store/instance.go b/backend/store/instance.go
new file mode 100644
index 0000000000..c8999711f7
--- /dev/null
+++ b/backend/store/instance.go
@@ -0,0 +1,302 @@
+package store
+
+import (
+ "context"
+ "fmt"
+ "strings"
+
+ "github.com/bytebase/bytebase"
+ "github.com/bytebase/bytebase/api"
+)
+
+var (
+ _ api.InstanceService = (*InstanceService)(nil)
+)
+
+// InstanceService represents a service for managing instance.
+type InstanceService struct {
+ l *bytebase.Logger
+ db *DB
+}
+
+// NewInstanceService returns a new instance of InstanceService.
+func NewInstanceService(logger *bytebase.Logger, db *DB) *InstanceService {
+ return &InstanceService{l: logger, db: db}
+}
+
+// CreateInstance creates a new instance.
+func (s *InstanceService) CreateInstance(ctx context.Context, create *api.InstanceCreate) (*api.Instance, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ instance, err := createInstance(ctx, tx, create)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return instance, nil
+}
+
+// FindInstanceList retrieves a list of instances based on find.
+func (s *InstanceService) FindInstanceList(ctx context.Context, find *api.InstanceFind) ([]*api.Instance, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ list, err := findInstanceList(ctx, tx, find)
+ if err != nil {
+ return []*api.Instance{}, err
+ }
+
+ return list, nil
+}
+
+// FindInstance retrieves a single instance based on find.
+// Returns ENOTFOUND if no matching record.
+// Returns the first matching one and prints a warning if finding more than 1 matching records.
+func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFind) (*api.Instance, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ list, err := findInstanceList(ctx, tx, find)
+ if err != nil {
+ return nil, err
+ } else if len(list) == 0 {
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance not found: %v", find)}
+ } else if len(list) > 1 {
+ s.l.Logf(bytebase.WARN, "found mulitple instances: %d, expect 1", len(list))
+ }
+ return list[0], nil
+}
+
+// PatchInstanceByID updates an existing instance by ID.
+// Returns ENOTFOUND if instance does not exist.
+func (s *InstanceService) PatchInstanceByID(ctx context.Context, patch *api.InstancePatch) (*api.Instance, error) {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer tx.Rollback()
+
+ instance, err := patchInstance(ctx, tx, patch)
+ if err != nil {
+ return nil, FormatError(err)
+ }
+
+ if err := tx.Commit(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return instance, nil
+}
+
+// createInstance creates a new instance.
+func createInstance(ctx context.Context, tx *Tx, create *api.InstanceCreate) (*api.Instance, error) {
+ // Insert row into database.
+ row, err := tx.QueryContext(ctx, `
+ INSERT INTO instance (
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+ 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,
+ create.EnvironmentId,
+ create.Name,
+ create.ExternalLink,
+ create.Host,
+ create.Port,
+ )
+
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer row.Close()
+
+ row.Next()
+ var instance api.Instance
+ instance.Environment = &api.ResourceObject{}
+ if err := row.Scan(
+ &instance.ID,
+ &instance.RowStatus,
+ &instance.CreatorId,
+ &instance.CreatedTs,
+ &instance.UpdaterId,
+ &instance.UpdatedTs,
+ &instance.WorkspaceId,
+ &instance.Environment.ID,
+ &instance.Name,
+ &instance.ExternalLink,
+ &instance.Host,
+ &instance.Port,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return &instance, nil
+}
+
+func findInstanceList(ctx context.Context, tx *Tx, find *api.InstanceFind) (_ []*api.Instance, err error) {
+ // Build WHERE clause.
+ where, args := []string{"1 = 1"}, []interface{}{}
+ if v := find.ID; v != nil {
+ where, args = append(where, "id = ?"), append(args, *v)
+ }
+ if v := find.WorkspaceId; v != nil {
+ where, args = append(where, "workspace_id = ?"), append(args, *v)
+ }
+
+ rows, err := tx.QueryContext(ctx, `
+ SELECT
+ id,
+ row_status,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ FROM instance
+ 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.Instance, 0)
+ for rows.Next() {
+ var instance api.Instance
+ instance.Environment = &api.ResourceObject{}
+ if err := rows.Scan(
+ &instance.ID,
+ &instance.RowStatus,
+ &instance.CreatorId,
+ &instance.CreatedTs,
+ &instance.UpdaterId,
+ &instance.UpdatedTs,
+ &instance.WorkspaceId,
+ &instance.Environment.ID,
+ &instance.Name,
+ &instance.ExternalLink,
+ &instance.Host,
+ &instance.Port,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ list = append(list, &instance)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return list, nil
+}
+
+// patchInstance updates a instance by ID. Returns the new state of the instance after update.
+func patchInstance(ctx context.Context, tx *Tx, patch *api.InstancePatch) (*api.Instance, 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)
+ }
+ if v := patch.ExternalLink; v != nil {
+ set, args = append(set, "external_link = ?"), append(args, *v)
+ }
+ if v := patch.Host; v != nil {
+ set, args = append(set, "host = ?"), append(args, *v)
+ }
+ if v := patch.Port; v != nil {
+ set, args = append(set, "port = ?"), append(args, *v)
+ }
+
+ args = append(args, patch.ID)
+
+ // Execute update query with RETURNING.
+ row, err := tx.QueryContext(ctx, `
+ UPDATE instance
+ SET `+strings.Join(set, ", ")+`
+ WHERE id = ?
+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, workspace_id, environment_id, name, external_link, host, port
+ `,
+ args...,
+ )
+ if err != nil {
+ return nil, FormatError(err)
+ }
+ defer row.Close()
+
+ if row.Next() {
+ var instance api.Instance
+ instance.Environment = &api.ResourceObject{}
+ if err := row.Scan(
+ &instance.ID,
+ &instance.RowStatus,
+ &instance.CreatorId,
+ &instance.CreatedTs,
+ &instance.UpdaterId,
+ &instance.UpdatedTs,
+ &instance.WorkspaceId,
+ &instance.Environment.ID,
+ &instance.Name,
+ &instance.ExternalLink,
+ &instance.Host,
+ &instance.Port,
+ ); err != nil {
+ return nil, FormatError(err)
+ }
+
+ return &instance, nil
+ }
+
+ 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.down.sql b/backend/store/migration/0001_init_schema.down.sql
index a8271b9c0c..4dabe6fa07 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 instance;
+
DROP TABLE environment;
DROP TABLE member;
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 8a1b5eb5c9..427e85da40 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -168,4 +168,41 @@ SET
WHERE
rowid = old.rowid;
+END;
+
+-- Instance table stores the workspace instance
+CREATE TABLE instance (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ row_status TEXT NOT NULL CHECK (
+ row_status IN ('NORMAL', 'ARCHIVED', 'PENDING_DELETE')
+ ),
+ 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')),
+ workspace_id INTEGER NOT NULL REFERENCES workspace (id),
+ environment_id INTEGER NOT NULL REFERENCES environment (id),
+ name TEXT NOT NULL,
+ external_link TEXT NOT NULL,
+ host TEXT NOT NULL,
+ port TEXT NOT NULL,
+ UNIQUE(workspace_id, name)
+);
+
+INSERT INTO
+ sqlite_sequence (name, seq)
+VALUES
+ ('instance', 1000);
+
+CREATE TRIGGER IF NOT EXISTS `trigger_update_instance_modification_time`
+AFTER
+UPDATE
+ ON `instance` FOR EACH ROW BEGIN
+UPDATE
+ `instance`
+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
index beb23c2fe7..ad0833b631 100644
--- a/backend/store/seed/0030_environment.sql
+++ b/backend/store/seed/0030_environment.sql
@@ -1,5 +1,6 @@
INSERT INTO
environment (
+ id,
row_status,
workspace_id,
creator_id,
@@ -8,10 +9,11 @@ INSERT INTO
`order`
)
VALUES
- ('NORMAL', 1, 1001, 1001, 'Sandbox A', 0);
+ (2001, 'NORMAL', 1, 1001, 1001, 'Sandbox A', 0);
INSERT INTO
environment (
+ id,
row_status,
workspace_id,
creator_id,
@@ -20,10 +22,11 @@ INSERT INTO
`order`
)
VALUES
- ('NORMAL', 1, 1001, 1001, 'Integration', 1);
+ (2002, 'NORMAL', 1, 1001, 1001, 'Integration', 1);
INSERT INTO
environment (
+ id,
row_status,
workspace_id,
creator_id,
@@ -32,10 +35,11 @@ INSERT INTO
`order`
)
VALUES
- ('NORMAL', 1, 1001, 1001, 'Staging', 2);
+ (2003, 'NORMAL', 1, 1001, 1001, 'Staging', 2);
INSERT INTO
environment (
+ id,
row_status,
workspace_id,
creator_id,
@@ -44,10 +48,11 @@ INSERT INTO
`order`
)
VALUES
- ('NORMAL', 1, 1001, 1001, 'Prod', 3);
+ (2004, 'NORMAL', 1, 1001, 1001, 'Prod', 3);
INSERT INTO
environment (
+ id,
row_status,
workspace_id,
creator_id,
@@ -56,4 +61,12 @@ INSERT INTO
`order`
)
VALUES
- ('ARCHIVED', 1, 1001, 1001, 'Archived Env 1', 4);
\ No newline at end of file
+ (
+ 2005,
+ 'ARCHIVED',
+ 1,
+ 1001,
+ 1001,
+ 'Archived Env 1',
+ 4
+ );
\ No newline at end of file
diff --git a/backend/store/seed/0040_instance.sql b/backend/store/seed/0040_instance.sql
new file mode 100644
index 0000000000..fdc81a5449
--- /dev/null
+++ b/backend/store/seed/0040_instance.sql
@@ -0,0 +1,134 @@
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+VALUES
+ (
+ 3001,
+ 'NORMAL',
+ 1001,
+ 1001,
+ 1,
+ 2001,
+ 'ON - premise MySQL instance',
+ 'google.com',
+ 'localhost',
+ '3306'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+VALUES
+ (
+ 3002,
+ 'NORMAL',
+ 1001,
+ 1001,
+ 1,
+ 2002,
+ 'AWS RDS instance',
+ 'google.com',
+ '127.0.0.1',
+ ''
+ );
+
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+VALUES
+ (
+ 3003,
+ 'NORMAL',
+ 1001,
+ 1001,
+ 1,
+ 2003,
+ 'GCP Cloud SQL instance',
+ 'google.com',
+ '13.24.32.122',
+ '15202'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+VALUES
+ (
+ 3004,
+ 'NORMAL',
+ 1001,
+ 1001,
+ 1,
+ 2004,
+ 'Azure SQL instance',
+ 'google.com',
+ 'mydb.com',
+ '1234'
+ );
+
+INSERT INTO
+ instance (
+ id,
+ row_status,
+ creator_id,
+ updater_id,
+ workspace_id,
+ environment_id,
+ name,
+ external_link,
+ host,
+ port
+ )
+VALUES
+ (
+ 3005,
+ 'NORMAL',
+ 1001,
+ 1001,
+ 1,
+ 2004,
+ 'AliCloud RDS instance',
+ 'google.com',
+ 'rds.com',
+ '5678'
+ );
\ No newline at end of file
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index f9469a0b30..b897fa9643 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -99,7 +99,8 @@ axios.interceptors.request.use((request) => {
!request.url!.startsWith("/api/auth/signup") &&
!request.url!.startsWith("/api/principal") &&
!request.url!.startsWith("/api/member") &&
- !request.url!.startsWith("/api/environment"))
+ !request.url!.startsWith("/api/environment") &&
+ !request.url!.startsWith("/api/instance"))
) {
request.url = request.url!.replace("/api", "/mock");
}
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index 2358732bcb..4224ec04d6 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -41,7 +41,7 @@ const workspacesSeeder = (server: any) => {
for (let i = 0; i < 5; i++) {
environmentList1.push(
server.create("environment", {
- id: 1001 + i,
+ id: 2001 + i,
workspace: workspace1,
creatorId: ws1Owner.id,
updaterId: ws1Owner.id,
@@ -54,7 +54,7 @@ const workspacesSeeder = (server: any) => {
for (let i = 0; i < 5; i++) {
environmentList2.push(
server.create("environment", {
- id: 2001 + i,
+ id: 12001 + i,
workspace: workspace2,
creatorId: ws2DBA.id,
updaterId: ws2DBA.id,
@@ -124,7 +124,8 @@ const workspacesSeeder = (server: any) => {
environmentList1,
projectList1,
ws1DBA,
- DEFAULT_PROJECT_ID
+ DEFAULT_PROJECT_ID,
+ 2001
);
const instanceList2 = createInstanceList(
@@ -133,7 +134,8 @@ const workspacesSeeder = (server: any) => {
environmentList2,
projectList2,
ws2DBA,
- "2"
+ "2",
+ 12001
);
// Database
@@ -813,7 +815,8 @@ const createInstanceList = (
enviromentList: { id: string }[],
projectList: { id: string }[],
dba: { id: string },
- defaultProjectId: ProjectId
+ defaultProjectId: ProjectId,
+ startInstanceId: number
): Instance[] => {
const instanceNamelist = [
"On-premise MySQL instance",
@@ -826,6 +829,7 @@ const createInstanceList = (
const instanceList = [];
for (let i = 0; i < 5; i++) {
const instance = server.create("instance", {
+ id: startInstanceId + i,
workspaceId: workspaceId,
name:
instanceNamelist[Math.floor(Math.random() * instanceNamelist.length)] +