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

Foreign Key Usage Design Spec #12

Merged
merged 21 commits into from
Dec 21, 2021
Merged

Conversation

ghislaineguerin
Copy link
Contributor

@ghislaineguerin ghislaineguerin commented Nov 11, 2021

This PR contains the specs needed to implement the design for Usage of Foreign Key Contraints

@ghislaineguerin ghislaineguerin marked this pull request as ready for review November 14, 2021 09:20
@ghislaineguerin ghislaineguerin requested a review from a team as a code owner November 14, 2021 09:20
@github-actions github-actions bot requested review from eito-fis, kgodey, mathemancer, pavish, seancolsen and silentninja and removed request for a team November 14, 2021 09:20
@kgodey kgodey requested a review from dmos62 November 15, 2021 22:57
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

I think this looks good overall. Added some comments with further thoughts.

design/specs/foreign-key-constraints.md Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
@seancolsen seancolsen removed their assignment Nov 16, 2021
@dmos62
Copy link
Contributor

dmos62 commented Nov 16, 2021

Nice work! I've a few quick notes. These may have been addressed already.

Additional options and defaults

Postgres provides some options for FKs, like what to do when a referenced column is deleted or updated, or whether to even allow that (ON UPDATE, ON DELETE). Also, there's an option for whether or not a multi-column FK can have referencing cells that are undefined (MATCH FULL, MATCH SIMPLE).

For the sake of development speed we might just want to use a sensible default at the moment. If so, it might be nice to tell the user what that default is. I think defaults were discussed at some point and we arrived at ON UPDATE CASCADE, ON DELETE RESTRICT, and MATCH SIMPLE.

Terminology

SQL community's terms around FK are pretty confusing and not well established (I've seen referencing, referred, source, target, columns, etc.). When you're looking at a different SQL library or a different documentation, chances are that it will be calling these properties something new.

Concern here is that when the user will be looking at the create/edit FK constraint dialog it might be taxing for him to understand what do the terms referenced table, reference column, column (no prefix) mean. I'd say there isn't an easy solution for this: we either make it verbose or short but confusing. I'm leaning towards verbosity: referred table/column and referring table/column. Referred/referring being popular abbreviations for referenced/referencing.

Also, in the context of FKs, saying column or table without specifying whether we're talking about the referred or referring column/table is somewhat ambiguous. There's a colloquial convention that when you're ambiguous you mean the referring object, but it might take a user some extra time to realise that. Something to think about.

Copy link
Member

@pavish pavish left a comment

Choose a reason for hiding this comment

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

@ghislaineguerin This looks really good and detailed. I had a couple comments.

design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
@kgodey kgodey removed their assignment Nov 16, 2021
@kgodey kgodey added the status: review In review label Nov 16, 2021
@kgodey
Copy link
Contributor

kgodey commented Dec 3, 2021

@ghislaineguerin I updated the status of this PR to review and added everyone to the assignee list.

@dmos62 @mathemancer @pavish @seancolsen @silentninja Please unassign yourselves once you've reviewed.

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.

Aside from one clarifying question, this looks great!

Comment on lines 166 to 167
- If the table contains no records, the user sees an option to add a record.
- If there aren't any matches, the user sees an option to add a record for the newly entered value or try changing the 'Search Columns' table preference.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens after the user clicks "Add Record" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seancolsen we haven't defined that part of the flow yet. I assume we'll know more when we work on views as it also involves the creation of new records in other tables. I'll add a note for this.

Copy link
Contributor

@kgodey kgodey Dec 8, 2021

Choose a reason for hiding this comment

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

I think we should remove the "Add Record" option from the spec, we can add it in once we have it defined. It'll confuse implementation.

@seancolsen seancolsen removed their assignment Dec 3, 2021
Copy link
Contributor

@mathemancer mathemancer 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 overall.

Small comment: I noticed in the video for Scenario 2 that we "remove" the foreign key constraint from some parts of the UI, but we "delete" the foreign key constraint from others. I think these should be unified to one specific word/concept to avoid confusion, and that word/concept should be chosen carefully. We want to make sure the User understands they're not deleting any data when they take the action, but only the attachment between the tables.

