Created dormant automation tables#28378
Conversation
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughFive new database tables are added to support automation workflow persistence: Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
b5ec7fd to
34dad37
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28378 +/- ##
==========================================
+ Coverage 73.75% 73.94% +0.19%
==========================================
Files 1541 1541
Lines 132410 132375 -35
Branches 15859 15901 +42
==========================================
+ Hits 97655 97881 +226
+ Misses 33791 33530 -261
Partials 964 964
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
34dad37 to
881e03c
Compare
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run ghost:test:ci:integration:no-coverage |
✅ Succeeded | 1m 45s | View ↗ |
nx run ghost:test:ci:integration |
✅ Succeeded | 1m 6s | View ↗ |
nx run ghost:test:ci:e2e:no-coverage |
✅ Succeeded | 3m 46s | View ↗ |
nx run ghost:test:ci:e2e |
✅ Succeeded | 3m 32s | View ↗ |
nx run ghost-admin:test |
✅ Succeeded | 2m 55s | View ↗ |
nx build @tryghost/admin-toolbar |
✅ Succeeded | <1s | View ↗ |
nx build @tryghost/portal |
✅ Succeeded | <1s | View ↗ |
nx build @tryghost/sodo-search |
✅ Succeeded | <1s | View ↗ |
Additional runs (11) |
✅ Succeeded | ... | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-06-15 16:00:15 UTC
881e03c to
0f5ea06
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ghost/core/test/unit/server/data/seeders/data-generator.test.js (1)
37-49:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse
continueinstead ofbreakfor metadata rows.At Line 41, Line 46, and Line 49,
breakstops processing remaining keys, so a table with multiple metadata blocks can miss constraints in this test setup. That diverges fromcreateTable()behavior inghost/core/core/server/data/schema/commands.js, which applies each metadata block independently.Suggested patch
if (rowName === '@@UNIQUE_CONSTRAINTS@@') { for (const constraints of row) { table.unique(constraints); } - break; + continue; } else if (rowName === '@@INDEXES@@') { for (const indexes of row) { table.index(indexes); } - break; + continue; } else if (rowName === '@@PRIMARY_KEY@@') { table.primary(row); - break; + continue; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ghost/core/test/unit/server/data/seeders/data-generator.test.js` around lines 37 - 49, The test's loop handling metadata keys uses break for the '@@UNIQUE_CONSTRAINTS@@', '@@INDEXES@@', and '@@PRIMARY_KEY@@' branches (checking rowName), which prematurely stops processing other metadata blocks; change those break statements to continue so each metadata block is applied independently (ensure table.unique(...), table.index(...), and table.primary(...) branches use continue) to match createTable() behavior in createTable()/core server data schema commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@ghost/core/test/unit/server/data/seeders/data-generator.test.js`:
- Around line 37-49: The test's loop handling metadata keys uses break for the
'@@UNIQUE_CONSTRAINTS@@', '@@INDEXES@@', and '@@PRIMARY_KEY@@' branches
(checking rowName), which prematurely stops processing other metadata blocks;
change those break statements to continue so each metadata block is applied
independently (ensure table.unique(...), table.index(...), and
table.primary(...) branches use continue) to match createTable() behavior in
createTable()/core server data schema commands.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 89930146-68b6-4b79-afc3-170fc2dce263
📒 Files selected for processing (8)
ghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.45/2026-06-11-19-59-19-create-automation-tables.jsghost/core/core/server/data/schema/commands.jsghost/core/core/server/data/schema/schema.jsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.jsghost/core/test/unit/server/data/schema/schema.test.jsghost/core/test/unit/server/data/seeders/data-generator.test.js
0f5ea06 to
237acc3
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
ghost/core/core/server/data/schema/schema.js (1)
1211-1213: ⚖️ Poor tradeoffComposite unique constraint on timestamp + ID could fail under high concurrency.
The unique constraint on
['created_at', 'action_id']prevents multiple revisions with identical timestamps for the same action. While unlikely, rapid concurrent revisions could theoretically create two records in the same millisecond, causing a constraint violation.Consider using a monotonic sequence (e.g., auto-increment
revision_number) or widening timestamp precision if this becomes an issue in practice.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ghost/core/core/server/data/schema/schema.js` around lines 1211 - 1213, The composite unique constraint array '@@UNIQUE_CONSTRAINTS@@' currently uses ['created_at','action_id'], which can race under very high concurrency; change the schema to remove that constraint and instead introduce a monotonic revision token (e.g., add a revision_number integer/serial column on the revisions table and enforce uniqueness on ['action_id','revision_number']) or, alternatively, widen timestamp precision (e.g., use a timestamptz with nanosecond precision) and update the constraint to ['created_at','action_id'] only if precision is guaranteed; update any code that inserts revisions (functions/methods that create revision rows) to populate/increment revision_number or rely on the DB sequence so uniqueness is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Line 1200: The foreign key field automation_id lacks a cascade delete policy
so deleting an automation leaves orphaned rows; update the schema definition for
the table containing automation_id to include cascadeDelete: true on the
automation_id column (i.e., change the automation_id field definition to include
cascadeDelete: true alongside type/maxlength/nullable/references), mirroring
patterns used by webhooks.integration_id and products_benefits.product_id; run
or add any required migration to apply the cascade behavior to the DB if schema
changes are persisted via migrations.
- Around line 1216-1217: The foreign key definitions for source_action_id and
target_action_id currently reference automation_actions.id but lack cascade
delete; update both field definitions (source_action_id and target_action_id) to
include onDelete: 'CASCADE' (keeping references: 'automation_actions.id' and
other properties) so that deleting an automation_actions row will cascade-delete
the corresponding edges.
- Line 1206: The foreign key definition for action_id in schema.js currently
lacks a cascade-on-delete rule, so update the action_id column definition (the
entry named action_id in core/server/data/schema/schema.js) to include a cascade
delete policy (e.g., add onDelete: 'CASCADE' or cascade: true according to the
schema API used) so that deleting an automation_actions row will also remove its
revisions; ensure the updated definition keeps maxlength: 24 and nullable: false
and references: 'automation_actions.id'.
---
Nitpick comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Around line 1211-1213: The composite unique constraint array
'@@UNIQUE_CONSTRAINTS@@' currently uses ['created_at','action_id'], which can
race under very high concurrency; change the schema to remove that constraint
and instead introduce a monotonic revision token (e.g., add a revision_number
integer/serial column on the revisions table and enforce uniqueness on
['action_id','revision_number']) or, alternatively, widen timestamp precision
(e.g., use a timestamptz with nanosecond precision) and update the constraint to
['created_at','action_id'] only if precision is guaranteed; update any code that
inserts revisions (functions/methods that create revision rows) to
populate/increment revision_number or rely on the DB sequence so uniqueness is
preserved.
🪄 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: ebc54ad4-ec1a-4a11-bbe2-585e22c5a0e2
📒 Files selected for processing (8)
ghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.45/2026-06-11-19-59-19-create-automation-tables.jsghost/core/core/server/data/schema/commands.jsghost/core/core/server/data/schema/schema.jsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.jsghost/core/test/unit/server/data/schema/schema.test.jsghost/core/test/unit/server/data/seeders/data-generator.test.js
🚧 Files skipped from review as they are similar to previous changes (4)
- ghost/core/test/integration/exporter/exporter.test.js
- ghost/core/test/unit/server/data/schema/schema.test.js
- ghost/core/core/server/data/schema/commands.js
- ghost/core/test/unit/server/data/seeders/data-generator.test.js
f36ff62 to
b5c2ef6
Compare
closes https://linear.app/ghost/issue/NY-1305 This creates empty automation tables which we'll soon fill in. You might wish to compare these to the [temporary in-memory database][0] we've been using. [0]: https://github.com/TryGhost/Ghost/blob/983f2e74f02479208c22426508935ebd99bd7e06/ghost/core/core/server/services/automations/temporary-fake-database.ts#L50-L114
b5c2ef6 to
69c22d8
Compare
cmraible
left a comment
There was a problem hiding this comment.
One question re: the on-delete behavior, otherwise LGTM!
| updated_at: {type: 'dateTime', nullable: false}, | ||
| deleted_at: {type: 'dateTime', nullable: true}, | ||
| automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'automations.id', cascadeDelete: true}, | ||
| automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'automations.id', restrictDelete: true}, |
There was a problem hiding this comment.
praise: I think this is the default behavior if omitted, but I like that this is explicit about it

closes https://linear.app/ghost/issue/NY-1305
This creates empty automation tables which we'll soon fill in. You might wish to compare these to the temporary in-memory database we've been using.