-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Added migration to create default email_design_settings row
#26975
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
base: main
Are you sure you want to change the base?
Changes from all commits
1f7473d
c869c7e
891eaa9
c1045b9
061c5ce
4292770
a551b22
7df4008
5d069fc
f0ff03d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| const logging = require('@tryghost/logging'); | ||
| const {default: ObjectID} = require('bson-objectid'); | ||
| const {createTransactionalMigration} = require('../../utils'); | ||
|
|
||
| const DEFAULT_SLUG = 'default-automated-email'; | ||
|
|
||
| module.exports = createTransactionalMigration( | ||
| async function up(knex) { | ||
| logging.info('Inserting default email_design_settings row'); | ||
|
|
||
| const existing = await knex('email_design_settings').where({slug: DEFAULT_SLUG}).first(); | ||
|
|
||
| if (existing) { | ||
| logging.warn('Default email_design_settings row already exists, skipping'); | ||
| return; | ||
| } | ||
|
|
||
| await knex('email_design_settings').insert({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd meant to bring this up yesterday: would it make sense to seed these styles from the first active newsletter (avoiding saying "default" lol) if it exists? one spot it could get clunky is if there's something like a header image in the newsletter, it might not make sense in the welcome email. i think seeding like how you have it is probably right but just wanted to bring it up before we ship this piece. A "copy design from newsletter" button would probably be a better way to smooth out the experience for people that do want stuff the same or want to save most of the effort of copying colors etc.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The risk of this, I think, is if someone already has a welcome email set up, they might be surprised to see its design change. But you could make the argument the other way too.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think I agree that this is probably right as-is, to avoid surprises with the welcome email design changing without any user intervention.
This is a good idea though, might be something we can fit in before GA |
||
| id: (new ObjectID()).toHexString(), | ||
| slug: DEFAULT_SLUG, | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| background_color: 'light', | ||
| header_background_color: 'transparent', | ||
| show_header_title: true, | ||
| button_color: 'accent', | ||
| button_corners: 'rounded', | ||
| button_style: 'fill', | ||
| link_color: 'accent', | ||
| link_style: 'underline', | ||
| body_font_category: 'sans_serif', | ||
| title_font_category: 'sans_serif', | ||
| title_font_weight: 'bold', | ||
| image_corners: 'square', | ||
| show_badge: true, | ||
| created_at: knex.raw('current_timestamp') | ||
| }); | ||
| }, | ||
| async function down(knex) { | ||
| logging.info('Deleting default email_design_settings row'); | ||
|
|
||
| await knex('email_design_settings').where({slug: DEFAULT_SLUG}).del(); | ||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| const ghostBookshelf = require('./base'); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: creating the model is required for the fixtures to work
|
||
|
|
||
| const EmailDesignSetting = ghostBookshelf.Model.extend({ | ||
| tableName: 'email_design_settings', | ||
|
|
||
| defaults() { | ||
| return { | ||
| background_color: 'light', | ||
| header_background_color: 'transparent', | ||
| show_header_title: true, | ||
| button_color: 'accent', | ||
| button_corners: 'rounded', | ||
| button_style: 'fill', | ||
| link_color: 'accent', | ||
| link_style: 'underline', | ||
| body_font_category: 'sans_serif', | ||
| title_font_category: 'sans_serif', | ||
| title_font_weight: 'bold', | ||
| image_corners: 'square', | ||
| show_badge: true | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
| module.exports = { | ||
| EmailDesignSetting: ghostBookshelf.model('EmailDesignSetting', EmailDesignSetting) | ||
| }; | ||
cmraible marked this conversation as resolved.
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: When would this ever happen? If it did, should we throw an error instead?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the normal course of a Ghost site, it's highly unlikely that it would, so honest answer is probably never.
Good question - I think not, but I'm happy to be challenged on that. Rationale for not throwing an error: it doesn't hurt anything to no-op here: if the row already exists, nothing really breaks in Ghost.
If we instead throw an error, it would block any subsequent migrations from running, and prevent Ghost from booting. I do think there's a valid fail-fast argument to be made that preventing Ghost from booting if the schema/data is in an unexpected state is the right thing to do, which would be an interesting discussion. Practically speaking though, I'm mostly just following the existing conventions in previous migrations: