Added dormant tables for welcome email automations#27183
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughTwo new database tables, 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
towards https://linear.app/ghost/issue/NY-1188 ref #27183 We just added two new tables: `welcome_email_automations` and `welcome_email_automated_emails`. This adds dormant models for those, which are based on the existing `AutomatedEmail` model. **You may wish to review a diff of these with their associated `AutomatedEmail` counterpart, which will make these changes look much smaller.** For example, I ran these commands as part of self-review: ```sh vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automation}.js vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automated-email}.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automation}.test.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automated-email}.test.js ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)
towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)
towards https://linear.app/ghost/issue/NY-1188 This change should have no user impact. It adds `welcome_email_automations` and `welcome_email_automated_emails` tables. These are split up from the existing `automated_emails` table with two additions in `welcome_email_automated_emails`: - `delay_days` - `next_welcome_email_automated_email_id` You may wish to review a diff between `automated_emails` and the new tables: ```diff diff --git a/j.js b/j.js index dded3c3..68070f4 100644 --- a/j.js +++ b/j.js @@ -1,8 +1,16 @@ -automated_emails: { +welcome_email_automations: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'inactive', validations: {isIn: [['active', 'inactive']]}}, name: {type: 'string', maxlength: 191, nullable: false, unique: true}, slug: {type: 'string', maxlength: 191, nullable: false, unique: true}, + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true} +}, +welcome_email_automated_emails: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'welcome_email_automations.id', constraintName: 'weae_automation_id_foreign', cascadeDelete: true}, + next_welcome_email_automated_email_id: {type: 'string', maxlength: 24, nullable: true, references: 'welcome_email_automated_emails.id', constraintName: 'weae_next_email_id_foreign', cascadeDelete: false}, + delay_days: {type: 'integer', nullable: false}, subject: {type: 'string', maxlength: 300, nullable: false}, lexical: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, sender_name: {type: 'string', maxlength: 191, nullable: true}, @@ -10,9 +18,5 @@ automated_emails: { sender_reply_to: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}}, email_design_setting_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_design_settings.id'}, created_at: {type: 'dateTime', nullable: false}, - updated_at: {type: 'dateTime', nullable: true}, - '@@indexes@@': [ - ['slug'], - ['status'] - ] + updated_at: {type: 'dateTime', nullable: true} }, ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 We just added two new tables: `welcome_email_automations` and `welcome_email_automated_emails`. This adds dormant models for those, which are based on the existing `AutomatedEmail` model. **You may wish to review a diff of these with their associated `AutomatedEmail` counterpart, which will make these changes look much smaller.** For example, I ran these commands as part of self-review: ```sh vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automation}.js vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automated-email}.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automation}.test.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automated-email}.test.js ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)
towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Line 1182: The delay_days integer field currently allows negatives; update the
schema and migration so delay_days enforces non-negative values: in schema.js
(the delay_days field) add a validation constraint (e.g., "minimum: 0") to the
field definition; mirror the same constraint in the migration
2026-04-06-14-27-21-add-welcome-email-automation-tables.js by making the column
non-negative (use .unsigned() for integer columns where supported or add an
explicit CHECK constraint like "delay_days >= 0" in the table definition) so
both fresh installs and upgrades enforce delay_days >= 0.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8ff1a4ea-3149-4baa-b711-81f6ed9278f0
📒 Files selected for processing (5)
ghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.27/2026-04-06-14-27-21-add-welcome-email-automation-tables.jsghost/core/core/server/data/schema/schema.jsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.js
cmraible
left a comment
There was a problem hiding this comment.
Looks good! Main suggestion is to use the existing addTable() migration util for consistency, and I think CodeRabbit's suggestion re: delay_days is valid as well, though not blocking from my perspective.
...ver/data/migrations/versions/6.27/2026-04-06-14-27-21-add-welcome-email-automation-tables.js
Outdated
Show resolved
Hide resolved
|
cmraible
left a comment
There was a problem hiding this comment.
Looks good, thanks for addressing the feedback!
towards https://linear.app/ghost/issue/NY-1188 ref #27183 We just added two new tables: `welcome_email_automations` and `welcome_email_automated_emails`. This adds dormant models for those, which are based on the existing `AutomatedEmail` model. **You may wish to review a diff of these with their associated `AutomatedEmail` counterpart, which will make these changes look much smaller.** For example, I ran these commands as part of self-review: ```sh vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automation}.js vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automated-email}.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automation}.test.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automated-email}.test.js ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 We just added two new tables: `welcome_email_automations` and `welcome_email_automated_emails`. This adds dormant models for those, which are based on the existing `AutomatedEmail` model. **You may wish to review a diff of these with their associated `AutomatedEmail` counterpart, which will make these changes look much smaller.** For example, I ran these commands as part of self-review: ```sh vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automation}.js vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automated-email}.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automation}.test.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automated-email}.test.js ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)
towards https://linear.app/ghost/issue/NY-1188 This change should have no user impact. It adds `welcome_email_automations` and `welcome_email_automated_emails` tables. These are split up from the existing `automated_emails` table with two additions in `welcome_email_automated_emails`: - `delay_days` - `next_welcome_email_automated_email_id` You may wish to review a diff between `automated_emails` and the new tables: ```diff diff --git a/j.js b/j.js index dded3c3..68070f4 100644 --- a/j.js +++ b/j.js @@ -1,8 +1,16 @@ -automated_emails: { +welcome_email_automations: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'inactive', validations: {isIn: [['active', 'inactive']]}}, name: {type: 'string', maxlength: 191, nullable: false, unique: true}, slug: {type: 'string', maxlength: 191, nullable: false, unique: true}, + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true} +}, +welcome_email_automated_emails: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'welcome_email_automations.id', constraintName: 'weae_automation_id_foreign', cascadeDelete: true}, + next_welcome_email_automated_email_id: {type: 'string', maxlength: 24, nullable: true, references: 'welcome_email_automated_emails.id', constraintName: 'weae_next_email_id_foreign', cascadeDelete: false}, + delay_days: {type: 'integer', nullable: false}, subject: {type: 'string', maxlength: 300, nullable: false}, lexical: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, sender_name: {type: 'string', maxlength: 191, nullable: true}, @@ -10,9 +18,5 @@ automated_emails: { sender_reply_to: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}}, email_design_setting_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_design_settings.id'}, created_at: {type: 'dateTime', nullable: false}, - updated_at: {type: 'dateTime', nullable: true}, - '@@indexes@@': [ - ['slug'], - ['status'] - ] + updated_at: {type: 'dateTime', nullable: true} }, ```
towards https://linear.app/ghost/issue/NY-1188 ref #27183 We just added two new tables: `welcome_email_automations` and `welcome_email_automated_emails`. This adds dormant models for those, which are based on the existing `AutomatedEmail` model. **You may wish to review a diff of these with their associated `AutomatedEmail` counterpart, which will make these changes look much smaller.** For example, I ran these commands as part of self-review: ```sh vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automation}.js vimdiff ghost/core/core/server/models/{automated-email,welcome-email-automated-email}.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automation}.test.js vimdiff ghost/core/test/unit/server/models/{automated-email,welcome-email-automated-email}.test.js ```
…es (#27185) towards https://linear.app/ghost/issue/NY-1188 ref #27183 ref #27184 Previous patches added new dormant tables and models. This change actually uses them. More specifically, this does a database migration to move `automated_emails` to `welcome_email_automations` and `welcome_email_automated_emails`. Then, it updates all relevant code to use those new tables. The old model is deleted, but the tables are not. (That's forthcoming.)



towards https://linear.app/ghost/issue/NY-1188
This change should have no user impact. It adds
welcome_email_automationsandwelcome_email_automated_emailstables.These are split up from the existing
automated_emailstable with two additions inwelcome_email_automated_emails:delay_daysnext_welcome_email_automated_email_idYou may wish to review a diff between
automated_emailsand the new tables: