Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(pg): remove the pg prefix from symbols (#671)
Danny Xu3abfbf9bcad3
diff --git a/api/backup.go b/api/backup.goindex cc2c2e8a44..a2c807cf2a 100644--- a/api/backup.go+++ b/api/backup.go@@ -213,6 +213,6 @@ type BackupService interface {PatchBackup(ctx context.Context, patch *BackupPatch) (*Backup, error)FindBackupSetting(ctx context.Context, find *BackupSettingFind) (*BackupSetting, error)UpsertBackupSetting(ctx context.Context, upsert *BackupSettingUpsert) (*BackupSetting, error)- PgUpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *BackupSettingUpsert) (*BackupSetting, error)+ UpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *BackupSettingUpsert) (*BackupSetting, error)FindBackupSettingsMatch(ctx context.Context, match *BackupSettingsMatch) ([]*BackupSetting, error)}diff --git a/api/data_source.go b/api/data_source.goindex 5e3b1c3693..3c87edb3cf 100644--- a/api/data_source.go+++ b/api/data_source.go@@ -112,7 +112,6 @@ type DataSourceService interface {CreateDataSource(ctx context.Context, create *DataSourceCreate) (*DataSource, error)// This is specifically used to create the admin data source when creating the instance.CreateDataSourceTx(ctx context.Context, tx *sql.Tx, create *DataSourceCreate) (*DataSource, error)- PgCreateDataSourceTx(ctx context.Context, tx *sql.Tx, create *DataSourceCreate) (*DataSource, error)FindDataSourceList(ctx context.Context, find *DataSourceFind) ([]*DataSource, error)FindDataSource(ctx context.Context, find *DataSourceFind) (*DataSource, error)PatchDataSource(ctx context.Context, patch *DataSourcePatch) (*DataSource, error)diff --git a/api/database.go b/api/database.goindex a5ad1b1013..13a49c1cfb 100644--- a/api/database.go+++ b/api/database.go@@ -141,7 +141,7 @@ type DatabasePatch struct {type DatabaseService interface {CreateDatabase(ctx context.Context, create *DatabaseCreate) (*Database, error)// This is specifically used to create the * database when creating the instance.- PgCreateDatabaseTx(ctx context.Context, tx *sql.Tx, create *DatabaseCreate) (*Database, error)+ CreateDatabaseTx(ctx context.Context, tx *sql.Tx, create *DatabaseCreate) (*Database, error)FindDatabaseList(ctx context.Context, find *DatabaseFind) ([]*Database, error)FindDatabase(ctx context.Context, find *DatabaseFind) (*Database, error)PatchDatabase(ctx context.Context, patch *DatabasePatch) (*Database, error)diff --git a/api/project.go b/api/project.goindex f875d4bf1d..88b8c27a5c 100644--- a/api/project.go+++ b/api/project.go@@ -310,5 +310,5 @@ type ProjectService interface {FindProject(ctx context.Context, find *ProjectFind) (*Project, error)PatchProject(ctx context.Context, patch *ProjectPatch) (*Project, error)// This is specifically used to update the ProjectWorkflowType when linking/unlinking the repository.- PgPatchProjectTx(ctx context.Context, tx *sql.Tx, patch *ProjectPatch) (*Project, error)+ PatchProjectTx(ctx context.Context, tx *sql.Tx, patch *ProjectPatch) (*Project, error)}diff --git a/api/task_check_run.go b/api/task_check_run.goindex 23eb7af4ac..19cfe2f869 100644--- a/api/task_check_run.go+++ b/api/task_check_run.go@@ -197,6 +197,5 @@ type TaskCheckRunService interface {CreateTaskCheckRunIfNeeded(ctx context.Context, create *TaskCheckRunCreate) (*TaskCheckRun, error)FindTaskCheckRunList(ctx context.Context, find *TaskCheckRunFind) ([]*TaskCheckRun, error)FindTaskCheckRunListTx(ctx context.Context, tx *sql.Tx, find *TaskCheckRunFind) ([]*TaskCheckRun, error)- PgFindTaskCheckRunListTx(ctx context.Context, tx *sql.Tx, find *TaskCheckRunFind) ([]*TaskCheckRun, error)PatchTaskCheckRunStatus(ctx context.Context, patch *TaskCheckRunStatusPatch) (*TaskCheckRun, error)}diff --git a/api/task_run.go b/api/task_run.goindex 03a55faa4c..045488bd6e 100644--- a/api/task_run.go+++ b/api/task_run.go@@ -124,8 +124,8 @@ type TaskRunStatusPatch struct {// TaskRunService is the service for task runs.type TaskRunService interface {- PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)- PgFindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)- PgFindTaskRunTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)- PgPatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)+ CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)+ FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)+ FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)+ PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)}diff --git a/store/activity.go b/store/activity.goindex 38c83bbeae..c4d698a41c 100644--- a/store/activity.go+++ b/store/activity.go@@ -34,7 +34,7 @@ func (s *ActivityService) CreateActivity(ctx context.Context, create *api.Activi}defer tx.PTx.Rollback()- activity, err := pgCreateActivity(ctx, tx.PTx, create)+ activity, err := createActivity(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -93,7 +93,7 @@ func (s *ActivityService) PatchActivity(ctx context.Context, patch *api.Activity}defer tx.PTx.Rollback()- activity, err := pgPatchActivity(ctx, tx.PTx, patch)+ activity, err := patchActivity(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -113,7 +113,7 @@ func (s *ActivityService) DeleteActivity(ctx context.Context, delete *api.Activi}defer tx.PTx.Rollback()- if err := pgDeleteActivity(ctx, tx.PTx, delete); err != nil {+ if err := deleteActivity(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -124,8 +124,8 @@ func (s *ActivityService) DeleteActivity(ctx context.Context, delete *api.Activireturn nil}-// pgCreateActivity creates a new activity.-func pgCreateActivity(ctx context.Context, tx *sql.Tx, create *api.ActivityCreate) (*api.Activity, error) {+// createActivity creates a new activity.+func createActivity(ctx context.Context, tx *sql.Tx, create *api.ActivityCreate) (*api.Activity, error) {// Insert row into activity.row, err := tx.QueryContext(ctx, `INSERT INTO activity (@@ -244,8 +244,8 @@ func findActivityList(ctx context.Context, tx *sql.Tx, find *api.ActivityFind) (return list, nil}-// pgPatchActivity updates a activity by ID. Returns the new state of the activity after update.-func pgPatchActivity(ctx context.Context, tx *sql.Tx, patch *api.ActivityPatch) (*api.Activity, error) {+// patchActivity updates a activity by ID. Returns the new state of the activity after update.+func patchActivity(ctx context.Context, tx *sql.Tx, patch *api.ActivityPatch) (*api.Activity, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Comment; v != nil {@@ -291,8 +291,8 @@ func pgPatchActivity(ctx context.Context, tx *sql.Tx, patch *api.ActivityPatch)return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("activity ID not found: %d", patch.ID)}}-// pgDeleteActivity permanently deletes a activity by ID.-func pgDeleteActivity(ctx context.Context, tx *sql.Tx, delete *api.ActivityDelete) error {+// deleteActivity permanently deletes a activity by ID.+func deleteActivity(ctx context.Context, tx *sql.Tx, delete *api.ActivityDelete) error {// Remove row from activity.if _, err := tx.ExecContext(ctx, `DELETE FROM activity WHERE id = $1`, delete.ID); err != nil {return FormatError(err)diff --git a/store/anomaly.go b/store/anomaly.goindex a2f7095e5b..58f44fe352 100644--- a/store/anomaly.go+++ b/store/anomaly.go@@ -50,7 +50,7 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.Anvar anomaly *api.Anomalyif len(list) == 0 {- anomaly, err = pgCreateAnomaly(ctx, tx.PTx, upsert)+ anomaly, err = createAnomaly(ctx, tx.PTx, upsert)if err != nil {return nil, err}@@ -61,7 +61,7 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.AnUpdaterID: upsert.CreatorID,Payload: upsert.Payload,}- anomaly, err = pgPatchAnomaly(ctx, tx.PTx, patch)+ anomaly, err = patchAnomaly(ctx, tx.PTx, patch)if err != nil {return nil, err}@@ -101,7 +101,7 @@ func (s *AnomalyService) ArchiveAnomaly(ctx context.Context, archive *api.Anomal}defer tx.PTx.Rollback()- if err := pgArchiveAnomaly(ctx, tx.PTx, archive); err != nil {+ if err := archiveAnomaly(ctx, tx.PTx, archive); err != nil {return FormatError(err)}@@ -112,8 +112,8 @@ func (s *AnomalyService) ArchiveAnomaly(ctx context.Context, archive *api.Anomalreturn nil}-// pgCreateAnomaly creates a new anomaly.-func pgCreateAnomaly(ctx context.Context, tx *sql.Tx, upsert *api.AnomalyUpsert) (*api.Anomaly, error) {+// createAnomaly creates a new anomaly.+func createAnomaly(ctx context.Context, tx *sql.Tx, upsert *api.AnomalyUpsert) (*api.Anomaly, error) {// Inserts row into database.row, err := tx.QueryContext(ctx, `INSERT INTO anomaly (@@ -250,8 +250,8 @@ type anomalyPatch struct {Payload string}-// pgPatchAnomaly patches an anomaly-func pgPatchAnomaly(ctx context.Context, tx *sql.Tx, patch *anomalyPatch) (*api.Anomaly, error) {+// patchAnomaly patches an anomaly+func patchAnomaly(ctx context.Context, tx *sql.Tx, patch *anomalyPatch) (*api.Anomaly, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}set, args = append(set, "payload = $2"), append(args, patch.Payload)@@ -301,8 +301,8 @@ func pgPatchAnomaly(ctx context.Context, tx *sql.Tx, patch *anomalyPatch) (*api.return &anomaly, err}-// pgArchiveAnomaly archives an anomaly by ID.-func pgArchiveAnomaly(ctx context.Context, tx *sql.Tx, archive *api.AnomalyArchive) error {+// archiveAnomaly archives an anomaly by ID.+func archiveAnomaly(ctx context.Context, tx *sql.Tx, archive *api.AnomalyArchive) error {if archive.InstanceID == nil && archive.DatabaseID == nil {return &common.Error{Code: common.Internal, Err: fmt.Errorf("failed to close anomaly, should specify either instanceID or databaseID")}}diff --git a/store/backup.go b/store/backup.goindex 43cea2efed..9e3f62b075 100644--- a/store/backup.go+++ b/store/backup.go@@ -35,7 +35,7 @@ func (s *BackupService) CreateBackup(ctx context.Context, create *api.BackupCrea}defer tx.PTx.Rollback()- backup, err := s.pgCreateBackup(ctx, tx.PTx, create)+ backup, err := s.createBackup(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -94,7 +94,7 @@ func (s *BackupService) PatchBackup(ctx context.Context, patch *api.BackupPatch)}defer tx.PTx.Rollback()- backup, err := s.pgPatchBackup(ctx, tx.PTx, patch)+ backup, err := s.patchBackup(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -106,8 +106,8 @@ func (s *BackupService) PatchBackup(ctx context.Context, patch *api.BackupPatch)return backup, nil}-// pgCreateBackup creates a new backup.-func (s *BackupService) pgCreateBackup(ctx context.Context, tx *sql.Tx, create *api.BackupCreate) (*api.Backup, error) {+// createBackup creates a new backup.+func (s *BackupService) createBackup(ctx context.Context, tx *sql.Tx, create *api.BackupCreate) (*api.Backup, error) {// Insert row into backup.row, err := tx.QueryContext(ctx, `INSERT INTO backup (@@ -233,8 +233,8 @@ func (s *BackupService) findBackupList(ctx context.Context, tx *sql.Tx, find *apreturn list, nil}-// pgPatchBackup updates a backup by ID. Returns the new state of the backup after update.-func (s *BackupService) pgPatchBackup(ctx context.Context, tx *sql.Tx, patch *api.BackupPatch) (*api.Backup, error) {+// patchBackup updates a backup by ID. Returns the new state of the backup after update.+func (s *BackupService) patchBackup(ctx context.Context, tx *sql.Tx, patch *api.BackupPatch) (*api.Backup, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}set, args = append(set, "status = $2"), append(args, patch.Status)@@ -391,7 +391,7 @@ func (s *BackupService) UpsertBackupSetting(ctx context.Context, upsert *api.Bac}defer tx.PTx.Rollback()- backup, err := s.PgUpsertBackupSettingTx(ctx, tx.PTx, upsert)+ backup, err := s.UpsertBackupSettingTx(ctx, tx.PTx, upsert)if err != nil {return nil, err}@@ -403,8 +403,8 @@ func (s *BackupService) UpsertBackupSetting(ctx context.Context, upsert *api.Bacreturn backup, nil}-// PgUpsertBackupSettingTx updates an existing backup setting.-func (s *BackupService) PgUpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *api.BackupSettingUpsert) (*api.BackupSetting, error) {+// UpsertBackupSettingTx updates an existing backup setting.+func (s *BackupService) UpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *api.BackupSettingUpsert) (*api.BackupSetting, error) {// Upsert row into backup_setting.row, err := tx.QueryContext(ctx, `INSERT INTO backup_setting (diff --git a/store/bookmark.go b/store/bookmark.goindex 9fc56b2bad..b0efe469a5 100644--- a/store/bookmark.go+++ b/store/bookmark.go@@ -34,7 +34,7 @@ func (s *BookmarkService) CreateBookmark(ctx context.Context, create *api.Bookma}defer tx.PTx.Rollback()- bookmark, err := pgCreateBookmark(ctx, tx.PTx, create)+ bookmark, err := createBookmark(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -93,7 +93,7 @@ func (s *BookmarkService) DeleteBookmark(ctx context.Context, delete *api.Bookma}defer tx.PTx.Rollback()- if err := pgDeleteBookmark(ctx, tx.PTx, delete); err != nil {+ if err := deleteBookmark(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -104,8 +104,8 @@ func (s *BookmarkService) DeleteBookmark(ctx context.Context, delete *api.Bookmareturn nil}-// pgCreateBookmark creates a new bookmark.-func pgCreateBookmark(ctx context.Context, tx *sql.Tx, create *api.BookmarkCreate) (*api.Bookmark, error) {+// createBookmark creates a new bookmark.+func createBookmark(ctx context.Context, tx *sql.Tx, create *api.BookmarkCreate) (*api.Bookmark, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO bookmark (@@ -198,8 +198,8 @@ func findBookmarkList(ctx context.Context, tx *sql.Tx, find *api.BookmarkFind) (return list, nil}-// pgDeleteBookmark permanently deletes a bookmark by ID.-func pgDeleteBookmark(ctx context.Context, tx *sql.Tx, delete *api.BookmarkDelete) error {+// deleteBookmark permanently deletes a bookmark by ID.+func deleteBookmark(ctx context.Context, tx *sql.Tx, delete *api.BookmarkDelete) error {// Remove row from database.result, err := tx.ExecContext(ctx, `DELETE FROM bookmark WHERE id = $1`, delete.ID)if err != nil {diff --git a/store/column.go b/store/column.goindex 603f200840..57429a2620 100644--- a/store/column.go+++ b/store/column.go@@ -34,7 +34,7 @@ func (s *ColumnService) CreateColumn(ctx context.Context, create *api.ColumnCrea}defer tx.PTx.Rollback()- column, err := s.pgCreateColumn(ctx, tx.PTx, create)+ column, err := s.createColumn(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -93,7 +93,7 @@ func (s *ColumnService) PatchColumn(ctx context.Context, patch *api.ColumnPatch)}defer tx.PTx.Rollback()- column, err := s.pgPatchColumn(ctx, tx.PTx, patch)+ column, err := s.patchColumn(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -105,8 +105,8 @@ func (s *ColumnService) PatchColumn(ctx context.Context, patch *api.ColumnPatch)return column, nil}-// pgCreateColumn creates a new column.-func (s *ColumnService) pgCreateColumn(ctx context.Context, tx *sql.Tx, create *api.ColumnCreate) (*api.Column, error) {+// createColumn creates a new column.+func (s *ColumnService) createColumn(ctx context.Context, tx *sql.Tx, create *api.ColumnCreate) (*api.Column, error) {defaultStr := sql.NullString{}if create.Default != nil {defaultStr = sql.NullString{@@ -263,8 +263,8 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *sql.Tx, find *apreturn list, nil}-// pgPatchColumn updates a column by ID. Returns the new state of the column after update.-func (s *ColumnService) pgPatchColumn(ctx context.Context, tx *sql.Tx, patch *api.ColumnPatch) (*api.Column, error) {+// patchColumn updates a column by ID. Returns the new state of the column after update.+func (s *ColumnService) patchColumn(ctx context.Context, tx *sql.Tx, patch *api.ColumnPatch) (*api.Column, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}diff --git a/store/data_source.go b/store/data_source.goindex 2269e3b47f..a0f4acceaf 100644--- a/store/data_source.go+++ b/store/data_source.go@@ -34,7 +34,7 @@ func (s *DataSourceService) CreateDataSource(ctx context.Context, create *api.Da}defer tx.PTx.Rollback()- dataSource, err := s.pgCreateDataSource(ctx, tx.PTx, create)+ dataSource, err := s.createDataSource(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -51,11 +51,6 @@ func (s *DataSourceService) CreateDataSourceTx(ctx context.Context, tx *sql.Tx,return s.createDataSource(ctx, tx, create)}-// PgCreateDataSourceTx creates a data source with a transaction.-func (s *DataSourceService) PgCreateDataSourceTx(ctx context.Context, tx *sql.Tx, create *api.DataSourceCreate) (*api.DataSource, error) {- return s.pgCreateDataSource(ctx, tx, create)-}-// FindDataSourceList retrieves a list of data sources based on find.func (s *DataSourceService) FindDataSourceList(ctx context.Context, find *api.DataSourceFind) ([]*api.DataSource, error) {tx, err := s.db.BeginTx(ctx, nil)@@ -103,7 +98,7 @@ func (s *DataSourceService) PatchDataSource(ctx context.Context, patch *api.Data}defer tx.PTx.Rollback()- dataSource, err := s.pgPatchDataSource(ctx, tx.PTx, patch)+ dataSource, err := s.patchDataSource(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -117,59 +112,6 @@ func (s *DataSourceService) PatchDataSource(ctx context.Context, patch *api.Data// createDataSource creates a new dataSource.func (s *DataSourceService) createDataSource(ctx context.Context, tx *sql.Tx, create *api.DataSourceCreate) (*api.DataSource, error) {- // Insert row into dataSource.- row, err := tx.QueryContext(ctx, `- INSERT INTO data_source (- creator_id,- updater_id,- instance_id,- database_id,- name,- type,- username,- password- )- VALUES (?, ?, ?, ?, ?, ?, ?, ?)- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, name, type, username, password- `,- create.CreatorID,- create.CreatorID,- create.InstanceID,- create.DatabaseID,- create.Name,- create.Type,- create.Username,- create.Password,- )-- if err != nil {- return nil, FormatError(err)- }- defer row.Close()-- row.Next()- var dataSource api.DataSource- if err := row.Scan(- &dataSource.ID,- &dataSource.CreatorID,- &dataSource.CreatedTs,- &dataSource.UpdaterID,- &dataSource.UpdatedTs,- &dataSource.InstanceID,- &dataSource.DatabaseID,- &dataSource.Name,- &dataSource.Type,- &dataSource.Username,- &dataSource.Password,- ); err != nil {- return nil, FormatError(err)- }-- return &dataSource, nil-}--// pgCreateDataSource creates a new dataSource.-func (s *DataSourceService) pgCreateDataSource(ctx context.Context, tx *sql.Tx, create *api.DataSourceCreate) (*api.DataSource, error) {// Insert row into dataSource.row, err := tx.QueryContext(ctx, `INSERT INTO data_source (@@ -285,8 +227,8 @@ func (s *DataSourceService) findDataSourceList(ctx context.Context, tx *sql.Tx,return list, nil}-// pgPatchDataSource updates a dataSource by ID. Returns the new state of the dataSource after update.-func (s *DataSourceService) pgPatchDataSource(ctx context.Context, tx *sql.Tx, patch *api.DataSourcePatch) (*api.DataSource, error) {+// patchDataSource updates a dataSource by ID. Returns the new state of the dataSource after update.+func (s *DataSourceService) patchDataSource(ctx context.Context, tx *sql.Tx, patch *api.DataSourcePatch) (*api.DataSource, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Username; v != nil {diff --git a/store/database.go b/store/database.goindex 86fff37fed..b45963f6de 100644--- a/store/database.go+++ b/store/database.go@@ -45,7 +45,7 @@ func (s *DatabaseService) CreateDatabase(ctx context.Context, create *api.Databa}defer tx.PTx.Rollback()- database, err := s.PgCreateDatabaseTx(ctx, tx.PTx, create)+ database, err := s.CreateDatabaseTx(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -57,14 +57,14 @@ func (s *DatabaseService) CreateDatabase(ctx context.Context, create *api.Databareturn database, nil}-// PgCreateDatabaseTx creates a database with a transaction.-func (s *DatabaseService) PgCreateDatabaseTx(ctx context.Context, tx *sql.Tx, create *api.DatabaseCreate) (*api.Database, error) {+// CreateDatabaseTx creates a database with a transaction.+func (s *DatabaseService) CreateDatabaseTx(ctx context.Context, tx *sql.Tx, create *api.DatabaseCreate) (*api.Database, error) {backupPlanPolicy, err := s.policyService.GetBackupPlanPolicy(ctx, create.EnvironmentID)if err != nil {return nil, err}- database, err := s.pgCreateDatabase(ctx, tx, create)+ database, err := s.createDatabase(ctx, tx, create)if err != nil {return nil, err}@@ -84,7 +84,7 @@ func (s *DatabaseService) PgCreateDatabaseTx(ctx context.Context, tx *sql.Tx, crcase api.BackupPlanPolicyScheduleWeekly:backupSettingUpsert.DayOfWeek = rand.Intn(7)}- if _, err := s.backupService.PgUpsertBackupSettingTx(ctx, tx, backupSettingUpsert); err != nil {+ if _, err := s.backupService.UpsertBackupSettingTx(ctx, tx, backupSettingUpsert); err != nil {return nil, err}}@@ -167,7 +167,7 @@ func (s *DatabaseService) PatchDatabase(ctx context.Context, patch *api.Database}defer tx.PTx.Rollback()- database, err := s.pgPatchDatabase(ctx, tx.PTx, patch)+ database, err := s.patchDatabase(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -183,8 +183,8 @@ func (s *DatabaseService) PatchDatabase(ctx context.Context, patch *api.Databasereturn database, nil}-// pgCreateDatabase creates a new database.-func (s *DatabaseService) pgCreateDatabase(ctx context.Context, tx *sql.Tx, create *api.DatabaseCreate) (*api.Database, error) {+// createDatabase creates a new database.+func (s *DatabaseService) createDatabase(ctx context.Context, tx *sql.Tx, create *api.DatabaseCreate) (*api.Database, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO db (@@ -332,8 +332,8 @@ func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *sql.Tx, findreturn list, nil}-// pgPatchDatabase updates a database by ID. Returns the new state of the database after update.-func (s *DatabaseService) pgPatchDatabase(ctx context.Context, tx *sql.Tx, patch *api.DatabasePatch) (*api.Database, error) {+// patchDatabase updates a database by ID. Returns the new state of the database after update.+func (s *DatabaseService) patchDatabase(ctx context.Context, tx *sql.Tx, patch *api.DatabasePatch) (*api.Database, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.ProjectID; v != nil {diff --git a/store/deploy.go b/store/deploy.goindex a6bceae513..e8d188420c 100644--- a/store/deploy.go+++ b/store/deploy.go@@ -108,7 +108,7 @@ func (s *DeploymentConfigService) UpsertDeploymentConfig(ctx context.Context, up}defer tx.PTx.Rollback()- cfg, err := s.pgUpsertDeploymentConfig(ctx, tx.PTx, upsert)+ cfg, err := s.upsertDeploymentConfig(ctx, tx.PTx, upsert)if err != nil {return nil, FormatError(err)}@@ -120,7 +120,7 @@ func (s *DeploymentConfigService) UpsertDeploymentConfig(ctx context.Context, upreturn cfg, nil}-func (s *DeploymentConfigService) pgUpsertDeploymentConfig(ctx context.Context, tx *sql.Tx, upsert *api.DeploymentConfigUpsert) (*api.DeploymentConfig, error) {+func (s *DeploymentConfigService) upsertDeploymentConfig(ctx context.Context, tx *sql.Tx, upsert *api.DeploymentConfigUpsert) (*api.DeploymentConfig, error) {row, err := tx.QueryContext(ctx, `INSERT INTO deployment_config (creator_id,diff --git a/store/environment.go b/store/environment.goindex 430e6477d8..82ca10b7f6 100644--- a/store/environment.go+++ b/store/environment.go@@ -36,7 +36,7 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, create *api.}defer tx.PTx.Rollback()- environment, err := s.pgCreateEnvironment(ctx, tx.PTx, create)+ environment, err := s.createEnvironment(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -121,7 +121,7 @@ func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.En}defer tx.PTx.Rollback()- environment, err := s.pgPatchEnvironment(ctx, tx.PTx, patch)+ environment, err := s.patchEnvironment(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -138,7 +138,7 @@ func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.En}// createEnvironment creates a new environment.-func (s *EnvironmentService) pgCreateEnvironment(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*api.Environment, error) {+func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*api.Environment, error) {// The order is the MAX(order) + 1row1, err1 := tx.QueryContext(ctx, `SELECT "order"@@ -260,8 +260,8 @@ func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Txreturn list, nil}-// pgPatchEnvironment updates a environment by ID. Returns the new state of the environment after update.-func (s *EnvironmentService) pgPatchEnvironment(ctx context.Context, tx *sql.Tx, patch *api.EnvironmentPatch) (*api.Environment, error) {+// patchEnvironment updates a environment by ID. Returns the new state of the environment after update.+func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *sql.Tx, patch *api.EnvironmentPatch) (*api.Environment, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.RowStatus; v != nil {diff --git a/store/inbox.go b/store/inbox.goindex 88c9f17e62..3c7c9b4921 100644--- a/store/inbox.go+++ b/store/inbox.go@@ -36,7 +36,7 @@ func (s *InboxService) CreateInbox(ctx context.Context, create *api.InboxCreate)}defer tx.PTx.Rollback()- inbox, err := s.pgCreateInbox(ctx, tx.PTx, create)+ inbox, err := s.createInbox(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -95,7 +95,7 @@ func (s *InboxService) PatchInbox(ctx context.Context, patch *api.InboxPatch) (*}defer tx.PTx.Rollback()- inbox, err := s.pgPatchInbox(ctx, tx.PTx, patch)+ inbox, err := s.patchInbox(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -160,8 +160,8 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*return &inboxSummary, nil}-// pgCreateInbox creates a new inbox.-func (s *InboxService) pgCreateInbox(ctx context.Context, tx *sql.Tx, create *api.InboxCreate) (*api.Inbox, error) {+// createInbox creates a new inbox.+func (s *InboxService) createInbox(ctx context.Context, tx *sql.Tx, create *api.InboxCreate) (*api.Inbox, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO inbox (@@ -275,8 +275,8 @@ func findInboxList(ctx context.Context, tx *sql.Tx, find *api.InboxFind) (_ []*areturn list, nil}-// pgPatchInbox updates a inbox by ID. Returns the new state of the inbox after update.-func (s *InboxService) pgPatchInbox(ctx context.Context, tx *sql.Tx, patch *api.InboxPatch) (*api.Inbox, error) {+// patchInbox updates a inbox by ID. Returns the new state of the inbox after update.+func (s *InboxService) patchInbox(ctx context.Context, tx *sql.Tx, patch *api.InboxPatch) (*api.Inbox, error) {// Build UPDATE clause.set, args := []string{"status = $1"}, []interface{}{patch.Status}args = append(args, patch.ID)diff --git a/store/instance.go b/store/instance.goindex 2c4b879aa1..51d6259e6f 100644--- a/store/instance.go+++ b/store/instance.go@@ -39,7 +39,7 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.Instan}defer tx.PTx.Rollback()- instance, err := pgCreateInstance(ctx, tx.PTx, create)+ instance, err := createInstance(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -54,7 +54,7 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.InstanCharacterSet: api.DefaultCharactorSetName,Collation: api.DefaultCollationName,}- allDatabase, err := s.databaseService.PgCreateDatabaseTx(ctx, tx.PTx, databaseCreate)+ allDatabase, err := s.databaseService.CreateDatabaseTx(ctx, tx.PTx, databaseCreate)if err != nil {return nil, err}@@ -69,7 +69,7 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.InstanUsername: create.Username,Password: create.Password,}- if _, err = s.dataSourceService.PgCreateDataSourceTx(ctx, tx.PTx, adminDataSourceCreate); err != nil {+ if _, err = s.dataSourceService.CreateDataSourceTx(ctx, tx.PTx, adminDataSourceCreate); err != nil {return nil, err}@@ -184,7 +184,7 @@ func (s *InstanceService) PatchInstance(ctx context.Context, patch *api.Instance}defer tx.PTx.Rollback()- instance, err := pgPatchInstance(ctx, tx.PTx, patch)+ instance, err := patchInstance(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -200,8 +200,8 @@ func (s *InstanceService) PatchInstance(ctx context.Context, patch *api.Instancereturn instance, nil}-// pgCreateInstance creates a new instance.-func pgCreateInstance(ctx context.Context, tx *sql.Tx, create *api.InstanceCreate) (*api.Instance, error) {+// createInstance creates a new instance.+func createInstance(ctx context.Context, tx *sql.Tx, create *api.InstanceCreate) (*api.Instance, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO instance (@@ -313,8 +313,8 @@ func findInstanceList(ctx context.Context, tx *sql.Tx, find *api.InstanceFind) (return list, nil}-// pgPatchInstance updates a instance by ID. Returns the new state of the instance after update.-func pgPatchInstance(ctx context.Context, tx *sql.Tx, patch *api.InstancePatch) (*api.Instance, error) {+// patchInstance updates a instance by ID. Returns the new state of the instance after update.+func patchInstance(ctx context.Context, tx *sql.Tx, patch *api.InstancePatch) (*api.Instance, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.RowStatus; v != nil {diff --git a/store/instance_user.go b/store/instance_user.goindex 3edc13626d..265d170636 100644--- a/store/instance_user.go+++ b/store/instance_user.go@@ -32,7 +32,7 @@ func (s *InstanceUserService) UpsertInstanceUser(ctx context.Context, upsert *ap}defer tx.PTx.Rollback()- instanceUser, err := pgUpsertInstanceUser(ctx, tx.PTx, upsert)+ instanceUser, err := upsertInstanceUser(ctx, tx.PTx, upsert)if err != nil {return nil, err}@@ -68,7 +68,7 @@ func (s *InstanceUserService) DeleteInstanceUser(ctx context.Context, delete *ap}defer tx.PTx.Rollback()- if err := pgDeleteInstanceUser(ctx, tx.PTx, delete); err != nil {+ if err := deleteInstanceUser(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -79,8 +79,8 @@ func (s *InstanceUserService) DeleteInstanceUser(ctx context.Context, delete *apreturn nil}-// pgUpsertInstanceUser upserts a new instanceUser.-func pgUpsertInstanceUser(ctx context.Context, tx *sql.Tx, upsert *api.InstanceUserUpsert) (*api.InstanceUser, error) {+// upsertInstanceUser upserts a new instanceUser.+func upsertInstanceUser(ctx context.Context, tx *sql.Tx, upsert *api.InstanceUserUpsert) (*api.InstanceUser, error) {// Upsert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO instance_user (@@ -166,8 +166,8 @@ func findInstanceUserList(ctx context.Context, tx *sql.Tx, find *api.InstanceUsereturn list, nil}-// pgDeleteInstanceUser permanently deletes a instance user by ID.-func pgDeleteInstanceUser(ctx context.Context, tx *sql.Tx, delete *api.InstanceUserDelete) error {+// deleteInstanceUser permanently deletes a instance user by ID.+func deleteInstanceUser(ctx context.Context, tx *sql.Tx, delete *api.InstanceUserDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM instance_user WHERE id = $1`, delete.ID); err != nil {return FormatError(err)diff --git a/store/issue.go b/store/issue.goindex e1b3e83cf9..157d46849c 100644--- a/store/issue.go+++ b/store/issue.go@@ -37,7 +37,7 @@ func (s *IssueService) CreateIssue(ctx context.Context, create *api.IssueCreate)}defer tx.PTx.Rollback()- issue, err := s.pgCreateIssue(ctx, tx.PTx, create)+ issue, err := s.createIssue(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -111,7 +111,7 @@ func (s *IssueService) PatchIssue(ctx context.Context, patch *api.IssuePatch) (*}defer tx.PTx.Rollback()- issue, err := s.pgPatchIssue(ctx, tx.PTx, patch)+ issue, err := s.patchIssue(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -127,8 +127,8 @@ func (s *IssueService) PatchIssue(ctx context.Context, patch *api.IssuePatch) (*return issue, nil}-// pgCreateIssue creates a new issue.-func (s *IssueService) pgCreateIssue(ctx context.Context, tx *sql.Tx, create *api.IssueCreate) (*api.Issue, error) {+// createIssue creates a new issue.+func (s *IssueService) createIssue(ctx context.Context, tx *sql.Tx, create *api.IssueCreate) (*api.Issue, error) {row, err := tx.QueryContext(ctx, `INSERT INTO issue (creator_id,@@ -269,8 +269,8 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *sql.Tx, find *api.return list, nil}-// pgPatchIssue updates a issue by ID. Returns the new state of the issue after update.-func (s *IssueService) pgPatchIssue(ctx context.Context, tx *sql.Tx, patch *api.IssuePatch) (*api.Issue, error) {+// patchIssue updates a issue by ID. Returns the new state of the issue after update.+func (s *IssueService) patchIssue(ctx context.Context, tx *sql.Tx, patch *api.IssuePatch) (*api.Issue, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Name; v != nil {diff --git a/store/issue_subscriber.go b/store/issue_subscriber.goindex 23f4fb6d2a..c450f32fd9 100644--- a/store/issue_subscriber.go+++ b/store/issue_subscriber.go@@ -33,7 +33,7 @@ func (s *IssueSubscriberService) CreateIssueSubscriber(ctx context.Context, crea}defer tx.PTx.Rollback()- issueSubscriber, err := pgCreateIssueSubscriber(ctx, tx.PTx, create)+ issueSubscriber, err := createIssueSubscriber(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -69,7 +69,7 @@ func (s *IssueSubscriberService) DeleteIssueSubscriber(ctx context.Context, dele}defer tx.PTx.Rollback()- if err := pgDeleteIssueSubscriber(ctx, tx.PTx, delete); err != nil {+ if err := deleteIssueSubscriber(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -80,8 +80,8 @@ func (s *IssueSubscriberService) DeleteIssueSubscriber(ctx context.Context, delereturn nil}-// pgCreateIssueSubscriber creates a new issueSubscriber.-func pgCreateIssueSubscriber(ctx context.Context, tx *sql.Tx, create *api.IssueSubscriberCreate) (*api.IssueSubscriber, error) {+// createIssueSubscriber creates a new issueSubscriber.+func createIssueSubscriber(ctx context.Context, tx *sql.Tx, create *api.IssueSubscriberCreate) (*api.IssueSubscriber, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO issue_subscriber (@@ -155,8 +155,8 @@ func findIssueSubscriberList(ctx context.Context, tx *sql.Tx, find *api.IssueSubreturn list, nil}-// pgDeleteIssueSubscriber permanently deletes a issueSubscriber by ID.-func pgDeleteIssueSubscriber(ctx context.Context, tx *sql.Tx, delete *api.IssueSubscriberDelete) error {+// deleteIssueSubscriber permanently deletes a issueSubscriber by ID.+func deleteIssueSubscriber(ctx context.Context, tx *sql.Tx, delete *api.IssueSubscriberDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM issue_subscriber WHERE issue_id = $1 AND subscriber_id = $2`, delete.IssueID, delete.SubscriberID); err != nil {return FormatError(err)diff --git a/store/label.go b/store/label.goindex 96a0418138..0aeae5ad6c 100644--- a/store/label.go+++ b/store/label.go@@ -185,7 +185,7 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPat}for _, upsert := range upserts {- if err := s.pgUpsertLabelValue(ctx, tx.PTx, upsert); err != nil {+ if err := s.upsertLabelValue(ctx, tx.PTx, upsert); err != nil {return nil, err}}@@ -198,7 +198,7 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPatreturn labelKey, nil}-func (s *LabelService) pgUpsertLabelValue(ctx context.Context, tx *sql.Tx, upsert labelValueUpsert) error {+func (s *LabelService) upsertLabelValue(ctx context.Context, tx *sql.Tx, upsert labelValueUpsert) error {// Upsert row into label_valueif _, err := tx.ExecContext(ctx, `INSERT INTO label_value (@@ -304,7 +304,7 @@ func (s *LabelService) findDatabaseLabels(ctx context.Context, tx *sql.Tx, findreturn ret, nil}-func (s *LabelService) pgUpsertDatabaseLabel(ctx context.Context, tx *sql.Tx, upsert *api.DatabaseLabelUpsert) (*api.DatabaseLabel, error) {+func (s *LabelService) upsertDatabaseLabel(ctx context.Context, tx *sql.Tx, upsert *api.DatabaseLabelUpsert) (*api.DatabaseLabel, error) {// Upsert row into db_labelrow, err := tx.QueryContext(ctx, `INSERT INTO db_label (@@ -385,7 +385,7 @@ func (s *LabelService) SetDatabaseLabelList(ctx context.Context, labelList []*apKey: oldLabel.Key,Value: oldLabel.Value,}- if _, err := s.pgUpsertDatabaseLabel(ctx, tx.PTx, upsert); err != nil {+ if _, err := s.upsertDatabaseLabel(ctx, tx.PTx, upsert); err != nil {return nil, err}}@@ -403,7 +403,7 @@ func (s *LabelService) SetDatabaseLabelList(ctx context.Context, labelList []*apKey: label.Key,Value: label.Value,}- label, err := s.pgUpsertDatabaseLabel(ctx, tx.PTx, upsert)+ label, err := s.upsertDatabaseLabel(ctx, tx.PTx, upsert)if err != nil {return nil, err}diff --git a/store/member.go b/store/member.goindex c5451cb85f..3fb34f978a 100644--- a/store/member.go+++ b/store/member.go@@ -36,7 +36,7 @@ func (s *MemberService) CreateMember(ctx context.Context, create *api.MemberCrea}defer tx.PTx.Rollback()- member, err := pgCreateMember(ctx, tx.PTx, create)+ member, err := createMember(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -121,7 +121,7 @@ func (s *MemberService) PatchMember(ctx context.Context, patch *api.MemberPatch)}defer tx.PTx.Rollback()- member, err := pgPatchMember(ctx, tx.PTx, patch)+ member, err := patchMember(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -137,8 +137,8 @@ func (s *MemberService) PatchMember(ctx context.Context, patch *api.MemberPatch)return member, nil}-// pgCreateMember creates a new member.-func pgCreateMember(ctx context.Context, tx *sql.Tx, create *api.MemberCreate) (*api.Member, error) {+// createMember creates a new member.+func createMember(ctx context.Context, tx *sql.Tx, create *api.MemberCreate) (*api.Member, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO member (@@ -242,8 +242,8 @@ func findMemberList(ctx context.Context, tx *sql.Tx, find *api.MemberFind) (_ []return list, nil}-// pgPatchMember updates a member by ID. Returns the new state of the member after update.-func pgPatchMember(ctx context.Context, tx *sql.Tx, patch *api.MemberPatch) (*api.Member, error) {+// patchMember updates a member by ID. Returns the new state of the member after update.+func patchMember(ctx context.Context, tx *sql.Tx, patch *api.MemberPatch) (*api.Member, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.RowStatus; v != nil {diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sqlindex 68892f0ad7..4d06e052fe 100644--- a/store/migration/10001__init_schema.sql+++ b/store/migration/10001__init_schema.sql@@ -1 +1,1093 @@-PRAGMA user_version = 10001;+-- updated_ts trigger.+CREATE OR REPLACE FUNCTION trigger_after_update_updated_ts()+RETURNS TRIGGER AS $$+BEGIN+ NEW.updated_ts = extract(epoch from now());+ RETURN NEW;+END;+$$ LANGUAGE plpgsql;++-- principal+CREATE TABLE principal (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ -- allowed types are 'END_USER', 'SYSTEM_BOT'.+ type TEXT NOT NULL,+ name TEXT NOT NULL,+ email TEXT NOT NULL UNIQUE,+ password_hash TEXT NOT NULL+);++CREATE INDEX idx_principal_email ON principal(email);++ALTER SEQUENCE principal_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_principal_modification_time+AFTER+UPDATE+ ON principal FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Default bytebase system account id is 1+INSERT INTO+ principal (+ id,+ creator_id,+ updater_id,+ type,+ name,+ email,+ password_hash+ )+VALUES+ (+ 1,+ 1,+ 1,+ 'SYSTEM_BOT',+ 'Bytebase',+ '[email protected]',+ ''+ );++-- Setting+CREATE TABLE setting (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL UNIQUE,+ value TEXT NOT NULL,+ description TEXT NOT NULL DEFAULT ''+);++ALTER SEQUENCE setting_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_setting_modification_time+AFTER+UPDATE+ ON setting FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Member+-- We separate the concept from Principal because if we support multiple workspace in the future, each workspace can have different member for the same principal+CREATE TABLE member (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ -- allowed status are 'INVITED', 'ACTIVE'.+ status TEXT NOT NULL,+ -- allowed roles are 'OWNER', 'DBA', 'DEVELOPER'.+ role TEXT NOT NULL,+ principal_id INTEGER NOT NULL REFERENCES principal (id) UNIQUE+);++ALTER SEQUENCE member_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_member_modification_time+AFTER+UPDATE+ ON member FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Environment+CREATE TABLE environment (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL UNIQUE,+ "order" INTEGER NOT NULL+);++ALTER SEQUENCE environment_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_environment_modification_time+AFTER+UPDATE+ ON environment FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Policy+-- policy stores the policies for each environment.+-- Policies are associated with environments. Since we may have policies not associated with environment later, we name the table policy.+CREATE TABLE policy (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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),+ -- allowed types are in the format of 'bb.policy.*'.+ type TEXT NOT NULL,+ payload TEXT NOT NULL+);++CREATE INDEX idx_policy_environment_id ON policy(environment_id);++CREATE UNIQUE INDEX idx_policy_environment_id_type ON policy(environment_id, type);++ALTER SEQUENCE policy_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_policy_modification_time+AFTER+UPDATE+ ON policy FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Project+CREATE TABLE project (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL,+ key TEXT NOT NULL UNIQUE,+ -- allowed workflow types are 'UI', 'VCS'.+ workflow_type TEXT NOT NULL,+ -- allowed visibilities are 'PUBLIC', 'PRIVATE'.+ visibility TEXT NOT NULL,+ -- allowed tenant modes are 'DISABLED', 'TENANT'.+ tenant_mode TEXT NOT NULL DEFAULT 'DISABLED',+ -- db_name_template is only used when a project is in tenant mode.+ -- Empty value means {{DB_NAME}}.+ db_name_template TEXT NOT NULL,+ -- allowed role_provider types are 'BYTEBASE', 'GITLAB_SELF_HOST'.+ role_provider TEXT NOT NULL DEFAULT 'BYTEBASE'+);++INSERT INTO+ project (+ id,+ creator_id,+ updater_id,+ name,+ key,+ workflow_type,+ visibility,+ tenant_mode,+ db_name_template+ )+VALUES+ (+ 1,+ 1,+ 1,+ 'Default',+ 'DEFAULT',+ 'UI',+ 'PUBLIC',+ 'DISABLED',+ ''+ );++ALTER SEQUENCE project_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_project_modification_time+AFTER+UPDATE+ ON project FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Project member+CREATE TABLE project_member (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ project_id INTEGER NOT NULL REFERENCES project (id),+ -- allowed roles are 'OWNER', 'DEVELOPER'.+ role TEXT NOT NULL,+ principal_id INTEGER NOT NULL REFERENCES principal (id),+ -- allowed role_provider are 'BYTEBASE', 'GITLAB_SELF_HOST'.+ role_provider TEXT NOT NULL DEFAULT 'BYTEBASE',+ -- payload is determined by the type of role_provider+ payload TEXT NOT NULL DEFAULT '',+ UNIQUE(project_id, principal_id)+);++ALTER SEQUENCE project_member_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_project_member_modification_time+AFTER+UPDATE+ ON project_member FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Project Hook+CREATE TABLE project_webhook (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ project_id INTEGER NOT NULL REFERENCES project (id),+ -- allowed types are in the format of 'bb.plugin.webhook.*'.+ type TEXT NOT NULL,+ name TEXT NOT NULL,+ url TEXT NOT NULL,+ -- Comma separated list of activity triggers.+ activity_list TEXT NOT NULL,+ UNIQUE(project_id, url)+);++CREATE INDEX idx_project_webhook_project_id ON project_webhook(project_id);++ALTER SEQUENCE project_webhook_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_project_webhook_modification_time+AFTER+UPDATE+ ON project_webhook FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Instance+CREATE TABLE instance (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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),+ name TEXT NOT NULL,+ -- allowed engines are 'MYSQL', 'POSTGRES', 'TIDB', 'CLICKHOUSE', 'SNOWFLAKE', 'SQLITE'.+ engine TEXT NOT NULL,+ engine_version TEXT NOT NULL DEFAULT '',+ host TEXT NOT NULL,+ port TEXT NOT NULL,+ external_link TEXT NOT NULL DEFAULT ''+);++ALTER SEQUENCE instance_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_instance_modification_time+AFTER+UPDATE+ ON instance FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Instance user stores the users for a particular instance+CREATE TABLE instance_user (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ instance_id INTEGER NOT NULL REFERENCES instance (id),+ name TEXT NOT NULL,+ "grant" TEXT NOT NULL,+ UNIQUE(instance_id, name)+);++ALTER SEQUENCE instance_user_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_instance_user_modification_time+AFTER+UPDATE+ ON instance_user FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- db stores the databases for a particular instance+-- data is synced periodically from the instance+CREATE TABLE db (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ instance_id INTEGER NOT NULL REFERENCES instance (id),+ project_id INTEGER NOT NULL REFERENCES project (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,+ -- allowed sync status are 'OK', 'NOT_FOUND'.+ sync_status TEXT NOT NULL,+ last_successful_sync_ts BIGINT NOT NULL,+ schema_version TEXT NOT NULL,+ name TEXT NOT NULL,+ character_set TEXT NOT NULL,+ "collation" TEXT NOT NULL,+ UNIQUE(instance_id, name)+);++CREATE INDEX idx_db_instance_id ON db(instance_id);++ALTER SEQUENCE db_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_db_modification_time+AFTER+UPDATE+ ON db FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- tbl stores the table for a particular database+-- data is synced periodically from the instance+CREATE TABLE tbl (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ type TEXT NOT NULL,+ engine TEXT NOT NULL,+ "collation" TEXT NOT NULL,+ row_count BIGINT NOT NULL,+ data_size BIGINT NOT NULL,+ index_size BIGINT NOT NULL,+ data_free BIGINT NOT NULL,+ create_options TEXT NOT NULL,+ comment TEXT NOT NULL,+ UNIQUE(database_id, name)+);++CREATE INDEX idx_tbl_database_id ON tbl(database_id);++ALTER SEQUENCE tbl_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_tbl_modification_time+AFTER+UPDATE+ ON tbl FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- col stores the column for a particular table from a particular database+-- data is synced periodically from the instance+CREATE TABLE col (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id),+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ position INTEGER NOT NULL,+ "default" TEXT,+ nullable BOOLEAN NOT NULL,+ type TEXT NOT NULL,+ character_set TEXT NOT NULL,+ "collation" TEXT NOT NULL,+ comment TEXT NOT NULL,+ UNIQUE(database_id, table_id, name)+);++CREATE INDEX idx_col_database_id_table_id ON col(database_id, table_id);++ALTER SEQUENCE col_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_col_modification_time+AFTER+UPDATE+ ON col FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- idx stores the index for a particular table from a particular database+-- data is synced periodically from the instance+CREATE TABLE idx (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id),+ table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ expression TEXT NOT NULL,+ position INTEGER NOT NULL,+ type TEXT NOT NULL,+ "unique" BOOLEAN NOT NULL,+ visible BOOLEAN NOT NULL,+ comment TEXT NOT NULL,+ UNIQUE(database_id, table_id, name, expression)+);++CREATE INDEX idx_idx_database_id_table_id ON idx(database_id, table_id);++ALTER SEQUENCE idx_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_idx_modification_time+AFTER+UPDATE+ ON idx FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- vw stores the view for a particular database+-- data is synced periodically from the instance+CREATE TABLE vw (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ definition TEXT NOT NULL,+ comment TEXT NOT NULL,+ UNIQUE(database_id, name)+);++CREATE INDEX idx_vw_database_id ON vw(database_id);++ALTER SEQUENCE vw_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_vw_modification_time+AFTER+UPDATE+ ON vw FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- data_source table stores the data source for a particular database+CREATE TABLE data_source (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ instance_id INTEGER NOT NULL REFERENCES instance (id),+ database_id INTEGER NOT NULL REFERENCES db (id),+ name TEXT NOT NULL,+ -- allowed types are 'ADMIN', 'RW', 'RO'.+ type TEXT NOT NULL,+ username TEXT NOT NULL,+ password TEXT NOT NULL,+ ssl_key TEXT NOT NULL DEFAULT '',+ ssl_cert TEXT NOT NULL DEFAULT '',+ ssl_ca TEXT NOT NULL DEFAULT '',+ UNIQUE(database_id, name)+);++CREATE INDEX idx_data_source_instance_id ON data_source(instance_id);++ALTER SEQUENCE data_source_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_data_source_modification_time+AFTER+UPDATE+ ON data_source FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- backup stores the backups for a particular database.+CREATE TABLE backup (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id),+ name TEXT NOT NULL,+ -- allowed status are 'PENDING_CREATE', 'DONE', 'FAILED'.+ status TEXT NOT NULL,+ -- allowed types are 'MANUAL', 'AUTOMATIC'.+ type TEXT NOT NULL,+ -- allowed storage backends are 'LOCAL'.+ storage_backend TEXT NOT NULL,+ migration_history_version TEXT NOT NULL,+ path TEXT NOT NULL,+ comment TEXT NOT NULL DEFAULT '',+ UNIQUE(database_id, name)+);++CREATE INDEX idx_backup_database_id ON backup(database_id);++ALTER SEQUENCE backup_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_backup_modification_time+AFTER+UPDATE+ ON backup FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- backup_setting stores the backup settings for a particular database.+-- This is a strict version of cron expression using UTC timezone uniformly.+CREATE TABLE backup_setting (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL UNIQUE REFERENCES db (id),+ -- allowed enabled values are 0, 1.+ enabled BOOLEAN NOT NULL,+ -- allowed hour is from 0 to 23 (included).+ hour INTEGER NOT NULL,+ -- allowed day_of_week is from -1 to 6.+ -- day_of_week can be -1 which is wildcard (daily automatic backup).+ day_of_week INTEGER NOT NULL,+ -- hook_url is the callback url to be requested after a successful backup.+ hook_url TEXT NOT NULL+);++CREATE INDEX idx_backup_setting_database_id ON backup_setting(database_id);++ALTER SEQUENCE backup_setting_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_backup_setting_modification_time+AFTER+UPDATE+ ON backup_setting FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-----------------------+-- Pipeline related BEGIN+-- pipeline table+CREATE TABLE pipeline (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL,+ -- allowed status are 'OPEN', 'DONE', 'CANCELED'.+ status TEXT NOT NULL+);++CREATE INDEX idx_pipeline_status ON pipeline(status);++ALTER SEQUENCE pipeline_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_pipeline_modification_time+AFTER+UPDATE+ ON pipeline FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- stage table stores the stage for the pipeline+CREATE TABLE stage (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),+ environment_id INTEGER NOT NULL REFERENCES environment (id),+ name TEXT NOT NULL+);++CREATE INDEX idx_stage_pipeline_id ON stage(pipeline_id);++ALTER SEQUENCE stage_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_stage_modification_time+AFTER+UPDATE+ ON stage FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- task table stores the task for the stage+CREATE TABLE task (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),+ stage_id INTEGER NOT NULL REFERENCES stage (id),+ instance_id INTEGER NOT NULL REFERENCES instance (id),+ -- Could be empty for creating database task when the task isn't yet completed successfully.+ database_id INTEGER REFERENCES db (id),+ name TEXT NOT NULL,+ -- allowed status are 'PENDING', 'PENDING_APPROVAL', 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.+ status TEXT NOT NULL,+ -- allowed types are in the format of 'bb.task.*'.+ type TEXT NOT NULL,+ payload TEXT NOT NULL DEFAULT '',+ earliest_allowed_ts BIGINT NOT NULL DEFAULT 0+);++CREATE INDEX idx_task_pipeline_id_stage_id ON task(pipeline_id, stage_id);++CREATE INDEX idx_task_status ON task(status);++CREATE INDEX idx_task_earliest_allowed_ts ON task(earliest_allowed_ts);++ALTER SEQUENCE task_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_task_modification_time+AFTER+UPDATE+ ON task FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- task run table stores the task run+CREATE TABLE task_run (+ id SERIAL PRIMARY KEY,+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ task_id INTEGER NOT NULL REFERENCES task (id),+ name TEXT NOT NULL,+ -- allowed status are 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.+ status TEXT NOT NULL,+ -- allowed types are in the format of 'bb.task.*'.+ type TEXT NOT NULL,+ code INTEGER NOT NULL DEFAULT 0,+ comment TEXT NOT NULL DEFAULT '',+ -- result saves the task run result in json format+ result TEXT NOT NULL DEFAULT '',+ payload TEXT NOT NULL DEFAULT ''+);++CREATE INDEX idx_task_run_task_id ON task_run(task_id);++ALTER SEQUENCE task_run_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_task_run_modification_time+AFTER+UPDATE+ ON task_run FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- task check run table stores the task check run+CREATE TABLE task_check_run (+ id SERIAL PRIMARY KEY,+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ task_id INTEGER NOT NULL REFERENCES task (id),+ -- allowed status are 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.+ status TEXT NOT NULL,+ -- allowed types are in the format of 'bb.task-check.*'.+ type TEXT NOT NULL,+ code INTEGER NOT NULL DEFAULT 0,+ comment TEXT NOT NULL DEFAULT '',+ -- result saves the task check run result in json format+ result TEXT NOT NULL DEFAULT '',+ payload TEXT NOT NULL DEFAULT ''+);++CREATE INDEX idx_task_check_run_task_id ON task_check_run(task_id);++ALTER SEQUENCE task_check_run_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_task_check_run_modification_time+AFTER+UPDATE+ ON task_check_run FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Pipeline related END+-----------------------+-- issue+-- Each issue links a pipeline driving the resolution.+CREATE TABLE issue (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ project_id INTEGER NOT NULL REFERENCES project (id),+ pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),+ name TEXT NOT NULL,+ -- allowed status are 'OPEN', 'DONE', 'CANCELED'.+ status TEXT NOT NULL,+ -- allowed types are in the format of 'bb.issue.*'.+ type TEXT NOT NULL,+ description TEXT NOT NULL DEFAULT '',+ -- we require an assignee, if user wants to unassign herself, she can re-assign to the system account.+ assignee_id INTEGER NOT NULL REFERENCES principal (id),+ payload TEXT NOT NULL DEFAULT ''+);++CREATE INDEX idx_issue_project_id ON issue(project_id);++CREATE INDEX idx_issue_pipeline_id ON issue(pipeline_id);++CREATE INDEX idx_issue_creator_id ON issue(creator_id);++CREATE INDEX idx_issue_assignee_id ON issue(assignee_id);++CREATE INDEX idx_issue_created_ts ON issue(created_ts);++ALTER SEQUENCE issue_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_issue_modification_time+AFTER+UPDATE+ ON issue FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- stores the issue subscribers. Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.+-- We use a separate table mainly because we can't leverage indexed query if the subscriber id is stored+-- as a comma separated id list in the issue table.+CREATE TABLE issue_subscriber (+ issue_id INTEGER NOT NULL REFERENCES issue (id),+ subscriber_id INTEGER NOT NULL REFERENCES principal (id),+ PRIMARY KEY (issue_id, subscriber_id)+);++CREATE INDEX idx_issue_subscriber_subscriber_id ON issue_subscriber(subscriber_id);++-- activity table stores the activity for the container such as issue+CREATE TABLE activity (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ -- container_id is not zero.+ container_id INTEGER NOT NULL,+ -- allowed types are in the format of 'bb.*'.+ type TEXT NOT NULL,+ -- allowed levels are 'INFO', 'WARN', 'ERROR'.+ level TEXT NOT NULL,+ comment TEXT NOT NULL DEFAULT '',+ payload TEXT NOT NULL DEFAULT ''+);++CREATE INDEX idx_activity_container_id ON activity(container_id);++CREATE INDEX idx_activity_created_ts ON activity(created_ts);++ALTER SEQUENCE activity_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_activity_modification_time+AFTER+UPDATE+ ON activity FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- inbox table stores the inbox entry for the corresponding activity.+-- Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.+-- We design in this way because:+-- 1. The table may potentially contain a lot of rows (an issue activity will generate one inbox record per issue subscriber)+-- 2. Does not provide much value besides what's contained in the related activity record.+CREATE TABLE inbox (+ id SERIAL PRIMARY KEY,+ receiver_id INTEGER NOT NULL REFERENCES principal (id),+ activity_id INTEGER NOT NULL REFERENCES activity (id),+ -- allowed status are 'UNREAD', 'READ'.+ status TEXT NOT NULL+);++CREATE INDEX idx_inbox_receiver_id_activity_id ON inbox(receiver_id, activity_id);++CREATE INDEX idx_inbox_receiver_id_status ON inbox(receiver_id, status);++ALTER SEQUENCE inbox_id_seq RESTART WITH 100;++-- bookmark table stores the bookmark for the user+CREATE TABLE bookmark (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL,+ link TEXT NOT NULL,+ UNIQUE(creator_id, link)+);++ALTER SEQUENCE bookmark_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_bookmark_modification_time+AFTER+UPDATE+ ON bookmark FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- vcs table stores the version control provider config+CREATE TABLE vcs (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ name TEXT NOT NULL,+ -- allowed types are 'GITLAB_SELF_HOST'.+ type TEXT NOT NULL,+ -- instance_url follows (instance_url LIKE 'http://%' OR instance_url LIKE 'https://%') AND instance_url = rtrim(instance_url, '/')+ instance_url TEXT NOT NULL,+ -- api_url follows (api_url LIKE 'http://%' OR api_url LIKE 'https://%') AND api_url = rtrim(api_url, '/').+ api_url TEXT NOT NULL,+ application_id TEXT NOT NULL,+ secret TEXT NOT NULL+);++ALTER SEQUENCE vcs_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_vcs_modification_time+AFTER+UPDATE+ ON vcs FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- repository table stores the repository setting for a project+-- A vcs is associated with many repositories.+-- A project can only link one repository (at least for now).+CREATE TABLE repository (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ vcs_id INTEGER NOT NULL REFERENCES vcs (id),+ project_id INTEGER NOT NULL UNIQUE REFERENCES project (id),+ -- Name from the corresponding VCS provider.+ -- For GitLab, this is the project name. e.g. project 1+ name TEXT NOT NULL,+ -- Full path from the corresponding VCS provider.+ -- For GitLab, this is the project full path. e.g. group1/project-1+ full_path TEXT NOT NULL,+ -- Web url from the corresponding VCS provider.+ -- For GitLab, this is the project web url. e.g. https://gitlab.example.com/group1/project-1+ web_url TEXT NOT NULL,+ -- Branch we are interested.+ -- For GitLab, this corresponds to webhook's push_events_branch_filter. Wildcard is supported+ branch_filter TEXT NOT NULL DEFAULT '',+ -- Base working directory we are interested.+ base_directory TEXT NOT NULL DEFAULT '',+ -- The file path template for matching the commited migration script.+ file_path_template TEXT NOT NULL DEFAULT '',+ -- The file path template for storing the latest schema auto-generated by Bytebase after migration.+ -- If empty, then Bytebase won't auto generate it.+ schema_path_template TEXT NOT NULL DEFAULT '',+ -- Repository id from the corresponding VCS provider.+ -- For GitLab, this is the project id. e.g. 123+ external_id TEXT NOT NULL,+ -- Push webhook id from the corresponding VCS provider.+ -- For GitLab, this is the project webhook id. e.g. 123+ external_webhook_id TEXT NOT NULL,+ -- Identify the host of the webhook url where the webhook event sends. We store this to identify stale webhook url whose url doesn't match the current bytebase --host.+ webhook_url_host TEXT NOT NULL,+ -- Identify the target repository receiving the webhook event. This is a random string.+ webhook_endpoint_id TEXT NOT NULL UNIQUE,+ -- For GitLab, webhook request contains this in the 'X-Gitlab-Token" header and we compare it with the one stored in db to validate it sends to the expected endpoint.+ webhook_secret_token TEXT NOT NULL,+ -- access_token, expires_ts, refresh_token belongs to the user linking the project to the VCS repository.+ access_token TEXT NOT NULL,+ expires_ts BIGINT NOT NULL,+ refresh_token TEXT NOT NULL+);++ALTER SEQUENCE repository_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_repository_modification_time+AFTER+UPDATE+ ON repository FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Anomaly+-- anomaly stores various anomalies found by the scanner.+-- For now, anomaly can be associated with a particular instance or database.+CREATE TABLE anomaly (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ instance_id INTEGER NOT NULL REFERENCES instance (id),+ -- NULL if it's an instance anomaly+ database_id INTEGER NULL REFERENCES db (id),+ -- allowed types are in the format of 'bb.anomaly.*'.+ type TEXT NOT NULL,+ payload TEXT NOT NULL DEFAULT ''+);++CREATE INDEX idx_anomaly_instance_id_row_status_type ON anomaly(instance_id, row_status, type);+CREATE INDEX idx_anomaly_database_id_row_status_type ON anomaly(database_id, row_status, type);++ALTER SEQUENCE anomaly_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_anomaly_modification_time+AFTER+UPDATE+ ON anomaly FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Label+-- label_key stores available label keys at workspace level.+CREATE TABLE label_key (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ key TEXT NOT NULL+);++-- key's are unique within the label_key table.+CREATE UNIQUE INDEX idx_label_key_key ON label_key(key);++ALTER SEQUENCE label_key_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_label_key_modification_time+AFTER+UPDATE+ ON label_key FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- label_value stores available label key values at workspace level.+CREATE TABLE label_value (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ key TEXT NOT NULL,+ value TEXT NOT NULL,+ FOREIGN KEY(key) REFERENCES label_key(key)+);++-- key/value's are unique within the label_value table.+CREATE UNIQUE INDEX idx_label_value_key_value ON label_value(key, value);++ALTER SEQUENCE label_value_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_label_value_modification_time+AFTER+UPDATE+ ON label_value FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- db_label stores labels asscociated with databases.+CREATE TABLE db_label (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ database_id INTEGER NOT NULL REFERENCES db (id),+ key TEXT NOT NULL,+ value TEXT NOT NULL,+ FOREIGN KEY(key, value) REFERENCES label_value(key, value)+);++-- database_id/key's are unique within the db_label table.+CREATE UNIQUE INDEX idx_db_label_database_id_key ON db_label(database_id, key);++ALTER SEQUENCE db_label_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_db_label_modification_time+AFTER+UPDATE+ ON db_label FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- Deployment Configuration.+-- deployment_config stores deployment configurations at project level.+CREATE TABLE deployment_config (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ project_id INTEGER NOT NULL REFERENCES project (id),+ name TEXT NOT NULL,+ config TEXT NOT NULL+);++CREATE UNIQUE INDEX idx_deployment_config_project_id ON deployment_config(project_id);++ALTER SEQUENCE deployment_config_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_deployment_config_modification_time+AFTER+UPDATE+ ON deployment_config FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();++-- sheet table stores general statements.+CREATE TABLE sheet (+ id SERIAL PRIMARY KEY,+ -- allowed row status are 'NORMAL', 'ARCHIVED'.+ row_status TEXT NOT NULL DEFAULT 'NORMAL',+ creator_id INTEGER NOT NULL REFERENCES principal (id),+ 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()),+ project_id INTEGER NOT NULL REFERENCES project (id),+ database_id INTEGER NULL REFERENCES db (id),+ name TEXT NOT NULL,+ statement TEXT NOT NULL,+ -- allowed visibilities are 'PRIVATE', 'PROJECT', 'PUBLIC'.+ visibility TEXT NOT NULL DEFAULT 'PRIVATE'+);++CREATE INDEX idx_sheet_creator_id ON sheet(creator_id);++CREATE INDEX idx_sheet_project_id_row_status ON sheet(project_id, row_status);++CREATE INDEX idx_sheet_database_id_row_status ON sheet(database_id, row_status);++ALTER SEQUENCE sheet_id_seq RESTART WITH 100;++CREATE TRIGGER trigger_update_sheet_modification_time+AFTER+UPDATE+ ON sheet FOR EACH ROW+EXECUTE FUNCTION trigger_after_update_updated_ts();diff --git a/store/migration/README.md b/store/migration/README.mddeleted file mode 100644index 56cc8c33a4..0000000000--- a/store/migration/README.md+++ /dev/null@@ -1,9 +0,0 @@-We prepend each migration file with PRAGMA user_version = xxxxx; and make the migration file name prefix-correspond to that user_version. By doing this, our program knows which migration file to apply/skip-according to the current user_version from the data file.--PRAGMA user_version is a 4 byte integer and we encode it with {{major version}} and {{minor version}} info, where the 4 least significant digits are reserved for {{minor version}}--- Major version 1, minor version 1: 10001\_\_init_schema.sql -> PRAGMA user_version = 10001;-- Major version 1, minor version 2: 10002\_\_minor_feature_foo.sql -> PRAGMA user_version = 10002;-- Major version 2, minor version 1: 20001\_\_major_feature_bar.sql -> PRAGMA user_version = 20001;diff --git a/store/sqlite.go b/store/pg_engine.gosimilarity index 91%rename from store/sqlite.gorename to store/pg_engine.goindex 0e3bb34717..7a3de19956 100644--- a/store/sqlite.go+++ b/store/pg_engine.go@@ -42,15 +42,15 @@ const (createDatabaseSchemaVersion = "10000")-//go:embed pg_migration-var pgMigrationFS embed.FS+//go:embed migration+var migrationFS embed.FS-//go:embed pg_seed-var pgSeedFS embed.FS+//go:embed seed+var seedFS embed.FS// DB represents the database connection.type DB struct {- PgDB *sql.DB+ db *sql.DBl *zap.Logger@@ -106,7 +106,7 @@ func (db *DB) Open(ctx context.Context) (err error) {if db.readonly {db.l.Info("Database is opened in readonly mode. Skip migration and seeding.")// The database storing metadata is the same as user name.- db.PgDB, err = d.GetDbConnection(ctx, databaseName)+ db.db, err = d.GetDbConnection(ctx, databaseName)if err != nil {return fmt.Errorf("failed to connect to database %q which may not be setup yet, error: %v", databaseName, err)}@@ -131,12 +131,12 @@ func (db *DB) Open(ctx context.Context) (err error) {}db.l.Info(fmt.Sprintf("Current schema version after migration: %s", verAfter))- db.PgDB, err = d.GetDbConnection(ctx, databaseName)+ db.db, err = d.GetDbConnection(ctx, databaseName)if err != nil {return fmt.Errorf("failed to connect to database %q, error: %v", db.connCfg.Username, err)}- if err := db.pgSeed(verBefore, verAfter); err != nil {+ if err := db.seed(verBefore, verAfter); err != nil {return fmt.Errorf("failed to seed: %w."+" It could be Bytebase is running against an old Bytebase schema. If you are developing Bytebase, you can remove pgdata"+" directory under the same directory where the bytebase binary resides. and restart again to let"+@@ -168,10 +168,10 @@ func getLatestVersion(ctx context.Context, d dbdriver.Driver, database string) (return versionFromInt(v), nil}-// pgSeed loads the seed data for testing-func (db *DB) pgSeed(verBefore, verAfter version) error {- db.l.Info(fmt.Sprintf("Seeding database from pg_%s, force: %t ...", db.seedDir, db.forceResetSeed))- names, err := fs.Glob(pgSeedFS, fmt.Sprintf("pg_%s/*.sql", db.seedDir))+// seed loads the seed data for testing+func (db *DB) seed(verBefore, verAfter version) error {+ db.l.Info(fmt.Sprintf("Seeding database from %s, force: %t ...", db.seedDir, db.forceResetSeed))+ names, err := fs.Glob(seedFS, fmt.Sprintf("%s/*.sql", db.seedDir))if err != nil {return err}@@ -191,7 +191,7 @@ func (db *DB) pgSeed(verBefore, verAfter version) error {}ver := versionFromInt(version)if db.forceResetSeed || ver.biggerThan(verBefore) && !ver.biggerThan(verAfter) {- if err := db.pgSeedFile(name); err != nil {+ if err := db.seedFile(name); err != nil {return fmt.Errorf("seed error: name=%q err=%w", name, err)}} else {@@ -203,17 +203,17 @@ func (db *DB) pgSeed(verBefore, verAfter version) error {return nil}-// pgSeedFile runs a single seed file within a transaction.-func (db *DB) pgSeedFile(name string) error {+// seedFile runs a single seed file within a transaction.+func (db *DB) seedFile(name string) error {db.l.Info(fmt.Sprintf("Seeding %s...", name))- tx, err := db.PgDB.Begin()+ tx, err := db.db.Begin()if err != nil {return err}defer tx.Rollback()// Read and execute migration file.- if buf, err := fs.ReadFile(pgSeedFS, name); err != nil {+ if buf, err := fs.ReadFile(seedFS, name); err != nil {return err} else if _, err := tx.Exec(string(buf)); err != nil {return err@@ -260,14 +260,14 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da}// Apply migrations- pgNames, err := fs.Glob(pgMigrationFS, "pg_migration/*.sql")+ names, err := fs.Glob(migrationFS, "migration/*.sql")if err != nil {return err}// Sort the migration up file in ascending order.- sort.Strings(pgNames)+ sort.Strings(names)- for _, name := range pgNames {+ for _, name := range names {versionPrefix := strings.Split(filepath.Base(name), "__")[0]version, err := strconv.Atoi(versionPrefix)if err != nil {@@ -275,9 +275,9 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da}v := versionFromInt(version)if v.biggerThan(curVer) {- // Migrate pg migration files.+ // Migrate migration files.db.l.Info(fmt.Sprintf("Migrating %s...", name))- buf, err := fs.ReadFile(pgMigrationFS, name)+ buf, err := fs.ReadFile(migrationFS, name)if err != nil {return err}@@ -309,8 +309,8 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da// Close closes the database connection.func (db *DB) Close() error {// Close database.- if db.PgDB != nil {- if err := db.PgDB.Close(); err != nil {+ if db.db != nil {+ if err := db.db.Close(); err != nil {return err}}@@ -321,7 +321,7 @@ func (db *DB) Close() error {// provides a reference to the database and a fixed timestamp at the start of// the transaction. The timestamp allows us to mock time during tests as well.func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {- ptx, err := db.PgDB.BeginTx(ctx, opts)+ ptx, err := db.db.BeginTx(ctx, opts)if err != nil {return nil, err}diff --git a/store/pg_migration/10001__init_schema.sql b/store/pg_migration/10001__init_schema.sqldeleted file mode 100644index 4d06e052fe..0000000000--- a/store/pg_migration/10001__init_schema.sql+++ /dev/null@@ -1,1093 +0,0 @@--- updated_ts trigger.-CREATE OR REPLACE FUNCTION trigger_after_update_updated_ts()-RETURNS TRIGGER AS $$-BEGIN- NEW.updated_ts = extract(epoch from now());- RETURN NEW;-END;-$$ LANGUAGE plpgsql;---- principal-CREATE TABLE principal (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- -- allowed types are 'END_USER', 'SYSTEM_BOT'.- type TEXT NOT NULL,- name TEXT NOT NULL,- email TEXT NOT NULL UNIQUE,- password_hash TEXT NOT NULL-);--CREATE INDEX idx_principal_email ON principal(email);--ALTER SEQUENCE principal_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_principal_modification_time-AFTER-UPDATE- ON principal FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Default bytebase system account id is 1-INSERT INTO- principal (- id,- creator_id,- updater_id,- type,- name,- email,- password_hash- )-VALUES- (- 1,- 1,- 1,- 'SYSTEM_BOT',- 'Bytebase',- '[email protected]',- ''- );---- Setting-CREATE TABLE setting (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL UNIQUE,- value TEXT NOT NULL,- description TEXT NOT NULL DEFAULT ''-);--ALTER SEQUENCE setting_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_setting_modification_time-AFTER-UPDATE- ON setting FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Member--- We separate the concept from Principal because if we support multiple workspace in the future, each workspace can have different member for the same principal-CREATE TABLE member (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- -- allowed status are 'INVITED', 'ACTIVE'.- status TEXT NOT NULL,- -- allowed roles are 'OWNER', 'DBA', 'DEVELOPER'.- role TEXT NOT NULL,- principal_id INTEGER NOT NULL REFERENCES principal (id) UNIQUE-);--ALTER SEQUENCE member_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_member_modification_time-AFTER-UPDATE- ON member FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Environment-CREATE TABLE environment (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL UNIQUE,- "order" INTEGER NOT NULL-);--ALTER SEQUENCE environment_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_environment_modification_time-AFTER-UPDATE- ON environment FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Policy--- policy stores the policies for each environment.--- Policies are associated with environments. Since we may have policies not associated with environment later, we name the table policy.-CREATE TABLE policy (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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),- -- allowed types are in the format of 'bb.policy.*'.- type TEXT NOT NULL,- payload TEXT NOT NULL-);--CREATE INDEX idx_policy_environment_id ON policy(environment_id);--CREATE UNIQUE INDEX idx_policy_environment_id_type ON policy(environment_id, type);--ALTER SEQUENCE policy_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_policy_modification_time-AFTER-UPDATE- ON policy FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Project-CREATE TABLE project (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL,- key TEXT NOT NULL UNIQUE,- -- allowed workflow types are 'UI', 'VCS'.- workflow_type TEXT NOT NULL,- -- allowed visibilities are 'PUBLIC', 'PRIVATE'.- visibility TEXT NOT NULL,- -- allowed tenant modes are 'DISABLED', 'TENANT'.- tenant_mode TEXT NOT NULL DEFAULT 'DISABLED',- -- db_name_template is only used when a project is in tenant mode.- -- Empty value means {{DB_NAME}}.- db_name_template TEXT NOT NULL,- -- allowed role_provider types are 'BYTEBASE', 'GITLAB_SELF_HOST'.- role_provider TEXT NOT NULL DEFAULT 'BYTEBASE'-);--INSERT INTO- project (- id,- creator_id,- updater_id,- name,- key,- workflow_type,- visibility,- tenant_mode,- db_name_template- )-VALUES- (- 1,- 1,- 1,- 'Default',- 'DEFAULT',- 'UI',- 'PUBLIC',- 'DISABLED',- ''- );--ALTER SEQUENCE project_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_project_modification_time-AFTER-UPDATE- ON project FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Project member-CREATE TABLE project_member (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- project_id INTEGER NOT NULL REFERENCES project (id),- -- allowed roles are 'OWNER', 'DEVELOPER'.- role TEXT NOT NULL,- principal_id INTEGER NOT NULL REFERENCES principal (id),- -- allowed role_provider are 'BYTEBASE', 'GITLAB_SELF_HOST'.- role_provider TEXT NOT NULL DEFAULT 'BYTEBASE',- -- payload is determined by the type of role_provider- payload TEXT NOT NULL DEFAULT '',- UNIQUE(project_id, principal_id)-);--ALTER SEQUENCE project_member_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_project_member_modification_time-AFTER-UPDATE- ON project_member FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Project Hook-CREATE TABLE project_webhook (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- project_id INTEGER NOT NULL REFERENCES project (id),- -- allowed types are in the format of 'bb.plugin.webhook.*'.- type TEXT NOT NULL,- name TEXT NOT NULL,- url TEXT NOT NULL,- -- Comma separated list of activity triggers.- activity_list TEXT NOT NULL,- UNIQUE(project_id, url)-);--CREATE INDEX idx_project_webhook_project_id ON project_webhook(project_id);--ALTER SEQUENCE project_webhook_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_project_webhook_modification_time-AFTER-UPDATE- ON project_webhook FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Instance-CREATE TABLE instance (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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),- name TEXT NOT NULL,- -- allowed engines are 'MYSQL', 'POSTGRES', 'TIDB', 'CLICKHOUSE', 'SNOWFLAKE', 'SQLITE'.- engine TEXT NOT NULL,- engine_version TEXT NOT NULL DEFAULT '',- host TEXT NOT NULL,- port TEXT NOT NULL,- external_link TEXT NOT NULL DEFAULT ''-);--ALTER SEQUENCE instance_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_instance_modification_time-AFTER-UPDATE- ON instance FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Instance user stores the users for a particular instance-CREATE TABLE instance_user (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- instance_id INTEGER NOT NULL REFERENCES instance (id),- name TEXT NOT NULL,- "grant" TEXT NOT NULL,- UNIQUE(instance_id, name)-);--ALTER SEQUENCE instance_user_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_instance_user_modification_time-AFTER-UPDATE- ON instance_user FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- db stores the databases for a particular instance--- data is synced periodically from the instance-CREATE TABLE db (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- instance_id INTEGER NOT NULL REFERENCES instance (id),- project_id INTEGER NOT NULL REFERENCES project (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,- -- allowed sync status are 'OK', 'NOT_FOUND'.- sync_status TEXT NOT NULL,- last_successful_sync_ts BIGINT NOT NULL,- schema_version TEXT NOT NULL,- name TEXT NOT NULL,- character_set TEXT NOT NULL,- "collation" TEXT NOT NULL,- UNIQUE(instance_id, name)-);--CREATE INDEX idx_db_instance_id ON db(instance_id);--ALTER SEQUENCE db_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_db_modification_time-AFTER-UPDATE- ON db FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- tbl stores the table for a particular database--- data is synced periodically from the instance-CREATE TABLE tbl (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,- name TEXT NOT NULL,- type TEXT NOT NULL,- engine TEXT NOT NULL,- "collation" TEXT NOT NULL,- row_count BIGINT NOT NULL,- data_size BIGINT NOT NULL,- index_size BIGINT NOT NULL,- data_free BIGINT NOT NULL,- create_options TEXT NOT NULL,- comment TEXT NOT NULL,- UNIQUE(database_id, name)-);--CREATE INDEX idx_tbl_database_id ON tbl(database_id);--ALTER SEQUENCE tbl_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_tbl_modification_time-AFTER-UPDATE- ON tbl FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- col stores the column for a particular table from a particular database--- data is synced periodically from the instance-CREATE TABLE col (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id),- table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,- name TEXT NOT NULL,- position INTEGER NOT NULL,- "default" TEXT,- nullable BOOLEAN NOT NULL,- type TEXT NOT NULL,- character_set TEXT NOT NULL,- "collation" TEXT NOT NULL,- comment TEXT NOT NULL,- UNIQUE(database_id, table_id, name)-);--CREATE INDEX idx_col_database_id_table_id ON col(database_id, table_id);--ALTER SEQUENCE col_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_col_modification_time-AFTER-UPDATE- ON col FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- idx stores the index for a particular table from a particular database--- data is synced periodically from the instance-CREATE TABLE idx (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id),- table_id INTEGER NOT NULL REFERENCES tbl (id) ON DELETE CASCADE,- name TEXT NOT NULL,- expression TEXT NOT NULL,- position INTEGER NOT NULL,- type TEXT NOT NULL,- "unique" BOOLEAN NOT NULL,- visible BOOLEAN NOT NULL,- comment TEXT NOT NULL,- UNIQUE(database_id, table_id, name, expression)-);--CREATE INDEX idx_idx_database_id_table_id ON idx(database_id, table_id);--ALTER SEQUENCE idx_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_idx_modification_time-AFTER-UPDATE- ON idx FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- vw stores the view for a particular database--- data is synced periodically from the instance-CREATE TABLE vw (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id) ON DELETE CASCADE,- name TEXT NOT NULL,- definition TEXT NOT NULL,- comment TEXT NOT NULL,- UNIQUE(database_id, name)-);--CREATE INDEX idx_vw_database_id ON vw(database_id);--ALTER SEQUENCE vw_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_vw_modification_time-AFTER-UPDATE- ON vw FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- data_source table stores the data source for a particular database-CREATE TABLE data_source (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- instance_id INTEGER NOT NULL REFERENCES instance (id),- database_id INTEGER NOT NULL REFERENCES db (id),- name TEXT NOT NULL,- -- allowed types are 'ADMIN', 'RW', 'RO'.- type TEXT NOT NULL,- username TEXT NOT NULL,- password TEXT NOT NULL,- ssl_key TEXT NOT NULL DEFAULT '',- ssl_cert TEXT NOT NULL DEFAULT '',- ssl_ca TEXT NOT NULL DEFAULT '',- UNIQUE(database_id, name)-);--CREATE INDEX idx_data_source_instance_id ON data_source(instance_id);--ALTER SEQUENCE data_source_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_data_source_modification_time-AFTER-UPDATE- ON data_source FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- backup stores the backups for a particular database.-CREATE TABLE backup (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id),- name TEXT NOT NULL,- -- allowed status are 'PENDING_CREATE', 'DONE', 'FAILED'.- status TEXT NOT NULL,- -- allowed types are 'MANUAL', 'AUTOMATIC'.- type TEXT NOT NULL,- -- allowed storage backends are 'LOCAL'.- storage_backend TEXT NOT NULL,- migration_history_version TEXT NOT NULL,- path TEXT NOT NULL,- comment TEXT NOT NULL DEFAULT '',- UNIQUE(database_id, name)-);--CREATE INDEX idx_backup_database_id ON backup(database_id);--ALTER SEQUENCE backup_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_backup_modification_time-AFTER-UPDATE- ON backup FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- backup_setting stores the backup settings for a particular database.--- This is a strict version of cron expression using UTC timezone uniformly.-CREATE TABLE backup_setting (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL UNIQUE REFERENCES db (id),- -- allowed enabled values are 0, 1.- enabled BOOLEAN NOT NULL,- -- allowed hour is from 0 to 23 (included).- hour INTEGER NOT NULL,- -- allowed day_of_week is from -1 to 6.- -- day_of_week can be -1 which is wildcard (daily automatic backup).- day_of_week INTEGER NOT NULL,- -- hook_url is the callback url to be requested after a successful backup.- hook_url TEXT NOT NULL-);--CREATE INDEX idx_backup_setting_database_id ON backup_setting(database_id);--ALTER SEQUENCE backup_setting_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_backup_setting_modification_time-AFTER-UPDATE- ON backup_setting FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---------------------------- Pipeline related BEGIN--- pipeline table-CREATE TABLE pipeline (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL,- -- allowed status are 'OPEN', 'DONE', 'CANCELED'.- status TEXT NOT NULL-);--CREATE INDEX idx_pipeline_status ON pipeline(status);--ALTER SEQUENCE pipeline_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_pipeline_modification_time-AFTER-UPDATE- ON pipeline FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- stage table stores the stage for the pipeline-CREATE TABLE stage (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),- environment_id INTEGER NOT NULL REFERENCES environment (id),- name TEXT NOT NULL-);--CREATE INDEX idx_stage_pipeline_id ON stage(pipeline_id);--ALTER SEQUENCE stage_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_stage_modification_time-AFTER-UPDATE- ON stage FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- task table stores the task for the stage-CREATE TABLE task (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),- stage_id INTEGER NOT NULL REFERENCES stage (id),- instance_id INTEGER NOT NULL REFERENCES instance (id),- -- Could be empty for creating database task when the task isn't yet completed successfully.- database_id INTEGER REFERENCES db (id),- name TEXT NOT NULL,- -- allowed status are 'PENDING', 'PENDING_APPROVAL', 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.- status TEXT NOT NULL,- -- allowed types are in the format of 'bb.task.*'.- type TEXT NOT NULL,- payload TEXT NOT NULL DEFAULT '',- earliest_allowed_ts BIGINT NOT NULL DEFAULT 0-);--CREATE INDEX idx_task_pipeline_id_stage_id ON task(pipeline_id, stage_id);--CREATE INDEX idx_task_status ON task(status);--CREATE INDEX idx_task_earliest_allowed_ts ON task(earliest_allowed_ts);--ALTER SEQUENCE task_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_task_modification_time-AFTER-UPDATE- ON task FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- task run table stores the task run-CREATE TABLE task_run (- id SERIAL PRIMARY KEY,- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- task_id INTEGER NOT NULL REFERENCES task (id),- name TEXT NOT NULL,- -- allowed status are 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.- status TEXT NOT NULL,- -- allowed types are in the format of 'bb.task.*'.- type TEXT NOT NULL,- code INTEGER NOT NULL DEFAULT 0,- comment TEXT NOT NULL DEFAULT '',- -- result saves the task run result in json format- result TEXT NOT NULL DEFAULT '',- payload TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_task_run_task_id ON task_run(task_id);--ALTER SEQUENCE task_run_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_task_run_modification_time-AFTER-UPDATE- ON task_run FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- task check run table stores the task check run-CREATE TABLE task_check_run (- id SERIAL PRIMARY KEY,- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- task_id INTEGER NOT NULL REFERENCES task (id),- -- allowed status are 'RUNNING', 'DONE', 'FAILED', 'CANCELED'.- status TEXT NOT NULL,- -- allowed types are in the format of 'bb.task-check.*'.- type TEXT NOT NULL,- code INTEGER NOT NULL DEFAULT 0,- comment TEXT NOT NULL DEFAULT '',- -- result saves the task check run result in json format- result TEXT NOT NULL DEFAULT '',- payload TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_task_check_run_task_id ON task_check_run(task_id);--ALTER SEQUENCE task_check_run_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_task_check_run_modification_time-AFTER-UPDATE- ON task_check_run FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Pipeline related END--------------------------- issue--- Each issue links a pipeline driving the resolution.-CREATE TABLE issue (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- project_id INTEGER NOT NULL REFERENCES project (id),- pipeline_id INTEGER NOT NULL REFERENCES pipeline (id),- name TEXT NOT NULL,- -- allowed status are 'OPEN', 'DONE', 'CANCELED'.- status TEXT NOT NULL,- -- allowed types are in the format of 'bb.issue.*'.- type TEXT NOT NULL,- description TEXT NOT NULL DEFAULT '',- -- we require an assignee, if user wants to unassign herself, she can re-assign to the system account.- assignee_id INTEGER NOT NULL REFERENCES principal (id),- payload TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_issue_project_id ON issue(project_id);--CREATE INDEX idx_issue_pipeline_id ON issue(pipeline_id);--CREATE INDEX idx_issue_creator_id ON issue(creator_id);--CREATE INDEX idx_issue_assignee_id ON issue(assignee_id);--CREATE INDEX idx_issue_created_ts ON issue(created_ts);--ALTER SEQUENCE issue_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_issue_modification_time-AFTER-UPDATE- ON issue FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- stores the issue subscribers. Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.--- We use a separate table mainly because we can't leverage indexed query if the subscriber id is stored--- as a comma separated id list in the issue table.-CREATE TABLE issue_subscriber (- issue_id INTEGER NOT NULL REFERENCES issue (id),- subscriber_id INTEGER NOT NULL REFERENCES principal (id),- PRIMARY KEY (issue_id, subscriber_id)-);--CREATE INDEX idx_issue_subscriber_subscriber_id ON issue_subscriber(subscriber_id);---- activity table stores the activity for the container such as issue-CREATE TABLE activity (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- -- container_id is not zero.- container_id INTEGER NOT NULL,- -- allowed types are in the format of 'bb.*'.- type TEXT NOT NULL,- -- allowed levels are 'INFO', 'WARN', 'ERROR'.- level TEXT NOT NULL,- comment TEXT NOT NULL DEFAULT '',- payload TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_activity_container_id ON activity(container_id);--CREATE INDEX idx_activity_created_ts ON activity(created_ts);--ALTER SEQUENCE activity_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_activity_modification_time-AFTER-UPDATE- ON activity FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- inbox table stores the inbox entry for the corresponding activity.--- Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.--- We design in this way because:--- 1. The table may potentially contain a lot of rows (an issue activity will generate one inbox record per issue subscriber)--- 2. Does not provide much value besides what's contained in the related activity record.-CREATE TABLE inbox (- id SERIAL PRIMARY KEY,- receiver_id INTEGER NOT NULL REFERENCES principal (id),- activity_id INTEGER NOT NULL REFERENCES activity (id),- -- allowed status are 'UNREAD', 'READ'.- status TEXT NOT NULL-);--CREATE INDEX idx_inbox_receiver_id_activity_id ON inbox(receiver_id, activity_id);--CREATE INDEX idx_inbox_receiver_id_status ON inbox(receiver_id, status);--ALTER SEQUENCE inbox_id_seq RESTART WITH 100;---- bookmark table stores the bookmark for the user-CREATE TABLE bookmark (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL,- link TEXT NOT NULL,- UNIQUE(creator_id, link)-);--ALTER SEQUENCE bookmark_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_bookmark_modification_time-AFTER-UPDATE- ON bookmark FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- vcs table stores the version control provider config-CREATE TABLE vcs (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- name TEXT NOT NULL,- -- allowed types are 'GITLAB_SELF_HOST'.- type TEXT NOT NULL,- -- instance_url follows (instance_url LIKE 'http://%' OR instance_url LIKE 'https://%') AND instance_url = rtrim(instance_url, '/')- instance_url TEXT NOT NULL,- -- api_url follows (api_url LIKE 'http://%' OR api_url LIKE 'https://%') AND api_url = rtrim(api_url, '/').- api_url TEXT NOT NULL,- application_id TEXT NOT NULL,- secret TEXT NOT NULL-);--ALTER SEQUENCE vcs_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_vcs_modification_time-AFTER-UPDATE- ON vcs FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- repository table stores the repository setting for a project--- A vcs is associated with many repositories.--- A project can only link one repository (at least for now).-CREATE TABLE repository (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- vcs_id INTEGER NOT NULL REFERENCES vcs (id),- project_id INTEGER NOT NULL UNIQUE REFERENCES project (id),- -- Name from the corresponding VCS provider.- -- For GitLab, this is the project name. e.g. project 1- name TEXT NOT NULL,- -- Full path from the corresponding VCS provider.- -- For GitLab, this is the project full path. e.g. group1/project-1- full_path TEXT NOT NULL,- -- Web url from the corresponding VCS provider.- -- For GitLab, this is the project web url. e.g. https://gitlab.example.com/group1/project-1- web_url TEXT NOT NULL,- -- Branch we are interested.- -- For GitLab, this corresponds to webhook's push_events_branch_filter. Wildcard is supported- branch_filter TEXT NOT NULL DEFAULT '',- -- Base working directory we are interested.- base_directory TEXT NOT NULL DEFAULT '',- -- The file path template for matching the commited migration script.- file_path_template TEXT NOT NULL DEFAULT '',- -- The file path template for storing the latest schema auto-generated by Bytebase after migration.- -- If empty, then Bytebase won't auto generate it.- schema_path_template TEXT NOT NULL DEFAULT '',- -- Repository id from the corresponding VCS provider.- -- For GitLab, this is the project id. e.g. 123- external_id TEXT NOT NULL,- -- Push webhook id from the corresponding VCS provider.- -- For GitLab, this is the project webhook id. e.g. 123- external_webhook_id TEXT NOT NULL,- -- Identify the host of the webhook url where the webhook event sends. We store this to identify stale webhook url whose url doesn't match the current bytebase --host.- webhook_url_host TEXT NOT NULL,- -- Identify the target repository receiving the webhook event. This is a random string.- webhook_endpoint_id TEXT NOT NULL UNIQUE,- -- For GitLab, webhook request contains this in the 'X-Gitlab-Token" header and we compare it with the one stored in db to validate it sends to the expected endpoint.- webhook_secret_token TEXT NOT NULL,- -- access_token, expires_ts, refresh_token belongs to the user linking the project to the VCS repository.- access_token TEXT NOT NULL,- expires_ts BIGINT NOT NULL,- refresh_token TEXT NOT NULL-);--ALTER SEQUENCE repository_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_repository_modification_time-AFTER-UPDATE- ON repository FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Anomaly--- anomaly stores various anomalies found by the scanner.--- For now, anomaly can be associated with a particular instance or database.-CREATE TABLE anomaly (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- instance_id INTEGER NOT NULL REFERENCES instance (id),- -- NULL if it's an instance anomaly- database_id INTEGER NULL REFERENCES db (id),- -- allowed types are in the format of 'bb.anomaly.*'.- type TEXT NOT NULL,- payload TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_anomaly_instance_id_row_status_type ON anomaly(instance_id, row_status, type);-CREATE INDEX idx_anomaly_database_id_row_status_type ON anomaly(database_id, row_status, type);--ALTER SEQUENCE anomaly_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_anomaly_modification_time-AFTER-UPDATE- ON anomaly FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Label--- label_key stores available label keys at workspace level.-CREATE TABLE label_key (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- key TEXT NOT NULL-);---- key's are unique within the label_key table.-CREATE UNIQUE INDEX idx_label_key_key ON label_key(key);--ALTER SEQUENCE label_key_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_label_key_modification_time-AFTER-UPDATE- ON label_key FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- label_value stores available label key values at workspace level.-CREATE TABLE label_value (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- key TEXT NOT NULL,- value TEXT NOT NULL,- FOREIGN KEY(key) REFERENCES label_key(key)-);---- key/value's are unique within the label_value table.-CREATE UNIQUE INDEX idx_label_value_key_value ON label_value(key, value);--ALTER SEQUENCE label_value_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_label_value_modification_time-AFTER-UPDATE- ON label_value FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- db_label stores labels asscociated with databases.-CREATE TABLE db_label (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- database_id INTEGER NOT NULL REFERENCES db (id),- key TEXT NOT NULL,- value TEXT NOT NULL,- FOREIGN KEY(key, value) REFERENCES label_value(key, value)-);---- database_id/key's are unique within the db_label table.-CREATE UNIQUE INDEX idx_db_label_database_id_key ON db_label(database_id, key);--ALTER SEQUENCE db_label_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_db_label_modification_time-AFTER-UPDATE- ON db_label FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- Deployment Configuration.--- deployment_config stores deployment configurations at project level.-CREATE TABLE deployment_config (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- project_id INTEGER NOT NULL REFERENCES project (id),- name TEXT NOT NULL,- config TEXT NOT NULL-);--CREATE UNIQUE INDEX idx_deployment_config_project_id ON deployment_config(project_id);--ALTER SEQUENCE deployment_config_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_deployment_config_modification_time-AFTER-UPDATE- ON deployment_config FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();---- sheet table stores general statements.-CREATE TABLE sheet (- id SERIAL PRIMARY KEY,- -- allowed row status are 'NORMAL', 'ARCHIVED'.- row_status TEXT NOT NULL DEFAULT 'NORMAL',- creator_id INTEGER NOT NULL REFERENCES principal (id),- 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()),- project_id INTEGER NOT NULL REFERENCES project (id),- database_id INTEGER NULL REFERENCES db (id),- name TEXT NOT NULL,- statement TEXT NOT NULL,- -- allowed visibilities are 'PRIVATE', 'PROJECT', 'PUBLIC'.- visibility TEXT NOT NULL DEFAULT 'PRIVATE'-);--CREATE INDEX idx_sheet_creator_id ON sheet(creator_id);--CREATE INDEX idx_sheet_project_id_row_status ON sheet(project_id, row_status);--CREATE INDEX idx_sheet_database_id_row_status ON sheet(database_id, row_status);--ALTER SEQUENCE sheet_id_seq RESTART WITH 100;--CREATE TRIGGER trigger_update_sheet_modification_time-AFTER-UPDATE- ON sheet FOR EACH ROW-EXECUTE FUNCTION trigger_after_update_updated_ts();diff --git a/store/pipeline.go b/store/pipeline.goindex 91779e6c6f..213f7c1aba 100644--- a/store/pipeline.go+++ b/store/pipeline.go@@ -36,7 +36,7 @@ func (s *PipelineService) CreatePipeline(ctx context.Context, create *api.Pipeli}defer tx.PTx.Rollback()- pipeline, err := s.pgCreatePipeline(ctx, tx.PTx, create)+ pipeline, err := s.createPipeline(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -121,7 +121,7 @@ func (s *PipelineService) PatchPipeline(ctx context.Context, patch *api.Pipeline}defer tx.PTx.Rollback()- pipeline, err := s.pgPatchPipeline(ctx, tx.PTx, patch)+ pipeline, err := s.patchPipeline(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -138,7 +138,7 @@ func (s *PipelineService) PatchPipeline(ctx context.Context, patch *api.Pipeline}// createPipeline creates a new pipeline.-func (s *PipelineService) pgCreatePipeline(ctx context.Context, tx *sql.Tx, create *api.PipelineCreate) (*api.Pipeline, error) {+func (s *PipelineService) createPipeline(ctx context.Context, tx *sql.Tx, create *api.PipelineCreate) (*api.Pipeline, error) {row, err := tx.QueryContext(ctx, `INSERT INTO pipeline (creator_id,@@ -229,8 +229,8 @@ func (s *PipelineService) findPipelineList(ctx context.Context, tx *sql.Tx, findreturn list, nil}-// pgPatchPipeline updates a pipeline by ID. Returns the new state of the pipeline after update.-func (s *PipelineService) pgPatchPipeline(ctx context.Context, tx *sql.Tx, patch *api.PipelinePatch) (*api.Pipeline, error) {+// patchPipeline updates a pipeline by ID. Returns the new state of the pipeline after update.+func (s *PipelineService) patchPipeline(ctx context.Context, tx *sql.Tx, patch *api.PipelinePatch) (*api.Pipeline, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Status; v != nil {diff --git a/store/policy.go b/store/policy.goindex f485680835..c83bfbd392 100644--- a/store/policy.go+++ b/store/policy.go@@ -145,7 +145,7 @@ func (s *PolicyService) UpsertPolicy(ctx context.Context, upsert *api.PolicyUpse}defer tx.PTx.Rollback()- policy, err := s.pgUpsertPolicy(ctx, tx.PTx, upsert)+ policy, err := s.upsertPolicy(ctx, tx.PTx, upsert)if err != nil {return nil, err}@@ -158,7 +158,7 @@ func (s *PolicyService) UpsertPolicy(ctx context.Context, upsert *api.PolicyUpse}// upsertPolicy updates an existing policy.-func (s *PolicyService) pgUpsertPolicy(ctx context.Context, tx *sql.Tx, upsert *api.PolicyUpsert) (*api.Policy, error) {+func (s *PolicyService) upsertPolicy(ctx context.Context, tx *sql.Tx, upsert *api.PolicyUpsert) (*api.Policy, error) {// Upsert row into policy.row, err := tx.QueryContext(ctx, `INSERT INTO policy (diff --git a/store/principal.go b/store/principal.goindex 53438118e4..b5ed7c9506 100644--- a/store/principal.go+++ b/store/principal.go@@ -36,7 +36,7 @@ func (s *PrincipalService) CreatePrincipal(ctx context.Context, create *api.Prin}defer tx.PTx.Rollback()- principal, err := pgCreatePrincipal(ctx, tx.PTx, create)+ principal, err := createPrincipal(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -122,7 +122,7 @@ func (s *PrincipalService) PatchPrincipal(ctx context.Context, patch *api.Princi}defer tx.PTx.Rollback()- principal, err := pgPatchPrincipal(ctx, tx.PTx, patch)+ principal, err := patchPrincipal(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -138,8 +138,8 @@ func (s *PrincipalService) PatchPrincipal(ctx context.Context, patch *api.Princireturn principal, nil}-// pgCreatePrincipal creates a new principal.-func pgCreatePrincipal(ctx context.Context, tx *sql.Tx, create *api.PrincipalCreate) (*api.Principal, error) {+// createPrincipal creates a new principal.+func createPrincipal(ctx context.Context, tx *sql.Tx, create *api.PrincipalCreate) (*api.Principal, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO principal (@@ -242,8 +242,8 @@ func findPrincipalList(ctx context.Context, tx *sql.Tx, find *api.PrincipalFind)return list, nil}-// pgPatchPrincipal updates a principal by ID. Returns the new state of the principal after update.-func pgPatchPrincipal(ctx context.Context, tx *sql.Tx, patch *api.PrincipalPatch) (*api.Principal, error) {+// patchPrincipal updates a principal by ID. Returns the new state of the principal after update.+func patchPrincipal(ctx context.Context, tx *sql.Tx, patch *api.PrincipalPatch) (*api.Principal, error) {set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Name; v != nil {set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)diff --git a/store/project.go b/store/project.goindex 45fe503f2f..85430f4f92 100644--- a/store/project.go+++ b/store/project.go@@ -36,7 +36,7 @@ func (s *ProjectService) CreateProject(ctx context.Context, create *api.ProjectC}defer tx.PTx.Rollback()- project, err := pgCreateProject(ctx, tx.PTx, create)+ project, err := createProject(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -121,7 +121,7 @@ func (s *ProjectService) PatchProject(ctx context.Context, patch *api.ProjectPat}defer tx.PTx.Rollback()- project, err := pgPatchProject(ctx, tx.PTx, patch)+ project, err := patchProject(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -137,10 +137,10 @@ func (s *ProjectService) PatchProject(ctx context.Context, patch *api.ProjectPatreturn project, nil}-// PgPatchProjectTx updates an existing project by ID.+// PatchProjectTx updates an existing project by ID.// Returns ENOTFOUND if project does not exist.-func (s *ProjectService) PgPatchProjectTx(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*api.Project, error) {- project, err := pgPatchProject(ctx, tx, patch)+func (s *ProjectService) PatchProjectTx(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*api.Project, error) {+ project, err := patchProject(ctx, tx, patch)if err != nil {return nil, FormatError(err)@@ -153,8 +153,8 @@ func (s *ProjectService) PgPatchProjectTx(ctx context.Context, tx *sql.Tx, patchreturn project, nil}-// pgCreateProject creates a new project.-func pgCreateProject(ctx context.Context, tx *sql.Tx, create *api.ProjectCreate) (*api.Project, error) {+// createProject creates a new project.+func createProject(ctx context.Context, tx *sql.Tx, create *api.ProjectCreate) (*api.Project, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO project (@@ -271,8 +271,8 @@ func findProjectList(ctx context.Context, tx *sql.Tx, find *api.ProjectFind) (_return list, nil}-// pgPatchProject updates a project by ID. Returns the new state of the project after update.-func pgPatchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*api.Project, error) {+// patchProject updates a project by ID. Returns the new state of the project after update.+func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*api.Project, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.RowStatus; v != nil {diff --git a/store/project_member.go b/store/project_member.goindex 100abb53a6..3dab15fd78 100644--- a/store/project_member.go+++ b/store/project_member.go@@ -34,7 +34,7 @@ func (s *ProjectMemberService) CreateProjectMember(ctx context.Context, create *}defer tx.PTx.Rollback()- projectMember, err := pgCreateProjectMember(ctx, tx.PTx, create)+ projectMember, err := createProjectMember(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -92,7 +92,7 @@ func (s *ProjectMemberService) PatchProjectMember(ctx context.Context, patch *ap}defer tx.PTx.Rollback()- projectMember, err := pgPatchProjectMember(ctx, tx.PTx, patch)+ projectMember, err := patchProjectMember(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -112,7 +112,7 @@ func (s *ProjectMemberService) DeleteProjectMember(ctx context.Context, delete *}defer tx.PTx.Rollback()- if err := pgDeleteProjectMember(ctx, tx.PTx, delete); err != nil {+ if err := deleteProjectMember(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -123,8 +123,8 @@ func (s *ProjectMemberService) DeleteProjectMember(ctx context.Context, delete *return nil}-// pgCreateProjectMember creates a new projectMember.-func pgCreateProjectMember(ctx context.Context, tx *sql.Tx, create *api.ProjectMemberCreate) (*api.ProjectMember, error) {+// createProjectMember creates a new projectMember.+func createProjectMember(ctx context.Context, tx *sql.Tx, create *api.ProjectMemberCreate) (*api.ProjectMember, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO project_member (@@ -222,8 +222,8 @@ func findProjectMemberList(ctx context.Context, tx *sql.Tx, find *api.ProjectMemreturn list, nil}-// pgPatchProjectMember updates a projectMember by ID. Returns the new state of the projectMember after update.-func pgPatchProjectMember(ctx context.Context, tx *sql.Tx, patch *api.ProjectMemberPatch) (*api.ProjectMember, error) {+// patchProjectMember updates a projectMember by ID. Returns the new state of the projectMember after update.+func patchProjectMember(ctx context.Context, tx *sql.Tx, patch *api.ProjectMemberPatch) (*api.ProjectMember, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Role; v != nil {@@ -267,8 +267,8 @@ func pgPatchProjectMember(ctx context.Context, tx *sql.Tx, patch *api.ProjectMemreturn nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member ID not found: %d", patch.ID)}}-// pgDeleteProjectMember permanently deletes a projectMember by ID.-func pgDeleteProjectMember(ctx context.Context, tx *sql.Tx, delete *api.ProjectMemberDelete) error {+// deleteProjectMember permanently deletes a projectMember by ID.+func deleteProjectMember(ctx context.Context, tx *sql.Tx, delete *api.ProjectMemberDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM project_member WHERE id = $1`, delete.ID); err != nil {return FormatError(err)diff --git a/store/project_webhook.go b/store/project_webhook.goindex 067adc6ec8..edd84c2a38 100644--- a/store/project_webhook.go+++ b/store/project_webhook.go@@ -34,7 +34,7 @@ func (s *ProjectWebhookService) CreateProjectWebhook(ctx context.Context, create}defer tx.PTx.Rollback()- projectWebhook, err := pgCreateProjectWebhook(ctx, tx.PTx, create)+ projectWebhook, err := createProjectWebhook(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -93,7 +93,7 @@ func (s *ProjectWebhookService) PatchProjectWebhook(ctx context.Context, patch *}defer tx.PTx.Rollback()- projectWebhook, err := pgPatchProjectWebhook(ctx, tx.PTx, patch)+ projectWebhook, err := patchProjectWebhook(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -113,7 +113,7 @@ func (s *ProjectWebhookService) DeleteProjectWebhook(ctx context.Context, delete}defer tx.PTx.Rollback()- if err := pgDeleteProjectWebhook(ctx, tx.PTx, delete); err != nil {+ if err := deleteProjectWebhook(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -124,8 +124,8 @@ func (s *ProjectWebhookService) DeleteProjectWebhook(ctx context.Context, deletereturn nil}-// pgCreateProjectWebhook creates a new projectWebhook.-func pgCreateProjectWebhook(ctx context.Context, tx *sql.Tx, create *api.ProjectWebhookCreate) (*api.ProjectWebhook, error) {+// createProjectWebhook creates a new projectWebhook.+func createProjectWebhook(ctx context.Context, tx *sql.Tx, create *api.ProjectWebhookCreate) (*api.ProjectWebhook, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO project_webhook (@@ -246,8 +246,8 @@ func findProjectWebhookList(ctx context.Context, tx *sql.Tx, find *api.ProjectWereturn list, nil}-// pgPatchProjectWebhook updates a projectWebhook by ID. Returns the new state of the projectWebhook after update.-func pgPatchProjectWebhook(ctx context.Context, tx *sql.Tx, patch *api.ProjectWebhookPatch) (*api.ProjectWebhook, error) {+// patchProjectWebhook updates a projectWebhook by ID. Returns the new state of the projectWebhook after update.+func patchProjectWebhook(ctx context.Context, tx *sql.Tx, patch *api.ProjectWebhookPatch) (*api.ProjectWebhook, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Name; v != nil {@@ -301,8 +301,8 @@ func pgPatchProjectWebhook(ctx context.Context, tx *sql.Tx, patch *api.ProjectWereturn nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook ID not found: %d", patch.ID)}}-// pgDeleteProjectWebhook permanently deletes a projectWebhook by ID.-func pgDeleteProjectWebhook(ctx context.Context, tx *sql.Tx, delete *api.ProjectWebhookDelete) error {+// deleteProjectWebhook permanently deletes a projectWebhook by ID.+func deleteProjectWebhook(ctx context.Context, tx *sql.Tx, delete *api.ProjectWebhookDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM project_webhook WHERE id = $1`, delete.ID); err != nil {return FormatError(err)diff --git a/store/repository.go b/store/repository.goindex ef50d73b16..66d1844f01 100644--- a/store/repository.go+++ b/store/repository.go@@ -36,7 +36,7 @@ func (s *RepositoryService) CreateRepository(ctx context.Context, create *api.Re}defer tx.PTx.Rollback()- repository, err := s.pgCreateRepository(ctx, tx.PTx, create)+ repository, err := s.createRepository(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -95,7 +95,7 @@ func (s *RepositoryService) PatchRepository(ctx context.Context, patch *api.Repo}defer tx.PTx.Rollback()- repository, err := pgPatchRepository(ctx, tx.PTx, patch)+ repository, err := patchRepository(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -115,7 +115,7 @@ func (s *RepositoryService) DeleteRepository(ctx context.Context, delete *api.Re}defer tx.PTx.Rollback()- if err := s.pgDeleteRepository(ctx, tx.PTx, delete); err != nil {+ if err := s.deleteRepository(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -126,8 +126,8 @@ func (s *RepositoryService) DeleteRepository(ctx context.Context, delete *api.Rereturn nil}-// pgCreateRepository creates a new repository.-func (s *RepositoryService) pgCreateRepository(ctx context.Context, tx *sql.Tx, create *api.RepositoryCreate) (*api.Repository, error) {+// createRepository creates a new repository.+func (s *RepositoryService) createRepository(ctx context.Context, tx *sql.Tx, create *api.RepositoryCreate) (*api.Repository, error) {// Updates the project workflow_type to "VCS"workflowType := api.VCSWorkflowprojectPatch := api.ProjectPatch{@@ -135,7 +135,7 @@ func (s *RepositoryService) pgCreateRepository(ctx context.Context, tx *sql.Tx,UpdaterID: create.CreatorID,WorkflowType: &workflowType,}- if _, err := s.projectService.PgPatchProjectTx(ctx, tx, &projectPatch); err != nil {+ if _, err := s.projectService.PatchProjectTx(ctx, tx, &projectPatch); err != nil {return nil, err}@@ -312,8 +312,8 @@ func findRepositoryList(ctx context.Context, tx *sql.Tx, find *api.RepositoryFinreturn list, nil}-// pgPatchRepository updates a repository by ID. Returns the new state of the repository after update.-func pgPatchRepository(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPatch) (*api.Repository, error) {+// patchRepository updates a repository by ID. Returns the new state of the repository after update.+func patchRepository(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPatch) (*api.Repository, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.BranchFilter; v != nil {@@ -389,8 +389,8 @@ func pgPatchRepository(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPatreturn nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository ID not found: %d", patch.ID)}}-// pgDeleteRepository permanently deletes a repository by ID.-func (s *RepositoryService) pgDeleteRepository(ctx context.Context, tx *sql.Tx, delete *api.RepositoryDelete) error {+// deleteRepository permanently deletes a repository by ID.+func (s *RepositoryService) deleteRepository(ctx context.Context, tx *sql.Tx, delete *api.RepositoryDelete) error {// Updates the project workflow_type to "UI"workflowType := api.UIWorkflowprojectPatch := api.ProjectPatch{@@ -398,7 +398,7 @@ func (s *RepositoryService) pgDeleteRepository(ctx context.Context, tx *sql.Tx,UpdaterID: delete.DeleterID,WorkflowType: &workflowType,}- if _, err := s.projectService.PgPatchProjectTx(ctx, tx, &projectPatch); err != nil {+ if _, err := s.projectService.PatchProjectTx(ctx, tx, &projectPatch); err != nil {return err}diff --git a/store/pg_seed/README.md b/store/seed/README.mdsimilarity index 100%rename from store/pg_seed/README.mdrename to store/seed/README.mddiff --git a/store/pg_seed/release/10001__init_seed.sql b/store/seed/release/10001__init_seed.sqlsimilarity index 100%rename from store/pg_seed/release/10001__init_seed.sqlrename to store/seed/release/10001__init_seed.sqldiff --git a/store/pg_seed/release/README.md b/store/seed/release/README.mdsimilarity index 100%rename from store/pg_seed/release/README.mdrename to store/seed/release/README.mddiff --git a/store/pg_seed/test/10000__reset.sql b/store/seed/test/10000__reset.sqlsimilarity index 100%rename from store/pg_seed/test/10000__reset.sqlrename to store/seed/test/10000__reset.sqldiff --git a/store/pg_seed/test/10001__principal.sql b/store/seed/test/10001__principal.sqlsimilarity index 100%rename from store/pg_seed/test/10001__principal.sqlrename to store/seed/test/10001__principal.sqldiff --git a/store/pg_seed/test/10010__workspace.sql b/store/seed/test/10010__workspace.sqlsimilarity index 100%rename from store/pg_seed/test/10010__workspace.sqlrename to store/seed/test/10010__workspace.sqldiff --git a/store/pg_seed/test/10020__member.sql b/store/seed/test/10020__member.sqlsimilarity index 100%rename from store/pg_seed/test/10020__member.sqlrename to store/seed/test/10020__member.sqldiff --git a/store/pg_seed/test/10030__project.sql b/store/seed/test/10030__project.sqlsimilarity index 100%rename from store/pg_seed/test/10030__project.sqlrename to store/seed/test/10030__project.sqldiff --git a/store/pg_seed/test/10040__project_member.sql b/store/seed/test/10040__project_member.sqlsimilarity index 100%rename from store/pg_seed/test/10040__project_member.sqlrename to store/seed/test/10040__project_member.sqldiff --git a/store/pg_seed/test/10041__project_webhook.sql b/store/seed/test/10041__project_webhook.sqlsimilarity index 100%rename from store/pg_seed/test/10041__project_webhook.sqlrename to store/seed/test/10041__project_webhook.sqldiff --git a/store/pg_seed/test/10050__environment.sql b/store/seed/test/10050__environment.sqlsimilarity index 100%rename from store/pg_seed/test/10050__environment.sqlrename to store/seed/test/10050__environment.sqldiff --git a/store/pg_seed/test/10051__policy.sql b/store/seed/test/10051__policy.sqlsimilarity index 100%rename from store/pg_seed/test/10051__policy.sqlrename to store/seed/test/10051__policy.sqldiff --git a/store/pg_seed/test/10060__instance.sql b/store/seed/test/10060__instance.sqlsimilarity index 100%rename from store/pg_seed/test/10060__instance.sqlrename to store/seed/test/10060__instance.sqldiff --git a/store/pg_seed/test/10061__instance_user.sql b/store/seed/test/10061__instance_user.sqlsimilarity index 100%rename from store/pg_seed/test/10061__instance_user.sqlrename to store/seed/test/10061__instance_user.sqldiff --git a/store/pg_seed/test/10070__db.sql b/store/seed/test/10070__db.sqlsimilarity index 100%rename from store/pg_seed/test/10070__db.sqlrename to store/seed/test/10070__db.sqldiff --git a/store/pg_seed/test/10071__tbl.sql b/store/seed/test/10071__tbl.sqlsimilarity index 100%rename from store/pg_seed/test/10071__tbl.sqlrename to store/seed/test/10071__tbl.sqldiff --git a/store/pg_seed/test/10072__col.sql b/store/seed/test/10072__col.sqlsimilarity index 100%rename from store/pg_seed/test/10072__col.sqlrename to store/seed/test/10072__col.sqldiff --git a/store/pg_seed/test/10073__idx.sql b/store/seed/test/10073__idx.sqlsimilarity index 100%rename from store/pg_seed/test/10073__idx.sqlrename to store/seed/test/10073__idx.sqldiff --git a/store/pg_seed/test/10074__backup.sql b/store/seed/test/10074__backup.sqlsimilarity index 100%rename from store/pg_seed/test/10074__backup.sqlrename to store/seed/test/10074__backup.sqldiff --git a/store/pg_seed/test/10080__data_source.sql b/store/seed/test/10080__data_source.sqlsimilarity index 100%rename from store/pg_seed/test/10080__data_source.sqlrename to store/seed/test/10080__data_source.sqldiff --git a/store/pg_seed/test/10090__pipeline.sql b/store/seed/test/10090__pipeline.sqlsimilarity index 100%rename from store/pg_seed/test/10090__pipeline.sqlrename to store/seed/test/10090__pipeline.sqldiff --git a/store/pg_seed/test/10100__stage.sql b/store/seed/test/10100__stage.sqlsimilarity index 100%rename from store/pg_seed/test/10100__stage.sqlrename to store/seed/test/10100__stage.sqldiff --git a/store/pg_seed/test/10110__task.sql b/store/seed/test/10110__task.sqlsimilarity index 100%rename from store/pg_seed/test/10110__task.sqlrename to store/seed/test/10110__task.sqldiff --git a/store/pg_seed/test/10120__task_run.sql b/store/seed/test/10120__task_run.sqlsimilarity index 100%rename from store/pg_seed/test/10120__task_run.sqlrename to store/seed/test/10120__task_run.sqldiff --git a/store/pg_seed/test/10121__task_check_run.sql b/store/seed/test/10121__task_check_run.sqlsimilarity index 100%rename from store/pg_seed/test/10121__task_check_run.sqlrename to store/seed/test/10121__task_check_run.sqldiff --git a/store/pg_seed/test/10130__issue.sql b/store/seed/test/10130__issue.sqlsimilarity index 100%rename from store/pg_seed/test/10130__issue.sqlrename to store/seed/test/10130__issue.sqldiff --git a/store/pg_seed/test/10131__issue_subscriber.sql b/store/seed/test/10131__issue_subscriber.sqlsimilarity index 100%rename from store/pg_seed/test/10131__issue_subscriber.sqlrename to store/seed/test/10131__issue_subscriber.sqldiff --git a/store/pg_seed/test/10140__activity.sql b/store/seed/test/10140__activity.sqlsimilarity index 100%rename from store/pg_seed/test/10140__activity.sqlrename to store/seed/test/10140__activity.sqldiff --git a/store/pg_seed/test/10150__inbox.sql b/store/seed/test/10150__inbox.sqlsimilarity index 100%rename from store/pg_seed/test/10150__inbox.sqlrename to store/seed/test/10150__inbox.sqldiff --git a/store/pg_seed/test/10160__bookmark.sql b/store/seed/test/10160__bookmark.sqlsimilarity index 100%rename from store/pg_seed/test/10160__bookmark.sqlrename to store/seed/test/10160__bookmark.sqldiff --git a/store/pg_seed/test/10170__vcs.sql b/store/seed/test/10170__vcs.sqlsimilarity index 100%rename from store/pg_seed/test/10170__vcs.sqlrename to store/seed/test/10170__vcs.sqldiff --git a/store/pg_seed/test/10180__repository.sql b/store/seed/test/10180__repository.sqlsimilarity index 100%rename from store/pg_seed/test/10180__repository.sqlrename to store/seed/test/10180__repository.sqldiff --git a/store/pg_seed/test/10190__anomaly.sql b/store/seed/test/10190__anomaly.sqlsimilarity index 100%rename from store/pg_seed/test/10190__anomaly.sqlrename to store/seed/test/10190__anomaly.sqldiff --git a/store/pg_seed/test/10200__label.sql b/store/seed/test/10200__label.sqlsimilarity index 100%rename from store/pg_seed/test/10200__label.sqlrename to store/seed/test/10200__label.sqldiff --git a/store/pg_seed/test/10210__deployment_config.sql b/store/seed/test/10210__deployment_config.sqlsimilarity index 100%rename from store/pg_seed/test/10210__deployment_config.sqlrename to store/seed/test/10210__deployment_config.sqldiff --git a/store/pg_seed/test/10220__sheet.sql b/store/seed/test/10220__sheet.sqlsimilarity index 100%rename from store/pg_seed/test/10220__sheet.sqlrename to store/seed/test/10220__sheet.sqldiff --git a/store/pg_seed/test/README.md b/store/seed/test/README.mdsimilarity index 100%rename from store/pg_seed/test/README.mdrename to store/seed/test/README.mddiff --git a/store/setting.go b/store/setting.goindex 1f3fe607e8..ec606c44f4 100644--- a/store/setting.go+++ b/store/setting.go@@ -44,7 +44,7 @@ func (s *SettingService) CreateSettingIfNotExist(ctx context.Context, create *ap}defer tx.PTx.Rollback()- setting, err := pgCreateSetting(ctx, tx.PTx, create)+ setting, err := createSetting(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -105,7 +105,7 @@ func (s *SettingService) PatchSetting(ctx context.Context, patch *api.SettingPat}defer tx.PTx.Rollback()- setting, err := pgPatchSetting(ctx, tx.PTx, patch)+ setting, err := patchSetting(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -117,8 +117,8 @@ func (s *SettingService) PatchSetting(ctx context.Context, patch *api.SettingPatreturn setting, nil}-// pgCreateSetting creates a new setting.-func pgCreateSetting(ctx context.Context, tx *sql.Tx, create *api.SettingCreate) (*api.Setting, error) {+// createSetting creates a new setting.+func createSetting(ctx context.Context, tx *sql.Tx, create *api.SettingCreate) (*api.Setting, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO setting (@@ -206,8 +206,8 @@ func findSettingList(ctx context.Context, tx *sql.Tx, find *api.SettingFind) (_return list, nil}-// pgPatchSetting updates a setting by name. Returns the new state of the setting after update.-func pgPatchSetting(ctx context.Context, tx *sql.Tx, patch *api.SettingPatch) (*api.Setting, error) {+// patchSetting updates a setting by name. Returns the new state of the setting after update.+func patchSetting(ctx context.Context, tx *sql.Tx, patch *api.SettingPatch) (*api.Setting, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}set, args = append(set, "value = $2"), append(args, patch.Value)diff --git a/store/sheet.go b/store/sheet.goindex cff19ed9c5..098cda321c 100644--- a/store/sheet.go+++ b/store/sheet.go@@ -34,7 +34,7 @@ func (s *SheetService) CreateSheet(ctx context.Context, create *api.SheetCreate)}defer tx.PTx.Rollback()- sheet, err := pgCreateSheet(ctx, tx.PTx, create)+ sheet, err := createSheet(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -54,7 +54,7 @@ func (s *SheetService) PatchSheet(ctx context.Context, patch *api.SheetPatch) (*}defer tx.PTx.Rollback()- sheet, err := pgPatchSheet(ctx, tx.PTx, patch)+ sheet, err := patchSheet(ctx, tx.PTx, patch)if err != nil {return nil, err}@@ -113,7 +113,7 @@ func (s *SheetService) DeleteSheet(ctx context.Context, delete *api.SheetDelete)}defer tx.PTx.Rollback()- if err := pgDeleteSheet(ctx, tx.PTx, delete); err != nil {+ if err := deleteSheet(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -124,8 +124,8 @@ func (s *SheetService) DeleteSheet(ctx context.Context, delete *api.SheetDelete)return nil}-// pgCreateSheet creates a new sheet.-func pgCreateSheet(ctx context.Context, tx *sql.Tx, create *api.SheetCreate) (*api.Sheet, error) {+// createSheet creates a new sheet.+func createSheet(ctx context.Context, tx *sql.Tx, create *api.SheetCreate) (*api.Sheet, error) {row, err := tx.QueryContext(ctx, `INSERT INTO sheet (creator_id,@@ -179,8 +179,8 @@ func pgCreateSheet(ctx context.Context, tx *sql.Tx, create *api.SheetCreate) (*areturn &sheet, nil}-// pgPatchSheet updates a sheet's name/statement/visibility.-func pgPatchSheet(ctx context.Context, tx *sql.Tx, patch *api.SheetPatch) (*api.Sheet, error) {+// patchSheet updates a sheet's name/statement/visibility.+func patchSheet(ctx context.Context, tx *sql.Tx, patch *api.SheetPatch) (*api.Sheet, error) {set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Name; v != nil {set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, api.RowStatus(*v))@@ -317,8 +317,8 @@ func findSheetList(ctx context.Context, tx *sql.Tx, find *api.SheetFind) (_ []*areturn list, nil}-// pgDeleteSheet permanently deletes a sheet by ID.-func pgDeleteSheet(ctx context.Context, tx *sql.Tx, delete *api.SheetDelete) error {+// deleteSheet permanently deletes a sheet by ID.+func deleteSheet(ctx context.Context, tx *sql.Tx, delete *api.SheetDelete) error {if _, err := tx.ExecContext(ctx, `DELETE FROM sheet WHERE id = $1`, delete.ID); err != nil {return FormatError(err)}diff --git a/store/stage.go b/store/stage.goindex 2c045a2ac9..d3a6d9df97 100644--- a/store/stage.go+++ b/store/stage.go@@ -34,7 +34,7 @@ func (s *StageService) CreateStage(ctx context.Context, create *api.StageCreate)}defer tx.PTx.Rollback()- stage, err := s.pgCreateStage(ctx, tx.PTx, create)+ stage, err := s.createStage(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -84,8 +84,8 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*apireturn list[0], nil}-// pgCreateStage creates a new stage.-func (s *StageService) pgCreateStage(ctx context.Context, tx *sql.Tx, create *api.StageCreate) (*api.Stage, error) {+// createStage creates a new stage.+func (s *StageService) createStage(ctx context.Context, tx *sql.Tx, create *api.StageCreate) (*api.Stage, error) {row, err := tx.QueryContext(ctx, `INSERT INTO stage (creator_id,diff --git a/store/table.go b/store/table.goindex 34422c7a7c..5d562a5e97 100644--- a/store/table.go+++ b/store/table.go@@ -34,7 +34,7 @@ func (s *TableService) CreateTable(ctx context.Context, create *api.TableCreate)}defer tx.PTx.Rollback()- table, err := s.pgCreateTable(ctx, tx.PTx, create)+ table, err := s.createTable(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -92,7 +92,7 @@ func (s *TableService) DeleteTable(ctx context.Context, delete *api.TableDelete)}defer tx.PTx.Rollback()- if err := pgDeleteTable(ctx, tx.PTx, delete); err != nil {+ if err := deleteTable(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -103,8 +103,8 @@ func (s *TableService) DeleteTable(ctx context.Context, delete *api.TableDelete)return nil}-// pgCreateTable creates a new table.-func (s *TableService) pgCreateTable(ctx context.Context, tx *sql.Tx, create *api.TableCreate) (*api.Table, error) {+// createTable creates a new table.+func (s *TableService) createTable(ctx context.Context, tx *sql.Tx, create *api.TableCreate) (*api.Table, error) {// Insert row into table.row, err := tx.QueryContext(ctx, `INSERT INTO tbl (@@ -249,8 +249,8 @@ func (s *TableService) findTableList(ctx context.Context, tx *sql.Tx, find *api.return list, nil}-// pgDeleteTable permanently deletes tables from a database.-func pgDeleteTable(ctx context.Context, tx *sql.Tx, delete *api.TableDelete) error {+// deleteTable permanently deletes tables from a database.+func deleteTable(ctx context.Context, tx *sql.Tx, delete *api.TableDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM tbl WHERE database_id = $1`, delete.DatabaseID); err != nil {return FormatError(err)diff --git a/store/table_index.go b/store/table_index.goindex c7d8957eff..84f1d70bc6 100644--- a/store/table_index.go+++ b/store/table_index.go@@ -34,7 +34,7 @@ func (s *IndexService) CreateIndex(ctx context.Context, create *api.IndexCreate)}defer tx.PTx.Rollback()- index, err := s.pgCreateIndex(ctx, tx.PTx, create)+ index, err := s.createIndex(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -84,8 +84,8 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*apireturn list[0], nil}-// pgCreateIndex creates a new index.-func (s *IndexService) pgCreateIndex(ctx context.Context, tx *sql.Tx, create *api.IndexCreate) (*api.Index, error) {+// createIndex creates a new index.+func (s *IndexService) createIndex(ctx context.Context, tx *sql.Tx, create *api.IndexCreate) (*api.Index, error) {// Insert row into index.row, err := tx.QueryContext(ctx, `INSERT INTO idx (diff --git a/store/task.go b/store/task.goindex bcdee8e4e7..5a0da0d616 100644--- a/store/task.go+++ b/store/task.go@@ -38,7 +38,7 @@ func (s *TaskService) CreateTask(ctx context.Context, create *api.TaskCreate) (*}defer tx.PTx.Rollback()- task, err := s.pgCreateTask(ctx, tx.PTx, create)+ task, err := s.createTask(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -58,7 +58,7 @@ func (s *TaskService) FindTaskList(ctx context.Context, find *api.TaskFind) ([]*}defer tx.PTx.Rollback()- list, err := s.pgFindTaskList(ctx, tx.PTx, find)+ list, err := s.findTaskList(ctx, tx.PTx, find)if err != nil {return []*api.Task{}, err}@@ -75,7 +75,7 @@ func (s *TaskService) FindTask(ctx context.Context, find *api.TaskFind) (*api.Ta}defer tx.PTx.Rollback()- return s.pgFindTask(ctx, tx.PTx, find)+ return s.findTask(ctx, tx.PTx, find)}// PatchTask updates an existing task.@@ -87,7 +87,7 @@ func (s *TaskService) PatchTask(ctx context.Context, patch *api.TaskPatch) (*api}defer tx.PTx.Rollback()- task, err := s.pgPatchTask(ctx, tx.PTx, patch)+ task, err := s.patchTask(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -108,7 +108,7 @@ func (s *TaskService) PatchTaskStatus(ctx context.Context, patch *api.TaskStatus}defer tx.PTx.Rollback()- task, err := s.pgPatchTaskStatus(ctx, tx.PTx, patch)+ task, err := s.patchTaskStatus(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -120,8 +120,8 @@ func (s *TaskService) PatchTaskStatus(ctx context.Context, patch *api.TaskStatusreturn task, nil}-// pgCreateTask creates a new task.-func (s *TaskService) pgCreateTask(ctx context.Context, tx *sql.Tx, create *api.TaskCreate) (*api.Task, error) {+// createTask creates a new task.+func (s *TaskService) createTask(ctx context.Context, tx *sql.Tx, create *api.TaskCreate) (*api.Task, error) {var row *sql.Rowsvar err error@@ -222,8 +222,8 @@ func (s *TaskService) pgCreateTask(ctx context.Context, tx *sql.Tx, create *api.return &task, nil}-func (s *TaskService) pgFindTask(ctx context.Context, tx *sql.Tx, find *api.TaskFind) (_ *api.Task, err error) {- list, err := s.pgFindTaskList(ctx, tx, find)+func (s *TaskService) findTask(ctx context.Context, tx *sql.Tx, find *api.TaskFind) (_ *api.Task, err error) {+ list, err := s.findTaskList(ctx, tx, find)if err != nil {return nil, err}@@ -236,7 +236,7 @@ func (s *TaskService) pgFindTask(ctx context.Context, tx *sql.Tx, find *api.Taskreturn list[0], nil}-func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.TaskFind) (_ []*api.Task, err error) {+func (s *TaskService) findTaskList(ctx context.Context, tx *sql.Tx, find *api.TaskFind) (_ []*api.Task, err error) {// Build WHERE clause.where, args := []string{"1 = 1"}, []interface{}{}if v := find.ID; v != nil {@@ -311,7 +311,7 @@ func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.taskRunFind := &api.TaskRunFind{TaskID: &task.ID,}- task.TaskRunList, err = s.TaskRunService.PgFindTaskRunListTx(ctx, tx, taskRunFind)+ task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx, taskRunFind)if err != nil {return nil, err}@@ -319,7 +319,7 @@ func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.taskCheckRunFind := &api.TaskCheckRunFind{TaskID: &task.ID,}- task.TaskCheckRunList, err = s.TaskCheckRunService.PgFindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)+ task.TaskCheckRunList, err = s.TaskCheckRunService.FindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)if err != nil {return nil, err}@@ -330,8 +330,8 @@ func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.return list, nil}-// pgPatchTask updates a task by ID. Returns the new state of the task after update.-func (s *TaskService) pgPatchTask(ctx context.Context, tx *sql.Tx, patch *api.TaskPatch) (*api.Task, error) {+// patchTask updates a task by ID. Returns the new state of the task after update.+func (s *TaskService) patchTask(ctx context.Context, tx *sql.Tx, patch *api.TaskPatch) (*api.Task, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.DatabaseID; v != nil {@@ -386,15 +386,15 @@ func (s *TaskService) pgPatchTask(ctx context.Context, tx *sql.Tx, patch *api.Tareturn nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}}-// pgPatchTaskStatus updates a task status by ID. Returns the new state of the task after update.-func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *api.TaskStatusPatch) (*api.Task, error) {+// patchTaskStatus updates a task status by ID. Returns the new state of the task after update.+func (s *TaskService) patchTaskStatus(ctx context.Context, tx *sql.Tx, patch *api.TaskStatusPatch) (*api.Task, error) {// Updates the corresponding task run if applicable.// We update the task run first because updating task below returns row and it's a bit complicated to// arrange code to prevent that opening row interfering with the task run update.taskFind := &api.TaskFind{ID: &patch.ID,}- task, err := s.pgFindTask(ctx, tx, taskFind)+ task, err := s.findTask(ctx, tx, taskFind)if err != nil {return nil, err}@@ -409,7 +409,7 @@ func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *api.TaskRunRunning,},}- taskRun, err := s.TaskRunService.PgFindTaskRunTx(ctx, tx, taskRunFind)+ taskRun, err := s.TaskRunService.FindTaskRunTx(ctx, tx, taskRunFind)if err != nil {return nil, err}@@ -424,7 +424,7 @@ func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *Type: task.Type,Payload: task.Payload,}- if _, err := s.TaskRunService.PgCreateTaskRunTx(ctx, tx, taskRunCreate); err != nil {+ if _, err := s.TaskRunService.CreateTaskRunTx(ctx, tx, taskRunCreate); err != nil {return nil, err}} else {@@ -449,7 +449,7 @@ func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *case api.TaskCanceled:taskRunStatusPatch.Status = api.TaskRunCanceled}- if _, err := s.TaskRunService.PgPatchTaskRunStatusTx(ctx, tx, taskRunStatusPatch); err != nil {+ if _, err := s.TaskRunService.PatchTaskRunStatusTx(ctx, tx, taskRunStatusPatch); err != nil {return nil, err}}@@ -508,7 +508,7 @@ func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *taskRunFind := &api.TaskRunFind{TaskID: &task.ID,}- task.TaskRunList, err = s.TaskRunService.PgFindTaskRunListTx(ctx, tx, taskRunFind)+ task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx, taskRunFind)if err != nil {return nil, err}@@ -516,7 +516,7 @@ func (s *TaskService) pgPatchTaskStatus(ctx context.Context, tx *sql.Tx, patch *taskCheckRunFind := &api.TaskCheckRunFind{TaskID: &task.ID,}- task.TaskCheckRunList, err = s.TaskCheckRunService.PgFindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)+ task.TaskCheckRunList, err = s.TaskCheckRunService.FindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)if err != nil {return nil, err}diff --git a/store/task_check_run.go b/store/task_check_run.goindex bb78178814..8ba4018cf3 100644--- a/store/task_check_run.go+++ b/store/task_check_run.go@@ -46,7 +46,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, crStatusList: &statusList,}- taskCheckRunList, err := s.PgFindTaskCheckRunListTx(ctx, tx.PTx, taskCheckRunFind)+ taskCheckRunList, err := s.FindTaskCheckRunListTx(ctx, tx.PTx, taskCheckRunFind)if err != nil {return nil, err}@@ -77,7 +77,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, crreturn taskCheckRunList[0], nil}- taskCheckRun, err := s.PgCreateTaskCheckRunTx(ctx, tx.PTx, create)+ taskCheckRun, err := s.createTaskCheckRunTx(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -89,8 +89,8 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, crreturn taskCheckRun, nil}-// PgCreateTaskCheckRunTx creates a new taskCheckRun.-func (s *TaskCheckRunService) PgCreateTaskCheckRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskCheckRunCreate) (*api.TaskCheckRun, error) {+// createTaskCheckRunTx creates a new taskCheckRun.+func (s *TaskCheckRunService) createTaskCheckRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskCheckRunCreate) (*api.TaskCheckRun, error) {rows, err := tx.QueryContext(ctx, `INSERT INTO task_check_run (creator_id,@@ -151,7 +151,7 @@ func (s *TaskCheckRunService) FindTaskCheckRunList(ctx context.Context, find *ap}defer tx.PTx.Rollback()- list, err := s.pgFindTaskCheckRunList(ctx, tx.PTx, find)+ list, err := s.findTaskCheckRunList(ctx, tx.PTx, find)if err != nil {return []*api.TaskCheckRun{}, err}@@ -169,16 +169,6 @@ func (s *TaskCheckRunService) FindTaskCheckRunListTx(ctx context.Context, tx *sqreturn list, nil}-// PgFindTaskCheckRunListTx retrieves a list of taskCheckRuns based on find.-func (s *TaskCheckRunService) PgFindTaskCheckRunListTx(ctx context.Context, tx *sql.Tx, find *api.TaskCheckRunFind) ([]*api.TaskCheckRun, error) {- list, err := s.pgFindTaskCheckRunList(ctx, tx, find)- if err != nil {- return []*api.TaskCheckRun{}, err- }-- return list, nil-}-// PatchTaskCheckRunStatus updates a taskCheckRun status. Returns the new state of the taskCheckRun after update.func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patch *api.TaskCheckRunStatusPatch) (*api.TaskCheckRun, error) {tx, err := s.db.BeginTx(ctx, nil)@@ -187,7 +177,7 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patch}defer tx.PTx.Rollback()- taskCheckRun, err := s.PgPatchTaskCheckRunStatusTx(ctx, tx.PTx, patch)+ taskCheckRun, err := s.patchTaskCheckRunStatusTx(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -199,8 +189,8 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patchreturn taskCheckRun, nil}-// PgPatchTaskCheckRunStatusTx updates a taskCheckRun status. Returns the new state of the taskCheckRun after update.-func (s *TaskCheckRunService) PgPatchTaskCheckRunStatusTx(ctx context.Context, tx *sql.Tx, patch *api.TaskCheckRunStatusPatch) (*api.TaskCheckRun, error) {+// patchTaskCheckRunStatusTx updates a taskCheckRun status. Returns the new state of the taskCheckRun after update.+func (s *TaskCheckRunService) patchTaskCheckRunStatusTx(ctx context.Context, tx *sql.Tx, patch *api.TaskCheckRunStatusPatch) (*api.TaskCheckRun, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}set, args = append(set, "status = $2"), append(args, patch.Status)@@ -254,85 +244,6 @@ func (s *TaskCheckRunService) PgPatchTaskCheckRunStatusTx(ctx context.Context, t}func (s *TaskCheckRunService) findTaskCheckRunList(ctx context.Context, tx *sql.Tx, find *api.TaskCheckRunFind) (_ []*api.TaskCheckRun, 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.TaskID; v != nil {- where, args = append(where, "task_id = ?"), append(args, *v)- }- if v := find.Type; v != nil {- where, args = append(where, "type = ?"), append(args, *v)- }- if v := find.StatusList; v != nil {- list := []string{}- for _, status := range *v {- list = append(list, "?")- args = append(args, status)- }- where = append(where, fmt.Sprintf("status in (%s)", strings.Join(list, ",")))- }-- orderAndLimit := ""- if find.Latest {- orderAndLimit = " ORDER BY updated_ts DESC LIMIT 1"- }-- rows, err := tx.QueryContext(ctx, `- SELECT- id,- creator_id,- created_ts,- updater_id,- updated_ts,- task_id,- status,- type,- code,- comment,- result,- payload- FROM task_check_run- WHERE `+strings.Join(where, " AND ")+orderAndLimit,- args...,- )- if err != nil {- return nil, FormatError(err)- }- defer rows.Close()-- // Iterate over result set and deserialize rows into list.- list := make([]*api.TaskCheckRun, 0)- for rows.Next() {- var taskCheckRun api.TaskCheckRun- if err := rows.Scan(- &taskCheckRun.ID,- &taskCheckRun.CreatorID,- &taskCheckRun.CreatedTs,- &taskCheckRun.UpdaterID,- &taskCheckRun.UpdatedTs,- &taskCheckRun.TaskID,- &taskCheckRun.Status,- &taskCheckRun.Type,- &taskCheckRun.Code,- &taskCheckRun.Comment,- &taskCheckRun.Result,- &taskCheckRun.Payload,- ); err != nil {- return nil, FormatError(err)- }-- list = append(list, &taskCheckRun)- }- if err := rows.Err(); err != nil {- return nil, FormatError(err)- }-- return list, nil-}--func (s *TaskCheckRunService) pgFindTaskCheckRunList(ctx context.Context, tx *sql.Tx, find *api.TaskCheckRunFind) (_ []*api.TaskCheckRun, err error) {// Build WHERE clause.where, args := []string{"1 = 1"}, []interface{}{}if v := find.ID; v != nil {diff --git a/store/task_run.go b/store/task_run.goindex 11a05c2f5e..56520959bc 100644--- a/store/task_run.go+++ b/store/task_run.go@@ -26,8 +26,8 @@ func NewTaskRunService(logger *zap.Logger, db *DB) *TaskRunService {return &TaskRunService{l: logger, db: db}}-// PgCreateTaskRunTx creates a new taskRun.-func (s *TaskRunService) PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskRunCreate) (*api.TaskRun, error) {+// CreateTaskRunTx creates a new taskRun.+func (s *TaskRunService) CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskRunCreate) (*api.TaskRun, error) {row, err := tx.QueryContext(ctx, `INSERT INTO task_run (creator_id,@@ -77,9 +77,9 @@ func (s *TaskRunService) PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, creareturn &taskRun, nil}-// PgFindTaskRunListTx retrieves a list of taskRuns based on find.-func (s *TaskRunService) PgFindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) ([]*api.TaskRun, error) {- list, err := s.pgFindTaskRunList(ctx, tx, find)+// FindTaskRunListTx retrieves a list of taskRuns based on find.+func (s *TaskRunService) FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) ([]*api.TaskRun, error) {+ list, err := s.findTaskRunList(ctx, tx, find)if err != nil {return []*api.TaskRun{}, err}@@ -87,10 +87,10 @@ func (s *TaskRunService) PgFindTaskRunListTx(ctx context.Context, tx *sql.Tx, fireturn list, nil}-// PgFindTaskRunTx retrieves a single taskRun based on find.+// FindTaskRunTx retrieves a single taskRun based on find.// Returns ECONFLICT if finding more than 1 matching records.-func (s *TaskRunService) PgFindTaskRunTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (*api.TaskRun, error) {- list, err := s.pgFindTaskRunList(ctx, tx, find)+func (s *TaskRunService) FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (*api.TaskRun, error) {+ list, err := s.findTaskRunList(ctx, tx, find)if err != nil {return nil, err}@@ -102,8 +102,8 @@ func (s *TaskRunService) PgFindTaskRunTx(ctx context.Context, tx *sql.Tx, find *return list[0], nil}-// PgPatchTaskRunStatusTx updates a taskRun status. Returns the new state of the taskRun after update.-func (s *TaskRunService) PgPatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *api.TaskRunStatusPatch) (*api.TaskRun, error) {+// PatchTaskRunStatusTx updates a taskRun status. Returns the new state of the taskRun after update.+func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *api.TaskRunStatusPatch) (*api.TaskRun, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}set, args = append(set, "status = $2"), append(args, patch.Status)@@ -163,7 +163,7 @@ func (s *TaskRunService) PgPatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx,return &taskRun, nil}-func (s *TaskRunService) pgFindTaskRunList(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (_ []*api.TaskRun, err error) {+func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (_ []*api.TaskRun, err error) {// Build WHERE clause.where, args := []string{"1 = 1"}, []interface{}{}if v := find.ID; v != nil {diff --git a/store/vcs.go b/store/vcs.goindex 9bff093278..5dc5a6e335 100644--- a/store/vcs.go+++ b/store/vcs.go@@ -34,7 +34,7 @@ func (s *VCSService) CreateVCS(ctx context.Context, create *api.VCSCreate) (*api}defer tx.PTx.Rollback()- vcs, err := pgCreateVCS(ctx, tx.PTx, create)+ vcs, err := createVCS(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -93,7 +93,7 @@ func (s *VCSService) PatchVCS(ctx context.Context, patch *api.VCSPatch) (*api.VC}defer tx.PTx.Rollback()- vcs, err := pgPatchVCS(ctx, tx.PTx, patch)+ vcs, err := patchVCS(ctx, tx.PTx, patch)if err != nil {return nil, FormatError(err)}@@ -113,7 +113,7 @@ func (s *VCSService) DeleteVCS(ctx context.Context, delete *api.VCSDelete) error}defer tx.PTx.Rollback()- if err := pgDeleteVCS(ctx, tx.PTx, delete); err != nil {+ if err := deleteVCS(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -124,8 +124,8 @@ func (s *VCSService) DeleteVCS(ctx context.Context, delete *api.VCSDelete) errorreturn nil}-// pgCreateVCS creates a new vcs.-func pgCreateVCS(ctx context.Context, tx *sql.Tx, create *api.VCSCreate) (*api.VCS, error) {+// createVCS creates a new vcs.+func createVCS(ctx context.Context, tx *sql.Tx, create *api.VCSCreate) (*api.VCS, error) {// Insert row into database.row, err := tx.QueryContext(ctx, `INSERT INTO vcs (@@ -235,8 +235,8 @@ func findVCSList(ctx context.Context, tx *sql.Tx, find *api.VCSFind) (_ []*api.Vreturn list, nil}-// pgPatchVCS updates a vcs by ID. Returns the new state of the vcs after update.-func pgPatchVCS(ctx context.Context, tx *sql.Tx, patch *api.VCSPatch) (*api.VCS, error) {+// patchVCS updates a vcs by ID. Returns the new state of the vcs after update.+func patchVCS(ctx context.Context, tx *sql.Tx, patch *api.VCSPatch) (*api.VCS, error) {// Build UPDATE clause.set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}if v := patch.Name; v != nil {@@ -288,8 +288,8 @@ func pgPatchVCS(ctx context.Context, tx *sql.Tx, patch *api.VCSPatch) (*api.VCS,return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("vcs ID not found: %d", patch.ID)}}-// pgDeleteVCS permanently deletes a vcs by ID.-func pgDeleteVCS(ctx context.Context, tx *sql.Tx, delete *api.VCSDelete) error {+// deleteVCS permanently deletes a vcs by ID.+func deleteVCS(ctx context.Context, tx *sql.Tx, delete *api.VCSDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM vcs WHERE id = $1`, delete.ID); err != nil {return FormatError(err)diff --git a/store/view.go b/store/view.goindex a888396896..2796905927 100644--- a/store/view.go+++ b/store/view.go@@ -34,7 +34,7 @@ func (s *ViewService) CreateView(ctx context.Context, create *api.ViewCreate) (*}defer tx.PTx.Rollback()- view, err := s.pgCreateView(ctx, tx.PTx, create)+ view, err := s.createView(ctx, tx.PTx, create)if err != nil {return nil, err}@@ -92,7 +92,7 @@ func (s *ViewService) DeleteView(ctx context.Context, delete *api.ViewDelete) er}defer tx.PTx.Rollback()- if err := pgDeleteView(ctx, tx.PTx, delete); err != nil {+ if err := deleteView(ctx, tx.PTx, delete); err != nil {return FormatError(err)}@@ -103,8 +103,8 @@ func (s *ViewService) DeleteView(ctx context.Context, delete *api.ViewDelete) erreturn nil}-// pgCreateView creates a new view.-func (s *ViewService) pgCreateView(ctx context.Context, tx *sql.Tx, create *api.ViewCreate) (*api.View, error) {+// createView creates a new view.+func (s *ViewService) createView(ctx context.Context, tx *sql.Tx, create *api.ViewCreate) (*api.View, error) {// Insert row into view.row, err := tx.QueryContext(ctx, `INSERT INTO vw (@@ -215,8 +215,8 @@ func (s *ViewService) findViewList(ctx context.Context, tx *sql.Tx, find *api.Vireturn list, nil}-// pgDeleteView permanently deletes views from a database.-func pgDeleteView(ctx context.Context, tx *sql.Tx, delete *api.ViewDelete) error {+// deleteView permanently deletes views from a database.+func deleteView(ctx context.Context, tx *sql.Tx, delete *api.ViewDelete) error {// Remove row from database.if _, err := tx.ExecContext(ctx, `DELETE FROM vw WHERE database_id = $1`, delete.DatabaseID); err != nil {return FormatError(err)