-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): 🐛 cascade delete result with games
- Loading branch information
1 parent
5e2a32f
commit 70457f2
Showing
4 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"conventionalCommits.scopes": [ | ||
"config", | ||
"api" | ||
"api", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package migration | ||
|
||
import ( | ||
"database/sql" | ||
"log/slog" | ||
"runtime" | ||
) | ||
|
||
func DatabaseUpdate_update0021_update0022(db *sql.DB, getInfo bool) (string, string, string, error) { | ||
// WARNING!!! | ||
// Do not change the update if it has already been installed by other developers or in production. | ||
// To correct the database, create a new update and register it in the list of updates. | ||
|
||
fromUpdateId, toUpdateId := ParseNameFuncUpdate(runtime.Caller(0)) | ||
description := "Add cascade delete for results when deleting games" | ||
if getInfo { | ||
return fromUpdateId, toUpdateId, description, nil | ||
} | ||
|
||
query := ` | ||
BEGIN; | ||
ALTER TABLE results DROP CONSTRAINT IF EXISTS results_game_id_fkey; | ||
ALTER TABLE results ADD CONSTRAINT results_game_id_fkey | ||
FOREIGN KEY (game_id) REFERENCES games(id) ON DELETE CASCADE; | ||
COMMIT; | ||
` | ||
_, err := db.Exec(query) | ||
if err != nil { | ||
slog.Error("Problem with select, query: " + query + "\\n error:" + err.Error()) | ||
return fromUpdateId, toUpdateId, description, err | ||
} | ||
return fromUpdateId, toUpdateId, description, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters