Skip to content

Added gift subscription notification columns to users table#27304

Merged
mike182uk merged 1 commit intomainfrom
BER-3523-add-db-columns
Apr 9, 2026
Merged

Added gift subscription notification columns to users table#27304
mike182uk merged 1 commit intomainfrom
BER-3523-add-db-columns

Conversation

@mike182uk
Copy link
Copy Markdown
Member

@mike182uk mike182uk commented Apr 9, 2026

ref https://linear.app/ghost/issue/BER-3523

Added gift subscription notification columns to the users table so a user can configure if they want to receive notifications for gift subscription related actions (purchase, redemption)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

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

Added two migration files that add gift_subscription_purchase_notification and gift_subscription_redemption_notification boolean columns to the users table (non-nullable, default true). Updated the exported schema to include both columns. Extended the User model defaults to set both notification flags to true. Updated the Content API author output serializer to remove both fields from serialized attrs. Updated the schema integrity unit test's expected MD5 hash to reflect schema changes.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding gift subscription notification columns to the users table.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of adding gift subscription notification columns to allow user configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 BER-3523-add-db-columns

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 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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`:
- Around line 185-186: The new schema fields
gift_subscription_purchase_notification and
gift_subscription_redemption_notification were added but not wired into user
notification behavior; update ghost/core/core/server/models/user.js by adding
these two keys to the user defaults block (alongside the other notification
defaults) and add recipient-filter branches in the recipient filtering logic
where filter strings are built (the code that appends "+...:true") to include
checks for gift_subscription_purchase_notification and
gift_subscription_redemption_notification so opt-outs are respected when
selecting recipients. Ensure you reference the existing default names and the
same "+...:true" filter pattern used for other notification types.
🪄 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: acbb45a0-8165-4f22-812a-58a979b6837c

📥 Commits

Reviewing files that changed from the base of the PR and between 9505bac and f65d37e.

📒 Files selected for processing (4)
  • ghost/core/core/server/data/migrations/versions/6.28/2026-04-09-13-25-36-add-gift-subscription-purchase-notification-column.js
  • ghost/core/core/server/data/migrations/versions/6.28/2026-04-09-13-25-51-add-gift-subscription-redemption-notification-column.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js

Comment on lines +185 to +186
gift_subscription_purchase_notification: {type: 'boolean', nullable: false, defaultTo: true},
gift_subscription_redemption_notification: {type: 'boolean', nullable: false, defaultTo: true},
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Apr 9, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Wire the new notification columns into user notification behavior.

Line 185 and Line 186 add persisted preferences, but ghost/core/core/server/models/user.js (defaults at Line 61-Line 76, filter logic at Line 500-Line 516) does not yet include these fields. As-is, gift notification opt-outs may not be enforced when recipients are selected.

Suggested follow-up (outside this file)
// ghost/core/core/server/models/user.js (defaults)
 defaults: function defaults() {
     return {
         ...
         donation_notifications: true,
+        gift_subscription_purchase_notification: true,
+        gift_subscription_redemption_notification: true
     };
 }

Also add corresponding recipient-filter branches for the gift notification event types in ghost/core/core/server/models/user.js where filter += '+...:true' is built.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/core/server/data/schema/schema.js` around lines 185 - 186, The new
schema fields gift_subscription_purchase_notification and
gift_subscription_redemption_notification were added but not wired into user
notification behavior; update ghost/core/core/server/models/user.js by adding
these two keys to the user defaults block (alongside the other notification
defaults) and add recipient-filter branches in the recipient filtering logic
where filter strings are built (the code that appends "+...:true") to include
checks for gift_subscription_purchase_notification and
gift_subscription_redemption_notification so opt-outs are respected when
selecting recipients. Ensure you reference the existing default names and the
same "+...:true" filter pattern used for other notification types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Implementation will be done in a follow up PR

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.

@mike182uk, understood! Would you like me to open a GitHub issue to track wiring gift_subscription_purchase_notification and gift_subscription_redemption_notification into ghost/core/core/server/models/user.js (defaults block and recipient-filter logic) so it's not forgotten?


