Skip to content

Dropped automated_emails table#27186

Open
EvanHahn wants to merge 4 commits intomainfrom
NY-1188-part-4
Open

Dropped automated_emails table#27186
EvanHahn wants to merge 4 commits intomainfrom
NY-1188-part-4

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented Apr 6, 2026

closes https://linear.app/ghost/issue/NY-1188
ref #27185

This removes the old automated emails table now that we aren't using it anymore.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • 6.x

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4323cefb-008c-44dc-88fe-33b623e91278

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch NY-1188-part-4

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the migration [pull request] Includes migration for review label Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

It looks like this PR contains a migration 👀
Here's the checklist for reviewing migrations:

General requirements

  • ⚠️ Tested performance on staging database servers, as performance on local machines is not comparable to a production environment
  • Satisfies idempotency requirement (both up() and down())
  • Does not reference models
  • Filename is in the correct format (and correctly ordered)
  • Targets the next minor version
  • All code paths have appropriate log messages
  • Uses the correct utils
  • Contains a minimal changeset
  • Does not mix DDL/DML operations
  • Tested in MySQL and SQLite

Schema changes

  • Both schema change and related migration have been implemented
  • For index changes: has been performance tested for large tables
  • For new tables/columns: fields use the appropriate predefined field lengths
  • For new tables/columns: field names follow the appropriate conventions
  • Does not drop a non-alpha table outside of a major version

Data changes

  • Mass updates/inserts are batched appropriately
  • Does not loop over large tables/datasets
  • Defends against missing or invalid data
  • For settings updates: follows the appropriate guidelines

@github-actions

This comment was marked as outdated.

EvanHahn added 2 commits April 6, 2026 13:41
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
```
@github-actions

This comment was marked as outdated.

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.)
closes https://linear.app/ghost/issue/NY-1188

This removes the old automated emails table now that we aren't using it
anymore.
@EvanHahn EvanHahn marked this pull request as ready for review April 6, 2026 19:47
@EvanHahn EvanHahn requested a review from cmraible April 6, 2026 19:47
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 6, 2026

Comment on lines +25 to +34
async function up(knex) {
const exists = await knex.schema.hasTable('automated_emails');
if (!exists) {
logging.warn('Skipping dropping table automated_emails - does not exist');
return;
}

logging.info('Dropping table: automated_emails');
await commands.deleteTable('automated_emails', knex);
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: use the dropTables migration util

Copy link
Copy Markdown
Collaborator

@cmraible cmraible left a comment

Choose a reason for hiding this comment

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

One minor suggestion on the migration, otherwise LGTM!

@EvanHahn
Copy link
Copy Markdown
Contributor Author

EvanHahn commented Apr 7, 2026

Moving this to draft until #27185 is merged. I'll regenerate the migration and address the PR review comment.

Base automatically changed from NY-1188-part-3 to main April 8, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

migration [pull request] Includes migration for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants