Skip to content

Commit

Permalink
feat(db): added deleted column to environments table (#2044)
Browse files Browse the repository at this point in the history
Added deleted column to the environments table. Adapted all queries to
this table.

Ref: SRX-9MM6SC
  • Loading branch information
diogo-nogueira-freiheit authored Oct 16, 2024
1 parent 26b9c2f commit abe3f6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE environments
ADD COLUMN IF NOT EXISTS deleted bool
DEFAULT false NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE environments
ADD COLUMN deleted bool
DEFAULT false NOT NULL;
6 changes: 4 additions & 2 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`,
Expand Down Expand Up @@ -5199,6 +5199,7 @@ ON
AND latest.name = environments.name
WHERE
environments.name IN (?` + strings.Repeat(",?", len(environmentNames)-1) + `)
AND deleted=false
LIMIT ?
`,
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit abe3f6b

Please sign in to comment.