Skip to content
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

Merged
merged 3 commits into from
Jan 18, 2024
Merged

feat: add primary keys to missing tables #5943

merged 3 commits into from
Jan 18, 2024

Conversation

sjaanus
Copy link
Contributor

@sjaanus sjaanus commented Jan 18, 2024

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.

Copy link

vercel bot commented Jan 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2024 9:21am
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2024 9:21am

exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE project_stats ADD PRIMARY KEY (project);
Copy link
Contributor Author

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);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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!

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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!

Copy link
Member

@sighphyre sighphyre left a 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;
Copy link
Contributor Author

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.

@sjaanus sjaanus merged commit 605125f into main Jan 18, 2024
7 checks passed
@sjaanus sjaanus deleted the missing-primary-keys branch January 18, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants