Skip to content

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

feat(pg): remove the dual write to sqlite (#621)

Danny Xu995be79cb004
diff --git a/api/backup.go b/api/backup.go
index f6ed1b586a..cc2c2e8a44 100644
--- a/api/backup.go
+++ b/api/backup.go
@@ -213,7 +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)
- UpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *BackupSettingUpsert) (*BackupSetting, error)
PgUpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *BackupSettingUpsert) (*BackupSetting, error)
FindBackupSettingsMatch(ctx context.Context, match *BackupSettingsMatch) ([]*BackupSetting, error)
}
diff --git a/api/database.go b/api/database.go
index e026d11b6d..ed9598ea01 100644
--- a/api/database.go
+++ b/api/database.go
@@ -141,7 +141,6 @@ 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.
- CreateDatabaseTx(ctx context.Context, tx *sql.Tx, create *DatabaseCreate) (*Database, error)
PgCreateDatabaseTx(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)
diff --git a/api/project.go b/api/project.go
index 3e6fa46009..f875d4bf1d 100644
--- a/api/project.go
+++ b/api/project.go
@@ -310,6 +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.
- PatchProjectTx(ctx context.Context, tx *sql.Tx, patch *ProjectPatch) (*Project, error)
PgPatchProjectTx(ctx context.Context, tx *sql.Tx, patch *ProjectPatch) (*Project, error)
}
diff --git a/api/task_check_run.go b/api/task_check_run.go
index 7e528ab3b2..23eb7af4ac 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -199,5 +199,4 @@ type TaskCheckRunService interface {
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)
- PatchTaskCheckRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskCheckRunStatusPatch) (*TaskCheckRun, error)
}
diff --git a/api/task_run.go b/api/task_run.go
index fc58fc6223..03a55faa4c 100644
--- a/api/task_run.go
+++ b/api/task_run.go
@@ -124,12 +124,8 @@ type TaskRunStatusPatch struct {
// TaskRunService is the service for task runs.
type TaskRunService interface {
- CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)
PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *TaskRunCreate) (*TaskRun, error)
- FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)
PgFindTaskRunListTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) ([]*TaskRun, error)
- FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)
PgFindTaskRunTx(ctx context.Context, tx *sql.Tx, find *TaskRunFind) (*TaskRun, error)
- PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)
PgPatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskRunStatusPatch) (*TaskRun, error)
}
diff --git a/store/activity.go b/store/activity.go
index a33e290f81..38c83bbeae 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -32,20 +32,13 @@ func (s *ActivityService) CreateActivity(ctx context.Context, create *api.Activi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
activity, err := pgCreateActivity(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createActivity(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *ActivityService) FindActivityList(ctx context.Context, find *api.Activi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findActivityList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *ActivityService) FindActivity(ctx context.Context, find *api.ActivityFi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findActivityList(ctx, tx.PTx, find)
@@ -100,20 +91,13 @@ func (s *ActivityService) PatchActivity(ctx context.Context, patch *api.Activity
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
activity, err := pgPatchActivity(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchActivity(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -127,19 +111,12 @@ func (s *ActivityService) DeleteActivity(ctx context.Context, delete *api.Activi
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteActivity(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteActivity(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -147,56 +124,6 @@ func (s *ActivityService) DeleteActivity(ctx context.Context, delete *api.Activi
return nil
}
-// 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 (
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- comment,
- payload
- )
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, container_id, type, level, comment, payload
- `,
- create.CreatorID,
- create.CreatorID,
- create.ContainerID,
- create.Type,
- create.Level,
- create.Comment,
- create.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var activity api.Activity
- if err := row.Scan(
- &activity.ID,
- &activity.CreatorID,
- &activity.CreatedTs,
- &activity.UpdaterID,
- &activity.UpdatedTs,
- &activity.ContainerID,
- &activity.Type,
- &activity.Level,
- &activity.Comment,
- &activity.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &activity, nil
-}
-
// pgCreateActivity creates a new activity.
func pgCreateActivity(ctx context.Context, tx *sql.Tx, create *api.ActivityCreate) (*api.Activity, error) {
// Insert row into activity.
@@ -317,53 +244,6 @@ func findActivityList(ctx context.Context, tx *sql.Tx, find *api.ActivityFind) (
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Comment; v != nil {
- set, args = append(set, "comment = ?"), append(args, api.Role(*v))
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE activity
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, container_id, type, level, comment, payload
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var activity api.Activity
- if err := row.Scan(
- &activity.ID,
- &activity.CreatorID,
- &activity.CreatedTs,
- &activity.UpdaterID,
- &activity.UpdatedTs,
- &activity.ContainerID,
- &activity.Type,
- &activity.Level,
- &activity.Comment,
- &activity.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &activity, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("activity ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -411,15 +291,6 @@ 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)}
}
-// 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 = ?`, delete.ID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteActivity permanently deletes a activity by ID.
func pgDeleteActivity(ctx context.Context, tx *sql.Tx, delete *api.ActivityDelete) error {
// Remove row from activity.
diff --git a/store/anomaly.go b/store/anomaly.go
index 97c39c1d1c..a2f7095e5b 100644
--- a/store/anomaly.go
+++ b/store/anomaly.go
@@ -34,7 +34,6 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.An
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
status := api.Normal
@@ -55,9 +54,6 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.An
if err != nil {
return nil, err
}
- if _, err := createAnomaly(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
} else if len(list) == 1 {
// Even if field value does not change, we still patch to update the updated_ts
patch := &anomalyPatch{
@@ -69,16 +65,10 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.An
if err != nil {
return nil, err
}
- if _, err = patchAnomaly(ctx, tx.Tx, patch); err != nil {
- return nil, err
- }
} else {
return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d active anomalies with filter %+v, expect 1", len(list), find)}
}
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -92,7 +82,6 @@ func (s *AnomalyService) FindAnomalyList(ctx context.Context, find *api.AnomalyF
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findAnomalyList(ctx, tx.PTx, find)
@@ -110,19 +99,12 @@ func (s *AnomalyService) ArchiveAnomaly(ctx context.Context, archive *api.Anomal
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgArchiveAnomaly(ctx, tx.PTx, archive); err != nil {
return FormatError(err)
}
- if err := archiveAnomaly(ctx, tx.Tx, archive); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -130,59 +112,6 @@ func (s *AnomalyService) ArchiveAnomaly(ctx context.Context, archive *api.Anomal
return nil
}
-// 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 (
- creator_id,
- updater_id,
- instance_id,
- database_id,
- type,
- payload
- )
- VALUES (?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, type, payload
- `,
- upsert.CreatorID,
- upsert.CreatorID,
- upsert.InstanceID,
- upsert.DatabaseID,
- upsert.Type,
- upsert.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var anomaly api.Anomaly
- databaseID := sql.NullInt32{}
- if err := row.Scan(
- &anomaly.ID,
- &anomaly.CreatorID,
- &anomaly.CreatedTs,
- &anomaly.UpdaterID,
- &anomaly.UpdatedTs,
- &anomaly.InstanceID,
- &databaseID,
- &anomaly.Type,
- &anomaly.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
- if databaseID.Valid {
- value := int(databaseID.Int32)
- anomaly.DatabaseID = &value
- }
- anomaly.Severity = api.AnomalySeverityFromType(anomaly.Type)
-
- return nil, err
-}
-
// pgCreateAnomaly creates a new anomaly.
func pgCreateAnomaly(ctx context.Context, tx *sql.Tx, upsert *api.AnomalyUpsert) (*api.Anomaly, error) {
// Inserts row into database.
@@ -321,57 +250,6 @@ type anomalyPatch struct {
Payload string
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "payload = ?"), append(args, patch.Payload)
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE anomaly
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, type, payload
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var anomaly api.Anomaly
- databaseID := sql.NullInt32{}
- if err := row.Scan(
- &anomaly.ID,
- &anomaly.CreatorID,
- &anomaly.CreatedTs,
- &anomaly.UpdaterID,
- &anomaly.UpdatedTs,
- &anomaly.InstanceID,
- &anomaly.DatabaseID,
- &anomaly.Type,
- &anomaly.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
- if databaseID.Valid {
- value := int(databaseID.Int32)
- anomaly.DatabaseID = &value
- }
- anomaly.Severity = api.AnomalySeverityFromType(anomaly.Type)
-
- return &anomaly, err
-}
-
// pgPatchAnomaly patches an anomaly
func pgPatchAnomaly(ctx context.Context, tx *sql.Tx, patch *anomalyPatch) (*api.Anomaly, error) {
// Build UPDATE clause.
@@ -423,50 +301,6 @@ func pgPatchAnomaly(ctx context.Context, tx *sql.Tx, patch *anomalyPatch) (*api.
return &anomaly, err
}
-// 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")}
- }
- 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, but not both")}
- }
- // Remove row from database.
- if archive.InstanceID != nil {
- result, err := tx.ExecContext(ctx,
- `UPDATE anomaly SET row_status = ? WHERE instance_id = ? AND database_id IS NULL AND type = ?`,
- api.Archived,
- *archive.InstanceID,
- archive.Type,
- )
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &common.Error{Code: common.NotFound, Err: fmt.Errorf("anomaly not found instance: %d type: %s", *archive.InstanceID, archive.Type)}
- }
- } else if archive.DatabaseID != nil {
- result, err := tx.ExecContext(ctx,
- `UPDATE anomaly SET row_status = ? WHERE database_id = ? AND type = ?`,
- api.Archived,
- *archive.DatabaseID,
- archive.Type,
- )
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &common.Error{Code: common.NotFound, Err: fmt.Errorf("anomaly not found database: %d type: %s", *archive.DatabaseID, archive.Type)}
- }
- }
-
- return nil
-}
-
// pgArchiveAnomaly archives an anomaly by ID.
func pgArchiveAnomaly(ctx context.Context, tx *sql.Tx, archive *api.AnomalyArchive) error {
if archive.InstanceID == nil && archive.DatabaseID == nil {
diff --git a/store/backup.go b/store/backup.go
index 660b023fb9..43cea2efed 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -33,20 +33,13 @@ func (s *BackupService) CreateBackup(ctx context.Context, create *api.BackupCrea
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
backup, err := s.pgCreateBackup(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createBackup(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -61,7 +54,6 @@ func (s *BackupService) FindBackup(ctx context.Context, find *api.BackupFind) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findBackupList(ctx, tx.PTx, find)
@@ -83,7 +75,6 @@ func (s *BackupService) FindBackupList(ctx context.Context, find *api.BackupFind
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findBackupList(ctx, tx.PTx, find)
@@ -101,20 +92,13 @@ func (s *BackupService) PatchBackup(ctx context.Context, patch *api.BackupPatch)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
backup, err := s.pgPatchBackup(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchBackup(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -122,62 +106,6 @@ func (s *BackupService) PatchBackup(ctx context.Context, patch *api.BackupPatch)
return backup, nil
}
-// 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 (
- creator_id,
- updater_id,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path
- )
- VALUES (?, ?, ?, ?, 'PENDING_CREATE', ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, status, type, storage_backend, migration_history_version, path, comment
- `,
- create.CreatorID,
- create.CreatorID,
- create.DatabaseID,
- create.Name,
- create.Type,
- create.StorageBackend,
- create.MigrationHistoryVersion,
- create.Path,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var backup api.Backup
- if err := row.Scan(
- &backup.ID,
- &backup.CreatorID,
- &backup.CreatedTs,
- &backup.UpdaterID,
- &backup.UpdatedTs,
- &backup.DatabaseID,
- &backup.Name,
- &backup.Status,
- &backup.Type,
- &backup.StorageBackend,
- &backup.MigrationHistoryVersion,
- &backup.Path,
- &backup.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &backup, nil
-}
-
// pgCreateBackup creates a new backup.
func (s *BackupService) pgCreateBackup(ctx context.Context, tx *sql.Tx, create *api.BackupCreate) (*api.Backup, error) {
// Insert row into backup.
@@ -305,54 +233,6 @@ func (s *BackupService) findBackupList(ctx context.Context, tx *sql.Tx, find *ap
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "status = ?"), append(args, patch.Status)
- set, args = append(set, "comment = ?"), append(args, patch.Comment)
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE backup
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, status, type, storage_backend, migration_history_version, path, comment
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var backup api.Backup
- if err := row.Scan(
- &backup.ID,
- &backup.CreatorID,
- &backup.CreatedTs,
- &backup.UpdaterID,
- &backup.UpdatedTs,
- &backup.DatabaseID,
- &backup.Name,
- &backup.Status,
- &backup.Type,
- &backup.StorageBackend,
- &backup.MigrationHistoryVersion,
- &backup.Path,
- &backup.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
- return &backup, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("backup ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -408,10 +288,9 @@ func (s *BackupService) FindBackupSetting(ctx context.Context, find *api.BackupS
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findBackupSetting(ctx, tx, find)
+ list, err := s.findBackupSetting(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -424,17 +303,17 @@ func (s *BackupService) FindBackupSetting(ctx context.Context, find *api.BackupS
return list[0], nil
}
-func (s *BackupService) findBackupSetting(ctx context.Context, tx *Tx, find *api.BackupSettingFind) (_ []*api.BackupSetting, err error) {
+func (s *BackupService) findBackupSetting(ctx context.Context, tx *sql.Tx, find *api.BackupSettingFind) (_ []*api.BackupSetting, 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)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -510,20 +389,13 @@ func (s *BackupService) UpsertBackupSetting(ctx context.Context, upsert *api.Bac
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
backup, err := s.PgUpsertBackupSettingTx(ctx, tx.PTx, upsert)
if err != nil {
return nil, err
}
- if _, err := s.UpsertBackupSettingTx(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -531,61 +403,6 @@ func (s *BackupService) UpsertBackupSetting(ctx context.Context, upsert *api.Bac
return backup, nil
}
-// 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 (
- creator_id,
- updater_id,
- database_id,
- enabled,
- hour,
- day_of_week,
- hook_url
- )
- VALUES (?, ?, ?, ?, ?, ?, ?)
- ON CONFLICT(database_id) DO UPDATE SET
- enabled = excluded.enabled,
- hour = excluded.hour,
- day_of_week = excluded.day_of_week,
- hook_url = excluded.hook_url
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, enabled, hour, day_of_week , hook_url
- `,
- upsert.UpdaterID,
- upsert.UpdaterID,
- upsert.DatabaseID,
- upsert.Enabled,
- upsert.Hour,
- upsert.DayOfWeek,
- upsert.HookURL,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var backupSetting api.BackupSetting
- if err := row.Scan(
- &backupSetting.ID,
- &backupSetting.CreatorID,
- &backupSetting.CreatedTs,
- &backupSetting.UpdaterID,
- &backupSetting.UpdatedTs,
- &backupSetting.DatabaseID,
- &backupSetting.Enabled,
- &backupSetting.Hour,
- &backupSetting.DayOfWeek,
- &backupSetting.HookURL,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &backupSetting, nil
-}
-
// PgUpsertBackupSettingTx updates an existing backup setting.
func (s *BackupService) PgUpsertBackupSettingTx(ctx context.Context, tx *sql.Tx, upsert *api.BackupSettingUpsert) (*api.BackupSetting, error) {
// Upsert row into backup_setting.
@@ -647,10 +464,9 @@ func (s *BackupService) FindBackupSettingsMatch(ctx context.Context, match *api.
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.PTx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -664,13 +480,13 @@ func (s *BackupService) FindBackupSettingsMatch(ctx context.Context, match *api.
hook_url
FROM backup_setting
WHERE
- enabled = 1
+ enabled = true
AND (
- (hour = ? AND day_of_week = ?)
+ (hour = $1 AND day_of_week = $2)
OR
- (hour = ? AND day_of_week = -1)
+ (hour = $3 AND day_of_week = -1)
OR
- (hour = -1 AND day_of_week = ?)
+ (hour = -1 AND day_of_week = $4)
)
`,
match.Hour, match.DayOfWeek, match.Hour, match.DayOfWeek,
diff --git a/store/bookmark.go b/store/bookmark.go
index 6cef4e868f..9fc56b2bad 100644
--- a/store/bookmark.go
+++ b/store/bookmark.go
@@ -32,20 +32,13 @@ func (s *BookmarkService) CreateBookmark(ctx context.Context, create *api.Bookma
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
bookmark, err := pgCreateBookmark(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createBookmark(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *BookmarkService) FindBookmarkList(ctx context.Context, find *api.Bookma
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findBookmarkList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *BookmarkService) FindBookmark(ctx context.Context, find *api.BookmarkFi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findBookmarkList(ctx, tx.PTx, find)
@@ -100,19 +91,12 @@ func (s *BookmarkService) DeleteBookmark(ctx context.Context, delete *api.Bookma
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteBookmark(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteBookmark(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -120,47 +104,6 @@ func (s *BookmarkService) DeleteBookmark(ctx context.Context, delete *api.Bookma
return nil
}
-// 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 (
- creator_id,
- updater_id,
- name,
- link
- )
- VALUES (?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, name, link
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- create.Link,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var bookmark api.Bookmark
- if err := row.Scan(
- &bookmark.ID,
- &bookmark.CreatorID,
- &bookmark.CreatedTs,
- &bookmark.UpdaterID,
- &bookmark.UpdatedTs,
- &bookmark.Name,
- &bookmark.Link,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &bookmark, nil
-}
-
// pgCreateBookmark creates a new bookmark.
func pgCreateBookmark(ctx context.Context, tx *sql.Tx, create *api.BookmarkCreate) (*api.Bookmark, error) {
// Insert row into database.
@@ -255,22 +198,6 @@ func findBookmarkList(ctx context.Context, tx *sql.Tx, find *api.BookmarkFind) (
return list, nil
}
-// 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 = ?`, delete.ID)
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &common.Error{Code: common.NotFound, Err: fmt.Errorf("bookmark ID not found: %d", delete.ID)}
- }
-
- return nil
-}
-
// pgDeleteBookmark permanently deletes a bookmark by ID.
func pgDeleteBookmark(ctx context.Context, tx *sql.Tx, delete *api.BookmarkDelete) error {
// Remove row from database.
diff --git a/store/column.go b/store/column.go
index f74bd6502a..603f200840 100644
--- a/store/column.go
+++ b/store/column.go
@@ -32,20 +32,13 @@ func (s *ColumnService) CreateColumn(ctx context.Context, create *api.ColumnCrea
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
column, err := s.pgCreateColumn(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createColumn(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *ColumnService) FindColumnList(ctx context.Context, find *api.ColumnFind
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findColumnList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *ColumnService) FindColumn(ctx context.Context, find *api.ColumnFind) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findColumnList(ctx, tx.PTx, find)
@@ -100,20 +91,13 @@ func (s *ColumnService) PatchColumn(ctx context.Context, patch *api.ColumnPatch)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
column, err := s.pgPatchColumn(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchColumn(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -121,83 +105,6 @@ func (s *ColumnService) PatchColumn(ctx context.Context, patch *api.ColumnPatch)
return column, nil
}
-// 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{
- String: *create.Default,
- Valid: true,
- }
- }
-
- // Insert row into column.
- row, err := tx.QueryContext(ctx, `
- INSERT INTO col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `+"`default`,"+`
- nullable,
- type,
- character_set,
- collation,
- comment
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, position, `+"`default`, "+`nullable, type, character_set, collation, comment
- `,
- create.CreatorID,
- create.CreatorID,
- create.DatabaseID,
- create.TableID,
- create.Name,
- create.Position,
- defaultStr,
- create.Nullable,
- create.Type,
- create.CharacterSet,
- create.Collation,
- create.Comment,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var column api.Column
- if err := row.Scan(
- &column.ID,
- &column.CreatorID,
- &column.CreatedTs,
- &column.UpdaterID,
- &column.UpdatedTs,
- &column.DatabaseID,
- &column.TableID,
- &column.Name,
- &column.Position,
- &defaultStr,
- &column.Nullable,
- &column.Type,
- &column.CharacterSet,
- &column.Collation,
- &column.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- if defaultStr.Valid {
- column.Default = &defaultStr.String
- }
-
- return &column, nil
-}
-
// pgCreateColumn creates a new column.
func (s *ColumnService) pgCreateColumn(ctx context.Context, tx *sql.Tx, create *api.ColumnCreate) (*api.Column, error) {
defaultStr := sql.NullString{}
@@ -356,60 +263,6 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *sql.Tx, find *ap
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE col
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, position, `default`, nullable, type, character_set, collation, comment"+`
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var column api.Column
- defaultStr := sql.NullString{}
- if err := row.Scan(
- &column.ID,
- &column.CreatorID,
- &column.CreatedTs,
- &column.UpdaterID,
- &column.UpdatedTs,
- &column.DatabaseID,
- &column.TableID,
- &column.Name,
- &column.Position,
- &defaultStr,
- &column.Nullable,
- &column.Type,
- &column.CharacterSet,
- &column.Collation,
- &column.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- if defaultStr.Valid {
- column.Default = &defaultStr.String
- }
-
- return &column, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("column ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/data_source.go b/store/data_source.go
index 98589c18b2..2269e3b47f 100644
--- a/store/data_source.go
+++ b/store/data_source.go
@@ -32,20 +32,13 @@ func (s *DataSourceService) CreateDataSource(ctx context.Context, create *api.Da
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
dataSource, err := s.pgCreateDataSource(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createDataSource(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -69,7 +62,6 @@ func (s *DataSourceService) FindDataSourceList(ctx context.Context, find *api.Da
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findDataSourceList(ctx, tx.PTx, find)
@@ -87,7 +79,6 @@ func (s *DataSourceService) FindDataSource(ctx context.Context, find *api.DataSo
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findDataSourceList(ctx, tx.PTx, find)
@@ -110,20 +101,13 @@ func (s *DataSourceService) PatchDataSource(ctx context.Context, patch *api.Data
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- dataSource, err := s.pgPatchDataSource(ctx, tx, patch)
+ dataSource, err := s.pgPatchDataSource(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchDataSource(ctx, tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -301,58 +285,8 @@ func (s *DataSourceService) findDataSourceList(ctx context.Context, tx *sql.Tx,
return list, nil
}
-// patchDataSource updates a dataSource by ID. Returns the new state of the dataSource after update.
-func (s *DataSourceService) patchDataSource(ctx context.Context, tx *Tx, patch *api.DataSourcePatch) (*api.DataSource, error) {
- // Build UPDATE clause.
- set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Username; v != nil {
- set, args = append(set, "username = ?"), append(args, *v)
- }
- if v := patch.Password; v != nil {
- set, args = append(set, "password = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.Tx.QueryContext(ctx, `
- UPDATE data_source
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, name, type, username, password
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if 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
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("dataSource ID not found: %d", patch.ID)}
-}
-
// pgPatchDataSource updates a dataSource by ID. Returns the new state of the dataSource after update.
-func (s *DataSourceService) pgPatchDataSource(ctx context.Context, tx *Tx, patch *api.DataSourcePatch) (*api.DataSource, error) {
+func (s *DataSourceService) pgPatchDataSource(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 {
@@ -365,7 +299,7 @@ func (s *DataSourceService) pgPatchDataSource(ctx context.Context, tx *Tx, patch
args = append(args, patch.ID)
// Execute update query with RETURNING.
- row, err := tx.Tx.QueryContext(ctx, fmt.Sprintf(`
+ row, err := tx.QueryContext(ctx, fmt.Sprintf(`
UPDATE data_source
SET `+strings.Join(set, ", ")+`
WHERE id = $%d
diff --git a/store/database.go b/store/database.go
index 3a7f3e6dc8..86fff37fed 100644
--- a/store/database.go
+++ b/store/database.go
@@ -43,20 +43,13 @@ func (s *DatabaseService) CreateDatabase(ctx context.Context, create *api.Databa
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
database, err := s.PgCreateDatabaseTx(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.CreateDatabaseTx(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -64,45 +57,6 @@ func (s *DatabaseService) CreateDatabase(ctx context.Context, create *api.Databa
return database, nil
}
-// 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.createDatabase(ctx, tx, create)
- if err != nil {
- return nil, err
- }
-
- // Enable automatic backup setting based on backup plan policy.
- if backupPlanPolicy.Schedule != api.BackupPlanPolicyScheduleUnset {
- backupSettingUpsert := &api.BackupSettingUpsert{
- UpdaterID: api.SystemBotID,
- DatabaseID: database.ID,
- Enabled: true,
- Hour: rand.Intn(24),
- HookURL: "",
- }
- switch backupPlanPolicy.Schedule {
- case api.BackupPlanPolicyScheduleDaily:
- backupSettingUpsert.DayOfWeek = -1
- case api.BackupPlanPolicyScheduleWeekly:
- backupSettingUpsert.DayOfWeek = rand.Intn(7)
- }
- if _, err := s.backupService.UpsertBackupSettingTx(ctx, tx, backupSettingUpsert); err != nil {
- return nil, err
- }
- }
-
- if err := s.cache.UpsertCache(api.DatabaseCache, database.ID, database); err != nil {
- return nil, err
- }
-
- return 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) {
backupPlanPolicy, err := s.policyService.GetBackupPlanPolicy(ctx, create.EnvironmentID)
@@ -148,7 +102,6 @@ func (s *DatabaseService) FindDatabaseList(ctx context.Context, find *api.Databa
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findDatabaseList(ctx, tx.PTx, find)
@@ -185,7 +138,6 @@ func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findDatabaseList(ctx, tx.PTx, find)
@@ -213,20 +165,13 @@ func (s *DatabaseService) PatchDatabase(ctx context.Context, patch *api.Database
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
database, err := s.pgPatchDatabase(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchDatabase(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -238,76 +183,6 @@ func (s *DatabaseService) PatchDatabase(ctx context.Context, patch *api.Database
return database, nil
}
-// 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 (
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, 'OK', (strftime('%s', 'now')), ?)
- RETURNING
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- `,
- create.CreatorID,
- create.CreatorID,
- create.InstanceID,
- create.ProjectID,
- create.Name,
- create.CharacterSet,
- create.Collation,
- create.SchemaVersion,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var database api.Database
- if err := row.Scan(
- &database.ID,
- &database.CreatorID,
- &database.CreatedTs,
- &database.UpdaterID,
- &database.UpdatedTs,
- &database.InstanceID,
- &database.ProjectID,
- &database.Name,
- &database.CharacterSet,
- &database.Collation,
- &database.SyncStatus,
- &database.LastSuccessfulSyncTs,
- &database.SchemaVersion,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &database, nil
-}
-
// pgCreateDatabase creates a new database.
func (s *DatabaseService) pgCreateDatabase(ctx context.Context, tx *sql.Tx, create *api.DatabaseCreate) (*api.Database, error) {
// Insert row into database.
@@ -457,86 +332,6 @@ func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *sql.Tx, find
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.ProjectID; v != nil {
- set, args = append(set, "project_id = ?"), append(args, *v)
- }
- if v := patch.SourceBackupID; v != nil {
- set, args = append(set, "source_backup_id = ?"), append(args, *v)
- }
- if v := patch.SchemaVersion; v != nil {
- set, args = append(set, "schema_version = ?"), append(args, *v)
- }
- if v := patch.SyncStatus; v != nil {
- set, args = append(set, "sync_status = ?"), append(args, api.SyncStatus(*v))
- }
- if v := patch.LastSuccessfulSyncTs; v != nil {
- set, args = append(set, "last_successful_sync_ts = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE db
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- instance_id,
- project_id,
- source_backup_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var database api.Database
- var nullSourceBackupID sql.NullInt64
- if err := row.Scan(
- &database.ID,
- &database.CreatorID,
- &database.CreatedTs,
- &database.UpdaterID,
- &database.UpdatedTs,
- &database.InstanceID,
- &database.ProjectID,
- &nullSourceBackupID,
- &database.Name,
- &database.CharacterSet,
- &database.Collation,
- &database.SyncStatus,
- &database.LastSuccessfulSyncTs,
- &database.SchemaVersion,
- ); err != nil {
- return nil, FormatError(err)
- }
- if nullSourceBackupID.Valid {
- database.SourceBackupID = int(nullSourceBackupID.Int64)
- }
- return &database, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("database ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/deploy.go b/store/deploy.go
index a34749b543..a6bceae513 100644
--- a/store/deploy.go
+++ b/store/deploy.go
@@ -32,7 +32,6 @@ func (s *DeploymentConfigService) FindDeploymentConfig(ctx context.Context, find
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
// Build WHERE clause.
@@ -107,20 +106,13 @@ func (s *DeploymentConfigService) UpsertDeploymentConfig(ctx context.Context, up
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
cfg, err := s.pgUpsertDeploymentConfig(ctx, tx.PTx, upsert)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.upsertDeploymentConfig(ctx, tx.Tx, upsert); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -128,52 +120,6 @@ func (s *DeploymentConfigService) UpsertDeploymentConfig(ctx context.Context, up
return cfg, nil
}
-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,
- updater_id,
- project_id,
- name,
- config
- )
- VALUES (?, ?, ?, ?, ?)
- ON CONFLICT(project_id) DO UPDATE SET
- creator_id = excluded.creator_id,
- updater_id = excluded.updater_id,
- name = excluded.name,
- config = excluded.config
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, name, config
- `,
- upsert.UpdaterID,
- upsert.UpdaterID,
- upsert.ProjectID,
- upsert.Name,
- upsert.Payload,
- )
-
- if err != nil {
- return nil, err
- }
- defer row.Close()
-
- row.Next()
- var cfg api.DeploymentConfig
- if err := row.Scan(
- &cfg.ID,
- &cfg.CreatorID,
- &cfg.CreatedTs,
- &cfg.UpdaterID,
- &cfg.UpdatedTs,
- &cfg.ProjectID,
- &cfg.Name,
- &cfg.Payload,
- ); err != nil {
- return nil, err
- }
- return &cfg, nil
-}
-
func (s *DeploymentConfigService) pgUpsertDeploymentConfig(ctx context.Context, tx *sql.Tx, upsert *api.DeploymentConfigUpsert) (*api.DeploymentConfig, error) {
row, err := tx.QueryContext(ctx, `
INSERT INTO deployment_config (
diff --git a/store/environment.go b/store/environment.go
index 77005a495c..430e6477d8 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -34,20 +34,13 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, create *api.
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
environment, err := s.pgCreateEnvironment(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createEnvironment(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -65,7 +58,6 @@ func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findEnvironmentList(ctx, tx.PTx, find)
@@ -102,7 +94,6 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findEnvironmentList(ctx, tx.PTx, find)
@@ -128,20 +119,13 @@ func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.En
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
environment, err := s.pgPatchEnvironment(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchEnvironment(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -153,69 +137,6 @@ func (s *EnvironmentService) PatchEnvironment(ctx context.Context, patch *api.En
return environment, nil
}
-// createEnvironment creates a new environment.
-func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*api.Environment, error) {
- // The order is the MAX(order) + 1
- row1, err1 := tx.QueryContext(ctx, `
- SELECT `+"`order`"+`
- FROM environment
- ORDER BY `+"`order`"+` DESC
- LIMIT 1
- `)
-
- if err1 != nil {
- return nil, FormatError(err1)
- }
- defer row1.Close()
-
- row1.Next()
- var order int
- if err1 := row1.Scan(
- &order,
- ); err1 != nil {
- return nil, FormatError(err1)
- }
-
- // Insert row into database.
- row2, err2 := tx.QueryContext(ctx, `
- INSERT INTO environment (
- creator_id,
- updater_id,
- name,
- `+"`order`"+`
- )
- VALUES (?, ?, ?, ?)
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`order`"+`
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- order+1,
- )
-
- if err2 != nil {
- return nil, FormatError(err2)
- }
- defer row2.Close()
-
- row2.Next()
- var environment api.Environment
- if err := row2.Scan(
- &environment.ID,
- &environment.RowStatus,
- &environment.CreatorID,
- &environment.CreatedTs,
- &environment.UpdaterID,
- &environment.UpdatedTs,
- &environment.Name,
- &environment.Order,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &environment, nil
-}
-
// createEnvironment creates a new environment.
func (s *EnvironmentService) pgCreateEnvironment(ctx context.Context, tx *sql.Tx, create *api.EnvironmentCreate) (*api.Environment, error) {
// The order is the MAX(order) + 1
@@ -339,56 +260,6 @@ func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Tx
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.RowStatus; v != nil {
- set, args = append(set, "row_status = ?"), append(args, api.RowStatus(*v))
- }
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.Order; v != nil {
- set, args = append(set, "`order` = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE environment
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`order`"+`
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var environment api.Environment
- if err := row.Scan(
- &environment.ID,
- &environment.RowStatus,
- &environment.CreatorID,
- &environment.CreatedTs,
- &environment.UpdaterID,
- &environment.UpdatedTs,
- &environment.Name,
- &environment.Order,
- ); err != nil {
- return nil, FormatError(err)
- }
- return &environment, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/inbox.go b/store/inbox.go
index 13457b8bdc..9aca653a40 100644
--- a/store/inbox.go
+++ b/store/inbox.go
@@ -34,20 +34,13 @@ func (s *InboxService) CreateInbox(ctx context.Context, create *api.InboxCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
inbox, err := s.pgCreateInbox(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createInbox(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -61,7 +54,6 @@ func (s *InboxService) FindInboxList(ctx context.Context, find *api.InboxFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findInboxList(ctx, tx.PTx, find)
@@ -79,7 +71,6 @@ func (s *InboxService) FindInbox(ctx context.Context, find *api.InboxFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findInboxList(ctx, tx.PTx, find)
@@ -102,20 +93,13 @@ func (s *InboxService) PatchInbox(ctx context.Context, patch *api.InboxPatch) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
inbox, err := s.pgPatchInbox(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchInbox(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -129,7 +113,6 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
row, err := tx.PTx.QueryContext(ctx, `
@@ -153,7 +136,7 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*
}
if inboxSummary.HasUnread {
- row2, err := tx.Tx.QueryContext(ctx, `
+ row2, err := tx.PTx.QueryContext(ctx, `
SELECT EXISTS (SELECT 1 FROM inbox, activity WHERE inbox.receiver_id = $1 AND inbox.status = 'UNREAD' AND inbox.activity_id = activity.id AND activity.level = 'ERROR')
`,
principalID,
@@ -177,50 +160,6 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*
return &inboxSummary, nil
}
-// 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 (
- receiver_id,
- activity_id,
- status
- )
- VALUES (?, ?, 'UNREAD')
- RETURNING id, receiver_id, activity_id, status
- `,
- create.ReceiverID,
- create.ActivityID,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var inbox api.Inbox
- var activityID int
- if err := row.Scan(
- &inbox.ID,
- &inbox.ReceiverID,
- &activityID,
- &inbox.Status,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- activityFind := &api.ActivityFind{
- ID: &activityID,
- }
- inbox.Activity, err = s.activityService.FindActivity(ctx, activityFind)
- if err != nil {
- return nil, FormatError(err)
- }
-
- return &inbox, nil
-}
-
// pgCreateInbox creates a new inbox.
func (s *InboxService) pgCreateInbox(ctx context.Context, tx *sql.Tx, create *api.InboxCreate) (*api.Inbox, error) {
// Insert row into database.
@@ -336,52 +275,6 @@ func findInboxList(ctx context.Context, tx *sql.Tx, find *api.InboxFind) (_ []*a
return list, nil
}
-// 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 = ?"}, []interface{}{patch.Status}
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE inbox
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, receiver_id, activity_id, `+"status"+`
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var inbox api.Inbox
- var activityID int
- if err := row.Scan(
- &inbox.ID,
- &inbox.ReceiverID,
- &activityID,
- &inbox.Status,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- activityFind := &api.ActivityFind{
- ID: &activityID,
- }
- inbox.Activity, err = s.activityService.FindActivity(ctx, activityFind)
- if err != nil {
- return nil, FormatError(err)
- }
-
- return &inbox, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("inbox ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/instance.go b/store/instance.go
index b2d847d4d2..2c4b879aa1 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -37,16 +37,12 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.Instan
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
instance, err := pgCreateInstance(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createInstance(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
// Create * database
databaseCreate := &api.DatabaseCreate{
@@ -62,9 +58,6 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.Instan
if err != nil {
return nil, err
}
- if _, err := s.databaseService.CreateDatabaseTx(ctx, tx.Tx, databaseCreate); err != nil {
- return nil, err
- }
// Create admin data source
adminDataSourceCreate := &api.DataSourceCreate{
@@ -79,13 +72,7 @@ func (s *InstanceService) CreateInstance(ctx context.Context, create *api.Instan
if _, err = s.dataSourceService.PgCreateDataSourceTx(ctx, tx.PTx, adminDataSourceCreate); err != nil {
return nil, err
}
- if _, err = s.dataSourceService.CreateDataSourceTx(ctx, tx.Tx, adminDataSourceCreate); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -103,7 +90,6 @@ func (s *InstanceService) FindInstanceList(ctx context.Context, find *api.Instan
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findInstanceList(ctx, tx.PTx, find)
@@ -128,7 +114,6 @@ func (s *InstanceService) CountInstance(ctx context.Context, find *api.InstanceF
if err != nil {
return 0, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
where, args := findInstanceQuery(find)
@@ -172,7 +157,6 @@ func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findInstanceList(ctx, tx.PTx, find)
@@ -198,20 +182,13 @@ func (s *InstanceService) PatchInstance(ctx context.Context, patch *api.Instance
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
instance, err := pgPatchInstance(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchInstance(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -223,61 +200,6 @@ func (s *InstanceService) PatchInstance(ctx context.Context, patch *api.Instance
return instance, nil
}
-// 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 (
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- external_link,
- host,
- port
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, environment_id, name, engine, engine_version, external_link, host, port
- `,
- create.CreatorID,
- create.CreatorID,
- create.EnvironmentID,
- create.Name,
- create.Engine,
- create.ExternalLink,
- create.Host,
- create.Port,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var instance api.Instance
- if err := row.Scan(
- &instance.ID,
- &instance.RowStatus,
- &instance.CreatorID,
- &instance.CreatedTs,
- &instance.UpdaterID,
- &instance.UpdatedTs,
- &instance.EnvironmentID,
- &instance.Name,
- &instance.Engine,
- &instance.EngineVersion,
- &instance.ExternalLink,
- &instance.Host,
- &instance.Port,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &instance, nil
-}
-
// pgCreateInstance creates a new instance.
func pgCreateInstance(ctx context.Context, tx *sql.Tx, create *api.InstanceCreate) (*api.Instance, error) {
// Insert row into database.
@@ -391,71 +313,6 @@ func findInstanceList(ctx context.Context, tx *sql.Tx, find *api.InstanceFind) (
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.RowStatus; v != nil {
- set, args = append(set, "row_status = ?"), append(args, api.RowStatus(*v))
- }
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.EngineVersion; v != nil {
- set, args = append(set, "engine_version = ?"), append(args, *v)
- }
- if v := patch.ExternalLink; v != nil {
- set, args = append(set, "external_link = ?"), append(args, *v)
- }
- if v := patch.Host; v != nil {
- set, args = append(set, "host = ?"), append(args, *v)
- }
- if v := patch.Port; v != nil {
- set, args = append(set, "port = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE instance
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, environment_id, name, engine, engine_version, external_link, host, port
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var instance api.Instance
- if err := row.Scan(
- &instance.ID,
- &instance.RowStatus,
- &instance.CreatorID,
- &instance.CreatedTs,
- &instance.UpdaterID,
- &instance.UpdatedTs,
- &instance.EnvironmentID,
- &instance.Name,
- &instance.Engine,
- &instance.EngineVersion,
- &instance.ExternalLink,
- &instance.Host,
- &instance.Port,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &instance, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("instance ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/instance_user.go b/store/instance_user.go
index 75fd6facf5..3edc13626d 100644
--- a/store/instance_user.go
+++ b/store/instance_user.go
@@ -30,20 +30,13 @@ func (s *InstanceUserService) UpsertInstanceUser(ctx context.Context, upsert *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
instanceUser, err := pgUpsertInstanceUser(ctx, tx.PTx, upsert)
if err != nil {
return nil, err
}
- if _, err := upsertInstanceUser(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -57,7 +50,6 @@ func (s *InstanceUserService) FindInstanceUserList(ctx context.Context, find *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findInstanceUserList(ctx, tx.PTx, find)
@@ -74,19 +66,12 @@ func (s *InstanceUserService) DeleteInstanceUser(ctx context.Context, delete *ap
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteInstanceUser(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteInstanceUser(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -94,49 +79,6 @@ func (s *InstanceUserService) DeleteInstanceUser(ctx context.Context, delete *ap
return nil
}
-// 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 (
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
- VALUES (?, ?, ?, ?, ?)
- ON CONFLICT (instance_id, name) DO UPDATE SET
- updater_id = excluded.updater_id,
- grant = excluded.grant
- RETURNING id, instance_id, name, grant
- `,
- upsert.CreatorID,
- upsert.CreatorID,
- upsert.InstanceID,
- upsert.Name,
- upsert.Grant,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var instanceUser api.InstanceUser
- if err := row.Scan(
- &instanceUser.ID,
- &instanceUser.InstanceID,
- &instanceUser.Name,
- &instanceUser.Grant,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return nil, err
-}
-
// pgUpsertInstanceUser upserts a new instanceUser.
func pgUpsertInstanceUser(ctx context.Context, tx *sql.Tx, upsert *api.InstanceUserUpsert) (*api.InstanceUser, error) {
// Upsert row into database.
@@ -224,15 +166,6 @@ func findInstanceUserList(ctx context.Context, tx *sql.Tx, find *api.InstanceUse
return list, nil
}
-// 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 = ?`, delete.ID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteInstanceUser permanently deletes a instance user by ID.
func pgDeleteInstanceUser(ctx context.Context, tx *sql.Tx, delete *api.InstanceUserDelete) error {
// Remove row from database.
diff --git a/store/issue.go b/store/issue.go
index b36e8a8faa..e1b3e83cf9 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -35,20 +35,13 @@ func (s *IssueService) CreateIssue(ctx context.Context, create *api.IssueCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
issue, err := s.pgCreateIssue(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createIssue(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -66,7 +59,6 @@ func (s *IssueService) FindIssueList(ctx context.Context, find *api.IssueFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findIssueList(ctx, tx.PTx, find)
@@ -92,7 +84,6 @@ func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findIssueList(ctx, tx.PTx, find)
@@ -118,20 +109,13 @@ func (s *IssueService) PatchIssue(ctx context.Context, patch *api.IssuePatch) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
issue, err := s.pgPatchIssue(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchIssue(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -143,63 +127,6 @@ func (s *IssueService) PatchIssue(ctx context.Context, patch *api.IssuePatch) (*
return issue, nil
}
-// 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,
- updater_id,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id,
- payload
- )
- VALUES (?, ?, ?, ?, ?, 'OPEN', ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, status, type, description, assignee_id, payload
- `,
- create.CreatorID,
- create.CreatorID,
- create.ProjectID,
- create.PipelineID,
- create.Name,
- create.Type,
- create.Description,
- create.AssigneeID,
- create.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var issue api.Issue
- if err := row.Scan(
- &issue.ID,
- &issue.CreatorID,
- &issue.CreatedTs,
- &issue.UpdaterID,
- &issue.UpdatedTs,
- &issue.ProjectID,
- &issue.PipelineID,
- &issue.Name,
- &issue.Status,
- &issue.Type,
- &issue.Description,
- &issue.AssigneeID,
- &issue.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &issue, nil
-}
-
// pgCreateIssue creates a new issue.
func (s *IssueService) pgCreateIssue(ctx context.Context, tx *sql.Tx, create *api.IssueCreate) (*api.Issue, error) {
row, err := tx.QueryContext(ctx, `
@@ -342,72 +269,6 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *sql.Tx, find *api.
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.Status; v != nil {
- set, args = append(set, "status = ?"), append(args, api.IssueStatus(*v))
- }
- if v := patch.Description; v != nil {
- set, args = append(set, "description = ?"), append(args, *v)
- }
- if v := patch.AssigneeID; v != nil {
- set, args = append(set, "assignee_id = ?"), append(args, *v)
- }
- if v := patch.Payload; v != nil {
- payload, err := json.Marshal(*patch.Payload)
- if err != nil {
- return nil, FormatError(err)
- }
- set, args = append(set, "`payload` = ?"), append(args, payload)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE issue
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, pipeline_id, name, status, type, description, assignee_id, payload
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var issue api.Issue
- if err := row.Scan(
- &issue.ID,
- &issue.CreatorID,
- &issue.CreatedTs,
- &issue.UpdaterID,
- &issue.UpdatedTs,
- &issue.ProjectID,
- &issue.PipelineID,
- &issue.Name,
- &issue.Status,
- &issue.Type,
- &issue.Description,
- &issue.AssigneeID,
- &issue.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &issue, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("unable to find issue ID to update: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/issue_subscriber.go b/store/issue_subscriber.go
index 6423fe5c13..23f4fb6d2a 100644
--- a/store/issue_subscriber.go
+++ b/store/issue_subscriber.go
@@ -31,20 +31,13 @@ func (s *IssueSubscriberService) CreateIssueSubscriber(ctx context.Context, crea
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
issueSubscriber, err := pgCreateIssueSubscriber(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createIssueSubscriber(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -58,7 +51,6 @@ func (s *IssueSubscriberService) FindIssueSubscriberList(ctx context.Context, fi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findIssueSubscriberList(ctx, tx.PTx, find)
@@ -75,19 +67,12 @@ func (s *IssueSubscriberService) DeleteIssueSubscriber(ctx context.Context, dele
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteIssueSubscriber(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteIssueSubscriber(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -95,38 +80,6 @@ func (s *IssueSubscriberService) DeleteIssueSubscriber(ctx context.Context, dele
return nil
}
-// 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 (
- issue_id,
- subscriber_id
- )
- VALUES (?, ?)
- RETURNING issue_id, subscriber_id
- `,
- create.IssueID,
- create.SubscriberID,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var issueSubscriber api.IssueSubscriber
- if err := row.Scan(
- &issueSubscriber.IssueID,
- &issueSubscriber.SubscriberID,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &issueSubscriber, nil
-}
-
// pgCreateIssueSubscriber creates a new issueSubscriber.
func pgCreateIssueSubscriber(ctx context.Context, tx *sql.Tx, create *api.IssueSubscriberCreate) (*api.IssueSubscriber, error) {
// Insert row into database.
@@ -202,15 +155,6 @@ func findIssueSubscriberList(ctx context.Context, tx *sql.Tx, find *api.IssueSub
return list, nil
}
-// 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 = ? AND subscriber_id = ?`, delete.IssueID, delete.SubscriberID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteIssueSubscriber permanently deletes a issueSubscriber by ID.
func pgDeleteIssueSubscriber(ctx context.Context, tx *sql.Tx, delete *api.IssueSubscriberDelete) error {
// Remove row from database.
diff --git a/store/label.go b/store/label.go
index 5ed05df8a9..96a0418138 100644
--- a/store/label.go
+++ b/store/label.go
@@ -32,7 +32,6 @@ func (s *LabelService) FindLabelKeyList(ctx context.Context, find *api.LabelKeyF
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
ret, err := s.findLabelKeyList(ctx, tx.PTx, find)
@@ -40,9 +39,6 @@ func (s *LabelService) FindLabelKeyList(ctx context.Context, find *api.LabelKeyF
return nil, err
}
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -145,7 +141,6 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPat
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
ret, err := s.findLabelKeyList(ctx, tx.PTx, &api.LabelKeyFind{})
@@ -193,14 +188,8 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPat
if err := s.pgUpsertLabelValue(ctx, tx.PTx, upsert); err != nil {
return nil, err
}
- if err := s.upsertLabelValue(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
}
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -209,33 +198,6 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPat
return labelKey, nil
}
-func (s *LabelService) upsertLabelValue(ctx context.Context, tx *sql.Tx, upsert labelValueUpsert) error {
- // Upsert row into label_value
- if _, err := tx.ExecContext(ctx, `
- INSERT INTO label_value (
- row_status,
- creator_id,
- updater_id,
- key,
- value
- )
- VALUES (?, ?, ?, ?, ?)
- ON CONFLICT(key, value) DO UPDATE SET
- row_status = excluded.row_status,
- creator_id = excluded.creator_id,
- updater_id = excluded.updater_id
- `,
- upsert.rowStatus,
- upsert.updaterID,
- upsert.updaterID,
- upsert.key,
- upsert.value,
- ); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
func (s *LabelService) pgUpsertLabelValue(ctx context.Context, tx *sql.Tx, upsert labelValueUpsert) error {
// Upsert row into label_value
if _, err := tx.ExecContext(ctx, `
@@ -269,7 +231,6 @@ func (s *LabelService) FindDatabaseLabelList(ctx context.Context, find *api.Data
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
databaseLabelList, err := s.findDatabaseLabels(ctx, tx.PTx, find)
@@ -277,9 +238,6 @@ func (s *LabelService) FindDatabaseLabelList(ctx context.Context, find *api.Data
return nil, err
}
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -346,57 +304,6 @@ func (s *LabelService) findDatabaseLabels(ctx context.Context, tx *sql.Tx, find
return ret, nil
}
-func (s *LabelService) upsertDatabaseLabel(ctx context.Context, tx *sql.Tx, upsert *api.DatabaseLabelUpsert) (*api.DatabaseLabel, error) {
- // Upsert row into db_label
- row, err := tx.QueryContext(ctx, `
- INSERT INTO db_label (
- row_status,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
- VALUES (?, ?, ?, ?, ?, ?)
- ON CONFLICT(database_id, key) DO UPDATE SET
- row_status = excluded.row_status,
- creator_id = excluded.creator_id,
- updater_id = excluded.updater_id,
- value = excluded.value
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, database_id, key, value
- `,
- upsert.RowStatus,
- upsert.UpdaterID,
- upsert.UpdaterID,
- upsert.DatabaseID,
- upsert.Key,
- upsert.Value,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var databaseLabel api.DatabaseLabel
- if err := row.Scan(
- &databaseLabel.ID,
- &databaseLabel.RowStatus,
- &databaseLabel.CreatorID,
- &databaseLabel.CreatedTs,
- &databaseLabel.UpdaterID,
- &databaseLabel.UpdatedTs,
- &databaseLabel.DatabaseID,
- &databaseLabel.Key,
- &databaseLabel.Value,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &databaseLabel, nil
-}
-
func (s *LabelService) pgUpsertDatabaseLabel(ctx context.Context, tx *sql.Tx, upsert *api.DatabaseLabelUpsert) (*api.DatabaseLabel, error) {
// Upsert row into db_label
row, err := tx.QueryContext(ctx, `
@@ -461,7 +368,6 @@ func (s *LabelService) SetDatabaseLabelList(ctx context.Context, labelList []*ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
var ret []*api.DatabaseLabel
@@ -482,9 +388,6 @@ func (s *LabelService) SetDatabaseLabelList(ctx context.Context, labelList []*ap
if _, err := s.pgUpsertDatabaseLabel(ctx, tx.PTx, upsert); err != nil {
return nil, err
}
- if _, err := s.upsertDatabaseLabel(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
}
for _, label := range labelList {
@@ -504,15 +407,9 @@ func (s *LabelService) SetDatabaseLabelList(ctx context.Context, labelList []*ap
if err != nil {
return nil, err
}
- if _, err := s.upsertDatabaseLabel(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
ret = append(ret, label)
}
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
diff --git a/store/member.go b/store/member.go
index c14d24b67b..c5451cb85f 100644
--- a/store/member.go
+++ b/store/member.go
@@ -34,20 +34,13 @@ func (s *MemberService) CreateMember(ctx context.Context, create *api.MemberCrea
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
member, err := pgCreateMember(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createMember(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -65,7 +58,6 @@ func (s *MemberService) FindMemberList(ctx context.Context, find *api.MemberFind
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findMemberList(ctx, tx.PTx, find)
@@ -102,7 +94,6 @@ func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findMemberList(ctx, tx.PTx, find)
@@ -128,20 +119,13 @@ func (s *MemberService) PatchMember(ctx context.Context, patch *api.MemberPatch)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
member, err := pgPatchMember(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchMember(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -153,51 +137,6 @@ func (s *MemberService) PatchMember(ctx context.Context, patch *api.MemberPatch)
return member, nil
}
-// 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 (
- creator_id,
- updater_id,
- status,
- role,
- principal_id
- )
- VALUES (?, ?, ?, ?, ?)
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, status, role, principal_id
- `,
- create.CreatorID,
- create.CreatorID,
- create.Status,
- create.Role,
- create.PrincipalID,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var member api.Member
- if err := row.Scan(
- &member.ID,
- &member.RowStatus,
- &member.CreatorID,
- &member.CreatedTs,
- &member.UpdaterID,
- &member.UpdatedTs,
- &member.Status,
- &member.Role,
- &member.PrincipalID,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &member, nil
-}
-
// pgCreateMember creates a new member.
func pgCreateMember(ctx context.Context, tx *sql.Tx, create *api.MemberCreate) (*api.Member, error) {
// Insert row into database.
@@ -303,55 +242,6 @@ func findMemberList(ctx context.Context, tx *sql.Tx, find *api.MemberFind) (_ []
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.RowStatus; v != nil {
- set, args = append(set, "row_status = ?"), append(args, api.RowStatus(*v))
- }
- if v := patch.Role; v != nil {
- set, args = append(set, "role = ?"), append(args, api.Role(*v))
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE member
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, status, role, principal_id
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var member api.Member
- if err := row.Scan(
- &member.ID,
- &member.RowStatus,
- &member.CreatorID,
- &member.CreatedTs,
- &member.UpdaterID,
- &member.UpdatedTs,
- &member.Status,
- &member.Role,
- &member.PrincipalID,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &member, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("member ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index e7278b5bc4..68892f0ad7 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -1,1430 +1 @@
PRAGMA user_version = 10001;
-PRAGMA foreign_keys = ON;
-
--- principal
-CREATE TABLE principal (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('principal', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_principal_modification_time`
-AFTER
-UPDATE
- ON `principal` FOR EACH ROW BEGIN
-UPDATE
- `principal`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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',
- ''
- );
-
--- Setting
-CREATE TABLE setting (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- name TEXT NOT NULL UNIQUE,
- value TEXT NOT NULL,
- description TEXT NOT NULL DEFAULT ''
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('setting', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_setting_modification_time`
-AFTER
-UPDATE
- ON `setting` FOR EACH ROW BEGIN
-UPDATE
- `setting`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('member', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_member_modification_time`
-AFTER
-UPDATE
- ON `member` FOR EACH ROW BEGIN
-UPDATE
- `member`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Environment
-CREATE TABLE environment (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- name TEXT NOT NULL UNIQUE,
- `order` INTEGER NOT NULL
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('environment', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_environment_modification_time`
-AFTER
-UPDATE
- ON `environment` FOR EACH ROW BEGIN
-UPDATE
- `environment`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('policy', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_policy_modification_time`
-AFTER
-UPDATE
- ON `policy` FOR EACH ROW BEGIN
-UPDATE
- `policy`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Project
-CREATE TABLE project (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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
-);
-
-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',
- ''
- );
-
-UPDATE
- sqlite_sequence
-SET
- seq = 100
-WHERE
- name = 'project';
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_project_modification_time`
-AFTER
-UPDATE
- ON `project` FOR EACH ROW BEGIN
-UPDATE
- `project`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Project member
-CREATE TABLE project_member (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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)
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('project_member', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_project_member_modification_time`
-AFTER
-UPDATE
- ON `project_member` FOR EACH ROW BEGIN
-UPDATE
- `project_member`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Project Hook
-CREATE TABLE project_webhook (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('project_webhook', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_project_webhook_modification_time`
-AFTER
-UPDATE
- ON `project_webhook` FOR EACH ROW BEGIN
-UPDATE
- `project_webhook`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Instance
-CREATE TABLE instance (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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 ''
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('instance', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_instance_modification_time`
-AFTER
-UPDATE
- ON `instance` FOR EACH ROW BEGIN
-UPDATE
- `instance`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Instance user stores the users for a particular instance
-CREATE TABLE instance_user (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- instance_id INTEGER NOT NULL REFERENCES instance (id),
- name TEXT NOT NULL,
- grant TEXT NOT NULL,
- UNIQUE(instance_id, name)
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('instance_user', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_instance_user_modification_time`
-AFTER
-UPDATE
- ON `instance_user` FOR EACH ROW BEGIN
-UPDATE
- `instance_user`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- db stores the databases for a particular instance
--- data is synced periodically from the instance
-CREATE TABLE db (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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 REFERENCES backup (id) ON DELETE SET NULL,
- -- 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('db', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_db_modification_time`
-AFTER
-UPDATE
- ON `db` FOR EACH ROW BEGIN
-UPDATE
- `db`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- tbl stores the table for a particular database
--- data is synced periodically from the instance
-CREATE TABLE tbl (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('tbl', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_tbl_modification_time`
-AFTER
-UPDATE
- ON `tbl` FOR EACH ROW BEGIN
-UPDATE
- `tbl`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- col stores the column for a particular table from a particular database
--- data is synced periodically from the instance
-CREATE TABLE col (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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 INTEGER 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('col', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_col_modification_time`
-AFTER
-UPDATE
- ON `col` FOR EACH ROW BEGIN
-UPDATE
- `col`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- idx stores the index for a particular table from a particular database
--- data is synced periodically from the instance
-CREATE TABLE idx (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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` INTEGER NOT NULL,
- visible INTEGER 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('idx', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_idx_modification_time`
-AFTER
-UPDATE
- ON `idx` FOR EACH ROW BEGIN
-UPDATE
- `idx`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- vw stores the view for a particular database
--- data is synced periodically from the instance
-CREATE TABLE vw (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('vw', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_vw_modification_time`
-AFTER
-UPDATE
- ON `vw` FOR EACH ROW BEGIN
-UPDATE
- `vw`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- data_source table stores the data source for a particular database
-CREATE TABLE data_source (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('data_source', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_data_source_modification_time`
-AFTER
-UPDATE
- ON `data_source` FOR EACH ROW BEGIN
-UPDATE
- `data_source`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- backup stores the backups for a particular database.
-CREATE TABLE backup (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('backup', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_backup_modification_time`
-AFTER
-UPDATE
- ON `backup` FOR EACH ROW BEGIN
-UPDATE
- `backup`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- database_id INTEGER NOT NULL UNIQUE REFERENCES db (id),
- -- allowed enabled values are 0, 1.
- enabled INTEGER 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('backup_setting', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_backup_setting_modification_time`
-AFTER
-UPDATE
- ON `backup_setting` FOR EACH ROW BEGIN
-UPDATE
- `backup_setting`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
------------------------
--- Pipeline related BEGIN
--- pipeline table
-CREATE TABLE pipeline (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- name TEXT NOT NULL,
- -- allowed status are 'OPEN', 'DONE', 'CANCELED'.
- status TEXT NOT NULL
-);
-
-CREATE INDEX idx_pipeline_status ON pipeline(status);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('pipeline', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_pipeline_modification_time`
-AFTER
-UPDATE
- ON `pipeline` FOR EACH ROW BEGIN
-UPDATE
- `pipeline`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- stage table stores the stage for the pipeline
-CREATE TABLE stage (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('stage', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_stage_modification_time`
-AFTER
-UPDATE
- ON `stage` FOR EACH ROW BEGIN
-UPDATE
- `stage`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- task table stores the task for the stage
-CREATE TABLE task (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('task', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_task_modification_time`
-AFTER
-UPDATE
- ON `task` FOR EACH ROW BEGIN
-UPDATE
- `task`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- task run table stores the task run
-CREATE TABLE task_run (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('task_run', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_task_run_modification_time`
-AFTER
-UPDATE
- ON `task_run` FOR EACH ROW BEGIN
-UPDATE
- `task_run`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- task check run table stores the task check run
-CREATE TABLE task_check_run (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('task_check_run', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_task_check_run_modification_time`
-AFTER
-UPDATE
- ON `task_check_run` FOR EACH ROW BEGIN
-UPDATE
- `task_check_run`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Pipeline related END
------------------------
--- issue
--- Each issue links a pipeline driving the resolution.
-CREATE TABLE issue (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('issue', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_issue_modification_time`
-AFTER
-UPDATE
- ON `issue` FOR EACH ROW BEGIN
-UPDATE
- `issue`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('activity', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_activity_modification_time`
-AFTER
-UPDATE
- ON `activity` FOR EACH ROW BEGIN
-UPDATE
- `activity`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- 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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('inbox', 100);
-
--- bookmark table stores the bookmark for the user
-CREATE TABLE bookmark (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- name TEXT NOT NULL,
- link TEXT NOT NULL,
- UNIQUE(creator_id, link)
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('bookmark', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_bookmark_modification_time`
-AFTER
-UPDATE
- ON `bookmark` FOR EACH ROW BEGIN
-UPDATE
- `bookmark`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- vcs table stores the version control provider config
-CREATE TABLE vcs (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('vcs', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_vcs_modification_time`
-AFTER
-UPDATE
- ON `vcs` FOR EACH ROW BEGIN
-UPDATE
- `vcs`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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
-);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('repository', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_repository_modification_time`
-AFTER
-UPDATE
- ON `repository` FOR EACH ROW BEGIN
-UPDATE
- `repository`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- 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 INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('anomaly', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_anomaly_modification_time`
-AFTER
-UPDATE
- ON `anomaly` FOR EACH ROW BEGIN
-UPDATE
- `anomaly`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Label
--- label_key stores available label keys at workspace level.
-CREATE TABLE label_key (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('label_key', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_label_key_modification_time`
-AFTER
-UPDATE
- ON `label_key` FOR EACH ROW BEGIN
-UPDATE
- `label_key`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- label_value stores available label key values at workspace level.
-CREATE TABLE label_value (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('label_value', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_label_value_modification_time`
-AFTER
-UPDATE
- ON `label_value` FOR EACH ROW BEGIN
-UPDATE
- `label_value`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- db_label stores labels asscociated with databases.
-CREATE TABLE db_label (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('db_label', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_db_label_modification_time`
-AFTER
-UPDATE
- ON `db_label` FOR EACH ROW BEGIN
-UPDATE
- `db_label`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- Deployment Configuration.
--- deployment_config stores deployment configurations at project level.
-CREATE TABLE deployment_config (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', '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);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('deployment_config', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_deployment_config_modification_time`
-AFTER
-UPDATE
- ON `deployment_config` FOR EACH ROW BEGIN
-UPDATE
- `deployment_config`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
-
--- sheet table stores the query for the user
-CREATE TABLE sheet (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- -- 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 (strftime('%s', 'now')),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- instance_id INTEGER NOT NULL REFERENCES instance (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_instance_id_row_status ON sheet(instance_id, row_status);
-
-CREATE INDEX idx_sheet_database_id_row_status ON sheet(database_id, row_status);
-
-INSERT INTO
- sqlite_sequence (name, seq)
-VALUES
- ('sheet', 100);
-
-CREATE TRIGGER IF NOT EXISTS `trigger_update_sheet_modification_time`
-AFTER
-UPDATE
- ON `sheet` FOR EACH ROW BEGIN
-UPDATE
- `sheet`
-SET
- updated_ts = (strftime('%s', 'now'))
-WHERE
- rowid = old.rowid;
-
-END;
diff --git a/store/pipeline.go b/store/pipeline.go
index cab6bd5151..91779e6c6f 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -34,20 +34,13 @@ func (s *PipelineService) CreatePipeline(ctx context.Context, create *api.Pipeli
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
pipeline, err := s.pgCreatePipeline(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createPipeline(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -65,7 +58,6 @@ func (s *PipelineService) FindPipelineList(ctx context.Context, find *api.Pipeli
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findPipelineList(ctx, tx.PTx, find)
@@ -102,7 +94,6 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findPipelineList(ctx, tx.PTx, find)
@@ -128,20 +119,13 @@ func (s *PipelineService) PatchPipeline(ctx context.Context, patch *api.Pipeline
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
pipeline, err := s.pgPatchPipeline(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchPipeline(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -153,45 +137,6 @@ func (s *PipelineService) PatchPipeline(ctx context.Context, patch *api.Pipeline
return pipeline, nil
}
-// createPipeline creates a new pipeline.
-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,
- updater_id,
- name,
- status
- )
- VALUES (?, ?, ?, 'OPEN')
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, name, status
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var pipeline api.Pipeline
- if err := row.Scan(
- &pipeline.ID,
- &pipeline.CreatorID,
- &pipeline.CreatedTs,
- &pipeline.UpdaterID,
- &pipeline.UpdatedTs,
- &pipeline.Name,
- &pipeline.Status,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &pipeline, nil
-}
-
// createPipeline creates a new pipeline.
func (s *PipelineService) pgCreatePipeline(ctx context.Context, tx *sql.Tx, create *api.PipelineCreate) (*api.Pipeline, error) {
row, err := tx.QueryContext(ctx, `
@@ -284,49 +229,6 @@ func (s *PipelineService) findPipelineList(ctx context.Context, tx *sql.Tx, find
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Status; v != nil {
- set, args = append(set, "status = ?"), append(args, api.PipelineStatus(*v))
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE pipeline
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, name, status
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var pipeline api.Pipeline
- if err := row.Scan(
- &pipeline.ID,
- &pipeline.CreatorID,
- &pipeline.CreatedTs,
- &pipeline.UpdaterID,
- &pipeline.UpdatedTs,
- &pipeline.Name,
- &pipeline.Status,
- ); err != nil {
- return nil, FormatError(err)
- }
- return &pipeline, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("pipeline ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/policy.go b/store/policy.go
index 86cfe49953..f485680835 100644
--- a/store/policy.go
+++ b/store/policy.go
@@ -41,7 +41,6 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findPolicy(ctx, tx.PTx, find)
@@ -144,20 +143,13 @@ func (s *PolicyService) UpsertPolicy(ctx context.Context, upsert *api.PolicyUpse
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
policy, err := s.pgUpsertPolicy(ctx, tx.PTx, upsert)
if err != nil {
return nil, err
}
- if _, err := s.upsertPolicy(ctx, tx.Tx, upsert); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -165,52 +157,6 @@ func (s *PolicyService) UpsertPolicy(ctx context.Context, upsert *api.PolicyUpse
return policy, nil
}
-// upsertPolicy updates an existing policy.
-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 (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
- VALUES (?, ?, ?, ?, ?)
- ON CONFLICT(environment_id, type) DO UPDATE SET
- payload = excluded.payload
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, environment_id, type, payload
- `,
- upsert.UpdaterID,
- upsert.UpdaterID,
- upsert.EnvironmentID,
- upsert.Type,
- upsert.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var policy api.Policy
- if err := row.Scan(
- &policy.ID,
- &policy.CreatorID,
- &policy.CreatedTs,
- &policy.UpdaterID,
- &policy.UpdatedTs,
- &policy.EnvironmentID,
- &policy.Type,
- &policy.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &policy, nil
-}
-
// upsertPolicy updates an existing policy.
func (s *PolicyService) pgUpsertPolicy(ctx context.Context, tx *sql.Tx, upsert *api.PolicyUpsert) (*api.Policy, error) {
// Upsert row into policy.
diff --git a/store/principal.go b/store/principal.go
index d6608a4844..53438118e4 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -34,20 +34,13 @@ func (s *PrincipalService) CreatePrincipal(ctx context.Context, create *api.Prin
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
principal, err := pgCreatePrincipal(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createPrincipal(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -65,7 +58,6 @@ func (s *PrincipalService) FindPrincipalList(ctx context.Context) ([]*api.Princi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findPrincipalList(ctx, tx.PTx, &api.PrincipalFind{})
@@ -102,7 +94,6 @@ func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.Principa
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findPrincipalList(ctx, tx.PTx, find)
@@ -129,20 +120,13 @@ func (s *PrincipalService) PatchPrincipal(ctx context.Context, patch *api.Princi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
principal, err := pgPatchPrincipal(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchPrincipal(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -154,53 +138,6 @@ func (s *PrincipalService) PatchPrincipal(ctx context.Context, patch *api.Princi
return principal, nil
}
-// 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 (
- creator_id,
- updater_id,
- type,
- name,
- email,
- password_hash
- )
- VALUES (?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
- `,
- create.CreatorID,
- create.CreatorID,
- create.Type,
- create.Name,
- create.Email,
- create.PasswordHash,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var principal api.Principal
- if err := row.Scan(
- &principal.ID,
- &principal.CreatorID,
- &principal.CreatedTs,
- &principal.UpdaterID,
- &principal.UpdatedTs,
- &principal.Type,
- &principal.Name,
- &principal.Email,
- &principal.PasswordHash,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &principal, nil
-}
-
// pgCreatePrincipal creates a new principal.
func pgCreatePrincipal(ctx context.Context, tx *sql.Tx, create *api.PrincipalCreate) (*api.Principal, error) {
// Insert row into database.
@@ -305,54 +242,6 @@ func findPrincipalList(ctx context.Context, tx *sql.Tx, find *api.PrincipalFind)
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.PasswordHash; v != nil {
- set, args = append(set, "password_hash = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE principal
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var principal api.Principal
- if err := row.Scan(
- &principal.ID,
- &principal.CreatorID,
- &principal.CreatedTs,
- &principal.UpdaterID,
- &principal.UpdatedTs,
- &principal.Type,
- &principal.Name,
- &principal.Email,
- &principal.PasswordHash,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &principal, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("principal ID not found: %d", patch.ID)}
-}
-
// 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) {
set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}
diff --git a/store/project.go b/store/project.go
index 74ae669b93..45fe503f2f 100644
--- a/store/project.go
+++ b/store/project.go
@@ -34,20 +34,13 @@ func (s *ProjectService) CreateProject(ctx context.Context, create *api.ProjectC
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
project, err := pgCreateProject(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createProject(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -65,7 +58,6 @@ func (s *ProjectService) FindProjectList(ctx context.Context, find *api.ProjectF
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectList(ctx, tx.PTx, find)
@@ -102,7 +94,6 @@ func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectList(ctx, tx.PTx, find)
@@ -128,20 +119,13 @@ func (s *ProjectService) PatchProject(ctx context.Context, patch *api.ProjectPat
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
project, err := pgPatchProject(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchProject(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -153,22 +137,6 @@ func (s *ProjectService) PatchProject(ctx context.Context, patch *api.ProjectPat
return project, nil
}
-// PatchProjectTx updates an existing project by ID.
-// Returns ENOTFOUND if project does not exist.
-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)
- }
-
- if err := s.cache.UpsertCache(api.ProjectCache, project.ID, project); err != nil {
- return nil, err
- }
-
- return project, nil
-}
-
// PgPatchProjectTx 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) {
@@ -185,58 +153,6 @@ func (s *ProjectService) PgPatchProjectTx(ctx context.Context, tx *sql.Tx, patch
return project, nil
}
-// 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 (
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
- VALUES (?, ?, ?, ?, 'UI', 'PUBLIC', ?, ?)
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, key, workflow_type, visibility, tenant_mode, db_name_template
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- strings.ToUpper(create.Key),
- create.TenantMode,
- create.DBNameTemplate,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var project api.Project
- if err := row.Scan(
- &project.ID,
- &project.RowStatus,
- &project.CreatorID,
- &project.CreatedTs,
- &project.UpdaterID,
- &project.UpdatedTs,
- &project.Name,
- &project.Key,
- &project.WorkflowType,
- &project.Visibility,
- &project.TenantMode,
- &project.DBNameTemplate,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &project, nil
-}
-
// pgCreateProject creates a new project.
func pgCreateProject(ctx context.Context, tx *sql.Tx, create *api.ProjectCreate) (*api.Project, error) {
// Insert row into database.
@@ -355,64 +271,6 @@ func findProjectList(ctx context.Context, tx *sql.Tx, find *api.ProjectFind) (_
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.RowStatus; v != nil {
- set, args = append(set, "row_status = ?"), append(args, api.RowStatus(*v))
- }
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.Key; v != nil {
- set, args = append(set, "key = ?"), append(args, strings.ToUpper(*v))
- }
- if v := patch.WorkflowType; v != nil {
- set, args = append(set, "`workflow_type` = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE project
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, key, workflow_type, visibility, tenant_mode, db_name_template
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var project api.Project
- if err := row.Scan(
- &project.ID,
- &project.RowStatus,
- &project.CreatorID,
- &project.CreatedTs,
- &project.UpdaterID,
- &project.UpdatedTs,
- &project.Name,
- &project.Key,
- &project.WorkflowType,
- &project.Visibility,
- &project.TenantMode,
- &project.DBNameTemplate,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &project, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/project_member.go b/store/project_member.go
index 5be8b953eb..100abb53a6 100644
--- a/store/project_member.go
+++ b/store/project_member.go
@@ -32,20 +32,13 @@ func (s *ProjectMemberService) CreateProjectMember(ctx context.Context, create *
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
projectMember, err := pgCreateProjectMember(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createProjectMember(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *ProjectMemberService) FindProjectMemberList(ctx context.Context, find *
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectMemberList(ctx, tx.PTx, find)
@@ -76,7 +68,6 @@ func (s *ProjectMemberService) FindProjectMember(ctx context.Context, find *api.
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectMemberList(ctx, tx.PTx, find)
@@ -99,20 +90,13 @@ func (s *ProjectMemberService) PatchProjectMember(ctx context.Context, patch *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
projectMember, err := pgPatchProjectMember(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchProjectMember(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -126,19 +110,12 @@ func (s *ProjectMemberService) DeleteProjectMember(ctx context.Context, delete *
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteProjectMember(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteProjectMember(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -146,50 +123,6 @@ func (s *ProjectMemberService) DeleteProjectMember(ctx context.Context, delete *
return nil
}
-// 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 (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
- VALUES (?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, role, principal_id
- `,
- create.CreatorID,
- create.CreatorID,
- create.ProjectID,
- create.Role,
- create.PrincipalID,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var projectMember api.ProjectMember
- if err := row.Scan(
- &projectMember.ID,
- &projectMember.CreatorID,
- &projectMember.CreatedTs,
- &projectMember.UpdaterID,
- &projectMember.UpdatedTs,
- &projectMember.ProjectID,
- &projectMember.Role,
- &projectMember.PrincipalID,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &projectMember, nil
-}
-
// pgCreateProjectMember creates a new projectMember.
func pgCreateProjectMember(ctx context.Context, tx *sql.Tx, create *api.ProjectMemberCreate) (*api.ProjectMember, error) {
// Insert row into database.
@@ -289,51 +222,6 @@ func findProjectMemberList(ctx context.Context, tx *sql.Tx, find *api.ProjectMem
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Role; v != nil {
- set, args = append(set, "role = ?"), append(args, api.Role(*v))
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE project_member
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, role, principal_id
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var projectMember api.ProjectMember
- if err := row.Scan(
- &projectMember.ID,
- &projectMember.CreatorID,
- &projectMember.CreatedTs,
- &projectMember.UpdaterID,
- &projectMember.UpdatedTs,
- &projectMember.ProjectID,
- &projectMember.Role,
- &projectMember.PrincipalID,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &projectMember, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -379,15 +267,6 @@ func pgPatchProjectMember(ctx context.Context, tx *sql.Tx, patch *api.ProjectMem
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member ID not found: %d", patch.ID)}
}
-// 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 = ?`, delete.ID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteProjectMember permanently deletes a projectMember by ID.
func pgDeleteProjectMember(ctx context.Context, tx *sql.Tx, delete *api.ProjectMemberDelete) error {
// Remove row from database.
diff --git a/store/project_webhook.go b/store/project_webhook.go
index 19045c88d9..067adc6ec8 100644
--- a/store/project_webhook.go
+++ b/store/project_webhook.go
@@ -32,20 +32,13 @@ func (s *ProjectWebhookService) CreateProjectWebhook(ctx context.Context, create
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
projectWebhook, err := pgCreateProjectWebhook(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createProjectWebhook(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *ProjectWebhookService) FindProjectWebhookList(ctx context.Context, find
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectWebhookList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *ProjectWebhookService) FindProjectWebhook(ctx context.Context, find *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findProjectWebhookList(ctx, tx.PTx, find)
@@ -100,20 +91,13 @@ func (s *ProjectWebhookService) PatchProjectWebhook(ctx context.Context, patch *
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
projectWebhook, err := pgPatchProjectWebhook(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchProjectWebhook(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -127,19 +111,12 @@ func (s *ProjectWebhookService) DeleteProjectWebhook(ctx context.Context, delete
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteProjectWebhook(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteProjectWebhook(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -147,58 +124,6 @@ func (s *ProjectWebhookService) DeleteProjectWebhook(ctx context.Context, delete
return nil
}
-// 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 (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, type, name, url, activity_list
- `,
- create.CreatorID,
- create.CreatorID,
- create.ProjectID,
- create.Type,
- create.Name,
- create.URL,
- strings.Join(create.ActivityList, ","),
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var projectWebhook api.ProjectWebhook
- var activityList string
- if err := row.Scan(
- &projectWebhook.ID,
- &projectWebhook.CreatorID,
- &projectWebhook.CreatedTs,
- &projectWebhook.UpdaterID,
- &projectWebhook.UpdatedTs,
- &projectWebhook.ProjectID,
- &projectWebhook.Type,
- &projectWebhook.Name,
- &projectWebhook.URL,
- &activityList,
- ); err != nil {
- return nil, FormatError(err)
- }
- projectWebhook.ActivityList = strings.Split(activityList, ",")
-
- return &projectWebhook, nil
-}
-
// pgCreateProjectWebhook creates a new projectWebhook.
func pgCreateProjectWebhook(ctx context.Context, tx *sql.Tx, create *api.ProjectWebhookCreate) (*api.ProjectWebhook, error) {
// Insert row into database.
@@ -321,61 +246,6 @@ func findProjectWebhookList(ctx context.Context, tx *sql.Tx, find *api.ProjectWe
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.URL; v != nil {
- set, args = append(set, "url = ?"), append(args, *v)
- }
- if v := patch.ActivityList; v != nil {
- set, args = append(set, "activity_list = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE project_webhook
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, project_id, type, name, url, activity_list
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var projectWebhook api.ProjectWebhook
- var activityList string
- if err := row.Scan(
- &projectWebhook.ID,
- &projectWebhook.CreatorID,
- &projectWebhook.CreatedTs,
- &projectWebhook.UpdaterID,
- &projectWebhook.UpdatedTs,
- &projectWebhook.ProjectID,
- &projectWebhook.Type,
- &projectWebhook.Name,
- &projectWebhook.URL,
- &activityList,
- ); err != nil {
- return nil, FormatError(err)
- }
- projectWebhook.ActivityList = strings.Split(activityList, ",")
-
- return &projectWebhook, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -431,15 +301,6 @@ func pgPatchProjectWebhook(ctx context.Context, tx *sql.Tx, patch *api.ProjectWe
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook ID not found: %d", patch.ID)}
}
-// 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 = ?`, delete.ID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteProjectWebhook permanently deletes a projectWebhook by ID.
func pgDeleteProjectWebhook(ctx context.Context, tx *sql.Tx, delete *api.ProjectWebhookDelete) error {
// Remove row from database.
diff --git a/store/repository.go b/store/repository.go
index 800992659d..907cb03ff1 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -34,20 +34,13 @@ func (s *RepositoryService) CreateRepository(ctx context.Context, create *api.Re
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
repository, err := s.pgCreateRepository(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createRepository(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -61,7 +54,6 @@ func (s *RepositoryService) FindRepositoryList(ctx context.Context, find *api.Re
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findRepositoryList(ctx, tx.PTx, find)
@@ -79,7 +71,6 @@ func (s *RepositoryService) FindRepository(ctx context.Context, find *api.Reposi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findRepositoryList(ctx, tx.PTx, find)
@@ -102,20 +93,13 @@ func (s *RepositoryService) PatchRepository(ctx context.Context, patch *api.Repo
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
repository, err := pgPatchRepository(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchRepository(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -129,19 +113,12 @@ func (s *RepositoryService) DeleteRepository(ctx context.Context, delete *api.Re
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := s.pgDeleteRepository(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := s.deleteRepository(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -149,103 +126,6 @@ func (s *RepositoryService) DeleteRepository(ctx context.Context, delete *api.Re
return nil
}
-// 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.VCSWorkflow
- projectPatch := api.ProjectPatch{
- ID: create.ProjectID,
- UpdaterID: create.CreatorID,
- WorkflowType: &workflowType,
- }
- if _, err := s.projectService.PatchProjectTx(ctx, tx, &projectPatch); err != nil {
- return nil, err
- }
-
- // Insert row into database.
- row, err := tx.QueryContext(ctx, `
- INSERT INTO repository (
- creator_id,
- updater_id,
- vcs_id,
- project_id,
- name,
- full_path,
- web_url,
- branch_filter,
- base_directory,
- file_path_template,
- schema_path_template,
- external_id,
- external_webhook_id,
- webhook_url_host,
- webhook_endpoint_id,
- webhook_secret_token,
- access_token,
- expires_ts,
- refresh_token
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, vcs_id, project_id, name, full_path, web_url, branch_filter, base_directory, file_path_template, schema_path_template, external_id, external_webhook_id, webhook_url_host, webhook_endpoint_id, webhook_secret_token, access_token, expires_ts, refresh_token
- `,
- create.CreatorID,
- create.CreatorID,
- create.VCSID,
- create.ProjectID,
- create.Name,
- create.FullPath,
- create.WebURL,
- create.BranchFilter,
- create.BaseDirectory,
- create.FilePathTemplate,
- create.SchemaPathTemplate,
- create.ExternalID,
- create.ExternalWebhookID,
- create.WebhookURLHost,
- create.WebhookEndpointID,
- create.WebhookSecretToken,
- create.AccessToken,
- create.ExpiresTs,
- create.RefreshToken,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var repository api.Repository
- if err := row.Scan(
- &repository.ID,
- &repository.CreatorID,
- &repository.CreatedTs,
- &repository.UpdaterID,
- &repository.UpdatedTs,
- &repository.VCSID,
- &repository.ProjectID,
- &repository.Name,
- &repository.FullPath,
- &repository.WebURL,
- &repository.BranchFilter,
- &repository.BaseDirectory,
- &repository.FilePathTemplate,
- &repository.SchemaPathTemplate,
- &repository.ExternalID,
- &repository.ExternalWebhookID,
- &repository.WebhookURLHost,
- &repository.WebhookEndpointID,
- &repository.WebhookSecretToken,
- &repository.AccessToken,
- &repository.ExpiresTs,
- &repository.RefreshToken,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &repository, nil
-}
-
// pgCreateRepository creates a new repository.
func (s *RepositoryService) pgCreateRepository(ctx context.Context, tx *sql.Tx, create *api.RepositoryCreate) (*api.Repository, error) {
// Updates the project workflow_type to "VCS"
@@ -432,83 +312,6 @@ func findRepositoryList(ctx context.Context, tx *sql.Tx, find *api.RepositoryFin
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.BranchFilter; v != nil {
- set, args = append(set, "branch_filter = ?"), append(args, *v)
- }
- if v := patch.BaseDirectory; v != nil {
- set, args = append(set, "base_directory = ?"), append(args, *v)
- }
- if v := patch.FilePathTemplate; v != nil {
- set, args = append(set, "file_path_template = ?"), append(args, *v)
- }
- if v := patch.SchemaPathTemplate; v != nil {
- set, args = append(set, "schema_path_template = ?"), append(args, *v)
- }
- if v := patch.AccessToken; v != nil {
- set, args = append(set, "access_token = ?"), append(args, *v)
- }
- if v := patch.ExpiresTs; v != nil {
- set, args = append(set, "expires_ts = ?"), append(args, *v)
- }
- if v := patch.RefreshToken; v != nil {
- set, args = append(set, "refresh_token = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE repository
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, vcs_id, project_id, name, full_path, web_url, branch_filter, base_directory, file_path_template, schema_path_template, external_id, external_webhook_id, webhook_url_host, webhook_endpoint_id, webhook_secret_token, access_token, expires_ts, refresh_token
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var repository api.Repository
- if err := row.Scan(
- &repository.ID,
- &repository.CreatorID,
- &repository.CreatedTs,
- &repository.UpdaterID,
- &repository.UpdatedTs,
- &repository.VCSID,
- &repository.ProjectID,
- &repository.Name,
- &repository.FullPath,
- &repository.WebURL,
- &repository.BranchFilter,
- &repository.BaseDirectory,
- &repository.FilePathTemplate,
- &repository.SchemaPathTemplate,
- &repository.ExternalID,
- &repository.ExternalWebhookID,
- &repository.WebhookURLHost,
- &repository.WebhookEndpointID,
- &repository.WebhookSecretToken,
- &repository.AccessToken,
- &repository.ExpiresTs,
- &repository.RefreshToken,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &repository, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -586,26 +389,6 @@ func pgPatchRepository(ctx context.Context, tx *sql.Tx, patch *api.RepositoryPat
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository ID not found: %d", patch.ID)}
}
-// 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.UIWorkflow
- projectPatch := api.ProjectPatch{
- ID: delete.ProjectID,
- UpdaterID: delete.DeleterID,
- WorkflowType: &workflowType,
- }
- if _, err := s.projectService.PatchProjectTx(ctx, tx, &projectPatch); err != nil {
- return err
- }
-
- // Remove row from database.
- if _, err := tx.ExecContext(ctx, `DELETE FROM repository WHERE project_id = ?`, delete.ProjectID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteRepository permanently deletes a repository by ID.
func (s *RepositoryService) pgDeleteRepository(ctx context.Context, tx *sql.Tx, delete *api.RepositoryDelete) error {
// Updates the project workflow_type to "UI"
diff --git a/store/seed/README.md b/store/seed/README.md
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/store/seed/release/10001__init_seed.sql b/store/seed/release/10001__init_seed.sql
deleted file mode 100644
index 85c22ffb4b..0000000000
--- a/store/seed/release/10001__init_seed.sql
+++ /dev/null
@@ -1,518 +0,0 @@
--- Create "test" and "prod" environments
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 'Test',
- 0
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 101,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_NEVER"}'
- );
-
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 'Prod',
- 1
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 102,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_ALWAYS"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 102,
- 'bb.policy.backup-plan',
- '{"schedule":"WEEKLY"}'
- );
-
--- Create label keys for `bb.location` and `bb.tenant`.
-INSERT INTO
- label_key (
- id,
- creator_id,
- updater_id,
- key
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 'bb.location'
- );
-
-INSERT INTO
- label_key (
- id,
- creator_id,
- updater_id,
- key
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 'bb.tenant'
- );
-
--- Create 1 "test", 1 "prod" instance (including * database and admin data source)
--- Both instances contains the connection info we expect user to setup according to https://docs.bytebase.com/install/docker#start-a-local-mysql-server-for-testing
--- Set host to 172.17.0.1 which is the default docker gateway ip.
--- Our quickstart guide suggests to run both Bytebase and MySQL using docker, and in such case, bytebase access the mysqld container via 172.17.0.1
--- "test" instance
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 'MySQL Test (Follow the "External Link" field to bring up the MySQL server)',
- 'MYSQL',
- '8.0.19',
- 'host.docker.internal',
- '3306',
- 'https://docs.bytebase.com/install/docker#start-a-local-mysql-server-for-testing'
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- password
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 101,
- 'Admin data source',
- 'ADMIN',
- 'root',
- 'testpwd1'
- );
-
--- "prod" instance
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 102,
- 'MySQL Prod (Follow the "External Link" field to bring up the MySQL server)',
- 'MYSQL',
- '8.0.19',
- 'host.docker.internal',
- '3306',
- 'https://docs.bytebase.com/install/docker#start-a-local-mysql-server-for-testing'
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 102,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- password
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 102,
- 102,
- 'Admin data source',
- 'ADMIN',
- 'root',
- 'testpwd1'
- );
-
--- Create pipeline/stage/task/issue for onboarding
--- Create pipeline 101 "Hello world"
-INSERT INTO
- pipeline (
- id,
- creator_id,
- updater_id,
- name,
- status
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 'Pipeline - Hello world',
- 'OPEN'
- );
-
--- Create stage 101, 102 for pipeline 101
-INSERT INTO
- stage (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 101,
- 'Test'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 101,
- 102,
- 'Prod'
- );
-
--- Create task 101 for stage 101
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 101,
- 101,
- NULL,
- 'Welcome',
- 'bb.task.general',
- 'RUNNING',
- '{"statement":"SELECT ''Welcome Builders'';"}'
- );
-
--- Create task 102 for stage 102
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 101,
- 102,
- 102,
- NULL,
- 'Let''s go',
- 'bb.task.general',
- 'PENDING_APPROVAL',
- '{"statement":"SELECT ''Let''s go'';"}'
- );
-
--- Create task_run for task 101
-INSERT INTO
- task_run (
- creator_id,
- updater_id,
- task_id,
- name,
- status,
- type,
- comment,
- result,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 101,
- 'Welcome',
- 'FAILED',
- 'bb.task.general',
- '',
- '{"detail":"Something is not right..."}',
- ''
- );
-
-INSERT INTO
- task_run (
- creator_id,
- updater_id,
- task_id,
- name,
- status,
- type,
- comment,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 101,
- 'Welcome',
- 'RUNNING',
- 'bb.task.general',
- 'Let''s give another try',
- ''
- );
-
--- Create issue 101 "Hello world"
-INSERT INTO
- issue (
- id,
- creator_id,
- updater_id,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 1,
- 101,
- 'Hello world!',
- 'OPEN',
- 'bb.issue.general',
- 'Welcome to Bytebase, this is the issue interface where developers and DBAs collaborate on database schema management issues such as: ' || char(10, 10) || ' - Creating a new database' || char(10) || ' - Creating a table' || char(10) || ' - Creating an index' || char(10) || ' - Adding/altering a column' || char(10) || ' - Troubleshooting performance issue' || char(10, 10) || 'Let''s try some simple tasks:' || char(10, 10) || '1. Bookmark this issue by clicking the star icon on the top of this page' || char(10) || '2. Leave a comment below to greet future comers' || char(10) || '3. Follow the Quickstart on the bottom left to get familiar with other features',
- 1
- );
-
--- Create activity 101
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 101,
- 'bb.issue.create',
- 'INFO'
- );
-
-INSERT INTO
- activity (
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- comment
- )
-VALUES
- (
- 1,
- 1,
- 101,
- 'bb.issue.comment.create',
- 'INFO',
- 'Go fish!'
- );
diff --git a/store/seed/release/README.md b/store/seed/release/README.md
deleted file mode 100644
index f888101b79..0000000000
--- a/store/seed/release/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-This folder contains the seed data for release. The release seed data is used when building with "release" tag or running with --demo.
-
-The seed data file name follows the same naming convention as the migration file like {{version_number}}\_\_{{description}}, where {{version_number}}
-corresponds to the migration file having the same {{version_number}}. The particular release seed data file is ONLY loaded when the corresponding migration file has been applied, which means it should only be loaded once together with running the migration file.
diff --git a/store/seed/test/10000__reset.sql b/store/seed/test/10000__reset.sql
deleted file mode 100644
index c7c9a278d7..0000000000
--- a/store/seed/test/10000__reset.sql
+++ /dev/null
@@ -1,125 +0,0 @@
--- For testing, we reset data on each run
--- Do not reset bb.auth.secret so that we don't need to re-login after restart
-DELETE FROM
- setting
-WHERE
- name != 'bb.auth.secret';
-
-DELETE FROM
- anomaly;
-
-DELETE FROM
- repository;
-
-DELETE FROM
- vcs;
-
-DELETE FROM
- bookmark;
-
-DELETE FROM
- inbox;
-
-DELETE FROM
- activity;
-
-DELETE FROM
- issue_subscriber;
-
-DELETE FROM
- issue;
-
-DELETE FROM
- task_check_run;
-
-DELETE FROM
- task_run;
-
-DELETE FROM
- task;
-
-DELETE FROM
- stage;
-
-DELETE FROM
- pipeline;
-
-DELETE FROM
- data_source;
-
-DELETE FROM
- vw;
-
-DELETE FROM
- idx;
-
-DELETE FROM
- col;
-
-DELETE FROM
- tbl;
-
-DELETE FROM
- backup;
-
-DELETE FROM
- backup_setting;
-
--- Delete in this order following foreign constraints.
-DELETE FROM
- db_label;
-
-DELETE FROM
- label_value;
-
-DELETE FROM
- label_key;
-
-DELETE FROM
- db;
-
-DELETE FROM
- instance_user;
-
-DELETE FROM
- instance;
-
-DELETE FROM
- policy;
-
-DELETE FROM
- environment;
-
-DELETE FROM
- project_webhook;
-
-DELETE FROM
- project_member;
-
-DELETE FROM
- deployment_config;
-
-DELETE FROM
- sheet;
-
--- Project 1 refers to DEFAULT project which is considered as part of schema
-DELETE FROM
- project
-WHERE
- id != 1;
-
-DELETE FROM
- member;
-
--- Principal 1 refers to bytebase system account which is considered as part of schema
-DELETE FROM
- principal
-WHERE
- id != 1;
-
-
--- By default, for every table, we reserve id <=100 for internal user
-UPDATE
- sqlite_sequence
-SET
- seq = 100;
diff --git a/store/seed/test/10001__principal.sql b/store/seed/test/10001__principal.sql
deleted file mode 100644
index 582c68db53..0000000000
--- a/store/seed/test/10001__principal.sql
+++ /dev/null
@@ -1,85 +0,0 @@
--- End user id starts at 101, we reserve the range between 1 ~ 100 for internal use.
--- Setting the id explicitly changes the next id value to be +1
--- 101
-INSERT INTO
- principal (
- creator_id,
- updater_id,
- type,
- name,
- email,
- password_hash
- )
-VALUES
- (
- 1,
- 1,
- 'END_USER',
- 'Demo Owner',
- -- 1024
- '$2a$10$/65QFlHOmDzXshEMt/qYuunbJrXtRLcaYDcRODbyOPa/9/N0N8Zc2'
- );
-
--- 102
-INSERT INTO
- principal (
- creator_id,
- updater_id,
- type,
- name,
- email,
- password_hash
- )
-VALUES
- (
- 1,
- 1,
- 'END_USER',
- 'Jerry DBA',
- -- 2048
- '$2a$10$Q2NJib9bRvDkap1N1RDP2O3HyxjCldwfvGoxAzZL5gbbBgKAFD4cq'
- );
-
--- 103
-INSERT INTO
- principal (
- creator_id,
- updater_id,
- type,
- name,
- email,
- password_hash
- )
-VALUES
- (
- 1,
- 1,
- 'END_USER',
- 'Tom Dev',
- -- 4096
- '$2a$10$X5bvIWk4BKhEaZqlNLGjgOUB09i97olKBfjTQT49zMtNGnhoy6GIW'
- );
-
--- 104
-INSERT INTO
- principal (
- creator_id,
- updater_id,
- type,
- name,
- email,
- password_hash
- )
-VALUES
- (
- 1,
- 1,
- 'END_USER',
- 'Jane Dev',
- -- 8192
- '$2a$10$2QTgsuKDTGYe68lpeqRqouw1dQTRhssrYSnwQVzQUctQvhnVIccRa'
- );
diff --git a/store/seed/test/10010__workspace.sql b/store/seed/test/10010__workspace.sql
deleted file mode 100644
index 026f1d2de6..0000000000
--- a/store/seed/test/10010__workspace.sql
+++ /dev/null
@@ -1 +0,0 @@
--- 0010 is reserved for workspace, but is not implemented yet.
diff --git a/store/seed/test/10020__member.sql b/store/seed/test/10020__member.sql
deleted file mode 100644
index f1af1d697e..0000000000
--- a/store/seed/test/10020__member.sql
+++ /dev/null
@@ -1,47 +0,0 @@
-INSERT INTO
- member (
- id,
- creator_id,
- updater_id,
- status,
- role,
- principal_id
- )
-VALUES
- (2001, 101, 101, 'ACTIVE', 'OWNER', 101);
-
-INSERT INTO
- member (
- id,
- creator_id,
- updater_id,
- status,
- role,
- principal_id
- )
-VALUES
- (2002, 101, 101, 'ACTIVE', 'DBA', 102);
-
-INSERT INTO
- member (
- id,
- creator_id,
- updater_id,
- status,
- role,
- principal_id
- )
-VALUES
- (2003, 101, 101, 'ACTIVE', 'DEVELOPER', 103);
-
-INSERT INTO
- member (
- id,
- creator_id,
- updater_id,
- status,
- role,
- principal_id
- )
-VALUES
- (2004, 101, 101, 'ACTIVE', 'DEVELOPER', 104);
diff --git a/store/seed/test/10030__project.sql b/store/seed/test/10030__project.sql
deleted file mode 100644
index 3e5e505f1f..0000000000
--- a/store/seed/test/10030__project.sql
+++ /dev/null
@@ -1,176 +0,0 @@
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3001,
- 101,
- 101,
- 'Test (UI)',
- 'TEST',
- 'UI',
- 'PUBLIC',
- 'DISABLED',
- ''
- );
-
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3002,
- 101,
- 101,
- 'Shop (Git)',
- 'SHP',
- 'VCS',
- 'PUBLIC',
- 'DISABLED',
- ''
- );
-
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3003,
- 101,
- 101,
- 'Blog (Git)',
- 'BLG',
- 'VCS',
- 'PUBLIC',
- 'DISABLED',
- ''
- );
-
-INSERT INTO
- project (
- id,
- row_status,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3004,
- 'ARCHIVED',
- 101,
- 101,
- 'Retired Project',
- 'RTR',
- 'UI',
- 'PUBLIC',
- 'DISABLED',
- ''
- );
-
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3005,
- 101,
- 101,
- 'Tenant (Git)',
- 'TNTG',
- 'VCS',
- 'PUBLIC',
- 'TENANT',
- ''
- );
-
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3006,
- 101,
- 101,
- 'Tenant (UI)',
- 'TNTU',
- 'UI',
- 'PUBLIC',
- 'TENANT',
- ''
- );
-
-INSERT INTO
- project (
- id,
- creator_id,
- updater_id,
- name,
- key,
- workflow_type,
- visibility,
- tenant_mode,
- db_name_template
- )
-VALUES
- (
- 3007,
- 101,
- 101,
- 'Tenant (db pattern)',
- 'TNMG',
- 'UI',
- 'PUBLIC',
- 'TENANT',
- '{{DB_NAME}}_{{TENANT}}'
- );
diff --git a/store/seed/test/10040__project_member.sql b/store/seed/test/10040__project_member.sql
deleted file mode 100644
index 0c9c9580ed..0000000000
--- a/store/seed/test/10040__project_member.sql
+++ /dev/null
@@ -1,315 +0,0 @@
--- Project 3001 membership
-INSERT INTO
- project_member (
- id,
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 4001,
- 101,
- 101,
- 3001,
- 'DEVELOPER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3001,
- 'OWNER',
- 102
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3001,
- 'DEVELOPER',
- 103
- );
-
--- Project 3002 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3002,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3002,
- 'DEVELOPER',
- 102
- );
-
--- Project 3003 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3003,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3003,
- 'DEVELOPER',
- 103
- );
-
--- Project 3004 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3004,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3004,
- 'OWNER',
- 102
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3004,
- 'DEVELOPER',
- 103
- );
-
--- Project 3005 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3005,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3005,
- 'DEVELOPER',
- 102
- );
-
--- Project 3006 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3006,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3006,
- 'DEVELOPER',
- 102
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3006,
- 'DEVELOPER',
- 103
- );
-
-
--- Project 3007 membership
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3007,
- 'OWNER',
- 101
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3007,
- 'DEVELOPER',
- 102
- );
-
-INSERT INTO
- project_member (
- creator_id,
- updater_id,
- project_id,
- role,
- principal_id
- )
-VALUES
- (
- 101,
- 101,
- 3007,
- 'DEVELOPER',
- 103
- );
diff --git a/store/seed/test/10041__project_webhook.sql b/store/seed/test/10041__project_webhook.sql
deleted file mode 100644
index 6598736a84..0000000000
--- a/store/seed/test/10041__project_webhook.sql
+++ /dev/null
@@ -1,130 +0,0 @@
--- Project 3001 hook
-INSERT INTO
- project_webhook (
- id,
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 4101,
- 101,
- 101,
- 3001,
- 'bb.plugin.webhook.wecom',
- 'WeCom',
- 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
-
-INSERT INTO
- project_webhook (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 101,
- 101,
- 3001,
- 'bb.plugin.webhook.dingtalk',
- 'DingTalk',
- 'https://oapi.dingtalk.com/robot/send?access_token=12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
-
--- Project 3002 hook
-INSERT INTO
- project_webhook (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 101,
- 101,
- 3002,
- 'bb.plugin.webhook.feishu',
- 'Feishu',
- 'https://open.feishu.cn/open-apis/bot/v2/hook/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
-
-INSERT INTO
- project_webhook (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 101,
- 101,
- 3002,
- 'bb.plugin.webhook.slack',
- 'Slack',
- 'https://hooks.slack.com/services/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
-
--- Project 3003 hook
-INSERT INTO
- project_webhook (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 101,
- 101,
- 3003,
- 'bb.plugin.webhook.discord',
- 'Discord',
- 'https://discord.com/api/webhooks/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
-
-INSERT INTO
- project_webhook (
- creator_id,
- updater_id,
- project_id,
- type,
- name,
- url,
- activity_list
- )
-VALUES
- (
- 101,
- 101,
- 3003,
- 'bb.plugin.webhook.teams',
- 'Teams',
- 'https://foo.webhook.office.com/webhookb2/12345',
- 'bb.issue.create,bb.issue.status.update,bb.pipeline.task.status.update,bb.issue.field.update,bb.issue.comment.create'
- );
diff --git a/store/seed/test/10050__environment.sql b/store/seed/test/10050__environment.sql
deleted file mode 100644
index 871edff99f..0000000000
--- a/store/seed/test/10050__environment.sql
+++ /dev/null
@@ -1,86 +0,0 @@
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 5001,
- 101,
- 101,
- 'Dev',
- 0
- );
-
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 5002,
- 101,
- 101,
- 'Integration',
- 1
- );
-
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 5003,
- 101,
- 101,
- 'Staging',
- 2
- );
-
-INSERT INTO
- environment (
- id,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 5004,
- 101,
- 101,
- 'Prod',
- 3
- );
-
-INSERT INTO
- environment (
- id,
- row_status,
- creator_id,
- updater_id,
- name,
- `order`
- )
-VALUES
- (
- 5005,
- 'ARCHIVED',
- 101,
- 101,
- 'Archived Env 1',
- 4
- );
diff --git a/store/seed/test/10051__policy.sql b/store/seed/test/10051__policy.sql
deleted file mode 100644
index 19d68b5e87..0000000000
--- a/store/seed/test/10051__policy.sql
+++ /dev/null
@@ -1,140 +0,0 @@
-INSERT INTO
- policy (
- id,
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 5101,
- 101,
- 101,
- 5001,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_NEVER"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5002,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_NEVER"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5003,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_ALWAYS"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5004,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_NEVER"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5005,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_NEVER"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5003,
- 'bb.policy.backup-plan',
- '{"schedule":"WEEKLY"}'
- );
-
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5004,
- 'bb.policy.backup-plan',
- '{"schedule":"DAILY"}'
- );
-
--- Test upsert.
-INSERT INTO
- policy (
- creator_id,
- updater_id,
- environment_id,
- type,
- payload
- )
-VALUES
- (
- 101,
- 101,
- 5004,
- 'bb.policy.pipeline-approval',
- '{"value":"MANUAL_APPROVAL_ALWAYS"}'
- )
- ON CONFLICT(environment_id, type) DO UPDATE SET
- payload = excluded.payload;
diff --git a/store/seed/test/10060__instance.sql b/store/seed/test/10060__instance.sql
deleted file mode 100644
index 62dbe49f37..0000000000
--- a/store/seed/test/10060__instance.sql
+++ /dev/null
@@ -1,244 +0,0 @@
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6001,
- 101,
- 101,
- 5001,
- 'Localhost Dev MySQL',
- 'MYSQL',
- '8.0.19',
- '127.0.0.1',
- '3306',
- 'bytebase.com/database/mysql'
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6002,
- 101,
- 101,
- 5002,
- 'On-premises Integration MySQL',
- 'MYSQL',
- '8.0.19',
- 'mysql.integration.example.com',
- '3306',
- 'bytebase.com/database/mysql'
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6003,
- 101,
- 101,
- 5003,
- 'On-premises Staging MySQL',
- 'MYSQL',
- '8.0.19',
- 'mysql.staging.example.com',
- '3306',
- 'bytebase.com/database/mysql'
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6004,
- 101,
- 101,
- 5004,
- 'On-premises Prod MySQL',
- 'MYSQL',
- '8.0.19',
- 'mysql.prod.example.com',
- '3306',
- 'bytebase.com/database/mysql'
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6005,
- 101,
- 101,
- 5001,
- 'Localhost Dev PostgreSQL',
- 'POSTGRES',
- '13.0',
- '127.0.0.1',
- '5432',
- "bytebase.com/database/postgres"
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6006,
- 101,
- 101,
- 5001,
- 'Localhost Dev TiDB',
- 'TIDB',
- '5.7.25-TiDB-v5.2.1',
- '127.0.0.1',
- '4000',
- "bytebase.com/database/tidb"
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6007,
- 101,
- 101,
- 5001,
- 'Localhost Dev ClickHouse',
- 'CLICKHOUSE',
- '21.10.2.15',
- '127.0.0.1',
- '9000',
- "bytebase.com/database/clickhouse"
- );
-
-INSERT INTO
- instance (
- id,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6008,
- 101,
- 101,
- 5001,
- 'Localhost Dev Snowflake',
- 'SNOWFLAKE',
- '21.10.2.15',
- '127.0.0.1',
- '',
- "bytebase.com/database/snowflake"
- );
-
-INSERT INTO
- instance (
- id,
- row_status,
- creator_id,
- updater_id,
- environment_id,
- name,
- engine,
- engine_version,
- host,
- port,
- external_link
- )
-VALUES
- (
- 6009,
- 'ARCHIVED',
- 101,
- 101,
- 5004,
- 'Retired Prod MySQL',
- 'MYSQL',
- '5.7.25',
- 'mysql.retired.example.com',
- '3306',
- "bytebase.com/database/mysql"
- );
diff --git a/store/seed/test/10061__instance_user.sql b/store/seed/test/10061__instance_user.sql
deleted file mode 100644
index 9b43148802..0000000000
--- a/store/seed/test/10061__instance_user.sql
+++ /dev/null
@@ -1,86 +0,0 @@
-INSERT INTO
- instance_user (
- id,
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
-VALUES
- (
- 6101,
- 1,
- 1,
- 6001,
- '`root`@`%`',
- 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
- );
-
-INSERT INTO
- instance_user (
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
-VALUES
- (
- 1,
- 1,
- 6002,
- '`root`@`%`',
- 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
- );
-
-INSERT INTO
- instance_user (
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
-VALUES
- (
- 1,
- 1,
- 6003,
- '`root`@`%`',
- 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
- );
-
-INSERT INTO
- instance_user (
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
-VALUES
- (
- 1,
- 1,
- 6004,
- '`root`@`%`',
- 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
- );
-
-INSERT INTO
- instance_user (
- creator_id,
- updater_id,
- instance_id,
- name,
- grant
- )
-VALUES
- (
- 1,
- 1,
- 6005,
- '`root`@`%`',
- 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION'
- );
diff --git a/store/seed/test/10070__db.sql b/store/seed/test/10070__db.sql
deleted file mode 100644
index 628803b593..0000000000
--- a/store/seed/test/10070__db.sql
+++ /dev/null
@@ -1,787 +0,0 @@
--- Database for sandbox environment instance 6001
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7001,
- 101,
- 101,
- 6001,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7002,
- 101,
- 101,
- 6001,
- 3001,
- 'testdb_dev',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7003,
- 101,
- 101,
- 6001,
- 3002,
- 'shop',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7004,
- 101,
- 101,
- 6001,
- 3003,
- 'blog',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for integration environment instance 6002
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7005,
- 101,
- 101,
- 6002,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7006,
- 101,
- 101,
- 6002,
- 3001,
- 'testdb_integration',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7007,
- 101,
- 101,
- 6002,
- 3002,
- 'shop',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7008,
- 101,
- 101,
- 6002,
- 3003,
- 'blog',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for staging environment instance 6003
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7009,
- 101,
- 101,
- 6003,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7010,
- 101,
- 101,
- 6003,
- 3001,
- 'testdb_staging',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7011,
- 101,
- 101,
- 6003,
- 3002,
- 'shop',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7012,
- 101,
- 101,
- 6003,
- 3003,
- 'blog',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for prod environment instance 6004
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7013,
- 101,
- 101,
- 6004,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7014,
- 101,
- 101,
- 6004,
- 3001,
- 'testdb_prod',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7015,
- 101,
- 101,
- 6004,
- 3002,
- 'shop',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7016,
- 101,
- 101,
- 6004,
- 3003,
- 'blog',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for dev environment PostgreSQL instance 6005
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7017,
- 101,
- 101,
- 6005,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for dev environment TiDB instance 6006
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7018,
- 101,
- 101,
- 6006,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for dev environment ClickHouse instance 6007
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7019,
- 101,
- 101,
- 6007,
- 1,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
-
--- Database for dev environment Snowflake instance 6008
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7020,
- 101,
- 101,
- 6008,
- 1,
- '*',
- '',
- '',
- 'OK',
- 0,
- ''
- );
-
--- Databases for tenant mode project.
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7021,
- 101,
- 101,
- 6001,
- 3005,
- 'tenant_db1',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- 'v1'
- );
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7022,
- 101,
- 101,
- 6002,
- 3005,
- 'tenant_db1',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- 'v1'
- );
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7023,
- 101,
- 101,
- 6001,
- 3006,
- 'tenant_db2',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- '2021v1'
- );
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7024,
- 101,
- 101,
- 6002,
- 3006,
- 'tenant_db2',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- '2021v1'
- );
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7025,
- 101,
- 101,
- 6001,
- 3007,
- 'db3_tenant1',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- '2022v0'
- );
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7026,
- 101,
- 101,
- 6002,
- 3007,
- 'db3_tenant2',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 1624558090,
- '2022v0'
- );
-
--- Database for prod environment archived mysql instance 6009
-INSERT INTO
- db (
- id,
- creator_id,
- updater_id,
- instance_id,
- project_id,
- name,
- character_set,
- collation,
- sync_status,
- last_successful_sync_ts,
- schema_version
- )
-VALUES
- (
- 7027,
- 101,
- 101,
- 6009,
- 3001,
- '*',
- 'utf8mb4',
- 'utf8mb4_general_ci',
- 'OK',
- 0,
- ''
- );
diff --git a/store/seed/test/10071__tbl.sql b/store/seed/test/10071__tbl.sql
deleted file mode 100644
index 2f6c15a8bd..0000000000
--- a/store/seed/test/10071__tbl.sql
+++ /dev/null
@@ -1,605 +0,0 @@
--- Table for database 7002 testdb_dev
-INSERT INTO
- tbl (
- id,
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 7101,
- 101,
- 101,
- 7002,
- 'tbl1',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1234,
- 16384,
- 0,
- 0,
- '',
- ''
- );
-
--- Table for database 7006 testdb_integration
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7006,
- 'tbl1',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1234,
- 16384,
- 16384,
- 65536,
- '',
- ''
- );
-
--- Table for database 7010 testdb_staging
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7010,
- 'tbl1',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 12234,
- 65536,
- 16384,
- 655360,
- '',
- ''
- );
-
--- Table for database 7014 testdb_prod
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7014,
- 'tbl1',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1234,
- 32768,
- 4096,
- 327680,
- '',
- ''
- );
-
--- Table for database 7003 shop
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7003,
- 'product',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1000,
- 4096,
- 0,
- 409600,
- '',
- ''
- );
-
--- Table for database 7007 shop
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7007,
- 'product',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1000,
- 4096,
- 1024,
- 0,
- '',
- ''
- );
-
--- Table for database 7004 blog
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 'user',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1000,
- 4096,
- 1024,
- 204800,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 'post',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 1000,
- 8192,
- 1024,
- 204800,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 'comment',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 30000,
- 65536,
- 4096,
- 102400,
- '',
- ''
- );
-
--- Table for database 7008 blog
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 'user',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 100,
- 4096,
- 0,
- 204800,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 'post',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 300,
- 4096,
- 1024,
- 102400,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 'comment',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 2000,
- 65536,
- 2048,
- 40960,
- '',
- ''
- );
-
--- Table for database 7012 blog
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 'user',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 200,
- 4096,
- 1024,
- 81920,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 'post',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 500,
- 4096,
- 1024,
- 8192,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 'comment',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 4000,
- 65536,
- 65536,
- 20480,
- '',
- ''
- );
-
--- Table for database 7016 blog
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 'user',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 200,
- 4096,
- 1024,
- 0,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 'post',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 500,
- 4096,
- 1024,
- 2048,
- '',
- ''
- );
-
-INSERT INTO
- tbl (
- creator_id,
- updater_id,
- database_id,
- name,
- type,
- ENGINE,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 'comment',
- 'BASE TABLE',
- 'InnoDB',
- 'utf8mb4_general_ci',
- 7000,
- 8192,
- 0,
- 8192,
- '',
- ''
- );
diff --git a/store/seed/test/10072__col.sql b/store/seed/test/10072__col.sql
deleted file mode 100644
index 393d28138a..0000000000
--- a/store/seed/test/10072__col.sql
+++ /dev/null
@@ -1,1693 +0,0 @@
--- Column for database 7002 testdb_dev, table 7101 tbl1
-INSERT INTO
- col (
- id,
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 7201,
- 101,
- 101,
- 7002,
- 7101,
- 'col1',
- 1,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- 'I am a comment'
- );
-
--- Column for database 7006 testdb_integration, table 7102 tbl1
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7006,
- 7102,
- 'col1',
- 1,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- 'I am a comment'
- );
-
--- Column for database 7010 testdb_staging, table 7103 tbl1
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7010,
- 7103,
- 'col1',
- 1,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- 'I am a comment'
- );
-
--- Column for database 7014 testdb_prod, table 7104 tbl1
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7014,
- 7104,
- 'col1',
- 1,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- 'I am a comment'
- );
-
--- Column for database 7003 shop, table 7105 product
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7003,
- 7105,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7003,
- 7105,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7003,
- 7105,
- 'description',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7007 shop, table 7106 product
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7007,
- 7106,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7007,
- 7106,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7007,
- 7106,
- 'description',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7004 blog, table 7107 user
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7107,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7107,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7107,
- 'email',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7004 blog, table 7108 post
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7108,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7108,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7108,
- 'content',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7108,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7004 blog, table 7109 comment
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7109,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7109,
- 'content',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7109,
- 'post_id',
- 3,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7109,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7008 blog, table 7110 user
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7110,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7110,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7110,
- 'email',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7008 blog, table 7111 post
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7111,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7111,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7111,
- 'content',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7111,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7008 blog, table 7112 comment
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7112,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7112,
- 'content',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7112,
- 'post_id',
- 3,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7112,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7012 blog, table 7113 user
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7113,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7113,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7113,
- 'email',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7012 blog, table 7114 post
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7114,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7114,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7114,
- 'content',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7114,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7012 blog, table 7115 comment
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7115,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7115,
- 'content',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7115,
- 'post_id',
- 3,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7115,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7016 blog, table 7116 user
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7116,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7116,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7116,
- 'email',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
--- Column for database 7008 blog, table 7117 post
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7117,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7117,
- 'name',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7117,
- 'content',
- 3,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7117,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
--- Column for database 7016 blog, table 7118 comment
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7118,
- 'id',
- 1,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7118,
- 'content',
- 2,
- NULL,
- 0,
- 'text',
- 'utf8mb4',
- 'utf8mb4_0900_ai_ci',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7118,
- 'post_id',
- 3,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
-
-INSERT INTO
- col (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- position,
- `default`,
- nullable,
- type,
- character_set,
- collation,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7118,
- 'author_id',
- 4,
- NULL,
- 0,
- 'int',
- '',
- '',
- ''
- );
diff --git a/store/seed/test/10073__idx.sql b/store/seed/test/10073__idx.sql
deleted file mode 100644
index dfe3f3344c..0000000000
--- a/store/seed/test/10073__idx.sql
+++ /dev/null
@@ -1,541 +0,0 @@
--- Index for database 7002 testdb_dev, table 7101 tbl1
-INSERT INTO
- idx (
- id,
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 7301,
- 101,
- 101,
- 7002,
- 7101,
- 'idx_col1',
- 'col1',
- 1,
- 'BTREE',
- 0,
- 1,
- ''
- );
-
--- Index for database 7006 testdb_dev, table 7102 tbl1
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7006,
- 7102,
- 'idx_col1',
- 'col1',
- 1,
- 'BTREE',
- 0,
- 1,
- ''
- );
-
--- Index for database 7010 testdb_dev, table 7103 tbl1
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7010,
- 7103,
- 'idx_col1',
- 'col1',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7014 testdb_dev, table 7104 tbl1
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7014,
- 7104,
- 'idx_col1',
- 'col1',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7003 shop, table 7105 product
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7003,
- 7105,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7007 shop, table 7106 product
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7007,
- 7106,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7004 blog, table 7107 user
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7107,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7004 blog, table 7108 post
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7108,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7004 blog, table 7109 comment
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7004,
- 7109,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7008 blog, table 7110 user
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7110,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7008 blog, table 7111 post
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7111,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7008 blog, table 7112 comment
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7008,
- 7112,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7012 blog, table 7113 user
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7113,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7012 blog, table 7114 post
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7114,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7012 blog, table 7115 comment
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7012,
- 7115,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7016 blog, table 7116 user
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7116,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7016 blog, table 7117 post
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7117,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
-
--- Index for database 7016 blog, table 7118 comment
-INSERT INTO
- idx (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `unique`,
- visible,
- comment
- )
-VALUES
- (
- 101,
- 101,
- 7016,
- 7118,
- 'PRIMARY',
- 'id',
- 1,
- 'BTREE',
- 1,
- 1,
- ''
- );
diff --git a/store/seed/test/10074__backup.sql b/store/seed/test/10074__backup.sql
deleted file mode 100644
index b0631239db..0000000000
--- a/store/seed/test/10074__backup.sql
+++ /dev/null
@@ -1,251 +0,0 @@
--- Backup for database 7015 (shop database in prod environment)
-INSERT INTO
- backup (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 7401,
- 101,
- 1629136800,
- 101,
- 1629136800,
- 7015,
- 'shop-prod-20210817T094000',
- 'DONE',
- 'MANUAL',
- 'LOCAL',
- 'v1_20210817094000',
- 'data/backup/db/7015/shop-prod-20210817T094000.sql',
- ''
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1629250800,
- 101,
- 1629250800,
- 7015,
- 'shop-prod-20210818T140000',
- 'DONE',
- 'MANUAL',
- 'LOCAL',
- 'v2_20210818140000',
- 'data/backup/db/7015/shop-prod-20210818T140000.sql',
- ''
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1627754400,
- 101,
- 1627754400,
- 7015,
- 'shop-prod-20210801T020000-autobackup',
- 'FAILED',
- 'AUTOMATIC',
- 'LOCAL',
- 'v3_20210801020000',
- 'data/backup/db/7015/shop-prod-20210801T020000-autobackup.sql',
- 'Something unfortunate happened. Here is a long long long long long long long long long long long long long long long long long long long long long long long long error message.'
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1628359200,
- 101,
- 1628359200,
- 7015,
- 'shop-prod-20210808T020000-autobackup',
- 'DONE',
- 'AUTOMATIC',
- 'LOCAL',
- 'v3_20210808020000',
- 'data/backup/db/7015/shop-prod-20210808T020000-autobackup.sql',
- ''
- );
-
--- Backup for database 7016 (blog database in prod environment)
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1629250800,
- 101,
- 1629250800,
- 7016,
- 'blog-prod-20210818T094000',
- 'DONE',
- 'MANUAL',
- 'LOCAL',
- 'v1_20210818094000',
- 'data/backup/db/7016/blog-prod-20210818T094000.sql',
- ''
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1629337200,
- 101,
- 1629337200,
- 7016,
- 'blog-prod-20210819T140000',
- 'DONE',
- 'MANUAL',
- 'LOCAL',
- 'v2_20210819140000',
- 'data/backup/db/7016/blog-prod-20210819T140000.sql',
- ''
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1627754400,
- 101,
- 1627754400,
- 7016,
- 'blog-prod-20210801T020000-autobackup',
- 'FAILED',
- 'AUTOMATIC',
- 'LOCAL',
- 'v3_20210801020000',
- 'data/backup/db/7016/blog-prod-20210801T020000-autobackup.sql',
- 'Something unfortunate happened. Here is a long long long long long long long long long long long long long long long long long long long long long long long long error message.'
- );
-
-INSERT INTO
- backup (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- status,
- type,
- storage_backend,
- migration_history_version,
- path,
- comment
- )
-VALUES
- (
- 101,
- 1628359200,
- 101,
- 1628359200,
- 7016,
- 'blog-prod-20210808T020000-autobackup',
- 'DONE',
- 'AUTOMATIC',
- 'LOCAL',
- 'v3_20210808020000',
- 'data/backup/db/7016/blog-prod-20210808T020000-autobackup.sql',
- ''
- );
diff --git a/store/seed/test/10080__data_source.sql b/store/seed/test/10080__data_source.sql
deleted file mode 100644
index 8eb765d6a6..0000000000
--- a/store/seed/test/10080__data_source.sql
+++ /dev/null
@@ -1,224 +0,0 @@
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8001,
- 1,
- 1,
- 6001,
- 7001,
- 'Admin data source',
- 'ADMIN',
- 'root',
- 'testpwd1'
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8002,
- 1,
- 1,
- 6002,
- 7005,
- 'Admin data source',
- 'ADMIN',
- 'admin',
- 'Integration12345'
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8003,
- 1,
- 1,
- 6003,
- 7009,
- 'Admin data source',
- 'ADMIN',
- 'admin',
- 'Staging12345'
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8004,
- 1,
- 1,
- 6004,
- 7013,
- 'Admin data source',
- 'ADMIN',
- 'root',
- 'testpwd1'
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8005,
- 1,
- 1,
- 6005,
- 7017,
- 'Admin data source',
- 'ADMIN',
- 'postgres',
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8006,
- 1,
- 1,
- 6006,
- 7018,
- 'Admin data source',
- 'ADMIN',
- 'root',
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8007,
- 1,
- 1,
- 6007,
- 7019,
- 'Admin data source',
- 'ADMIN',
- '',
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8008,
- 1,
- 1,
- 6008,
- 7020,
- 'Admin data source',
- 'ADMIN',
- '',
- ''
- );
-
-INSERT INTO
- data_source (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- name,
- TYPE,
- username,
- PASSWORD
- )
-VALUES
- (
- 8009,
- 1,
- 1,
- 6009,
- 7027,
- 'Admin data source',
- 'ADMIN',
- 'admin',
- 'Prod12345'
- );
diff --git a/store/seed/test/10090__pipeline.sql b/store/seed/test/10090__pipeline.sql
deleted file mode 100644
index abe14a2255..0000000000
--- a/store/seed/test/10090__pipeline.sql
+++ /dev/null
@@ -1,189 +0,0 @@
--- A single stage, single task "hello world"
-INSERT INTO
- pipeline (
- id,
- creator_id,
- updater_id,
- name,
- status
- )
-VALUES
- (
- 9001,
- 101,
- 101,
- 'Pipeline - Hello world',
- 'OPEN'
- );
-
--- A multiple stage Pipeline for simulating webhook push event to create table for shop project database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9002,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 'Pipeline - Create product table',
- 'OPEN'
- );
-
--- A two stage, each containing a single create table task, the 1st task has a failed task run
-INSERT INTO
- pipeline (
- id,
- creator_id,
- updater_id,
- name,
- status
- )
-VALUES
- (
- 9003,
- 103,
- 103,
- 'Pipeline - Create table ''tbl1''',
- 'CANCELED'
- );
-
--- Pipeline for simulating webhook push event to create table for blog project dev database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9004,
- 1,
- 1624865387,
- 1,
- 1624865387,
- 'Pipeline - Create user, post, comment table for dev environment',
- 'DONE'
- );
-
--- Pipeline for simulating webhook push event to create table for blog project integration database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9005,
- 1,
- 1624866790,
- 1,
- 1624866790,
- 'Pipeline - Create user, post, comment table for integration environment',
- 'DONE'
- );
-
--- Pipeline for simulating webhook push event to create table for blog project staging database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9006,
- 1,
- 1624868407,
- 1,
- 1624868407,
- 'Pipeline - Create user, post, comment table for staging environment',
- 'DONE'
- );
-
--- Pipeline for simulating webhook push event to create table for blog project prod database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9007,
- 1,
- 1624868680,
- 1,
- 1624868680,
- 'Pipeline - Create user, post, comment table for prod environment',
- 'DONE'
- );
-
--- Pipeline for simulating webhook push event to alter table for blog project dev database.
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9008,
- 1,
- 1624869944,
- 1,
- 1624869944,
- 'Pipeline - Add created_at column to user,post,comment table for dev environment',
- 'OPEN'
- );
-
--- Pipeline for multi-stage create table UI workflow
-INSERT INTO
- pipeline (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
- )
-VALUES
- (
- 9009,
- 103,
- 1624879944,
- 103,
- 1624879944,
- 'Pipeline - Create a new table tbl2',
- 'OPEN'
- );
diff --git a/store/seed/test/10100__stage.sql b/store/seed/test/10100__stage.sql
deleted file mode 100644
index a6824219f3..0000000000
--- a/store/seed/test/10100__stage.sql
+++ /dev/null
@@ -1,364 +0,0 @@
--- Stage for Pipeline 9001 "Hello world"
-INSERT INTO
- stage (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10001,
- 101,
- 101,
- 9001,
- 5004,
- 'Prod'
- );
-
--- Stage for Pipeline 9002 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10002,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 5001,
- 'Dev'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10003,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 5002,
- 'Integration'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10004,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 5003,
- 'Staging'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10005,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 5004,
- 'Prod'
- );
-
--- Stage for Pipeline 9003 create table
-INSERT INTO
- stage (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10006,
- 103,
- 103,
- 9003,
- 5001,
- 'Dev'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10007,
- 103,
- 103,
- 9003,
- 5002,
- 'Integration'
- );
-
--- Stage for Pipeline 9004 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10008,
- 1,
- 1624865387,
- 1,
- 1624865387,
- 9004,
- 5001,
- 'Dev'
- );
-
--- Stage for Pipeline 9005 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10009,
- 1,
- 1624866790,
- 1,
- 1624866790,
- 9005,
- 5002,
- 'Integration'
- );
-
--- Stage for Pipeline 9006 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10010,
- 1,
- 1624868407,
- 1,
- 1624868407,
- 9006,
- 5003,
- 'Staging'
- );
-
--- Stage for Pipeline 9007 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10011,
- 1,
- 1624868680,
- 1,
- 1624868680,
- 9007,
- 5004,
- 'Prod'
- );
-
--- Stage for Pipeline 9008 simulating webhook push event
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10012,
- 1,
- 1624869944,
- 1,
- 1624869944,
- 9008,
- 5001,
- 'Dev'
- );
-
--- Stage for Pipeline 9009 multi-stage create table UI workflow
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10013,
- 103,
- 1624879944,
- 103,
- 1624879944,
- 9009,
- 5001,
- 'Dev'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10014,
- 103,
- 1624879944,
- 103,
- 1624879944,
- 9009,
- 5002,
- 'Integration'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10015,
- 103,
- 1624879944,
- 103,
- 1624879944,
- 9009,
- 5003,
- 'Staging'
- );
-
-INSERT INTO
- stage (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- environment_id,
- name
- )
-VALUES
- (
- 10016,
- 103,
- 1624879944,
- 103,
- 1624879944,
- 9009,
- 5004,
- 'Prod'
- );
diff --git a/store/seed/test/10110__task.sql b/store/seed/test/10110__task.sql
deleted file mode 100644
index 578fed5cba..0000000000
--- a/store/seed/test/10110__task.sql
+++ /dev/null
@@ -1,519 +0,0 @@
--- Task for Pipeline 9001 "Hello world", Stage 10001 "Prod" to update database 7014 "testdb_prod"
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11001,
- 101,
- 101,
- 9001,
- 10001,
- 6004,
- 7014,
- 'Welcome',
- 'bb.task.general',
- 'PENDING_APPROVAL',
- '{"statement":"SELECT ''Welcome Tech Lead, DBA, Developer'';"}'
- );
-
--- Task for Pipeline 9002
--- Task for stage 10002 "Dev" to update database 7003 'shop'
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11002,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 10002,
- 6001,
- 7003,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10003 "Integration" to update database 7007 'shop'
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11003,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 10003,
- 6001,
- 7007,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10004 "Staging" to update database 7011 'shop'
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11004,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 10004,
- 6003,
- 7011,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'PENDING_APPROVAL',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10005 "Prod" to update database 7015 'proddb1'
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11005,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 9002,
- 10005,
- 6004,
- 7015,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'PENDING_APPROVAL',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for Pipeline 9003 create table
--- Task for stage 10006 "Dev" to craete table in database 7002 'testdb_dev'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11006,
- 103,
- 103,
- 9003,
- 10006,
- 6001,
- 7002,
- 'Update testdb_dev',
- 'bb.task.database.schema.update',
- 'FAILED',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_dev.tbl1;"}'
- );
-
--- Task for stage 10003 "Integration" to update database 7006 'testdb_integration'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11007,
- 103,
- 103,
- 9003,
- 10007,
- 6001,
- 7006,
- 'Update testdb_integration',
- 'bb.task.database.schema.update',
- 'PENDING',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl1 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_integration.tbl1;"}'
- );
-
--- Task for stage 10008 simulating webhook push event
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11008,
- 1,
- 1624865387,
- 1,
- 1624865387,
- 9004,
- 10008,
- 6001,
- 7004,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10009 simulating webhook push event
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11009,
- 1,
- 1624866790,
- 1,
- 1624866790,
- 9005,
- 10009,
- 6002,
- 7008,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"0765950c28c50dd07217aa0a133e8239e64f0ea1","title":"Create user, post, comment table for integration environment","message":"Create user, post, comment table for integration environment","createdTs":1624866787,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/0765950c28c50dd07217aa0a133e8239e64f0ea1","authorName":"tianzhou","added":"bytebase/integration/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10010 simulating webhook push event
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11010,
- 1,
- 1624868407,
- 1,
- 1624868407,
- 9006,
- 10010,
- 6003,
- 7012,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"149f18b8d94805be4b92e256ef1dc9f4a27d5157","title":"Create user, post, comment table for staging environment","message":"Create user, post, comment table for staging environment","createdTs":1624868403,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/149f18b8d94805be4b92e256ef1dc9f4a27d5157","authorName":"tianzhou","added":"bytebase/bytebase/staging/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10011 simulating webhook push event
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11011,
- 1,
- 1624868680,
- 1,
- 1624868680,
- 9007,
- 10011,
- 6004,
- 7016,
- 'Add initial schema',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"ec17d38d6581015feb49b341cc3da56cb0e354fb","title":"Create user, post, comment table for prod environment","message":"Create user, post, comment table for prod environment","createdTs":1624868676,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/ec17d38d6581015feb49b341cc3da56cb0e354fb","authorName":"tianzhou","added":"bytebase/prod/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task for stage 10012 simulating webhook push event
-INSERT INTO
- task (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11012,
- 1,
- 1624869944,
- 1,
- 1624869944,
- 9008,
- 10012,
- 6001,
- 7004,
- 'Add created at column',
- 'bb.task.database.schema.update',
- 'FAILED',
- '{"migrationType":"MIGRATE","statement":"ALTER TABLE `user` ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE post ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE comment ADD COLUMN `created_at` DATETIME NOT NULL;\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1624869938,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}}}'
- );
-
--- Task for Pipeline 9009 multi-stage create table UI workflow
--- Task for stage 10013 "Dev" to create table in database 7002 'testdb_dev'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11013,
- 103,
- 103,
- 9009,
- 10013,
- 6001,
- 7002,
- 'Update testdb_dev',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_dev.tbl2;"}'
- );
-
--- Task for stage 10014 "Integration" to create table in database 7006 'testdb_integration'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11014,
- 103,
- 103,
- 9009,
- 10014,
- 6002,
- 7006,
- 'Update testdb_integration',
- 'bb.task.database.schema.update',
- 'DONE',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl2 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_integration.tbl2;"}'
- );
-
-
--- Task for stage 10015 "Integration" to create table in database 7010 'testdb_staging'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11015,
- 103,
- 103,
- 9009,
- 10015,
- 6003,
- 7010,
- 'Update testdb_staging',
- 'bb.task.database.schema.update',
- 'FAILED',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_staging.tbl2;"}'
- );
-
--- Task for stage 10016 "prod" to create table in database 7014 'testdb_prod'
-INSERT INTO
- task (
- id,
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- type,
- status,
- payload
- )
-VALUES
- (
- 11016,
- 103,
- 103,
- 9009,
- 10016,
- 6004,
- 7014,
- 'Update testdb_prod',
- 'bb.task.database.schema.update',
- 'PENDING_APPROVAL',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_prod.tbl2 (name TEXT);", "rollbackStatement":"DROP TABLE testdb_prod.tbl2;"}'
- );
diff --git a/store/seed/test/10120__task_run.sql b/store/seed/test/10120__task_run.sql
deleted file mode 100644
index 3202b31506..0000000000
--- a/store/seed/test/10120__task_run.sql
+++ /dev/null
@@ -1,343 +0,0 @@
--- Task run for task 11002
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 101,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 11002,
- 'Add initial schema 1624873710',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task run for task 11003
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 102,
- 1,
- 1624883710,
- 1,
- 1624883710,
- 11003,
- 'Add initial schema 1624883710',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
- );
-
--- Failed task run for task 11006 create table
-INSERT INTO
- task_run (
- id,
- creator_id,
- updater_id,
- task_id,
- name,
- status,
- type,
- code,
- result
- )
-VALUES
- (
- 103,
- 101,
- 101,
- 11006,
- 'Update testdb_dev task run',
- 'FAILED',
- 'bb.task.database.schema.update',
- 103,
- '{"detail":"table \"tbl1\" already exists"}'
- );
-
--- Task run for task 11008
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 104,
- 1,
- 1624865387,
- 1,
- 1624865387,
- 11008,
- 'Add initial schema 1624865387',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task run for task 11009
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 105,
- 1,
- 1624866790,
- 1,
- 1624866790,
- 11009,
- 'Add initial schema 1624866790',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task run for task 11010
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 106,
- 1,
- 1624868407,
- 1,
- 1624868407,
- 11010,
- 'Add initial schema 1624868407',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Task run for task 11011
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 107,
- 1,
- 1624868680,
- 1,
- 1624868680,
- 11011,
- 'Add initial schema 1624868680',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}',
- '{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
- );
-
--- Failed task run for task 11012 create table
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 108,
- 1,
- 1624869944,
- 1,
- 1624869944,
- 11012,
- 'Add created at column 1624869944',
- 'FAILED',
- 'bb.task.database.schema.update',
- 201,
- '{"detail":"database ''blog'' has already applied version 202106280100"}',
- '{"migrationType":"MIGRATE","statement":"ALTER TABLE `user` ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE post ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE comment ADD COLUMN `created_at` DATETIME NOT NULL;\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1624869938,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}}}'
- );
-
--- Successful task run for task 10013 create table
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 109,
- 102,
- 1624879944,
- 102,
- 1624879944,
- 11013,
- 'Update testdb_dev task run',
- 'DONE',
- 'bb.task.database.schema.update',
- 0,
- '{"detail":"Applied migration version 20210830011437.11013 to database \"testdb_dev\"","migrationId":1,"version":"20210830011437.11013"}',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT)"}'
- );
-
--- Successful task run for task 10014 create table
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- result,
- payload
- )
-VALUES
- (
- 110,
- 102,
- 1624879944,
- 102,
- 1624879944,
- 11014,
- 'Update testdb_integration task run',
- 'DONE',
- 'bb.task.database.schema.update',
- '{"detail":"Applied migration version 20210830011437.11014 to database \"testdb_integration\"","migrationId":1,"version":"20210830011437.11014"}',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl2 (name TEXT)"}'
- );
-
--- Failed task run for task 10015 create table
-INSERT INTO
- task_run (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- result,
- payload
- )
-VALUES
- (
- 111,
- 102,
- 1624879944,
- 102,
- 1624879944,
- 11015,
- 'Update testdb_staging task run',
- 'FAILED',
- 'bb.task.database.schema.update',
- 103,
- '{"detail":"table \"tbl2\" already exists"}',
- '{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT)"}'
- );
diff --git a/store/seed/test/10121__task_check_run.sql b/store/seed/test/10121__task_check_run.sql
deleted file mode 100644
index 04831842b8..0000000000
--- a/store/seed/test/10121__task_check_run.sql
+++ /dev/null
@@ -1,54 +0,0 @@
--- Task run for task 11004
-INSERT INTO
- task_check_run (
- id,
- creator_id,
- updater_id,
- task_id,
- status,
- type,
- code,
- comment,
- result,
- payload
- )
-VALUES
- (
- 101,
- 1,
- 1,
- 11004,
- 'FAILED',
- 'bb.task-check.database.connect',
- 101,
- 'failed to connect database "shop": failed to connect database On-premises Staging MySQL/shop at "mysql.staging.example.com":"3306" with user "admin": dial tcp: lookup mysql.staging.example.com: no such host',
- '',
- ''
- );
-
-INSERT INTO
- task_check_run (
- id,
- creator_id,
- updater_id,
- task_id,
- status,
- type,
- code,
- comment,
- result,
- payload
- )
-VALUES
- (
- 102,
- 1,
- 1,
- 11004,
- 'DONE',
- 'bb.task-check.database.statement.syntax',
- 0,
- '',
- '{"resultList":[{"status":"SUCCESS","code":0,"title":"Syntax OK","content":"OK"}]}',
- '{"statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","dbType":"MYSQL","charset":"utf8mb4","collation":"utf8mb4_general_ci"}'
- );
diff --git a/store/seed/test/10130__issue.sql b/store/seed/test/10130__issue.sql
deleted file mode 100644
index 01fcae200a..0000000000
--- a/store/seed/test/10130__issue.sql
+++ /dev/null
@@ -1,275 +0,0 @@
--- Issue for the single stage, single step "Hello world" pipeline
-INSERT INTO
- issue (
- id,
- creator_id,
- updater_id,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13001,
- 1,
- 1,
- 3001,
- 9001,
- 'Hello world!',
- 'OPEN',
- 'bb.issue.general',
- 'Welcome to Bytebase, this is the issue interface where developers and DBAs collaborate on database schema management issues such as: ' || char(10, 10) || ' - Creating a new database' || char(10) || ' - Creating a table' || char(10) || ' - Creating an index' || char(10) || ' - Adding/Altering a column' || char(10) || ' - Troubleshooting performance issue' || char(10, 10) || 'Let''s try some simple tasks:' || char(10, 10) || '1. Bookmark this issue by clicking the star icon on the top of this page' || char(10) || '2. Leave a comment below to greet future comers',
- 101
- );
-
--- Issue for simulating webhook push event to create table in multi-stage for shop project.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13002,
- 103,
- 1624873710,
- 103,
- 1624873710,
- 3002,
- 9002,
- 'Create product table using multi-stage VCS workflow',
- 'OPEN',
- 'bb.issue.database.schema.update',
- 'Create product table using multi-stage VCS workflow',
- 101
- );
-
--- Issue for the multi stage create table pipeline, first stage has a failed task run
-INSERT INTO
- issue (
- id,
- creator_id,
- updater_id,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13003,
- 103,
- 103,
- 3001,
- 9003,
- 'Create a new table ''tbl1''',
- 'CANCELED',
- 'bb.issue.database.schema.update',
- 'Create tbl1.',
- 102
- );
-
--- Issue for simulating webhook push event to create table for blog project dev database.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13004,
- 1,
- 1624865387,
- 1,
- 1624865387,
- 3003,
- 9004,
- 'Create user, post, comment table for dev environment',
- 'DONE',
- 'bb.issue.database.schema.update',
- 'Create user, post, comment table for dev environment',
- 1
- );
-
--- Issue for simulating webhook push event to create table for blog project integration database.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13005,
- 1,
- 1624866790,
- 1,
- 1624866790,
- 3003,
- 9005,
- 'Create user, post, comment table for integration environment',
- 'DONE',
- 'bb.issue.database.schema.update',
- 'Create user, post, comment table for integration environment',
- 1
- );
-
--- Issue for simulating webhook push event to create table for blog project staging database.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13006,
- 1,
- 1624868407,
- 1,
- 1624868407,
- 3003,
- 9006,
- 'Create user, post, comment table for staging environment',
- 'DONE',
- 'bb.issue.database.schema.update',
- 'Create user, post, comment table for staging environment',
- 1
- );
-
--- Issue for simulating webhook push event to create table for blog project prod database.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13007,
- 1,
- 1624868680,
- 1,
- 1624868680,
- 3003,
- 9007,
- 'Create user, post, comment table for prod environment',
- 'DONE',
- 'bb.issue.database.schema.update',
- 'Create user, post, comment table for prod environment',
- 1
- );
-
--- Issue for simulating webhook push event to alter table for blog project dev database.
-INSERT INTO
- issue (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13008,
- 1,
- 1624869944,
- 1,
- 1624869944,
- 3003,
- 9008,
- 'Add created_at column to user,post,comment table for dev environment',
- 'OPEN',
- 'bb.issue.database.schema.update',
- 'Add created_at column to user,post,comment table for dev environment',
- 1
- );
-
--- Issue for multi-stage create table UI workflow
-INSERT INTO
- issue (
- id,
- creator_id,
- updater_id,
- project_id,
- pipeline_id,
- name,
- status,
- type,
- description,
- assignee_id
- )
-VALUES
- (
- 13009,
- 103,
- 103,
- 3001,
- 9009,
- 'Create a new table ''tbl2'' using multi-stage SQL review workflow',
- 'CANCELED',
- 'bb.issue.database.schema.update',
- 'Create tbl2 using multi-stage SQL review workflow',
- 102
- );
diff --git a/store/seed/test/10131__issue_subscriber.sql b/store/seed/test/10131__issue_subscriber.sql
deleted file mode 100644
index 4c2735ed8b..0000000000
--- a/store/seed/test/10131__issue_subscriber.sql
+++ /dev/null
@@ -1,123 +0,0 @@
--- Subscriber for issue 13001
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13001, 102);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13001, 103);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13001, 104);
-
--- Subscriber for issue 13002
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13002, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13002, 102);
-
--- Subscriber for issue 13003
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13003, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13003, 102);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13003, 103);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13003, 104);
-
--- Subscriber for issue 13004
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13004, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13004, 102);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13004, 103);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13004, 104);
-
--- Subscriber for issue 13005
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13005, 101);
-
--- Subscriber for issue 13006
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13006, 103);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13006, 104);
-
--- Subscriber for issue 13007
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13007, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13007, 102);
-
--- Subscriber for issue 13008
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13008, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13007, 103);
-
--- Subscriber for issue 13009
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13009, 101);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13009, 102);
-
-INSERT INTO
- issue_subscriber (issue_id, subscriber_id)
-VALUES
- (13009, 103);
diff --git a/store/seed/test/10140__activity.sql b/store/seed/test/10140__activity.sql
deleted file mode 100644
index fd781d22cd..0000000000
--- a/store/seed/test/10140__activity.sql
+++ /dev/null
@@ -1,1204 +0,0 @@
--- Activity for issue 13001
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- payload
- )
-VALUES
- (
- 14001,
- 1,
- 1,
- 13001,
- 'bb.issue.create',
- 'INFO',
- '{"issueName":"Hello world!"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- comment,
- payload
- )
-VALUES
- (
- 14002,
- 101,
- 101,
- 13001,
- 'bb.issue.comment.create',
- 'INFO',
- 'Welcome!',
- '{"issueName":"Hello world!"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- comment,
- payload
- )
-VALUES
- (
- 14003,
- 102,
- 102,
- 13001,
- 'bb.issue.comment.create',
- 'INFO',
- 'Let''s rock!',
- '{"issueName":"Hello world!"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- comment,
- payload
- )
-VALUES
- (
- 14004,
- 103,
- 103,
- 13001,
- 'bb.issue.comment.create',
- 'INFO',
- 'Go fish!',
- '{"issueName":"Hello world!"}'
- );
-
--- Activity for issue 13002
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- payload
- )
-VALUES
- (
- 14005,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.issue.create',
- 'INFO',
- '{"issueName":"Create product table"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 14006,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11002,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create product table","taskName":"Add initial schema"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 14007,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''shop''',
- '{"taskId":11002,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 14008,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11003,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 14009,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''shop''',
- '{"taskId":11003,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- payload
- )
-VALUES
- (
- 14010,
- 1,
- 1624873710,
- 1,
- 1624873710,
- 13002,
- 'bb.issue.field.update',
- 'INFO',
- '{"fieldId":"3","oldValue":"1","newValue":"101","issueName":"Create product table"}'
- );
-
--- Activity for issue 13003
-INSERT INTO
- activity (
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- payload
- )
-VALUES
- (
- 14011,
- 103,
- 1624873710,
- 103,
- 1624873710,
- 13003,
- 'bb.issue.create',
- 'INFO',
- '{"issueName":"CREATE a new TABLE ''tbl1''"}'
- );
-
--- Activity for failed task_run 12001
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 14012,
- 1,
- 1,
- 13003,
- 'bb.pipeline.task.status.update',
- 'ERROR',
- 'table "tbl1" already exists',
- '{"taskId":11006,"oldStatus":"RUNNING","newStatus":"FAILED","issueName":"Create a new table ''tbl1''","taskName":"Update testdb_dev"}'
- );
-
-INSERT INTO
- activity (
- id,
- creator_id,
- updater_id,
- container_id,
- type,
- level,
- payload
- )
-VALUES
- (
- 14013,
- 102,
- 102,
- 13003,
- 'bb.issue.status.update',
- 'INFO',
- '{"oldStatus":"OPEN","newStatus":"CANCELED","issueName":"Create a new table ''tbl1''"}'
- );
-
--- Activity for issue 13004
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624865387,
- 1,
- 1624865387,
- 13004,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Create user, post, comment table for dev environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624865388,
- 1,
- 1624865388,
- 13004,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11008,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624865388,
- 1,
- 1624865388,
- 13004,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''blog''',
- '{"taskId":11008,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624865388,
- 1,
- 1624865388,
- 13004,
- 'bb.issue.status.update',
- 'INFO',
- '',
- '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for dev environment"}'
- );
-
--- Activity for issue 13005
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624866790,
- 1,
- 1624866790,
- 13005,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Create user, post, comment table for integration environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624866791,
- 1,
- 1624866791,
- 13005,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11009,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624866791,
- 1,
- 1624866791,
- 13005,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''blog''',
- '{"taskId":11009,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624866791,
- 1,
- 1624866791,
- 13005,
- 'bb.issue.status.update',
- 'INFO',
- '',
- '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for integration environment"}'
- );
-
--- Activity for issue 13006
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868407,
- 1,
- 1624868407,
- 13006,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Create user, post, comment table for staging environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868408,
- 1,
- 1624868408,
- 13006,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11010,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868408,
- 1,
- 1624868408,
- 13006,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''blog''',
- '{"taskId":11010,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868408,
- 1,
- 1624868408,
- 13006,
- 'bb.issue.status.update',
- 'INFO',
- '',
- '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for staging environment"}'
- );
-
--- Activity for issue 13007
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868680,
- 1,
- 1624868680,
- 13007,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Create user, post, comment table for prod environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868681,
- 1,
- 1624868681,
- 13007,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11011,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868681,
- 1,
- 1624868681,
- 13007,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Established baseline version 202106280000 for database ''blog''',
- '{"taskId":11011,"oldStatus":"RUNNING","newStatus":"DONE"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624868681,
- 1,
- 1624868681,
- 13007,
- 'bb.issue.status.update',
- 'INFO',
- '',
- '{"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create user, post, comment table for prod environment"}'
- );
-
--- Activity for issue 13008
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624869944,
- 1,
- 1624869944,
- 13008,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Add created_at column to user,post,comment table for dev environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624869945,
- 1,
- 1624869945,
- 13008,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11012,"oldStatus":"PENDING","newStatus":"RUNNING"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624869945,
- 1,
- 1624869945,
- 13008,
- 'bb.pipeline.task.status.update',
- 'ERROR',
- 'database ''blog'' has already applied version 202106280100',
- '{"taskId":11012,"oldStatus":"RUNNING","newStatus":"FAILED"}'
- );
-
--- Activity for issue 13009
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 103,
- 1624879944,
- 103,
- 1624879944,
- 13009,
- 'bb.issue.create',
- 'INFO',
- '',
- '{"issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11015,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_dev"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Applied migration version 20210830011437.11013 to database "testdb_dev"',
- '{"taskId":11013,"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_dev"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11014,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_integration"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'INFO',
- 'Applied migration version 20210830011437.11014 to database "testdb_integration"',
- '{"taskId":11014,"oldStatus":"RUNNING","newStatus":"DONE","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_integration"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'INFO',
- '',
- '{"taskId":11015,"oldStatus":"PENDING","newStatus":"RUNNING","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_staging"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 13009,
- 'bb.pipeline.task.status.update',
- 'ERROR',
- 'table "tbl2" already exists',
- '{"taskId":11015,"oldStatus":"RUNNING","newStatus":"FAILED","issueName":"Create a new table ''tbl2'' using multi-stage SQL review workflow","taskName":"Update testdb_staging"}'
- );
-
--- Project activity for 3001
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 102,
- 1624879944,
- 102,
- 1624879944,
- 3001,
- 'bb.project.member.role.update',
- 'INFO',
- 'Changed Demo Owner ([email protected]) from OWNER to DEVELOPER.',
- ''
- );
-
--- Project activity for 3002
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 101,
- 1624879944,
- 101,
- 1624879944,
- 3002,
- 'bb.project.member.create',
- 'INFO',
- 'Granted Jerry DBA to [email protected] (DEVELOPER).',
- ''
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3002,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Create product table using multi-stage VCS workflow".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs": 1630940811,"url":"https://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}},"issueId":13002,"issueName":"Create product table using multi-stage VCS workflow"}'
- );
-
--- Project activity for 3003
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 101,
- 1624879944,
- 101,
- 1624879944,
- 3003,
- 'bb.project.member.create',
- 'INFO',
- 'Granted Tom Dev to [email protected] (DEVELOPER).',
- ''
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3003,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Add created_at column to user,post,comment table for dev environment".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1630943211,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}},"issueId":13008,"issueName":"Add created_at column to user,post,comment table for dev environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3003,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Create user, post, comment table for dev environment".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13004,"issueName":"Create user, post, comment table for dev environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3003,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Create user, post, comment table for integration environment".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"0765950c28c50dd07217aa0a133e8239e64f0ea1","title":"Create user, post, comment table for integration environment","message":"Create user, post, comment table for integration environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/0765950c28c50dd07217aa0a133e8239e64f0ea1","authorName":"tianzhou","added":"bytebase/integration/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13005,"issueName":"Create user, post, comment table for integration environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3003,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Create user, post, comment table for staging environment".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"149f18b8d94805be4b92e256ef1dc9f4a27d5157","title":"Create user, post, comment table for staging environment","message":"Create user, post, comment table for staging environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/149f18b8d94805be4b92e256ef1dc9f4a27d5157","authorName":"tianzhou","added":"bytebase/staging/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13006,"issueName":"Create user, post, comment table for staging environment"}'
- );
-
-INSERT INTO
- activity (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- container_id,
- type,
- level,
- COMMENT,
- payload
- )
-VALUES
- (
- 1,
- 1624879944,
- 1,
- 1624879944,
- 3003,
- 'bb.project.repository.push',
- 'INFO',
- 'Created issue "Create user, post, comment table for prod environment".',
- '{"pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"ec17d38d6581015feb49b341cc3da56cb0e354fb","title":"Create user, post, comment table for prod environment","message":"Create user, post, comment table for prod environment","createdTs": 1630941711,"url":"https://gitlab.bytebase.com/bytebase-demo/blog/-/commit/ec17d38d6581015feb49b341cc3da56cb0e354fb","authorName":"tianzhou","added":"bytebase/prod/blog__202106280000__baseline__add_initial_schema.sql"}},"issueId":13006,"issueName":"Create user, post, comment table for prod environment"}'
- );
diff --git a/store/seed/test/10150__inbox.sql b/store/seed/test/10150__inbox.sql
deleted file mode 100644
index 001c873adb..0000000000
--- a/store/seed/test/10150__inbox.sql
+++ /dev/null
@@ -1,179 +0,0 @@
--- Inbox for receiver 101
-INSERT INTO
- inbox (
- id,
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (
- 15001,
- 101,
- 14001,
- 'READ'
- );
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14003, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14004, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14005, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14010, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14012, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (101, 14013, 'UNREAD');
-
--- Inbox for receiver 102
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14001, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14002, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14004, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14005, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14006, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (102, 14013, 'UNREAD');
-
--- Inbox for receiver 103
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14001, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14002, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14003, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14005, 'READ');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14006, 'UNREAD');
-
-INSERT INTO
- inbox (
- receiver_id,
- activity_id,
- status
- )
-VALUES
- (103, 14013, 'UNREAD');
diff --git a/store/seed/test/10160__bookmark.sql b/store/seed/test/10160__bookmark.sql
deleted file mode 100644
index 9832892f65..0000000000
--- a/store/seed/test/10160__bookmark.sql
+++ /dev/null
@@ -1,17 +0,0 @@
--- Bookmark for issue 13001 "Hello world"
-INSERT INTO
- bookmark (
- id,
- creator_id,
- updater_id,
- name,
- link
- )
-VALUES
- (
- 16001,
- 101,
- 101,
- 'Hello world!',
- '/issue/hello-world-13001'
- );
diff --git a/store/seed/test/10170__vcs.sql b/store/seed/test/10170__vcs.sql
deleted file mode 100644
index e9b9cfcd44..0000000000
--- a/store/seed/test/10170__vcs.sql
+++ /dev/null
@@ -1,25 +0,0 @@
--- This is for demo purpose and the applciation_id has alraedy been deleted
-INSERT INTO
- vcs (
- id,
- creator_id,
- updater_id,
- name,
- type,
- instance_url,
- api_url,
- application_id,
- secret
- )
-VALUES
- (
- 17001,
- 101,
- 101,
- 'bytebase.gitlab.com',
- 'GITLAB_SELF_HOST',
- 'https://gitlab.bytebase.com',
- 'https://gitlab.bytebase.com/api/v4',
- 'fda62e44b5388b1ca6e72d5a7028a3c2c47157fc13fd98328e2bd446fae98fd8',
- '4ac5cf6f2e400398e34f753a5222432838e84349e8d5120c4adaa6a65278b765'
- );
diff --git a/store/seed/test/10180__repository.sql b/store/seed/test/10180__repository.sql
deleted file mode 100644
index dd308e8a6f..0000000000
--- a/store/seed/test/10180__repository.sql
+++ /dev/null
@@ -1,148 +0,0 @@
--- This is for demo purpose and the webhook has already been deleted
-INSERT INTO
- repository (
- id,
- creator_id,
- updater_id,
- vcs_id,
- project_id,
- name,
- full_path,
- web_url,
- branch_filter,
- base_directory,
- file_path_template,
- schema_path_template,
- external_id,
- external_webhook_id,
- webhook_url_host,
- webhook_endpoint_id,
- webhook_secret_token,
- access_token,
- expires_ts,
- refresh_token
- )
-VALUES
- (
- 18001,
- 101,
- 101,
- 17001,
- 3003,
- "Blog",
- "bytebase-demo/blog",
- "http://gitlab.bytebase.com/bytebase-demo/blog",
- "master",
- "bytebase",
- "{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql",
- "{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql",
- -- Refers to the bytebase-demo/blog
- "13",
- -- Refers to the webhook in bytebase-demo/blog
- "60",
- "https://demo.bytebase.com",
- "e99bf622-7f58-4d6b-a5be-b97af313d7ea",
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- 0,
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- );
-
-INSERT INTO
- repository (
- id,
- creator_id,
- updater_id,
- vcs_id,
- project_id,
- name,
- full_path,
- web_url,
- branch_filter,
- base_directory,
- file_path_template,
- schema_path_template,
- external_id,
- external_webhook_id,
- webhook_url_host,
- webhook_endpoint_id,
- webhook_secret_token,
- access_token,
- expires_ts,
- refresh_token
- )
-VALUES
- (
- 18002,
- 101,
- 101,
- 17001,
- 3002,
- "Shop",
- "bytebase-demo/shop",
- "http://gitlab.bytebase.com/bytebase-demo/shop",
- "master",
- "bytebase",
- "{{ENV_NAME}}/{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql",
- "{{ENV_NAME}}/.{{DB_NAME}}__LATEST.sql",
- -- Refers to the bytebase-demo/shop
- "14",
- -- Refers to the webhook in bytebase-demo/shop
- "61",
- "https://demo.bytebase.com",
- "c5e30130-7322-4f84-953a-d08168c047d1",
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- 0,
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- );
-
--- This is for demo purpose and the webhook has already been deleted
-INSERT INTO
- repository (
- id,
- creator_id,
- updater_id,
- vcs_id,
- project_id,
- name,
- full_path,
- web_url,
- branch_filter,
- base_directory,
- file_path_template,
- schema_path_template,
- external_id,
- external_webhook_id,
- webhook_url_host,
- webhook_endpoint_id,
- webhook_secret_token,
- access_token,
- expires_ts,
- refresh_token
- )
-VALUES
- (
- 18003,
- 101,
- 101,
- 17001,
- 3005,
- "Tenant",
- "bytebase-demo/tenant",
- "http://gitlab.bytebase.com/bytebase-demo/tenant",
- "master",
- "bytebase",
- "{{DB_NAME}}__{{VERSION}}__{{TYPE}}__{{DESCRIPTION}}.sql",
- ".{{DB_NAME}}__LATEST.sql",
- -- Refers to the bytebase-demo/tenant
- "15",
- -- Refers to the webhook in bytebase-demo/tenant
- "62",
- "https://demo.bytebase.com",
- "e48bf625-7f58-4d6b-a5be-b97af313d7ea",
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- 0,
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- );
diff --git a/store/seed/test/10190__anomaly.sql b/store/seed/test/10190__anomaly.sql
deleted file mode 100644
index 767393c1ab..0000000000
--- a/store/seed/test/10190__anomaly.sql
+++ /dev/null
@@ -1,113 +0,0 @@
--- Database anomalies
-INSERT INTO
- anomaly (
- id,
- creator_id,
- updater_id,
- instance_id,
- database_id,
- type,
- payload
- )
-VALUES
- (
- 19001,
- 1,
- 1,
- 6004,
- 7014,
- 'bb.anomaly.database.connection',
- '{"detail":"failed to connect database at mysql.prod.example.com:3306 with user \"root\": dial tcp: lookup mysql.prod.example.com: no such host"}'
- );
-
-INSERT INTO
- anomaly (
- creator_id,
- updater_id,
- instance_id,
- database_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 6004,
- 7014,
- 'bb.anomaly.database.backup.policy-violation',
- '{"environmentId":5004,"expectedSchedule":"DAILY","actualSchedule":"UNSET"}'
- );
-
-INSERT INTO
- anomaly (
- creator_id,
- updater_id,
- instance_id,
- database_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 6003,
- 7012,
- 'bb.anomaly.database.connection',
- '{"detail":"failed to connect database at mysql.staging.example.com:3306 with user \"root\": dial tcp: lookup mysql.staging.example.com: no such host"}'
- );
-
-INSERT INTO
- anomaly (
- creator_id,
- updater_id,
- instance_id,
- database_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 6003,
- 7012,
- 'bb.anomaly.database.backup.policy-violation',
- '{"environmentId":5003,"expectedSchedule":"WEEKLY","actualSchedule":"UNSET"}'
- );
-
--- Instance anomalies
-INSERT INTO
- anomaly (
- creator_id,
- updater_id,
- instance_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 6004,
- 'bb.anomaly.instance.connection',
- '{"detail":"failed to connect database at mysql.prod.example.com:3306 with user \"root\": dial tcp: lookup mysql.prod.example.com: no such host"}'
- );
-
-INSERT INTO
- anomaly (
- creator_id,
- updater_id,
- instance_id,
- type,
- payload
- )
-VALUES
- (
- 1,
- 1,
- 6003,
- 'bb.anomaly.instance.connection',
- '{"detail":"failed to connect database at mysql.staging.example.com:3306 with user \"admin\": dial tcp: lookup mysql.staging.example.com: no such host"}'
- );
diff --git a/store/seed/test/10200__label.sql b/store/seed/test/10200__label.sql
deleted file mode 100644
index c1a6899b3a..0000000000
--- a/store/seed/test/10200__label.sql
+++ /dev/null
@@ -1,252 +0,0 @@
--- Label key for `bb.location`.
-INSERT INTO
- label_key (
- id,
- creator_id,
- updater_id,
- key
- )
-VALUES
- (
- 20001,
- 1,
- 1,
- 'bb.location'
- );
-
--- Label key for `bb.tenant`.
-INSERT INTO
- label_key (
- id,
- creator_id,
- updater_id,
- key
- )
-VALUES
- (
- 20002,
- 1,
- 1,
- 'bb.tenant'
- );
-
--- Label values.
-INSERT INTO
- label_value (
- id,
- creator_id,
- updater_id,
- key,
- value
- )
-VALUES
- (
- 20010,
- 1,
- 1,
- "bb.location",
- "earth"
- );
-
-INSERT INTO
- label_value (
- id,
- creator_id,
- updater_id,
- key,
- value
- )
-VALUES
- (
- 20011,
- 1,
- 1,
- "bb.tenant",
- "bytebase"
- );
-
-INSERT INTO
- label_value (
- id,
- creator_id,
- updater_id,
- key,
- value
- )
-VALUES
- (
- 20012,
- 1,
- 1,
- "bb.tenant",
- "tenant1"
- );
-
-INSERT INTO
- label_value (
- id,
- creator_id,
- updater_id,
- key,
- value
- )
-VALUES
- (
- 20013,
- 1,
- 1,
- "bb.tenant",
- "tenant2"
- );
-
--- Database labels for database in tenant mode disabled project.
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20021,
- 1,
- 1,
- 7002,
- "bb.location",
- "earth"
- );
-
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20022,
- 1,
- 1,
- 7002,
- "bb.tenant",
- "bytebase"
- );
-
--- Database labels for database in tenant mode project.
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20023,
- 1,
- 1,
- 7021,
- "bb.location",
- "earth"
- );
-
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20024,
- 1,
- 1,
- 7022,
- "bb.tenant",
- "bytebase"
- );
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20025,
- 1,
- 1,
- 7023,
- "bb.location",
- "earth"
- );
-
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20026,
- 1,
- 1,
- 7024,
- "bb.tenant",
- "bytebase"
- );
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20027,
- 1,
- 1,
- 7025,
- "bb.tenant",
- "tenant1"
- );
-
-INSERT INTO
- db_label (
- id,
- creator_id,
- updater_id,
- database_id,
- key,
- value
- )
-VALUES
- (
- 20028,
- 1,
- 1,
- 7026,
- "bb.tenant",
- "tenant2"
- );
diff --git a/store/seed/test/10210__deployment_config.sql b/store/seed/test/10210__deployment_config.sql
deleted file mode 100644
index e9c45b34ec..0000000000
--- a/store/seed/test/10210__deployment_config.sql
+++ /dev/null
@@ -1,58 +0,0 @@
--- Deployment config with regional deployments for tenant mode project.
-INSERT INTO
- deployment_config (
- id,
- creator_id,
- updater_id,
- project_id,
- name,
- config
- )
-VALUES
- (
- 21001,
- 101,
- 101,
- 3005,
- 'regional-1',
- '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
- );
-
-INSERT INTO
- deployment_config (
- id,
- creator_id,
- updater_id,
- project_id,
- name,
- config
- )
-VALUES
- (
- 21002,
- 101,
- 101,
- 3006,
- 'regional-2',
- '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.location","operator":"In","values":["earth"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
- );
-
-
-INSERT INTO
- deployment_config (
- id,
- creator_id,
- updater_id,
- project_id,
- name,
- config
- )
-VALUES
- (
- 21003,
- 101,
- 101,
- 3007,
- 'db-pattern',
- '{"deployments":[{"name":"Dev Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Dev"]},{"key":"bb.tenant","operator":"In","values":["tenant1"]}]}}},{"name":"Integration Stage","spec":{"selector":{"matchExpressions":[{"key":"bb.environment","operator":"In","values":["Integration"]},{"key":"bb.tenant","operator":"Exists"}]}}}]}'
- );
diff --git a/store/seed/test/README.md b/store/seed/test/README.md
deleted file mode 100644
index c30cb3d170..0000000000
--- a/store/seed/test/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-This folder contains the seed data for test. The test seed data is used when NOT building with "release" tag or running with --demo. Test seed data is
-reloaded everytime we start the application (by setting forceResetSeed in the dev profile from the code)
-
-Each file represents the data for a particular table. The file name is something like YXXXX, where Y is the major version number and XXXX is the id
-start sequence number for that table, reasons for doing this:
-
-- Y (majar version number) corresponds to the major schema version the seed file applies to
-
-- Code loads the seed data in lexical file order, thus we maintain an explict order about how seed data is loaded since there exists order dependency between tables.
-
-- Because XXXX corresponds to the id prefix for the record, so we can identify the resource type by just looking the id, and catch errors that our code accidentally passes an ID for a different resource type.
diff --git a/store/setting.go b/store/setting.go
index 175d13a4ae..1f3fe607e8 100644
--- a/store/setting.go
+++ b/store/setting.go
@@ -42,20 +42,13 @@ func (s *SettingService) CreateSettingIfNotExist(ctx context.Context, create *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
setting, err := pgCreateSetting(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createSetting(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -72,7 +65,6 @@ func (s *SettingService) FindSettingList(ctx context.Context, find *api.SettingF
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findSettingList(ctx, tx.PTx, find)
@@ -89,7 +81,6 @@ func (s *SettingService) FindSetting(ctx context.Context, find *api.SettingFind)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findSettingList(ctx, tx.PTx, find)
@@ -112,20 +103,13 @@ func (s *SettingService) PatchSetting(ctx context.Context, patch *api.SettingPat
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
setting, err := pgPatchSetting(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchSetting(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -133,45 +117,6 @@ func (s *SettingService) PatchSetting(ctx context.Context, patch *api.SettingPat
return setting, nil
}
-// 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 (
- creator_id,
- updater_id,
- name,
- value,
- description
- )
- VALUES (?, ?, ?, ?, ?)
- RETURNING name, value, description
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- create.Value,
- create.Description,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var setting api.Setting
- if err := row.Scan(
- &setting.Name,
- &setting.Value,
- &setting.Description,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &setting, nil
-}
-
// pgCreateSetting creates a new setting.
func pgCreateSetting(ctx context.Context, tx *sql.Tx, create *api.SettingCreate) (*api.Setting, error) {
// Insert row into database.
@@ -261,48 +206,6 @@ func findSettingList(ctx context.Context, tx *sql.Tx, find *api.SettingFind) (_
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "value = ?"), append(args, patch.Value)
-
- args = append(args, patch.Name)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE setting
- SET `+strings.Join(set, ", ")+`
- WHERE name = ?
- RETURNING creator_id, created_ts, updater_id, updated_ts, name, value, description
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var setting api.Setting
- if err := row.Scan(
- &setting.CreatorID,
- &setting.CreatedTs,
- &setting.UpdaterID,
- &setting.UpdatedTs,
- &setting.Name,
- &setting.Value,
- &setting.Description,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &setting, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("setting not found: %s", patch.Name)}
-}
-
// 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) {
// Build UPDATE clause.
diff --git a/store/sheet.go b/store/sheet.go
index 0278d68fc9..7788504e71 100644
--- a/store/sheet.go
+++ b/store/sheet.go
@@ -32,20 +32,13 @@ func (s *SheetService) CreateSheet(ctx context.Context, create *api.SheetCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
sheet, err := pgCreateSheet(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createSheet(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,20 +52,13 @@ func (s *SheetService) PatchSheet(ctx context.Context, patch *api.SheetPatch) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
sheet, err := pgPatchSheet(ctx, tx.PTx, patch)
if err != nil {
return nil, err
}
- if _, err := patchSheet(ctx, tx.Tx, patch); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -86,7 +72,6 @@ func (s *SheetService) FindSheetList(ctx context.Context, find *api.SheetFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findSheetList(ctx, tx.PTx, find)
@@ -104,7 +89,6 @@ func (s *SheetService) FindSheet(ctx context.Context, find *api.SheetFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findSheetList(ctx, tx.PTx, find)
@@ -127,19 +111,12 @@ func (s *SheetService) DeleteSheet(ctx context.Context, delete *api.SheetDelete)
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteSheet(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteSheet(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -147,61 +124,6 @@ func (s *SheetService) DeleteSheet(ctx context.Context, delete *api.SheetDelete)
return nil
}
-// 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,
- updater_id,
- instance_id,
- database_id,
- name,
- statement,
- visibility
- )
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, name, statement, visibility
- `,
- create.CreatorID,
- create.CreatorID,
- create.InstanceID,
- create.DatabaseID,
- create.Name,
- create.Statement,
- create.Visibility,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var sheet api.Sheet
- databaseID := sql.NullInt32{}
- if err := row.Scan(
- &sheet.ID,
- &sheet.CreatorID,
- &sheet.CreatedTs,
- &sheet.UpdaterID,
- &sheet.UpdatedTs,
- &sheet.InstanceID,
- &databaseID,
- &sheet.Name,
- &sheet.Statement,
- &sheet.Visibility,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- if databaseID.Valid {
- value := int(databaseID.Int32)
- sheet.DatabaseID = &value
- }
-
- return &sheet, nil
-}
-
// pgCreateSheet creates a new sheet.
func pgCreateSheet(ctx context.Context, tx *sql.Tx, create *api.SheetCreate) (*api.Sheet, error) {
row, err := tx.QueryContext(ctx, `
@@ -257,64 +179,6 @@ func pgCreateSheet(ctx context.Context, tx *sql.Tx, create *api.SheetCreate) (*a
return &sheet, nil
}
-// patchSheet creates a new sheet.
-func patchSheet(ctx context.Context, tx *sql.Tx, patch *api.SheetPatch) (*api.Sheet, error) {
- set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, api.RowStatus(*v))
- }
- if v := patch.Statement; v != nil {
- set, args = append(set, "statement = ?"), append(args, *v)
- }
- if v := patch.Visibility; v != nil {
- set, args = append(set, "visibility = ?"), append(args, *v)
- }
-
- args = append(args, patch.ID)
-
- row, err := tx.QueryContext(ctx, `
- UPDATE sheet
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, instance_id, database_id, name, statement, visibility
- `,
- args...,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var sheet api.Sheet
- databaseID := sql.NullInt32{}
- if err := row.Scan(
- &sheet.ID,
- &sheet.CreatorID,
- &sheet.CreatedTs,
- &sheet.UpdaterID,
- &sheet.UpdatedTs,
- &sheet.InstanceID,
- &databaseID,
- &sheet.Name,
- &sheet.Statement,
- &sheet.Visibility,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- if databaseID.Valid {
- value := int(databaseID.Int32)
- sheet.DatabaseID = &value
- }
-
- return &sheet, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("sheet ID not found: %d", patch.ID)}
-}
-
// pgPatchSheet creates a new sheet.
func pgPatchSheet(ctx context.Context, tx *sql.Tx, patch *api.SheetPatch) (*api.Sheet, error) {
set, args := []string{"updater_id = $1"}, []interface{}{patch.UpdaterID}
@@ -458,21 +322,6 @@ func findSheetList(ctx context.Context, tx *sql.Tx, find *api.SheetFind) (_ []*a
return list, nil
}
-// deleteSheet permanently deletes a sheet by ID.
-func deleteSheet(ctx context.Context, tx *sql.Tx, delete *api.SheetDelete) error {
- result, err := tx.ExecContext(ctx, `DELETE FROM sheet WHERE id = ?`, delete.ID)
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &common.Error{Code: common.NotFound, Err: fmt.Errorf("sheet ID not found: %d", delete.ID)}
- }
-
- return nil
-}
-
// pgDeleteSheet permanently deletes a sheet by ID.
func pgDeleteSheet(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 {
diff --git a/store/sqlite.go b/store/sqlite.go
index edc8021def..e0acd14bb3 100644
--- a/store/sqlite.go
+++ b/store/sqlite.go
@@ -55,9 +55,6 @@ var migrationFS embed.FS
//go:embed pg_migration
var pgMigrationFS embed.FS
-//go:embed seed
-var seedFS embed.FS
-
//go:embed pg_seed
var pgSeedFS embed.FS
@@ -139,14 +136,6 @@ func (db *DB) Open() (err error) {
return fmt.Errorf("failed to get current schema version: %w", err)
}
- 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 bytebase_dev.db,"+
- " bytebase_dev.db-shm, bytebase_dev.db-wal under the same directory where the bytebase binary resides. and restart again to let"+
- " Bytebase create the latest schema. If you are running in production and don't want to reset the data, you can contact [email protected] for help",
- err)
- }
-
if err := db.pgSeed(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"+
@@ -173,41 +162,6 @@ func (db *DB) version() (ver version, err error) {
return versionFromInt(version), nil
}
-// 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
- }
-
- // We separate seed data for each table into their own seed file.
- // And there exists foreign key dependency among tables, so we
- // name the seed file as 10001_xxx.sql, 10002_xxx.sql. Here we sort
- // the file name so they are loaded accordingly.
- sort.Strings(names)
-
- // Loop over all seed files and execute them in order.
- for _, name := range names {
- versionPrefix := strings.Split(filepath.Base(name), "__")[0]
- version, err := strconv.Atoi(versionPrefix)
- if err != nil {
- return fmt.Errorf("invalid seed file format %s, expected number prefix", filepath.Base(name))
- }
- ver := versionFromInt(version)
- if db.forceResetSeed || ver.biggerThan(verBefore) && !ver.biggerThan(verAfter) {
- if err := db.seedFile(name); err != nil {
- return fmt.Errorf("seed error: name=%q err=%w", name, err)
- }
- } else {
- db.l.Info(fmt.Sprintf("Skip this seed file: %s. The corresponding seed version %s is not in the applicable range (%s, %s].",
- name, ver, verBefore, verAfter))
- }
- }
- db.l.Info("Completed database seeding.")
- return 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))
@@ -243,25 +197,6 @@ func (db *DB) pgSeed(verBefore, verAfter version) error {
return nil
}
-// 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.Db.Begin()
- if err != nil {
- return err
- }
- defer tx.Rollback()
-
- // Read and execute migration file.
- if buf, err := fs.ReadFile(seedFS, name); err != nil {
- return err
- } else if _, err := tx.Exec(string(buf)); err != nil {
- return err
- }
-
- return tx.Commit()
-}
-
// pgSeedFile runs a single seed file within a transaction.
func (db *DB) pgSeedFile(name string) error {
db.l.Info(fmt.Sprintf("Seeding %s...", name))
@@ -428,10 +363,6 @@ 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) {
- tx, err := db.Db.BeginTx(ctx, opts)
- if err != nil {
- return nil, err
- }
ptx, err := db.PgDB.BeginTx(ctx, opts)
if err != nil {
return nil, err
@@ -439,7 +370,6 @@ func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
// Return wrapper Tx that includes the transaction start time.
return &Tx{
- Tx: tx,
PTx: ptx,
db: db,
now: db.Now().UTC().Truncate(time.Second),
@@ -448,7 +378,6 @@ func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
// Tx wraps the SQL Tx object to provide a timestamp at the start of the transaction.
type Tx struct {
- Tx *sql.Tx
PTx *sql.Tx
db *DB
now time.Time
diff --git a/store/stage.go b/store/stage.go
index 10b1ce6e49..2c045a2ac9 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -32,20 +32,13 @@ func (s *StageService) CreateStage(ctx context.Context, create *api.StageCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
stage, err := s.pgCreateStage(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createStage(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *StageService) FindStageList(ctx context.Context, find *api.StageFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findStageList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findStageList(ctx, tx.PTx, find)
@@ -93,49 +84,6 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api
return list[0], nil
}
-// 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,
- updater_id,
- pipeline_id,
- environment_id,
- name
- )
- VALUES (?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, pipeline_id, environment_id, name`+`
- `,
- create.CreatorID,
- create.CreatorID,
- create.PipelineID,
- create.EnvironmentID,
- create.Name,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var stage api.Stage
- if err := row.Scan(
- &stage.ID,
- &stage.CreatorID,
- &stage.CreatedTs,
- &stage.UpdaterID,
- &stage.UpdatedTs,
- &stage.PipelineID,
- &stage.EnvironmentID,
- &stage.Name,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &stage, nil
-}
-
// pgCreateStage creates a new stage.
func (s *StageService) pgCreateStage(ctx context.Context, tx *sql.Tx, create *api.StageCreate) (*api.Stage, error) {
row, err := tx.QueryContext(ctx, `
diff --git a/store/table.go b/store/table.go
index 834d4a16bf..34422c7a7c 100644
--- a/store/table.go
+++ b/store/table.go
@@ -32,20 +32,13 @@ func (s *TableService) CreateTable(ctx context.Context, create *api.TableCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
table, err := s.pgCreateTable(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createTable(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,10 +52,9 @@ func (s *TableService) FindTableList(ctx context.Context, find *api.TableFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findTableList(ctx, tx, find)
+ list, err := s.findTableList(ctx, tx.PTx, find)
if err != nil {
return []*api.Table{}, err
}
@@ -77,10 +69,9 @@ func (s *TableService) FindTable(ctx context.Context, find *api.TableFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findTableList(ctx, tx, find)
+ list, err := s.findTableList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -99,19 +90,12 @@ func (s *TableService) DeleteTable(ctx context.Context, delete *api.TableDelete)
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteTable(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteTable(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -119,78 +103,6 @@ func (s *TableService) DeleteTable(ctx context.Context, delete *api.TableDelete)
return nil
}
-// 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 (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- type,
- engine,
- collation,
- row_count,
- data_size,
- index_size,
- data_free,
- create_options,
- comment
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, type, engine, collation, row_count, data_size, index_size, data_free, create_options, comment
- `,
- create.CreatorID,
- create.CreatedTs,
- create.CreatorID,
- create.UpdatedTs,
- create.DatabaseID,
- create.Name,
- create.Type,
- create.Engine,
- create.Collation,
- create.RowCount,
- create.DataSize,
- create.IndexSize,
- create.DataFree,
- create.CreateOptions,
- create.Comment,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var table api.Table
- if err := row.Scan(
- &table.ID,
- &table.CreatorID,
- &table.CreatedTs,
- &table.UpdaterID,
- &table.UpdatedTs,
- &table.DatabaseID,
- &table.Name,
- &table.Type,
- &table.Engine,
- &table.Collation,
- &table.RowCount,
- &table.DataSize,
- &table.IndexSize,
- &table.DataFree,
- &table.CreateOptions,
- &table.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &table, nil
-}
-
// pgCreateTable creates a new table.
func (s *TableService) pgCreateTable(ctx context.Context, tx *sql.Tx, create *api.TableCreate) (*api.Table, error) {
// Insert row into table.
@@ -263,7 +175,7 @@ func (s *TableService) pgCreateTable(ctx context.Context, tx *sql.Tx, create *ap
return &table, nil
}
-func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.TableFind) (_ []*api.Table, err error) {
+func (s *TableService) findTableList(ctx context.Context, tx *sql.Tx, find *api.TableFind) (_ []*api.Table, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
@@ -276,7 +188,7 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -337,15 +249,6 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
return list, nil
}
-// 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 = ?`, delete.DatabaseID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteTable permanently deletes tables from a database.
func pgDeleteTable(ctx context.Context, tx *sql.Tx, delete *api.TableDelete) error {
// Remove row from database.
diff --git a/store/table_index.go b/store/table_index.go
index 275d589a95..c7d8957eff 100644
--- a/store/table_index.go
+++ b/store/table_index.go
@@ -32,20 +32,13 @@ func (s *IndexService) CreateIndex(ctx context.Context, create *api.IndexCreate)
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
index, err := s.pgCreateIndex(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createIndex(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *IndexService) FindIndexList(ctx context.Context, find *api.IndexFind) (
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findIndexList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findIndexList(ctx, tx.PTx, find)
@@ -93,68 +84,6 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api
return list[0], nil
}
-// 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 (
- creator_id,
- updater_id,
- database_id,
- table_id,
- name,
- expression,
- position,
- type,
- `+"`unique`,"+`
- visible,
- comment
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, table_id, name, expression, position, type, `unique`, visible, comment"+`
- `,
- create.CreatorID,
- create.CreatorID,
- create.DatabaseID,
- create.TableID,
- create.Name,
- create.Expression,
- create.Position,
- create.Type,
- create.Unique,
- create.Visible,
- create.Comment,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var index api.Index
- if err := row.Scan(
- &index.ID,
- &index.CreatorID,
- &index.CreatedTs,
- &index.UpdaterID,
- &index.UpdatedTs,
- &index.DatabaseID,
- &index.TableID,
- &index.Name,
- &index.Expression,
- &index.Position,
- &index.Type,
- &index.Unique,
- &index.Visible,
- &index.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &index, nil
-}
-
// pgCreateIndex creates a new index.
func (s *IndexService) pgCreateIndex(ctx context.Context, tx *sql.Tx, create *api.IndexCreate) (*api.Index, error) {
// Insert row into index.
diff --git a/store/task.go b/store/task.go
index 821b60ff5b..bcdee8e4e7 100644
--- a/store/task.go
+++ b/store/task.go
@@ -36,20 +36,13 @@ func (s *TaskService) CreateTask(ctx context.Context, create *api.TaskCreate) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
task, err := s.pgCreateTask(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createTask(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -63,7 +56,6 @@ func (s *TaskService) FindTaskList(ctx context.Context, find *api.TaskFind) ([]*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.pgFindTaskList(ctx, tx.PTx, find)
@@ -81,7 +73,6 @@ func (s *TaskService) FindTask(ctx context.Context, find *api.TaskFind) (*api.Ta
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
return s.pgFindTask(ctx, tx.PTx, find)
@@ -94,20 +85,13 @@ func (s *TaskService) PatchTask(ctx context.Context, patch *api.TaskPatch) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
task, err := s.pgPatchTask(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchTask(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -122,20 +106,13 @@ func (s *TaskService) PatchTaskStatus(ctx context.Context, patch *api.TaskStatus
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
task, err := s.pgPatchTaskStatus(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.patchTaskStatus(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -143,108 +120,6 @@ func (s *TaskService) PatchTaskStatus(ctx context.Context, patch *api.TaskStatus
return task, nil
}
-// createTask creates a new task.
-func (s *TaskService) createTask(ctx context.Context, tx *sql.Tx, create *api.TaskCreate) (*api.Task, error) {
- var row *sql.Rows
- var err error
-
- if create.DatabaseID == nil {
- row, err = tx.QueryContext(ctx, `
- INSERT INTO task (
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- name,
- status,
- type,
- payload,
- earliest_allowed_ts
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, pipeline_id, stage_id, instance_id, database_id, name, status, type, payload, earliest_allowed_ts
- `,
- create.CreatorID,
- create.CreatorID,
- create.PipelineID,
- create.StageID,
- create.InstanceID,
- create.Name,
- create.Status,
- create.Type,
- create.Payload,
- create.EarliestAllowedTs,
- )
- } else {
- row, err = tx.QueryContext(ctx, `
- INSERT INTO task (
- creator_id,
- updater_id,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- status,
- type,
- payload,
- earliest_allowed_ts
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, pipeline_id, stage_id, instance_id, database_id, name, status, type, payload, earliest_allowed_ts
- `,
- create.CreatorID,
- create.CreatorID,
- create.PipelineID,
- create.StageID,
- create.InstanceID,
- create.DatabaseID,
- create.Name,
- create.Status,
- create.Type,
- create.Payload,
- create.EarliestAllowedTs,
- )
- }
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var task api.Task
- var databaseID sql.NullInt32
- task.TaskRunList = []*api.TaskRun{}
- task.TaskCheckRunList = []*api.TaskCheckRun{}
- if err := row.Scan(
- &task.ID,
- &task.CreatorID,
- &task.CreatedTs,
- &task.UpdaterID,
- &task.UpdatedTs,
- &task.PipelineID,
- &task.StageID,
- &task.InstanceID,
- &databaseID,
- &task.Name,
- &task.Status,
- &task.Type,
- &task.Payload,
- &task.EarliestAllowedTs,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- if databaseID.Valid {
- val := int(databaseID.Int32)
- task.DatabaseID = &val
- }
-
- return &task, nil
-}
-
// pgCreateTask creates a new task.
func (s *TaskService) pgCreateTask(ctx context.Context, tx *sql.Tx, create *api.TaskCreate) (*api.Task, error) {
var row *sql.Rows
@@ -347,20 +222,6 @@ func (s *TaskService) pgCreateTask(ctx context.Context, tx *sql.Tx, create *api.
return &task, nil
}
-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
- }
-
- if len(list) == 0 {
- return nil, nil
- } else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d tasks with filter %+v, expect 1", len(list), find)}
- }
- return list[0], 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)
if err != nil {
@@ -375,99 +236,6 @@ func (s *TaskService) pgFindTask(ctx context.Context, tx *sql.Tx, find *api.Task
return list[0], nil
}
-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 {
- where, args = append(where, "id = ?"), append(args, *v)
- }
- if v := find.PipelineID; v != nil {
- where, args = append(where, "pipeline_id = ?"), append(args, *v)
- }
- if v := find.StageID; v != nil {
- where, args = append(where, "stage_id = ?"), 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, ",")))
- }
-
- rows, err := tx.QueryContext(ctx, `
- SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- pipeline_id,
- stage_id,
- instance_id,
- database_id,
- name,
- status,
- type,
- payload,
- earliest_allowed_ts
- FROM task
- WHERE `+strings.Join(where, " AND "),
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer rows.Close()
-
- // Iterate over result set and deserialize rows into list.
- list := make([]*api.Task, 0)
- for rows.Next() {
- var task api.Task
- if err := rows.Scan(
- &task.ID,
- &task.CreatorID,
- &task.CreatedTs,
- &task.UpdaterID,
- &task.UpdatedTs,
- &task.PipelineID,
- &task.StageID,
- &task.InstanceID,
- &task.DatabaseID,
- &task.Name,
- &task.Status,
- &task.Type,
- &task.Payload,
- &task.EarliestAllowedTs,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- taskRunFind := &api.TaskRunFind{
- TaskID: &task.ID,
- }
- task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx, taskRunFind)
- if err != nil {
- return nil, err
- }
-
- taskCheckRunFind := &api.TaskCheckRunFind{
- TaskID: &task.ID,
- }
- task.TaskCheckRunList, err = s.TaskCheckRunService.FindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)
- if err != nil {
- return nil, err
- }
-
- list = append(list, &task)
- }
- if err := rows.Err(); err != nil {
- return nil, FormatError(err)
- }
- return list, nil
-}
-
func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.TaskFind) (_ []*api.Task, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
@@ -562,62 +330,6 @@ func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.DatabaseID; v != nil {
- set, args = append(set, "database_id = ?"), append(args, *v)
- }
- if v := patch.Payload; v != nil {
- set, args = append(set, "payload = ?"), append(args, *v)
- }
- if v := patch.EarliestAllowedTs; v != nil {
- set, args = append(set, "earliest_allowed_ts = ?"), append(args, *v)
- }
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE task
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, pipeline_id, stage_id, instance_id, database_id, name, status, type, payload, earliest_allowed_ts
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var task api.Task
- if err := row.Scan(
- &task.ID,
- &task.CreatorID,
- &task.CreatedTs,
- &task.UpdaterID,
- &task.UpdatedTs,
- &task.PipelineID,
- &task.StageID,
- &task.InstanceID,
- &task.DatabaseID,
- &task.Name,
- &task.Status,
- &task.Type,
- &task.Payload,
- &task.EarliestAllowedTs,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &task, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -674,138 +386,6 @@ func (s *TaskService) pgPatchTask(ctx context.Context, tx *sql.Tx, patch *api.Ta
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}
}
-// 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.findTask(ctx, tx, taskFind)
- if err != nil {
- return nil, err
- }
- if task == nil {
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}
- }
-
- if !(task.Status == api.TaskPendingApproval && patch.Status == api.TaskPending) {
- taskRunFind := &api.TaskRunFind{
- TaskID: &task.ID,
- StatusList: &[]api.TaskRunStatus{
- api.TaskRunRunning,
- },
- }
- taskRun, err := s.TaskRunService.FindTaskRunTx(ctx, tx, taskRunFind)
- if err != nil {
- return nil, err
- }
- if taskRun == nil {
- if patch.Status != api.TaskRunning {
- return nil, fmt.Errorf("no applicable running task to change status")
- }
- taskRunCreate := &api.TaskRunCreate{
- CreatorID: patch.UpdaterID,
- TaskID: task.ID,
- Name: fmt.Sprintf("%s %d", task.Name, time.Now().Unix()),
- Type: task.Type,
- Payload: task.Payload,
- }
- if _, err := s.TaskRunService.CreateTaskRunTx(ctx, tx, taskRunCreate); err != nil {
- return nil, err
- }
- } else {
- if patch.Status == api.TaskRunning {
- return nil, fmt.Errorf("task is already running: %v", task.Name)
- }
- taskRunStatusPatch := &api.TaskRunStatusPatch{
- ID: &taskRun.ID,
- UpdaterID: patch.UpdaterID,
- TaskID: &patch.ID,
- Code: patch.Code,
- Result: patch.Result,
- Comment: patch.Comment,
- }
- switch patch.Status {
- case api.TaskDone:
- taskRunStatusPatch.Status = api.TaskRunDone
- case api.TaskFailed:
- taskRunStatusPatch.Status = api.TaskRunFailed
- case api.TaskPending:
- case api.TaskPendingApproval:
- case api.TaskCanceled:
- taskRunStatusPatch.Status = api.TaskRunCanceled
- }
- if _, err := s.TaskRunService.PatchTaskRunStatusTx(ctx, tx, taskRunStatusPatch); err != nil {
- return nil, err
- }
- }
- }
-
- // Updates the task
- // Build UPDATE clause.
- set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "status = ?"), append(args, patch.Status)
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE task
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, pipeline_id, stage_id, instance_id, database_id, name, status, type, payload, earliest_allowed_ts
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var task api.Task
- if err := row.Scan(
- &task.ID,
- &task.CreatorID,
- &task.CreatedTs,
- &task.UpdaterID,
- &task.UpdatedTs,
- &task.PipelineID,
- &task.StageID,
- &task.InstanceID,
- &task.DatabaseID,
- &task.Name,
- &task.Status,
- &task.Type,
- &task.Payload,
- &task.EarliestAllowedTs,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- taskRunFind := &api.TaskRunFind{
- TaskID: &task.ID,
- }
- task.TaskRunList, err = s.TaskRunService.FindTaskRunListTx(ctx, tx, taskRunFind)
- if err != nil {
- return nil, err
- }
-
- taskCheckRunFind := &api.TaskCheckRunFind{
- TaskID: &task.ID,
- }
- task.TaskCheckRunList, err = s.TaskCheckRunService.FindTaskCheckRunListTx(ctx, tx, taskCheckRunFind)
- if err != nil {
- return nil, err
- }
-
- return &task, nil
- }
-
- return 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) {
// Updates the corresponding task run if applicable.
diff --git a/store/task_check_run.go b/store/task_check_run.go
index 926c1e8257..bb78178814 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -32,7 +32,6 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
statusList := []api.TaskCheckRunStatus{api.TaskCheckRunRunning}
@@ -82,13 +81,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
if err != nil {
return nil, err
}
- if _, err := s.CreateTaskCheckRunTx(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -96,56 +89,6 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
return taskCheckRun, nil
}
-// CreateTaskCheckRunTx creates a new taskCheckRun.
-func (s *TaskCheckRunService) CreateTaskCheckRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskCheckRunCreate) (*api.TaskCheckRun, error) {
- row, err := tx.QueryContext(ctx, `
- INSERT INTO task_check_run (
- creator_id,
- updater_id,
- task_id,
- status,
- type,
- comment,
- payload
- )
- VALUES (?, ?, ?, 'RUNNING', ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, status, type, code, comment, result, payload
- `,
- create.CreatorID,
- create.CreatorID,
- create.TaskID,
- create.Type,
- create.Comment,
- create.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var taskCheckRun api.TaskCheckRun
- if err := row.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)
- }
-
- return &taskCheckRun, nil
-}
-
// PgCreateTaskCheckRunTx creates a new taskCheckRun.
func (s *TaskCheckRunService) PgCreateTaskCheckRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskCheckRunCreate) (*api.TaskCheckRun, error) {
rows, err := tx.QueryContext(ctx, `
@@ -206,7 +149,6 @@ func (s *TaskCheckRunService) FindTaskCheckRunList(ctx context.Context, find *ap
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.pgFindTaskCheckRunList(ctx, tx.PTx, find)
@@ -243,20 +185,13 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patch
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
taskCheckRun, err := s.PgPatchTaskCheckRunStatusTx(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := s.PatchTaskCheckRunStatusTx(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -264,56 +199,6 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patch
return taskCheckRun, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "status = ?"), append(args, patch.Status)
- set, args = append(set, "code = ?"), append(args, patch.Code)
- set, args = append(set, "result = ?"), append(args, patch.Result)
-
- // Build WHERE clause.
- where := []string{"1 = 1"}
- if v := patch.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
- }
-
- row, err := tx.QueryContext(ctx, `
- UPDATE task_check_run
- SET `+strings.Join(set, ", ")+`
- WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, status, type, code, comment, result, payload
- `,
- args...,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var taskCheckRun api.TaskCheckRun
- if err := row.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)
- }
-
- return &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) {
// Build UPDATE clause.
diff --git a/store/task_run.go b/store/task_run.go
index 15ff596f1f..11a05c2f5e 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -26,57 +26,6 @@ func NewTaskRunService(logger *zap.Logger, db *DB) *TaskRunService {
return &TaskRunService{l: logger, db: db}
}
-// 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,
- updater_id,
- task_id,
- name,
- status,
- type,
- payload
- )
- VALUES (?, ?, ?, ?, 'RUNNING', ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, status, type, code, comment, result, payload
- `,
- create.CreatorID,
- create.CreatorID,
- create.TaskID,
- create.Name,
- create.Type,
- create.Payload,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var taskRun api.TaskRun
- if err := row.Scan(
- &taskRun.ID,
- &taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdaterID,
- &taskRun.UpdatedTs,
- &taskRun.TaskID,
- &taskRun.Name,
- &taskRun.Status,
- &taskRun.Type,
- &taskRun.Code,
- &taskRun.Comment,
- &taskRun.Result,
- &taskRun.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &taskRun, nil
-}
-
// PgCreateTaskRunTx creates a new taskRun.
func (s *TaskRunService) PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, create *api.TaskRunCreate) (*api.TaskRun, error) {
row, err := tx.QueryContext(ctx, `
@@ -128,16 +77,6 @@ func (s *TaskRunService) PgCreateTaskRunTx(ctx context.Context, tx *sql.Tx, crea
return &taskRun, nil
}
-// 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
- }
-
- return list, 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)
@@ -148,21 +87,6 @@ func (s *TaskRunService) PgFindTaskRunListTx(ctx context.Context, tx *sql.Tx, fi
return list, nil
}
-// FindTaskRunTx retrieves a single taskRun based on find.
-// Returns ECONFLICT if finding more than 1 matching records.
-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
- }
- if len(list) == 0 {
- return nil, nil
- } else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}
- }
- return list[0], nil
-}
-
// PgFindTaskRunTx 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) {
@@ -178,67 +102,6 @@ func (s *TaskRunService) PgFindTaskRunTx(ctx context.Context, tx *sql.Tx, find *
return list[0], nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- set, args = append(set, "status = ?"), append(args, patch.Status)
- if v := patch.Code; v != nil {
- set, args = append(set, "code = ?"), append(args, *v)
- }
- if v := patch.Comment; v != nil {
- set, args = append(set, "comment = ?"), append(args, *v)
- }
- if v := patch.Result; v != nil {
- set, args = append(set, "result = ?"), append(args, *v)
- }
-
- // Build WHERE clause.
- where := []string{"1 = 1"}
- if v := patch.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
- }
- if v := patch.TaskID; v != nil {
- where, args = append(where, "task_id = ?"), append(args, *v)
- }
-
- row, err := tx.QueryContext(ctx, `
- UPDATE task_run
- SET `+strings.Join(set, ", ")+`
- WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, status, type, code, comment, result, payload
- `,
- args...,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var taskRun api.TaskRun
- if err := row.Scan(
- &taskRun.ID,
- &taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdaterID,
- &taskRun.UpdatedTs,
- &taskRun.TaskID,
- &taskRun.Name,
- &taskRun.Status,
- &taskRun.Type,
- &taskRun.Code,
- &taskRun.Comment,
- &taskRun.Result,
- &taskRun.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &taskRun, 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) {
// Build UPDATE clause.
@@ -300,80 +163,6 @@ func (s *TaskRunService) PgPatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx,
return &taskRun, nil
}
-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 {
- 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.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, ",")))
- }
-
- rows, err := tx.QueryContext(ctx, `
- SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- task_id,
- name,
- status,
- type,
- code,
- comment,
- result,
- payload
- FROM task_run
- WHERE `+strings.Join(where, " AND "),
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer rows.Close()
-
- // Iterate over result set and deserialize rows into list.
- list := make([]*api.TaskRun, 0)
- for rows.Next() {
- var taskRun api.TaskRun
- if err := rows.Scan(
- &taskRun.ID,
- &taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdaterID,
- &taskRun.UpdatedTs,
- &taskRun.TaskID,
- &taskRun.Name,
- &taskRun.Status,
- &taskRun.Type,
- &taskRun.Code,
- &taskRun.Comment,
- &taskRun.Result,
- &taskRun.Payload,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- list = append(list, &taskRun)
- }
- if err := rows.Err(); err != nil {
- return nil, FormatError(err)
- }
-
- return list, nil
-}
-
func (s *TaskRunService) pgFindTaskRunList(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (_ []*api.TaskRun, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
diff --git a/store/vcs.go b/store/vcs.go
index 15c998df16..9bff093278 100644
--- a/store/vcs.go
+++ b/store/vcs.go
@@ -32,20 +32,13 @@ func (s *VCSService) CreateVCS(ctx context.Context, create *api.VCSCreate) (*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
vcs, err := pgCreateVCS(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := createVCS(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *VCSService) FindVCSList(ctx context.Context, find *api.VCSFind) ([]*api
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findVCSList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *VCSService) FindVCS(ctx context.Context, find *api.VCSFind) (*api.VCS,
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := findVCSList(ctx, tx.PTx, find)
@@ -100,20 +91,13 @@ func (s *VCSService) PatchVCS(ctx context.Context, patch *api.VCSPatch) (*api.VC
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
vcs, err := pgPatchVCS(ctx, tx.PTx, patch)
if err != nil {
return nil, FormatError(err)
}
- if _, err := patchVCS(ctx, tx.Tx, patch); err != nil {
- return nil, FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -127,19 +111,12 @@ func (s *VCSService) DeleteVCS(ctx context.Context, delete *api.VCSDelete) error
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteVCS(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteVCS(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -147,59 +124,6 @@ func (s *VCSService) DeleteVCS(ctx context.Context, delete *api.VCSDelete) error
return nil
}
-// 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 (
- creator_id,
- updater_id,
- name,
- type,
- instance_url,
- api_url,
- application_id,
- secret
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, name, type, instance_url, api_url, application_id, secret
- `,
- create.CreatorID,
- create.CreatorID,
- create.Name,
- create.Type,
- create.InstanceURL,
- create.APIURL,
- create.ApplicationID,
- create.Secret,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var vcs api.VCS
- if err := row.Scan(
- &vcs.ID,
- &vcs.CreatorID,
- &vcs.CreatedTs,
- &vcs.UpdaterID,
- &vcs.UpdatedTs,
- &vcs.Name,
- &vcs.Type,
- &vcs.InstanceURL,
- &vcs.APIURL,
- &vcs.ApplicationID,
- &vcs.Secret,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &vcs, nil
-}
-
// pgCreateVCS creates a new vcs.
func pgCreateVCS(ctx context.Context, tx *sql.Tx, create *api.VCSCreate) (*api.VCS, error) {
// Insert row into database.
@@ -311,59 +235,6 @@ func findVCSList(ctx context.Context, tx *sql.Tx, find *api.VCSFind) (_ []*api.V
return list, nil
}
-// 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 = ?"}, []interface{}{patch.UpdaterID}
- if v := patch.Name; v != nil {
- set, args = append(set, "name = ?"), append(args, *v)
- }
- if v := patch.ApplicationID; v != nil {
- set, args = append(set, "application_id = ?"), append(args, *v)
- }
- if v := patch.Secret; v != nil {
- set, args = append(set, "secret = ?"), append(args, *v)
- }
- args = append(args, patch.ID)
-
- // Execute update query with RETURNING.
- row, err := tx.QueryContext(ctx, `
- UPDATE vcs
- SET `+strings.Join(set, ", ")+`
- WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, name, type, instance_url, api_url, application_id, secret
- `,
- args...,
- )
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- if row.Next() {
- var vcs api.VCS
- if err := row.Scan(
- &vcs.ID,
- &vcs.CreatorID,
- &vcs.CreatedTs,
- &vcs.UpdaterID,
- &vcs.UpdatedTs,
- &vcs.Name,
- &vcs.Type,
- &vcs.InstanceURL,
- &vcs.APIURL,
- &vcs.ApplicationID,
- &vcs.Secret,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &vcs, nil
- }
-
- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("vcs ID not found: %d", patch.ID)}
-}
-
// 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) {
// Build UPDATE clause.
@@ -417,15 +288,6 @@ 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)}
}
-// 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 = ?`, delete.ID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteVCS permanently deletes a vcs by ID.
func pgDeleteVCS(ctx context.Context, tx *sql.Tx, delete *api.VCSDelete) error {
// Remove row from database.
diff --git a/store/view.go b/store/view.go
index f64419533a..a888396896 100644
--- a/store/view.go
+++ b/store/view.go
@@ -32,20 +32,13 @@ func (s *ViewService) CreateView(ctx context.Context, create *api.ViewCreate) (*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
view, err := s.pgCreateView(ctx, tx.PTx, create)
if err != nil {
return nil, err
}
- if _, err := s.createView(ctx, tx.Tx, create); err != nil {
- return nil, err
- }
- if err := tx.Tx.Commit(); err != nil {
- return nil, FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -59,7 +52,6 @@ func (s *ViewService) FindViewList(ctx context.Context, find *api.ViewFind) ([]*
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findViewList(ctx, tx.PTx, find)
@@ -77,7 +69,6 @@ func (s *ViewService) FindView(ctx context.Context, find *api.ViewFind) (*api.Vi
if err != nil {
return nil, FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
list, err := s.findViewList(ctx, tx.PTx, find)
@@ -99,19 +90,12 @@ func (s *ViewService) DeleteView(ctx context.Context, delete *api.ViewDelete) er
if err != nil {
return FormatError(err)
}
- defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
if err := pgDeleteView(ctx, tx.PTx, delete); err != nil {
return FormatError(err)
}
- if err := deleteView(ctx, tx.Tx, delete); err != nil {
- return FormatError(err)
- }
- if err := tx.Tx.Commit(); err != nil {
- return FormatError(err)
- }
if err := tx.PTx.Commit(); err != nil {
return FormatError(err)
}
@@ -119,57 +103,6 @@ func (s *ViewService) DeleteView(ctx context.Context, delete *api.ViewDelete) er
return nil
}
-// 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 (
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- database_id,
- name,
- definition,
- comment
- )
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`+
- "RETURNING id, creator_id, created_ts, updater_id, updated_ts, database_id, name, definition, comment"+`
- `,
- create.CreatorID,
- create.CreatedTs,
- create.CreatorID,
- create.UpdatedTs,
- create.DatabaseID,
- create.Name,
- create.Definition,
- create.Comment,
- )
-
- if err != nil {
- return nil, FormatError(err)
- }
- defer row.Close()
-
- row.Next()
- var view api.View
- if err := row.Scan(
- &view.ID,
- &view.CreatorID,
- &view.CreatedTs,
- &view.UpdaterID,
- &view.UpdatedTs,
- &view.DatabaseID,
- &view.Name,
- &view.Definition,
- &view.Comment,
- ); err != nil {
- return nil, FormatError(err)
- }
-
- return &view, nil
-}
-
// pgCreateView creates a new view.
func (s *ViewService) pgCreateView(ctx context.Context, tx *sql.Tx, create *api.ViewCreate) (*api.View, error) {
// Insert row into view.
@@ -282,15 +215,6 @@ func (s *ViewService) findViewList(ctx context.Context, tx *sql.Tx, find *api.Vi
return list, nil
}
-// 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 = ?`, delete.DatabaseID); err != nil {
- return FormatError(err)
- }
- return nil
-}
-
// pgDeleteView permanently deletes views from a database.
func pgDeleteView(ctx context.Context, tx *sql.Tx, delete *api.ViewDelete) error {
// Remove row from database.