-
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 22, 2024
1 parent
64b0a3f
commit b6a02e9
Showing
11 changed files
with
952 additions
and
855 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,30 @@ | ||
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 := "Added column display_name to users" | ||
if getInfo { | ||
return fromUpdateId, toUpdateId, description, nil | ||
} | ||
query := ` | ||
ALTER TABLE users | ||
ADD COLUMN display_name varchar(255); | ||
` | ||
_, 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 | ||
} |
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,46 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"log" | ||
"log/slog" | ||
"runtime" | ||
|
||
"github.com/jaswdr/faker/v2" | ||
) | ||
|
||
func DatabaseUpdate_update0013_update0013testdata(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 := "Insert test data to game_services" | ||
if getInfo { | ||
return fromUpdateId, toUpdateId, description, nil | ||
} | ||
query := ` | ||
SELECT id from users | ||
` | ||
rows, err := db.Query(query) | ||
if err != nil { | ||
slog.Error("Problem with select, query: " + query + "\n error:" + err.Error()) | ||
return fromUpdateId, toUpdateId, description, err | ||
} | ||
fake := faker.New() | ||
for rows.Next() { | ||
var id int | ||
if err := rows.Scan(&id); err != nil { | ||
log.Fatalf("Error scanning row: %v", err) | ||
} | ||
query := fmt.Sprintf("UPDATE users SET display_name = '%s' WHERE id = %d", fake.Person().Name(), id) | ||
_, 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 | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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