Skip to content

[database] Improve schema defaults #9309

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

Merged
merged 3 commits into from
Aug 12, 2024

Conversation

maximemulder
Copy link
Contributor

@maximemulder maximemulder commented Jul 17, 2024

Brief summary of changes

While browsing the database schema, I noticed there were a lot of default '0' everywhere, even for foreign keys ! This is an anti-pattern that is easy to fix and should not require any change to the codebase outside of the schema, so here is a PR.

List of changes:

  1. Drop the DEFAULT 0 for foreign key fields (we do not have any table with a record at index 0 as far as I know/checked)
  2. Change DEFAULT '0' (or '1') to DEFAULT 0 (or 1) for other fields, which is more correct (the former can notably raise type errors with some database engines IIRC).

I don't think the ALTER column SET DEFAULT 0 is actually useful in the SQL patch, but it cannot hurt.

I omitted the mri_protocol.Scan_type field as it is fixed in #9304 instead.

More broadly, it seems to me that there is an overuse of defaults in our database, but fixing everything would require a lot more work and analysis, and is therefore a job for another day.

Testing instructions (if applicable)

  1. Apply patch and/or reset Rainsinbread
  2. Use LORIS

@maximemulder maximemulder marked this pull request as ready for review July 17, 2024 03:13
@maximemulder
Copy link
Contributor Author

All tests are passing, pinging random people @ridz1208 @kongtiaowang if anyone wants to review it, if not I'll just add this PR to the next LORIS meeting.

Copy link
Collaborator

@ridz1208 ridz1208 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visual check passes. I would like IBIS @nicolasbrossard and CCNA @CamilleBeau to give the patch a test.

@CamilleBeau
Copy link
Contributor

@ridz1208 I ran the patch on CCNA database and did not get any errors

@nicolasbrossard
Copy link
Contributor

@ridz1208 Ran the patch on IBIS (uses V25) and did not get any errors or warnings.

@driusan driusan merged commit cacedd8 into aces:main Aug 12, 2024
28 checks passed
maximemulder added a commit to maximemulder/Loris that referenced this pull request Sep 25, 2024
1. Drop the `DEFAULT 0` for foreign key fields
2. Change `DEFAULT '0'` (or `'1'`) to `DEFAULT 0` (or `1`) for other
fields, which is more correct.

Omitted the `mri_protocol.Scan_type` field as it is fixed in aces#9304
instead.
@maximemulder maximemulder deleted the 2024-07-16_improve-database-defaults branch October 29, 2024 17:03
ZhichGaming pushed a commit to ZhichGaming/Loris that referenced this pull request Nov 25, 2024
1. Drop the `DEFAULT 0` for foreign key fields
2. Change `DEFAULT '0'` (or `'1'`) to `DEFAULT 0` (or `1`) for other
fields, which is more correct.

Omitted the `mri_protocol.Scan_type` field as it is fixed in aces#9304
instead.
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.

6 participants