-
-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: change forge_history for set "unique key" done_at
Converted to miliseconds and set the "done_at" to unique key.
- Loading branch information
Showing
3 changed files
with
35 additions
and
3 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,3 +1,31 @@ | ||
function onUpdateDatabase() | ||
return false -- true = There are others migrations file | false = this is the last migration file | ||
logger.info("Updating database to version 52 (player forge history unique done_at)") | ||
|
||
db.query([[ | ||
UPDATE forge_history | ||
SET done_at = done_at * 1000 | ||
WHERE done_at < 1000000000000; | ||
]]) | ||
|
||
db.query([[ | ||
UPDATE forge_history AS f1 | ||
JOIN ( | ||
SELECT | ||
id, | ||
done_at, | ||
ROW_NUMBER() OVER (PARTITION BY done_at ORDER BY id) AS row_num | ||
FROM forge_history | ||
) AS duplicates ON f1.id = duplicates.id | ||
SET f1.done_at = f1.done_at + (duplicates.row_num * 1) | ||
WHERE duplicates.row_num > 1; | ||
]]) | ||
|
||
local success = db.query("ALTER TABLE forge_history ADD UNIQUE KEY unique_done_at (done_at);") | ||
|
||
if not success then | ||
logger.error("Failed to add unique key to 'done_at'.") | ||
return false | ||
end | ||
|
||
return true | ||
end |
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,3 @@ | ||
function onUpdateDatabase() | ||
return false -- true = There are others migrations file | false = this is the last migration file | ||
end |
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