Added gifts database table#26995
Conversation
|
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:
WalkthroughAdds a new persisted 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/core/server/data/schema/schema.js (1)
1173-1207: Consider adding anupdated_atcolumn for tracking modifications.Most tables in the schema include
created_atandupdated_atcolumns (e.g.,offers,products,subscriptions). Whilepurchased_atserves 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
📒 Files selected for processing (3)
ghost/core/core/server/data/migrations/versions/6.23/2026-03-26-16-41-06-add-gifts-table.jsghost/core/core/server/data/schema/schema.jsghost/core/test/unit/server/data/schema/integrity.test.js
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ghost/core/core/server/data/schema/schema.js (2)
1173-1207: Consider adding anupdated_atfield for consistency and auditability.Most tables in this schema include an
updated_at: {type: 'dateTime', nullable: true}field to track when records are modified. Thegiftstable will likely have status transitions (purchased → redeemed → consumed, or purchased → expired, etc.), and havingupdated_athelps 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, ortier_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
📒 Files selected for processing (4)
ghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.23/2026-03-26-16-41-06-add-gifts-table.jsghost/core/core/server/data/schema/schema.jsghost/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
50635b0 to
931d238
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
ghost/core/core/server/data/schema/schema.js (2)
1198-1233: Consider adding indexes for common query patterns.The table lacks explicit indexes beyond unique constraints. Depending on expected query patterns, consider adding indexes for:
statusandexpires_at(for expiration batch jobs)buyer_member_id/redeemer_member_id(for member lookups)This can be deferred and added via migration once query patterns are established in production.
📊 Example index definition
refunded_at: {type: 'dateTime', nullable: true} + '@@INDEXES@@': [ + ['status', 'expires_at'], + ['buyer_member_id'], + ['redeemer_member_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 1198 - 1233, The gifts schema (object "gifts" in schema.js) currently only has unique constraints but no non-unique indexes; add non-unique indexes for common query patterns by creating a migration (or updating the schema index definitions) that adds indexes on status, expires_at, buyer_member_id and redeemer_member_id (and consider a composite index like (status, expires_at) for expiration batch queries) so lookups by member and expiration scans are efficient in production.
1224-1228: Consider adding a default value forstatus.The
statusfield lacks adefaultTovalue. Since gifts are created upon purchase, defaulting to'purchased'would provide a safety net if any code path fails to explicitly set the status.💡 Suggested change
status: { - type: 'string', maxlength: 50, nullable: false, validations: { + type: 'string', maxlength: 50, nullable: false, defaultTo: 'purchased', validations: { isIn: [['purchased', 'redeemed', 'consumed', 'expired', 'refunded']] } },🤖 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 1224 - 1228, The status column in the gifts schema currently has type, maxlength, nullable, and isIn validations but no default; update the status definition in schema.js (the status field with validations isIn: [['purchased', 'redeemed', 'consumed', 'expired', 'refunded']]) to include a defaultTo of 'purchased' so new gift records default to 'purchased' when not explicitly set; ensure the added default aligns with the existing type/validation and does not break nullable:false constraint.
🤖 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`:
- Line 1207: The schema field definition for tier_id (tier_id: {type: 'string',
maxlength: 24, nullable: false, unique: false, references: 'products.id'}) is
missing an explicit cascadeDelete behavior; update the tier_id column definition
in schema.js to include the appropriate cascade policy (either cascadeDelete:
true or cascadeDelete: false) to match the intended behavior for product/tier
deletions, mirroring the pattern used by other product foreign keys (see
subscriptions.tier_id and the product foreign keys that include cascadeDelete)
so the migration/schema is consistent and explicit.
---
Nitpick comments:
In `@ghost/core/core/server/data/schema/schema.js`:
- Around line 1198-1233: The gifts schema (object "gifts" in schema.js)
currently only has unique constraints but no non-unique indexes; add non-unique
indexes for common query patterns by creating a migration (or updating the
schema index definitions) that adds indexes on status, expires_at,
buyer_member_id and redeemer_member_id (and consider a composite index like
(status, expires_at) for expiration batch queries) so lookups by member and
expiration scans are efficient in production.
- Around line 1224-1228: The status column in the gifts schema currently has
type, maxlength, nullable, and isIn validations but no default; update the
status definition in schema.js (the status field with validations isIn:
[['purchased', 'redeemed', 'consumed', 'expired', 'refunded']]) to include a
defaultTo of 'purchased' so new gift records default to 'purchased' when not
explicitly set; ensure the added default aligns with the existing
type/validation and does not break nullable:false constraint.
🪄 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: 045168dd-44df-445f-a0db-4012a6a798f2
📒 Files selected for processing (5)
ghost/core/core/server/data/exporter/table-lists.jsghost/core/core/server/data/migrations/versions/6.25/2026-03-31-09-46-30-add-gifts-table.jsghost/core/core/server/data/schema/schema.jsghost/core/test/integration/exporter/exporter.test.jsghost/core/test/unit/server/data/schema/integrity.test.js
✅ Files skipped from review due to trivial changes (2)
- ghost/core/test/unit/server/data/schema/integrity.test.js
- ghost/core/core/server/data/migrations/versions/6.25/2026-03-31-09-46-30-add-gifts-table.js
🚧 Files skipped from review as they are similar to previous changes (1)
- ghost/core/test/integration/exporter/exporter.test.js
cc2791e to
8221f3f
Compare
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.)
|
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.)



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.)