diff --git a/database/migrations/postgres/1728910917892404_environments_deleted.up.sql b/database/migrations/postgres/1728910917892404_environments_deleted.up.sql new file mode 100644 index 000000000..278ba1cd0 --- /dev/null +++ b/database/migrations/postgres/1728910917892404_environments_deleted.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE environments +ADD COLUMN IF NOT EXISTS deleted bool +DEFAULT false NOT NULL; diff --git a/database/migrations/sqlite/1728977795361942_environments_deleted.up.sql b/database/migrations/sqlite/1728977795361942_environments_deleted.up.sql new file mode 100644 index 000000000..9dd34b24d --- /dev/null +++ b/database/migrations/sqlite/1728977795361942_environments_deleted.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE environments +ADD COLUMN deleted bool +DEFAULT false NOT NULL; diff --git a/pkg/db/db.go b/pkg/db/db.go index 4c89387c5..32a7ba3e8 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -5123,7 +5123,7 @@ func (h *DBHandler) DBSelectEnvironment(ctx context.Context, tx *sql.Tx, environ ` SELECT created, version, name, json, applications FROM environments -WHERE name=? +WHERE name=? AND deleted=false ORDER BY version DESC LIMIT 1; `, @@ -5199,6 +5199,7 @@ ON AND latest.name = environments.name WHERE environments.name IN (?` + strings.Repeat(",?", len(environmentNames)-1) + `) + AND deleted=false LIMIT ? `, ) @@ -5277,7 +5278,7 @@ func (h *DBHandler) DBWriteEnvironment(ctx context.Context, tx *sql.Tx, environm } insertQuery := h.AdaptQuery( - "INSERT Into environments (created, version, name, json, applications) VALUES (?, ?, ?, ?, ?);", + "INSERT Into environments (created, version, name, json, applications, deleted) VALUES (?, ?, ?, ?, ?, ?);", ) now, err := h.DBReadTransactionTimestamp(ctx, tx) if err != nil { @@ -5291,6 +5292,7 @@ func (h *DBHandler) DBWriteEnvironment(ctx context.Context, tx *sql.Tx, environm environmentName, jsonToInsert, string(applicationsJson), + false, ) if err != nil { return fmt.Errorf("could not write environment %s with config %v to environments table, error: %w", environmentName, environmentConfig, err)