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

Backend functions to modify table primary keys #4331

Merged
merged 24 commits into from
Mar 19, 2025

Conversation

mathemancer
Copy link
Contributor

@mathemancer mathemancer commented Mar 13, 2025

Fixes #4334
Fixes #4335
Fixes #4336

This PR adds

  • an attribute to TableMetaData to track the attnum of the most recent Mathesar-added primary key column,
  • A parameter drop_existing_primary_key_column parameter to the columns.add_primary_key_column RPC function.
  • A new data_modeling.change_primary_key function that lets a user set a current column of a table as its primary key.

Technical details

  • All new RPC functionality is documented in the standard way for our RPC functions
  • There are tests to verify things are working as expected.
  • These functions drop the previous primary key, whether it's single- or multi-column.
  • The mathesar_added_pkey_attnum attribute of TableMetaData is automatically maintained by any back end RPC function that adds a primary key column:
    • tables.add
    • tables.import
    • columns.add_primary_key_column
  • The mathesar_added_pkey_attnum attribute is available through any table-metadata-listing RPC function.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@seancolsen seancolsen mentioned this pull request Mar 15, 2025
7 tasks
@seancolsen
Copy link
Contributor

@mathemancer can you please sync this up with develop? Merge or rebase is fine with me — whatever you prefer.

(I'd merge develop into this branch myself, but since it's still in draft state I want to leave this choice up to you. Personally sometimes I like to retain the ability to easily rebase PRs when in draft state.)

For #4313, I need to base my work on this PR plus some of my work from #4327 (which is now in develop).

@mathemancer
Copy link
Contributor Author

@mathemancer can you please sync this up with develop? Merge or rebase is fine with me — whatever you prefer.

(I'd merge develop into this branch myself, but since it's still in draft state I want to leave this choice up to you. Personally sometimes I like to retain the ability to easily rebase PRs when in draft state.)

For #4313, I need to base my work on this PR plus some of my work from #4327 (which is now in develop).

It's merged in now.

@mathemancer mathemancer changed the title Pkey update functions Backend functions to modify table primary keys Mar 18, 2025
@mathemancer mathemancer marked this pull request as ready for review March 18, 2025 02:34
@mathemancer mathemancer requested a review from Anish9901 March 18, 2025 02:34
@mathemancer mathemancer added the pr-status: review A PR awaiting review label Mar 18, 2025
@mathemancer mathemancer added this to the v0.2.2 milestone Mar 18, 2025
Copy link
Member

@Anish9901 Anish9901 left a comment

Choose a reason for hiding this comment

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

Looks great! I added a code suggestion, should be good to merge after that.

Copy link
Contributor

@seancolsen seancolsen left a comment

Choose a reason for hiding this comment

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

I've now opened #4353 on top of this. This PR seems to give me everything I need. Thanks @mathemancer!

@mathemancer mathemancer added this pull request to the merge queue Mar 19, 2025
Merged via the queue into develop with commit 82f7eb6 Mar 19, 2025
98 checks passed
@mathemancer mathemancer deleted the pkey_update_functions branch March 19, 2025 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
None yet
3 participants