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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/migrations/20240118093611-missing-primary-keys.js
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);
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 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 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!

`,
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,
);
};
Loading