Skip to content

Added gifts database table#26995

Open
sagzy wants to merge 1 commit intomainfrom
add-gifts-table
Open

Added gifts database table#26995
sagzy wants to merge 1 commit intomainfrom
add-gifts-table

Conversation

@sagzy
Copy link
Copy Markdown
Contributor

@sagzy sagzy commented Mar 26, 2026

closes https://linear.app/ghost/issue/BER-3502
ref https://linear.app/ghost/project/gift-subscriptions-b7184e4f8972

Adding a new table in the context of the gift subscriptions project, to store gift data (buyer info, redeemer info, gift amount/currency/duration, etc.)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c2546dd-5140-497a-b4ed-f218d02ecc40

📥 Commits

Reviewing files that changed from the base of the PR and between a050218 and 50635b0.

📒 Files selected for processing (5)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/migrations/versions/6.24/2026-03-26-17-55-43-add-gifts-table.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
✅ Files skipped from review due to trivial changes (1)
  • ghost/core/test/unit/server/data/schema/integrity.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/schema/schema.js

Walkthrough

A new database table named gifts was introduced to persist gift and purchase lifecycle data. The table definition includes fields for buyer and redeemer information, payment identifiers, billing details (amount, currency, cadence), tier references, and status tracking with associated timestamps. Supporting changes include a database migration file, an updated schema integrity hash, inclusion of the gifts table in the backup export allowlist, and test updates to accommodate the new table in exporter validations.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Added gifts database table' directly and clearly describes the main change—a new database table for gifts was added across multiple files.
Description check ✅ Passed The PR description is directly related to the changeset, explaining the addition of a new gifts table for the gift subscriptions project and referencing relevant issues and context.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-gifts-table

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 Mar 26, 2026
@github-actions
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

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.

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

1173-1207: Consider adding an updated_at column for tracking modifications.

Most tables in the schema include created_at and updated_at columns (e.g., offers, products, subscriptions). While purchased_at serves as the creation timestamp, there's no column to track subsequent modifications to gift records (e.g., status changes, redemption updates).

If gifts are immutable after purchase, this is fine. Otherwise, consider adding:

        consumed_at: {type: 'dateTime', nullable: true}
+       created_at: {type: 'dateTime', nullable: false},
+       updated_at: {type: 'dateTime', nullable: true}
    }
🤖 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 1173 - 1207, The
gifts schema is missing an updated_at column to track modifications; add an
updated_at field to the gifts table definition (alongside the existing
purchased_at, redeemed_at, etc.) with the same type and nullability pattern used
elsewhere (e.g., type 'dateTime', nullable: true) so updates to records such as
status changes or redemption timestamps can be recorded; update any migration or
model logic that expects timestamps to include this new updated_at field where
necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Around line 1173-1207: The gifts schema is missing an updated_at column to
track modifications; add an updated_at field to the gifts table definition
(alongside the existing purchased_at, redeemed_at, etc.) with the same type and
nullability pattern used elsewhere (e.g., type 'dateTime', nullable: true) so
updates to records such as status changes or redemption timestamps can be
recorded; update any migration or model logic that expects timestamps to include
this new updated_at field where necessary.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 861d70a6-a191-4e9a-b974-39298c11f4f9

📥 Commits

Reviewing files that changed from the base of the PR and between f6e7cc8 and 8fed057.

📒 Files selected for processing (3)
  • ghost/core/core/server/data/migrations/versions/6.23/2026-03-26-16-41-06-add-gifts-table.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js

@sagzy sagzy force-pushed the add-gifts-table branch from 8fed057 to a050218 Compare March 26, 2026 17:17
duration: {type: 'integer', nullable: false, unsigned: true},

currency: {type: 'string', maxlength: 50, nullable: false},
amount: {type: 'integer', nullable: false},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unsigned: true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep good shout, updated

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.

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

1173-1207: Consider adding an updated_at field for consistency and auditability.