@mathemancer mathemancer removed their assignment Dec 8, 2021
@seancolsen
Copy link
Contributor

Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@ghislaineguerin This looks great overall. Some (hopefully) minor comments.

#### 2. The user selects a table from the list of available tables
- The user selects the table on the 'one side of the 'one-to-many' relationship.
- The user is not familiar with the concept of foreign keys.
- The user has created tables within Mathesar, where the ID column is automatically generated and sent as the primary key.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a good assumption to make. We should handle cases for all tables, even without primary keys.

We can solve this for the first version by not supporting creating links through scenario 1a. Perhaps we could have a little help message that says "Why don't I see all my tables in this list?" and explain that we only show tables with primary keys.

Copy link
Contributor

@silentninja silentninja Dec 9, 2021

Choose a reason for hiding this comment

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

I think it would be better if we show all the tables, but disable the table without a primary key with a text hint that conveys the message that the primary key is missing, this could be extended to directing them to create a 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.

I agree with @silentninja. I think it would be best to show the tables and prevent selection. I will add details for this in the spec.

Comment on lines 166 to 167
- If the table contains no records, the user sees an option to add a record.
- If there aren't any matches, the user sees an option to add a record for the newly entered value or try changing the 'Search Columns' table preference.
Copy link
Contributor

@kgodey kgodey Dec 8, 2021

Choose a reason for hiding this comment

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

I think we should remove the "Add Record" option from the spec, we can add it in once we have it defined. It'll confuse implementation.


### Linked Records for Multi-Column Foreign Key Constraints

- The current UI does not consider multi-column foreign key constraints and how those would be retrieved and selected.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should define this a bit, even if only to say that we treat it like a text column for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kgodey I've added additional information.


### Usage of Color

- A suggestion to use color as a means to differentiate table references has been included in this spec. However, there are implementation details that need to be discussed before the team can make a decision.
Copy link
Contributor

Choose a reason for hiding this comment

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

Decision about what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kgodey I've updated to add more detail.

- The user opens the column menu for a column that has a foreign key constraint applied
- The user clicks on the preferences link

## Components
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the constraints modal component?

@kgodey kgodey removed their assignment Dec 8, 2021
@silentninja silentninja removed their assignment Dec 9, 2021
@kgodey
Copy link
Contributor

kgodey commented Dec 9, 2021

@ghislaineguerin Please re-assign me when the spec is ready for re-review.

Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@ghislaineguerin Looks good overall, a couple of minor changes requested.


### Terminology

- `Remove` and `Delete` are used throughout this spec and should be applied consistently across the entire user interface as they are different affordances. `Remove` will be used for data that can be added back, while `Delete` will indicate data destruction.
Copy link
Contributor

Choose a reason for hiding this comment

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

We actually decided to use Delete for everything in mathesar-foundation/mathesar#872

#### 2. The user selects a table from the list of available tables
- The user selects the table on the 'one side of the 'one-to-many' relationship.
- The user is not familiar with the concept of foreign keys.
- The user has at least two tables with primary key constraints set.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we just need one table - the one that's being linked to. And it should be a single primary key and not a composite 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.

I agree. I've updated the assumptions.

@kgodey kgodey removed their assignment Dec 16, 2021
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@ghislaineguerin I noticed a typo, made a suggested fix along with a clarification.

design/specs/foreign-key-constraints.md Outdated Show resolved Hide resolved
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

Looks good other than my one suggested change.

@kgodey kgodey removed their assignment Dec 17, 2021
Co-authored-by: Kriti Godey <kriti@kritigodey.com>
@pavish pavish removed their assignment Dec 17, 2021
@dmos62 dmos62 removed their request for review December 21, 2021 16:21
@ghislaineguerin ghislaineguerin merged commit 6652f36 into master Dec 21, 2021
@ghislaineguerin ghislaineguerin deleted the spec-foreign-key-usage branch December 21, 2021 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

7 participants