-
-
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
exports.up = function (db, callback) { | ||
db.runSql( | ||
` | ||
ALTER TABLE project_stats ADD PRIMARY KEY (project); |
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
db.runSql( | ||
` | ||
ALTER TABLE project_stats ADD PRIMARY KEY (project); | ||
ALTER TABLE api_token_project ADD PRIMARY KEY (secret); |
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
` | ||
ALTER TABLE project_stats ADD PRIMARY KEY (project); | ||
ALTER TABLE api_token_project ADD PRIMARY KEY (secret); | ||
ALTER TABLE role_permission ADD COLUMN id SERIAL PRIMARY KEY; |
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.
No good column to add, so creating id column.
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.
Can we have a combined key? role_id + permission
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, serial will auto populate it
TIL!
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.
LGTM
db.runSql( | ||
` | ||
ALTER TABLE project_stats ADD PRIMARY KEY (project); | ||
ALTER TABLE api_token_project ADD COLUMN id SERIAL PRIMARY KEY; |
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.
@gastonfournier in this case I would use secret and project here also, if we using combined keys.
Follow up of #4303
We are adding primary keys to all tables missing them, currently role_permission, api_token_project, and project_stats.
By adding primary keys, the issue with migrations failing during upgrades in replicated database setups will be resolved.