Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add another migration that remigrates the proper way (#3719)
## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> Adds a migration that renames `token_name` back to `username`, then adds a new optional column named `token_name` ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> I've added fallbacks for resolving username/tokenname on insert and on making rows from results. But this adds another column renaming, which is worth discussing properly
- Loading branch information
Showing
3 changed files
with
40 additions
and
22 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
20 changes: 0 additions & 20 deletions
20
src/migrations/20230426110026-rename-api-token-username-field.js
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/migrations/20230510113903-fix-api-token-username-migration.js
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 @@ | ||
'use strict'; | ||
|
||
exports.up = function (db, callback) { | ||
db.runSql( | ||
` | ||
SELECT * FROM migrations WHERE name = '/20230426110026-rename-api-token-username-field'; | ||
`, | ||
(err, results) => { | ||
if (results.rows.length > 0) { | ||
db.runSql( | ||
` | ||
ALTER TABLE api_tokens RENAME COLUMN token_name TO username; | ||
ALTER TABLE api_tokens ADD COLUMN "token_name" text; | ||
UPDATE api_tokens SET token_name = username; | ||
DELETE FROM migrations WHERE name = '/20230426110026-rename-api-token-username-field'; | ||
`, | ||
); | ||
} else { | ||
db.runSql( | ||
` | ||
ALTER TABLE api_tokens ADD COLUMN "token_name" text; | ||
UPDATE api_tokens SET token_name = username; | ||
`, | ||
); | ||
} | ||
callback(); | ||
}, | ||
); | ||
}; | ||
|
||
exports.down = function (db, callback) { | ||
db.runSql( | ||
`ALTER TABLE api_tokens DROP COLUMN IF EXISTS "token_name";`, | ||
callback, | ||
); | ||
}; |