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

add check constraints instead of varchar #55

Merged
merged 9 commits into from
Jan 9, 2024

Conversation

sjib
Copy link
Contributor

@sjib sjib commented Dec 12, 2023

@sjib sjib requested a review from 3nids December 12, 2023 14:54
@3nids 3nids changed the title 2023 12 12 add check constraints instead of varchar add check constraints instead of varchar Dec 12, 2023
@ponceta ponceta added enhancement New feature or request datamodel Concerns the datamodel labels Dec 13, 2023
@ponceta ponceta self-requested a review December 13, 2023 05:35
@@ -61,7 +61,8 @@ WITH (
CREATE SEQUENCE tww_od.seq_txt_symbol_oid INCREMENT 1 MINVALUE 0 MAXVALUE 999999 START 0;
ALTER TABLE tww_od.txt_symbol ALTER COLUMN obj_id SET DEFAULT tww_sys.generate_oid('tww_od','txt_symbol');
COMMENT ON COLUMN tww_od.txt_symbol.obj_id IS 'INTERLIS STANDARD OID (with Postfix/Präfix), see www.interlis.ch';
ALTER TABLE tww_od.txt_symbol ADD COLUMN classname varchar(50) ;
ALTER TABLE tww_od.txt_symbol ADD COLUMN classname text;
ALTER TABLE tww_od.txt_symbol ADD CONSTRAINT length_max_50_symbol_classname CHECK(char_length(classname)<=50);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ALTER TABLE tww_od.txt_symbol ADD CONSTRAINT length_max_50_symbol_classname CHECK(char_length(classname)<=50);
ALTER TABLE tww_od.txt_symbol ADD CONSTRAINT classname_max_length CHECK(char_length(classname)<=50);

I would avoid extra long names (constraints are defined for tables, so the table name is implicit) and put the column identifier in front

Copy link
Member

Choose a reason for hiding this comment

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

I do not have a strong opinion on this except the constraint name should be :

  • as understandable as possible
  • unique (for views like tww_ws and tww_reaches)
  • as small as possible

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 can use the shortcut of the class to still make it unique. Else we will have for each class an identifier_max_length
So better dt_identifier_max_length (instead of drainless_toilett_identifier_max_lenght')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@3nids New version pushed - please check

Copy link
Contributor

Choose a reason for hiding this comment

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

They don't need to be unique as they are defined at the table level.

Again, I'd

  • drop the prefix
  • drop the length info (if the length changes, no need to rename the constraint)
  • length_max => max_length

but it's not that big of a deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From a users perspective it is helpful to understand why you get the error message. Let's go ahead as technically there are no obstacles anymore.

@3nids
Copy link
Contributor

3nids commented Dec 15, 2023

@ponceta you wanted to review this?

@3nids 3nids merged commit 8f629fc into main Jan 9, 2024
4 checks passed
@3nids 3nids deleted the 2023-12-12-add-check-constraints-instead-of-varchar branch January 9, 2024 13:58
cymed added a commit to cymed/TEKSI-wastewater that referenced this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datamodel Concerns the datamodel enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants