Skip to content

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

feat: add sheet source artifact (#5829)

p0nyaffce92d0477
diff --git a/backend/legacyapi/sheet.go b/backend/legacyapi/sheet.go
index 79b2c2baf2..f069bafb3a 100644
--- a/backend/legacyapi/sheet.go
+++ b/backend/legacyapi/sheet.go
@@ -22,6 +22,8 @@ type SheetSource string
const (
// SheetFromBytebase is the sheet created by Bytebase. e.g. SQL Editor.
SheetFromBytebase SheetSource = "BYTEBASE"
+ // SheetFromBytebaseArtifact is the artifact sheet.
+ SheetFromBytebaseArtifact SheetSource = "BYTEBASE_ARTIFACT"
// SheetFromGitLab is the sheet synced from GitLab (for both GitLab.com and self-hosted GitLab).
SheetFromGitLab SheetSource = "GITLAB"
// SheetFromGitHub is the sheet synced from GitHub (for both GitHub.com and GitHub Enterprise).
@@ -98,7 +100,7 @@ type SheetCreate struct {
Name string `jsonapi:"attr,name"`
Statement string `jsonapi:"attr,statement"`
Visibility SheetVisibility `jsonapi:"attr,visibility"`
- Source SheetSource
+ Source SheetSource `jsonapi:"attr,source"`
Type SheetType
Payload string `jsonapi:"attr,payload"`
}
diff --git a/backend/migrator/migration/dev/LATEST.sql b/backend/migrator/migration/dev/LATEST.sql
index 7a3abdd0f3..8c5ee3e9bb 100644
--- a/backend/migrator/migration/dev/LATEST.sql
+++ b/backend/migrator/migration/dev/LATEST.sql
@@ -1070,7 +1070,7 @@ CREATE TABLE sheet (
name TEXT NOT NULL,
statement TEXT NOT NULL,
visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'PROJECT', 'PUBLIC')) DEFAULT 'PRIVATE',
- source TEXT NOT NULL CHECK (source IN ('BYTEBASE', 'GITLAB', 'GITHUB', 'BITBUCKET')) DEFAULT 'BYTEBASE',
+ source TEXT NOT NULL CONSTRAINT sheet_source_check CHECK (source IN ('BYTEBASE', 'GITLAB', 'GITHUB', 'BITBUCKET', 'BYTEBASE_ARTIFACT')) DEFAULT 'BYTEBASE',
type TEXT NOT NULL CHECK (type IN ('SQL')) DEFAULT 'SQL',
payload JSONB NOT NULL DEFAULT '{}'
);
diff --git a/backend/migrator/migration/prod/1.18/0000##add_sheet_source_bytebase_artifact.sql b/backend/migrator/migration/prod/1.18/0000##add_sheet_source_bytebase_artifact.sql
new file mode 100644
index 0000000000..0d90040b1f
--- /dev/null
+++ b/backend/migrator/migration/prod/1.18/0000##add_sheet_source_bytebase_artifact.sql
@@ -0,0 +1,3 @@
+ALTER TABLE sheet DROP CONSTRAINT sheet_source_check;
+
+ALTER TABLE sheet ADD CONSTRAINT sheet_source_check CHECK (source IN ('BYTEBASE', 'GITLAB', 'GITHUB', 'BITBUCKET', 'BYTEBASE_ARTIFACT'));
diff --git a/backend/migrator/migration/prod/LATEST.sql b/backend/migrator/migration/prod/LATEST.sql
index 8fe503c9de..7fbf6b3d1c 100644
--- a/backend/migrator/migration/prod/LATEST.sql
+++ b/backend/migrator/migration/prod/LATEST.sql
@@ -1069,7 +1069,7 @@ CREATE TABLE sheet (
name TEXT NOT NULL,
statement TEXT NOT NULL,
visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'PROJECT', 'PUBLIC')) DEFAULT 'PRIVATE',
- source TEXT NOT NULL CHECK (source IN ('BYTEBASE', 'GITLAB', 'GITHUB', 'BITBUCKET')) DEFAULT 'BYTEBASE',
+ source TEXT NOT NULL CONSTRAINT sheet_source_check CHECK (source IN ('BYTEBASE', 'GITLAB', 'GITHUB', 'BITBUCKET', 'BYTEBASE_ARTIFACT')) DEFAULT 'BYTEBASE',
type TEXT NOT NULL CHECK (type IN ('SQL')) DEFAULT 'SQL',
payload JSONB NOT NULL DEFAULT '{}'
);
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 51ed2fbebb..c7cd219101 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("1.17.2"), releaseVersion)
+ require.Equal(t, semver.MustParse("1.18.0"), releaseVersion)
}
diff --git a/backend/server/sheet.go b/backend/server/sheet.go
index 485695f606..a6e1302b81 100644
--- a/backend/server/sheet.go
+++ b/backend/server/sheet.go
@@ -26,10 +26,14 @@ func (s *Server) registerSheetRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, sheetCreate); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed create sheet request").SetInternal(err)
}
+ sheetCreate.Type = api.SheetForSQL
if sheetCreate.Name == "" {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed sheet request, missing name")
}
+ if sheetCreate.Source == "" {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformed sheet request, missing source")
+ }
// If sheetCreate.DatabaseID is not nil, use its associated ProjectID as the new sheet's ProjectID.
if sheetCreate.DatabaseID != nil {
@@ -67,8 +71,6 @@ func (s *Server) registerSheetRoutes(g *echo.Group) {
}
}
- sheetCreate.Source = api.SheetFromBytebase
- sheetCreate.Type = api.SheetForSQL
sheet, err := s.store.CreateSheet(ctx, sheetCreate)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create sheet").SetInternal(err)
diff --git a/backend/server/webhook.go b/backend/server/webhook.go
index d2496c3133..013c8d77e3 100644
--- a/backend/server/webhook.go
+++ b/backend/server/webhook.go
@@ -1230,7 +1230,7 @@ func (s *Server) prepareIssueFromSDLFile(ctx context.Context, repo *api.Reposito
Name: file,
Statement: sdl,
Visibility: api.ProjectSheet,
- Source: api.SheetFromBytebase,
+ Source: api.SheetFromBytebaseArtifact,
Type: api.SheetForSQL,
})
if err != nil {
@@ -1292,7 +1292,7 @@ func (s *Server) prepareIssueFromFile(ctx context.Context, repo *api.Repository,
Name: fileInfo.item.FileName,
Statement: content,
Visibility: api.ProjectSheet,
- Source: api.SheetFromBytebase,
+ Source: api.SheetFromBytebaseArtifact,
Type: api.SheetForSQL,
})
if err != nil {
@@ -1328,7 +1328,7 @@ func (s *Server) prepareIssueFromFile(ctx context.Context, repo *api.Repository,
Name: fileInfo.item.FileName,
Statement: migrationFile.Statement,
Visibility: api.ProjectSheet,
- Source: api.SheetFromBytebase,
+ Source: api.SheetFromBytebaseArtifact,
Type: api.SheetForSQL,
})
if err != nil {
@@ -1378,7 +1378,7 @@ func (s *Server) prepareIssueFromFile(ctx context.Context, repo *api.Repository,
Name: fileInfo.item.FileName,
Statement: content,
Visibility: api.ProjectSheet,
- Source: api.SheetFromBytebase,
+ Source: api.SheetFromBytebaseArtifact,
Type: api.SheetForSQL,
})
if err != nil {
@@ -1451,7 +1451,7 @@ func (s *Server) tryUpdateTasksFromModifiedFile(ctx context.Context, databases [
Name: fileName,
Statement: statement,
Visibility: api.ProjectSheet,
- Source: api.SheetFromBytebase,
+ Source: api.SheetFromBytebaseArtifact,
Type: api.SheetForSQL,
})
if err != nil {
diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.go
index cbe8cad560..401b7b6122 100644
--- a/backend/tests/schema_update_test.go
+++ b/backend/tests/schema_update_test.go
@@ -253,6 +253,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
Name: "my-sheet",
Statement: "SELECT * FROM demo",
Visibility: api.PrivateSheet,
+ Source: api.SheetFromBytebase,
})
a.NoError(err)