🧠 Learnings used
Learnt from: rob-ghost
Repo: TryGhost/Ghost PR: 25791
File: ghost/core/core/server/api/endpoints/member-comment-ban.js:64-68
Timestamp: 2026-01-08T10:26:38.700Z
Learning: In the Ghost API, endpoints rely on the serialization layer to prepare frame.data[docName] as a non-empty array before query() executes. Endpoints access frame.data[docName][0] directly (e.g., frame.data.comment_bans[0], frame.data.members[0], frame.data.posts[0]) without per-endpoint validation. This pattern is common across API endpoints. When maintaining or creating endpoints, avoid duplicating validation for frame.data[docName] and ensure the serializer guarantees the shape and non-emptiness. If you add a new endpoint that uses this frame.data[docName], follow the same assumption and avoid redundant checks unless there's a documented exception.

Learnt from: rob-ghost
Repo: TryGhost/Ghost PR: 26219
File: ghost/core/test/e2e-api/members-comments/comments.test.js:939-983
Timestamp: 2026-02-04T15:58:09.124Z
Learning: In Ghost core tests and code that interact with the Ghost comments API, count.replies is a backward-compatible alias for count.total_replies (all descendants via parent_id) and does not represent direct replies. The new field count.direct_replies returns tree-native direct reply counts. Reviewers should verify any code paths, tests, or API surface areas that rely on count.replies are preserved for compatibility, and consider updating or adding tests to cover count.direct_replies for direct counts. When updating or adding tests, ensure behavior is documented and that any assertions reflect the distinction between total (including descendants) and direct reply counts to avoid regressions in API consumer expectations.

Learnt from: sagzy
Repo: TryGhost/Ghost PR: 26995
File: ghost/core/core/server/data/schema/schema.js:1207-1207
Timestamp: 2026-03-31T21:52:45.344Z
Learning: In the Ghost (TryGhost/Ghost) schema, tier records stored in the `products` table are not deletable; they can only be archived. Therefore, for foreign key columns that reference `products.id` (e.g., `tier_id` in tables like `gifts`/`subscriptions`), do not require or flag an explicit `cascadeDelete`/cascade-delete policy. Omitting cascade delete for these `products.id` references is intentional and correct—only flag cascade-related issues for actual deletable parent entities.

Learnt from: vershwal
Repo: TryGhost/Ghost PR: 27290
File: ghost/core/package.json:76-77
Timestamp: 2026-04-09T09:44:26.783Z
Learning: In the TryGhost/Ghost monorepo, treat `tryghost/admin-api-schema` as the single abstraction layer over AJV version differences. Do not raise code review findings for AJV-internal error field changes (e.g., `dataPath` → `instancePath` between AJV v6 and v8) when evaluating Ghost consumer code. The consumer-facing error contract for this package (`ValidationError` with `message`, `property`, `errorDetails`) is expected to remain stable, and Ghost wrapper code should not inspect raw AJV error objects—so review should focus on the stable `ValidationError` shape rather than AJV internals.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

E2E Tests Failed

To view the Playwright test report locally, run:

REPORT_DIR=$(mktemp -d) && gh run download 24192969177 -n playwright-report -D "$REPORT_DIR" && npx playwright show-report "$REPORT_DIR"

@mike182uk mike182uk force-pushed the BER-3523-add-db-columns branch 4 times, most recently from cd3a9a2 to ff8dae9 Compare April 9, 2026 14:42
Copy link
Copy Markdown
Contributor

@sagzy sagzy left a comment

Choose a reason for hiding this comment

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

LGTM. The migration PR is doing a bit more than usual, but feels fairly safe as it's a new setting

ref https://linear.app/ghost/issue/BER-3523

Added gift subscription notification columns to the `users` table so a user
can configure if they want to recieve these notifications
@mike182uk mike182uk force-pushed the BER-3523-add-db-columns branch from ff8dae9 to 49501b5 Compare April 9, 2026 15:57
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 9, 2026

@mike182uk mike182uk merged commit de75491 into main Apr 9, 2026
38 checks passed
@mike182uk mike182uk deleted the BER-3523-add-db-columns branch April 9, 2026 16:27
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