-
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.
- Loading branch information
Igor Polyakov
committed
Jun 18, 2024
1 parent
bbcb04b
commit 5b08643
Showing
24 changed files
with
467 additions
and
275 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
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,36 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql" | ||
"log/slog" | ||
"runtime" | ||
) | ||
|
||
func DatabaseUpdate_update0012_update0013(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 := "Change int id to uuid table results" | ||
if getInfo { | ||
return fromUpdateId, toUpdateId, description, nil | ||
} | ||
query := ` | ||
BEGIN; | ||
ALTER TABLE results ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); | ||
UPDATE results SET new_id = gen_random_uuid(); | ||
ALTER TABLE results DROP COLUMN id; | ||
ALTER TABLE results ADD CONSTRAINT new_id_pkey PRIMARY KEY (new_id); | ||
ALTER TABLE results RENAME COLUMN new_id TO id; | ||
COMMIT; | ||
` | ||
_, err := db.Exec(query) | ||
if err != nil { | ||
slog.Error("Problem with update, query: " + query + "\n error:" + err.Error()) | ||
return fromUpdateId, toUpdateId, description, err | ||
} | ||
|
||
return fromUpdateId, toUpdateId, description, nil | ||
} |
Oops, something went wrong.