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

Support for Composite Keys #26063

Open
marination opened this issue Apr 19, 2024 · 0 comments
Open

Support for Composite Keys #26063

marination opened this issue Apr 19, 2024 · 0 comments

Comments

@marination
Copy link
Collaborator

A composite key, in the context of relational databases, is a combination of two or more columns in a table that can be used to uniquely identify each row in the table. Uniqueness is only guaranteed when the columns are combined; when taken individually the columns do not guarantee uniqueness. (Src)

  • Frappe currently supports only single column unique key constraints
  • The current possibility for composite key implementations are hacky:
    1. Programatically handle this. I think this breaks the uniformity of where crucial parts of the schema are defined and just spreads it around.
      	def on_doctype_update():
      		frappe.db.add_unique("Bin", ["item_code", "warehouse"], constraint_name="unique_item_warehouse")
    2. Add an extra column C in your doctype that combines column A + column B (composite key) and add a uniqueness constraint on column C. This adds redundancy.

One challenge is the UI for this:

  • I could visualise moving the uniqueness configuration outside the Fields table altogether
  • Perhaps another table that supports specifiying 1 or more columns that form the constraints
  • The Fields table could then have some basic visual indicator of which rows are unique or part of a uniqueness constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant