Skip to content

Created dormant automation tables#28378

Merged
cmraible merged 3 commits into
mainfrom
ny1305-create-automation-tables
Jun 15, 2026
Merged

Created dormant automation tables#28378
cmraible merged 3 commits into
mainfrom
ny1305-create-automation-tables

Conversation

@EvanHahn

@EvanHahn EvanHahn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the migration [pull request] Includes migration for review label Jun 4, 2026
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Five new database tables are added to support automation workflow persistence: automation_actions, automation_action_revisions, automation_action_edges, automation_runs, and automation_run_steps. The schema definitions cover columns, type/status enums, composite primary and unique keys, foreign keys with cascade/set-null delete behaviors, and row-locking fields. A new @@PRIMARY_KEY@@ marker is introduced to schema/commands.js to support composite primary keys during table creation; the schema validation test and data-generator test are updated to handle this marker. A v6.46 migration creates all five tables in the database. The five tables are also added to the BACKUP_TABLES export list and the exporter integration test. Package versions for ghost-admin and ghost/core are bumped to 6.46.0-rc.0.

Possibly related PRs

  • TryGhost/Ghost#28521: Updates replaceAutomationGraph to batch-insert rows into automation_action_edges, directly building on the automation_action_edges table added in this PR.
  • TryGhost/Ghost#28523: Updates replaceAutomationGraph to soft-delete removed automation_actions via deleted_at, using the soft-delete column defined in this PR's automation_actions schema.
  • TryGhost/Ghost#27878: Introduces the automations graph editing API/service/repository that operates on the automation_actions, automation_action_edges, and automation_action_revisions tables created here.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: creating dormant automation tables in the database schema.
Description check ✅ Passed The description is related to the changeset, providing context about creating empty automation tables and referencing a Linear issue.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ny1305-create-automation-tables

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.

@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch from b5ec7fd to 34dad37 Compare June 4, 2026 21:22
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.94%. Comparing base (1742990) to head (f9bb250).
⚠️ Report is 8 commits behind head on main.

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              
Flag Coverage Δ
admin-tests 54.89% <ø> (ø)
e2e-tests 76.10% <100.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch from 34dad37 to 881e03c Compare June 11, 2026 21:01
@EvanHahn EvanHahn added the preview Deploy a PR preview environment label Jun 11, 2026
@nx-cloud

nx-cloud Bot commented Jun 11, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit f9bb250

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

@Ghost-Slimer Ghost-Slimer temporarily deployed to pr-preview-28378 June 11, 2026 21:08 Destroyed
@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch from 881e03c to 0f5ea06 Compare June 11, 2026 21:11
@EvanHahn EvanHahn marked this pull request as ready for review June 11, 2026 21:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Use continue instead of break for metadata rows.

At Line 41, Line 46, and Line 49, break stops processing remaining keys, so a table with multiple metadata blocks can miss constraints in this test setup. That diverges from createTable() behavior in ghost/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

📥 Commits

Reviewing files that changed from the base of the PR and between 983f2e7 and 0f5ea06.

📒 Files selected for processing (8)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/migrations/versions/6.45/2026-06-11-19-59-19-create-automation-tables.js
  • ghost/core/core/server/data/schema/commands.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/test/integration/exporter/exporter.test.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js
  • ghost/core/test/unit/server/data/schema/schema.test.js
  • ghost/core/test/unit/server/data/seeders/data-generator.test.js

@EvanHahn EvanHahn requested a review from cmraible June 11, 2026 21:31
@EvanHahn EvanHahn marked this pull request as draft June 11, 2026 21:34
@EvanHahn EvanHahn marked this pull request as ready for review June 11, 2026 21:36
@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch from 0f5ea06 to 237acc3 Compare June 11, 2026 21:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
ghost/core/core/server/data/schema/schema.js (1)

1211-1213: ⚖️ Poor tradeoff

Composite 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f5ea06 and 237acc3.

📒 Files selected for processing (8)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/migrations/versions/6.45/2026-06-11-19-59-19-create-automation-tables.js
  • ghost/core/core/server/data/schema/commands.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/test/integration/exporter/exporter.test.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js
  • ghost/core/test/unit/server/data/schema/schema.test.js
  • ghost/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

Comment thread ghost/core/core/server/data/schema/schema.js Outdated
Comment thread ghost/core/core/server/data/schema/schema.js Outdated
Comment thread ghost/core/core/server/data/schema/schema.js Outdated
@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch 3 times, most recently from f36ff62 to b5c2ef6 Compare June 14, 2026 02:47
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
@EvanHahn EvanHahn force-pushed the ny1305-create-automation-tables branch from b5c2ef6 to 69c22d8 Compare June 14, 2026 03:09

@cmraible cmraible left a comment

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.

One question re: the on-delete behavior, otherwise LGTM!

@EvanHahn EvanHahn added the ok to merge for me You can merge this on my behalf if you want. label Jun 15, 2026
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},

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.

praise: I think this is the default behavior if omitted, but I like that this is explicit about it

@cmraible cmraible merged commit 79f85a0 into main Jun 15, 2026
55 checks passed
@cmraible cmraible deleted the ny1305-create-automation-tables branch June 15, 2026 16:42
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 ok to merge for me You can merge this on my behalf if you want. preview Deploy a PR preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants