Skip to content

🐛 Updated base model to store null instead of empty string#10425

Merged
allouis merged 8 commits into
TryGhost:masterfrom
allouis:no-more-empty-strings-pls
Jan 28, 2019
Merged

🐛 Updated base model to store null instead of empty string#10425
allouis merged 8 commits into
TryGhost:masterfrom
allouis:no-more-empty-strings-pls

Conversation

@allouis
Copy link
Copy Markdown
Collaborator

@allouis allouis commented Jan 28, 2019

refs #10388

This updates the base model to retrieve column information, and explicitly set every property whose column is nullable and content is the empty string ("") to null

This is the first half of solving #10388 - This will stop all future updates from storing empty strings, but we will still need to clean up the DB.

Comment thread core/server/models/base/index.js Outdated
}
// Gets nullable strings
getNullableStringProperties: _.memoize(function getNullableStringProperties(options) {
return options.query.columnInfo().then((columns) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Using options.query here means that if the query is part of a transaction, this will be part of it too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we have to query the database to get the "nullable" information? 🤔
Can't we simply ask the schema?

Copy link
Copy Markdown
Collaborator Author

@allouis allouis Jan 28, 2019

Choose a reason for hiding this comment

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

We could do - but the database will hold the actual source of truth for whether it is nullable or not - losing sync might not be an issue we want to cater for though.

Do you think the model should have direct access to the db schema?

EDIT: just seen it already does - deffo quicker if we already have precedent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah IMO model layer is allowed to access the schema.

Comment thread core/server/models/base/index.js Outdated
return this.tableName;
}),

// Sets given values to `null`
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Useless and misleading comment

@allouis
Copy link
Copy Markdown
Collaborator Author

allouis commented Jan 28, 2019

@kirrg001 Would you mind having a quick look at this, specifically the changes to base model getNullableStringProperties?

@allouis
Copy link
Copy Markdown
Collaborator Author

allouis commented Jan 28, 2019

@kirrg001 This has been updated - looks much better

@kirrg001
Copy link
Copy Markdown
Contributor

Does this generic logic work with the settings model? If yes, this LGTM 👍

@allouis
Copy link
Copy Markdown
Collaborator Author

allouis commented Jan 28, 2019

Seems to work fine with title and description etc.. columns

@allouis allouis merged commit 95880dd into TryGhost:master Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants