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

Database inconsistencies: empty text values can be stored both as NULL as well as empty string #1723

Open
stijnvermeeren-swisstopo opened this issue Dec 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@stijnvermeeren-swisstopo
Copy link

stijnvermeeren-swisstopo commented Dec 5, 2024

Many text columns in the database are currently nullable. This means that an "empty" value can be stored both as an empty string, as well as a NULL value. However, mostly, there seems to be no semantic difference between a NULL value and an empty string value.

An example is the column borehole.project_name_bho. Here, the PROD database currently has 10211 entries with an empty string (SELECT * FROM bdms.borehole WHERE project_name_bho = '';), and values with 259 (SELECT * FROM bdms.borehole WHERE project_name_bho IS NULL;).

In particular, a NULL value appears in the database when creating a new borehole in the UI.
An empty string appears in the database when setting a value in editor mode, saving the borehole, then removing the value again, and saving the borehole again.

I think that it would make more sense to change all NULL values in the affected columns to an empty string, and then to make the column not nullable (with empty string as the default value). Then an empty text value would always be represented by an empty string in the database, reducing the risk of unexpected/inconsistent database query results.
(Note: a few text columns are already defined as "not nullable" like this, e.g. casing.name and section.name.)

An incomplete list of potentially affected database columns:

Table Column NULL values in PROD empty string values in PROD
borehole project_name_bho
borehole original_name_bho
borehole alternate_name_bho
borehole remarks_bho
borehole country_bho
borehole canton_bho
borehole municipality_bho
casing notes
completion name
completion notes
facies_description description
instrumentation name
instrumentation notes
layer uscs_original_lay
layer original_lithology
layer notes_lay
lithological_description description
observation comment
stratigraphy name_sty
stratigraphy notes_sty
workflow notes_wkf

There are a few cases of nullable text columns where there might actually be a semantic difference between NULL and empty string. Maybe codelist.text_cli_de is such an example ("no label available for German, fallback to English" versus "use an empty string as the label for German"?). This needs to be looked at by someone who is more familiar with the Boreholes application code base.

@gysimichael gysimichael added the enhancement New feature or request label Dec 6, 2024
@gysimichael gysimichael added this to the Schemaanpassungen milestone Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants