Ghost/core/server/models
Kevin Ansfield f45198245f Updated Settings.populateDefaults() to account for available columns
refs https://github.com/TryGhost/Ghost/issues/10318

`Settings.populateDefaults()` is run before migrations during Ghost's startup. This can cause problems when new settings table columns are added (and populated in `default-settings.json`) because `populateDefaults()` was using the model layer which assumes that those columns are available, resulting in `ER_BAD_FIELD_ERROR: Unknown column` type errors.

- query the database for the available `settings` table columns
- switch to using raw knex queries without Bookshelf for insertions so that we're in control of the columns that are added
- use `_.pick` to skip any properties in `default-settings.json` that do not match to an available column - those columns will be added and populated by later migrations
- moving away from using the model to insert settings has the side-effect of not emitting `settings.added/edited` and `settings.x.added/edited` events, this should be fine because `populateDefaults()` is called before anything else is set up and listening
- added a call to `populateDefaults()` in our knex-migrator "before migration" hook so that we have consistent db state across both startup initialised migrations and manually triggered knex migrations
2020-06-29 13:22:10 +00:00
..
base Renamed settings keys active_timezone to timezone 2020-06-24 14:11:20 +12:00
plugins Added ?paid query parameter to Admin API members browse endpoint (#11892) 2020-06-12 12:12:10 +01:00
relations Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
action.js Added model implementation for actions 2019-02-06 21:36:09 +01:00
api-key.js Moved core/server/lib/common/logging to core/shared/logging (#11857) 2020-05-28 19:30:23 +01:00
author.js Added plugin based author and public tag models in API v2 (#10284) 2019-01-03 20:30:35 +01:00
email.js Added default stats object to email model 2019-11-08 17:11:54 +07:00
index.js Updated var declarations to const/let and no lists 2020-04-29 16:51:13 +01:00
integration.js Ensured Admin API cannot fetch internal integrations (#10501) 2019-07-24 11:52:55 +02:00
invite.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
label.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
member-stripe-customer.js Added upsert method to stripe models 2019-10-09 16:24:51 +07:00
member.js Added ?paid query parameter to Admin API members browse endpoint (#11892) 2020-06-12 12:12:10 +01:00
mobiledoc-revision.js Added mobiledoc revisions functionality 2018-10-09 15:31:09 +02:00
permission.js Updated var declarations to const/let and no lists 2020-04-29 16:51:13 +01:00
post.js Fixed population of image sizes when forcing re-render of posts 2020-06-18 14:02:53 +01:00
posts-meta.js Moved core/server/lib/url-utils to core/shared/url-utils (#11856) 2020-05-28 11:57:02 +01:00
role.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
session.js Removed user_id constraint when upserting session (#10085) 2018-10-30 16:15:48 +07:00
settings.js Updated Settings.populateDefaults() to account for available columns 2020-06-29 13:22:10 +00:00
stripe-customer-subscription.js Prefixed stripe_customers_subscriptions with members 2019-10-09 16:24:51 +07:00
tag-public.js Added plugin based author and public tag models in API v2 (#10284) 2019-01-03 20:30:35 +01:00
tag.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
user.js refactored 'lib/image' imports to use destructuring (#11847) 2020-05-26 19:11:23 +01:00
webhook.js Updated var declarations to const/let and no lists 2020-04-29 16:51:13 +01:00