Most tables in this schema include an updated_at: {type: 'dateTime', nullable: true} field to track when records are modified. The gifts table will likely have status transitions (purchased → redeemed → consumed, or purchased → expired, etc.), and having updated_at helps track when these changes occur for debugging and auditing purposes.

Proposed fix
         refunded_at: {type: 'dateTime', nullable: true},
-        consumed_at: {type: 'dateTime', nullable: true}
+        consumed_at: {type: 'dateTime', nullable: true},
+        updated_at: {type: 'dateTime', nullable: true}
     }
🤖 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 1173 - 1207, Add
an updated_at column to the gifts table schema to match other tables and record
modification timestamps: inside the gifts schema object (adjacent to fields like
purchased_at, redeemed_at, status), add an updated_at: {type: 'dateTime',
nullable: true} entry so updates to status
(purchased/redeemed/consumed/expired/refunded) and other changes are auditable
and consistent with existing tables.

1197-1206: Consider adding indexes for common query patterns.

Depending on expected query patterns, you may want to add indexes on frequently queried columns like status, buyer_member_id, redeemer_member_id, or tier_id. This can be deferred until actual usage patterns are known.

Example index definition
'@@INDEXES@@': [
    ['status'],
    ['buyer_member_id'],
    ['tier_id']
]
🤖 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 1197 - 1206, The
schema for the vouchers table lacks indexes for columns likely used in filters
(e.g., status, buyer_member_id, redeemer_member_id, tier_id); add an
'@@INDEXES@@' entry to the schema definition (near the fields status,
purchased_at, redeemed_at, etc.) listing arrays for the columns you expect to
query frequently (for example ['status'], ['buyer_member_id'], ['tier_id'], and
optionally ['redeemer_member_id']) so the ORM/DB will create those indexes; keep
index names/defaults consistent with existing schema conventions when adding the
'@@INDEXES@@' block.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Around line 1173-1207: Add an updated_at column to the gifts table schema to
match other tables and record modification timestamps: inside the gifts schema
object (adjacent to fields like purchased_at, redeemed_at, status), add an
updated_at: {type: 'dateTime', nullable: true} entry so updates to status
(purchased/redeemed/consumed/expired/refunded) and other changes are auditable
and consistent with existing tables.
- Around line 1197-1206: The schema for the vouchers table lacks indexes for
columns likely used in filters (e.g., status, buyer_member_id,
redeemer_member_id, tier_id); add an '@@INDEXES@@' entry to the schema
definition (near the fields status, purchased_at, redeemed_at, etc.) listing
arrays for the columns you expect to query frequently (for example ['status'],
['buyer_member_id'], ['tier_id'], and optionally ['redeemer_member_id']) so the
ORM/DB will create those indexes; keep index names/defaults consistent with
existing schema conventions when adding the '@@INDEXES@@' block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e1cabf00-5cee-48d3-a893-52e032394b50

📥 Commits

Reviewing files that changed from the base of the PR and between 8fed057 and a050218.

📒 Files selected for processing (4)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/migrations/versions/6.23/2026-03-26-16-41-06-add-gifts-table.js
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js
✅ Files skipped from review due to trivial changes (3)
  • ghost/core/core/server/data/exporter/table-lists.js
  • ghost/core/core/server/data/migrations/versions/6.23/2026-03-26-16-41-06-add-gifts-table.js
  • ghost/core/test/unit/server/data/schema/integrity.test.js

@sagzy sagzy changed the title Added gifts database table Added gifts database table Mar 26, 2026
closes https://linear.app/ghost/issue/BER-3502
ref https://linear.app/ghost/project/gift-subscriptions-b7184e4f8972

Adds a new table in the context of the gift subscriptions project, to store gift data (buyer info, redeemer info, gift amount/currency/duration, etc.)
@sagzy sagzy force-pushed the add-gifts-table branch from a050218 to 50635b0 Compare March 26, 2026 17:58
@sonarqubecloud
Copy link
Copy Markdown

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