-
-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add primary keys to missing tables #5943
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
exports.up = function (db, callback) { | ||
db.runSql( | ||
` | ||
ALTER TABLE project_stats ADD PRIMARY KEY (project); | ||
ALTER TABLE api_token_project ADD PRIMARY KEY (secret, project); | ||
ALTER TABLE role_permission ADD COLUMN id SERIAL PRIMARY KEY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No good column to add, so creating id column. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a combined key? role_id + permission There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, there is also environment column. So it would have to be triple column primary key. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And no after checking, we can not use it, because environment is nullable and so is permission. We can not make environment not nullable, because root roles have no environment. So adding id seems only solution. @gastonfournier There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I appreciate you checking this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it populate past rows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, serial will auto populate it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
TIL! |
||
`, | ||
callback, | ||
); | ||
}; | ||
|
||
exports.down = function (db, callback) { | ||
db.runSql( | ||
` | ||
ALTER TABLE project_stats DROP CONSTRAINT project_stats_pkey; | ||
ALTER TABLE api_token_project DROP CONSTRAINT api_token_project_pkey; | ||
ALTER TABLE role_permission DROP CONSTRAINT role_permission_pkey; | ||
ALTER TABLE role_permission DROP COLUMN id; | ||
`, | ||
callback, | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding on unique existing column