-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Skipped set/drop nullable migration queries when not necessary #24533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes introduce and enhance utility functions for handling nullable column migrations in the database schema migration utilities. Two new asynchronous helper functions, Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
bce0956
to
df9890c
Compare
no issue - added pre-condition checks to `createDropNullableMigration` and `createSetNullableMigration` migration utils that skips expensive `ALTER TABLE` queries when the database is already in the correct state
df9890c
to
07b16da
Compare
createDropNullableMigration
when not necessaryThere was a problem hiding this comment.
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/test/integration/migrations/nullable-utils.test.js (1)
93-119
: Consider reusing the actual implementation functions to avoid duplication.These helper functions duplicate the logic from
ghost/core/core/server/data/migrations/utils/schema.js
. This creates a maintenance burden and could lead to tests passing even if the actual implementation changes.Consider importing and using the actual
isColumnNullable
andisColumnNotNullable
functions from the schema utils, or at least extract these helpers to a shared test utility file.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
ghost/core/core/server/data/migrations/utils/schema.js
(4 hunks)ghost/core/test/integration/migrations/nullable-utils.test.js
(1 hunks)ghost/core/test/unit/server/data/migrations/utils.test.js
(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: cathysarisky
PR: TryGhost/Ghost#0
File: :0-0
Timestamp: 2025-05-20T21:08:21.026Z
Learning: In the Ghost project, translation files (ghost/i18n/locales/*/*.json) commonly have blank values for translations, and this is normal behavior that should not be flagged in reviews. These empty translations will be filled in separate PRs.
ghost/core/test/integration/migrations/nullable-utils.test.js (3)
Learnt from: mike182uk
PR: #22471
File: apps/admin-x-activitypub/src/utils/pending-activity.ts:13-71
Timestamp: 2025-03-13T09:00:20.205Z
Learning: The pending activity utilities in the Ghost ActivityPub module are covered by tests in the file apps/admin-x-activitypub/test/unit/utils/pending-activity.ts
.
Learnt from: mike182uk
PR: #22471
File: apps/admin-x-activitypub/src/utils/pending-activity.ts:13-71
Timestamp: 2025-03-13T09:00:20.205Z
Learning: The pending activity utilities in Ghost's ActivityPub module are thoroughly tested in apps/admin-x-activitypub/test/unit/utils/pending-activity.ts
, which covers generatePendingActivityId
, isPendingActivity
, and generatePendingActivity
functions.
Learnt from: ErisDS
PR: #23588
File: ghost/core/test/e2e-api/admin/backup.test.js:136-148
Timestamp: 2025-05-29T10:37:26.369Z
Learning: In the Ghost test framework, when testing CSV exports via the admin API, the response body
field is empty while the actual CSV data is provided through the text
field. Tests should use expectEmptyBody()
and then validate the CSV content via .expect(({text}) => ...)
- this is not contradictory behavior.
ghost/core/core/server/data/migrations/utils/schema.js (1)
Learnt from: mike182uk
PR: #22471
File: apps/admin-x-activitypub/src/utils/pending-activity.ts:13-71
Timestamp: 2025-03-13T09:00:20.205Z
Learning: The pending activity utilities in Ghost's ActivityPub module are thoroughly tested in apps/admin-x-activitypub/test/unit/utils/pending-activity.ts
, which covers generatePendingActivityId
, isPendingActivity
, and generatePendingActivity
functions.
ghost/core/test/unit/server/data/migrations/utils.test.js (3)
Learnt from: mike182uk
PR: #22471
File: apps/admin-x-activitypub/src/utils/pending-activity.ts:13-71
Timestamp: 2025-03-13T09:00:20.205Z
Learning: The pending activity utilities in the Ghost ActivityPub module are covered by tests in the file apps/admin-x-activitypub/test/unit/utils/pending-activity.ts
.
Learnt from: mike182uk
PR: #22471
File: apps/admin-x-activitypub/src/utils/pending-activity.ts:13-71
Timestamp: 2025-03-13T09:00:20.205Z
Learning: The pending activity utilities in Ghost's ActivityPub module are thoroughly tested in apps/admin-x-activitypub/test/unit/utils/pending-activity.ts
, which covers generatePendingActivityId
, isPendingActivity
, and generatePendingActivity
functions.
Learnt from: ErisDS
PR: #23588
File: ghost/core/test/e2e-api/admin/backup.test.js:136-148
Timestamp: 2025-05-29T10:37:26.369Z
Learning: In the Ghost test framework, when testing CSV exports via the admin API, the response body
field is empty while the actual CSV data is provided through the text
field. Tests should use expectEmptyBody()
and then validate the CSV content via .expect(({text}) => ...)
- this is not contradictory behavior.
🧬 Code Graph Analysis (2)
ghost/core/core/server/data/migrations/utils/schema.js (2)
ghost/core/test/integration/migrations/nullable-utils.test.js (16)
knex
(19-19)knex
(60-60)knex
(94-94)knex
(108-108)logging
(5-5)isNotNullable
(286-286)response
(97-97)response
(101-101)response
(111-111)response
(115-115)response
(291-291)columnInfo
(98-98)columnInfo
(102-102)columnInfo
(112-112)columnInfo
(116-116)columnInfo
(292-292)ghost/core/test/unit/server/data/migrations/utils.test.js (14)
knex
(174-181)knex
(248-255)knex
(292-292)knex
(324-324)knex
(384-384)knex
(401-401)knex
(417-417)knex
(434-434)knex
(453-453)knex
(580-580)knex
(611-611)knex
(652-652)response
(738-738)columnInfo
(739-739)
ghost/core/test/unit/server/data/migrations/utils.test.js (3)
ghost/core/test/integration/migrations/nullable-utils.test.js (25)
knex
(19-19)knex
(60-60)knex
(94-94)knex
(108-108)response
(97-97)response
(101-101)response
(111-111)response
(115-115)response
(291-291)columnInfo
(98-98)columnInfo
(102-102)columnInfo
(112-112)columnInfo
(116-116)columnInfo
(292-292)migration
(123-123)migration
(149-149)migration
(170-172)migration
(199-199)migration
(225-225)migration
(247-249)migration
(272-272)migration
(298-298)utils
(7-7)should
(1-1)sinon
(2-2)ghost/core/core/server/data/migrations/utils/schema.js (10)
response
(181-181)response
(185-185)response
(202-202)response
(206-206)columnInfo
(182-182)columnInfo
(186-186)columnInfo
(203-203)columnInfo
(207-207)require
(2-2)require
(5-5)ghost/core/core/server/data/migrations/utils/settings.js (1)
require
(4-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Ghost-CLI tests
- GitHub Check: E2E tests
- GitHub Check: Acceptance tests (Node 22.13.1, sqlite3)
- GitHub Check: Acceptance tests (Node 22.13.1, mysql8)
- GitHub Check: Legacy tests (Node 22.13.1, sqlite3)
- GitHub Check: Legacy tests (Node 22.13.1, mysql8)
- GitHub Check: Unit tests (Node 22.13.1)
- GitHub Check: i18n
- GitHub Check: Lint
🔇 Additional comments (1)
ghost/core/core/server/data/migrations/utils/schema.js (1)
110-110
: Minor: Make logging consistent between up and down migrations.The down migration includes the foreign key status in the log message, but the up migration doesn't log when starting the operation after the checks pass.
Consider adding a matching info log in the up migration after the checks:
} + logging.info(`Setting nullable: ${table}.${column}`); - logging.info(`Setting nullable: ${table}.${column}`); await commands.setNullable(table, column, knex);Wait, I see the log is already there at line 89. Please disregard this comment.
no issue
createDropNullableMigration
andcreateSetNullableMigration
migration utils that skips expensiveALTER TABLE
queries when the database is already in the correct state