feat(migrations): Move StudioCMS Migration system from kysely package to sdk package#1153
feat(migrations): Move StudioCMS Migration system from kysely package to sdk package#1153Adammatthiesen merged 7 commits intomainfrom
Conversation
…ns, and URL mapping - Created initial migration script for setting up the StudioCMS database schema. - Added migration to drop deprecated tables from the database schema. - Implemented migration for creating a URL mapping table to manage URL mappings for the Storage Manager. - Introduced a script to automate migration creation with proper template handling and index updates. - Updated migrator to dynamically import and manage migrations.
🦋 Changeset detectedLatest commit: 9a0271d The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughCustom migration functionality is moved from Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as CLI (studiocms migrator)
participant SDK as `@withstudiocms/sdk`::migrator
participant Migrations as Migration modules
participant DB as Database (Kysely)
CLI->>SDK: import getMigratorLive(dialect)
SDK->>Migrations: load migrationIndex (dynamic import)
opt migration module returns whole module
Migrations-->>SDK: migration entries (module)
end
CLI->>SDK: invoke Effect-based migrator (toLatest/up/down/status)
SDK->>DB: execute migration operations via Kysely
DB-->>SDK: migration results / status
SDK-->>CLI: Effect resolves with MigrationResultSet or MigrationInfo[]
Notes:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
studiocms
@studiocms/auth0
@studiocms/blog
@studiocms/cloudinary-image-service
@studiocms/devapps
@studiocms/discord
@studiocms/github
@studiocms/google
@studiocms/html
@studiocms/markdoc
@studiocms/md
@studiocms/mdx
@studiocms/migrator
@studiocms/s3-storage
@studiocms/wysiwyg
@withstudiocms/auth-kit
@withstudiocms/component-registry
@withstudiocms/effect
@withstudiocms/internal_helpers
@withstudiocms/kysely
@withstudiocms/sdk
commit: |
Allure Test Report for this PR:✅ Allure Report | History |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/@withstudiocms/sdk/package.json (1)
1-72: Add theengines.nodefield to specify Node.js runtime support.Per coding guidelines, set an
engines.nodefield to target Node.js only and avoid Bun/Deno-specific configurations. Example:"engines": { "node": ">=18.17.0" }(adjust version as needed for project requirements).packages/@withstudiocms/sdk/src/migrator.ts (1)
21-38: Inconsistent return handling between Vitest and production paths.The Vitest path (line 34) returns the module directly via
return await migrations[migrationPath](), while the production path (line 37) destructures and reconstructs:.then(({ up, down }) => ({ up, down })).This could lead to subtle differences if the migration modules export additional properties. For consistency, consider applying the same pattern to both paths.
🔧 Proposed fix for consistency
const importMigration = async (name: string): Promise<Migration> => { if (import.meta.env?.VITEST) { // When using vitest, we need to dynamically import the migrations directly from the built dist folder const migrations = import.meta.glob<{ up: (db: Kysely<any>) => Promise<void>; down: (db: Kysely<any>) => Promise<void>; }>('../dist/migrations/*.js'); const migrationPath = `../dist/migrations/${name}.js`; if (!migrations[migrationPath]) { throw new Error(`Migration not found: ${name}`); } - return await migrations[migrationPath](); + const module = await migrations[migrationPath](); + return { up: module.up, down: module.down }; } return await import(`./migrations/${name}.js`).then(({ up, down }) => ({ up, down })); };
🤖 Fix all issues with AI agents
In @.changeset/young-rabbits-ask.md:
- Line 6: Typo in the package name: replace the incorrect string
'@withstudiomcs/kysely' with the correct '@withstudiocms/kysely' in the
.changeset/young-rabbits-ask.md entry so the migration note refers to the proper
package name; search for '@withstudiomcs/kysely' and update all occurrences to
'@withstudiocms/kysely'.
🧹 Nitpick comments (7)
packages/@withstudiocms/kysely/src/test-utils.ts (3)
33-49: Documentation references commented-out methods.The class documentation at lines 43 and 48 still references
getMigrator()as an available method, but those methods are now commented out. This creates misleading documentation for users of this class.Consider either:
- Removing the
getMigratorreferences from the documentation examples- Adding a note that migrator functionality has moved to
@withstudiocms/sdk/migrator♻️ Proposed documentation fix
* @example * ```ts * const fixture = new DBFixture<YourSchemaType>({ * suiteName: 'example-suite', * cwd: import.meta.url, * }); * * // Using Effect-based utilities * await fixture.effect.cleanup(); * const client = fixture.effect.getClient(); -* const migrator = fixture.effect.getMigrator(); * * // Using JavaScript-based utilities * await fixture.js.cleanup(); * const client = fixture.js.getClient(); -* const migrator = fixture.js.getMigrator(); +* +* // For migrations, use @withstudiocms/sdk/migrator * ```
110-118: Consider removing commented-out code or adding a TODO for cleanup.Leaving commented-out code can lead to confusion over time. Since the migration functionality has moved to
@withstudiocms/sdk, consider either:
- Removing the commented code entirely
- Adding a TODO comment with a cleanup timeline or issue reference
141-146: Documentation comment describes a non-functional method.The JSDoc comment at lines 141-145 documents the
getMigratormethod, but the implementation is commented out. Either remove both the documentation and the commented implementation, or leave a note explaining the migration to the SDK.packages/@withstudiocms/kysely/src/core/migrator.ts (3)
85-109: Documentation references outdated parameter name.The JSDoc at lines 88-91 still references
migrationFolderand describes it as a "Filesystem path to the directory containing migration files," but the parameter is nowmigrations: Record<string, Migration>which is a direct object of migrations, not a filesystem path.♻️ Proposed documentation fix
/** - * Create a factory for constructing a Kysely `Migrator` that loads migration files from a filesystem folder. + * Create a factory for constructing a Kysely `Migrator` using a pre-loaded migrations record. * * @typeParam Schema - The database schema type parameter for the provided `Kysely` instance. - * @param migrationFolder - Filesystem path to the directory containing migration files. This path is forwarded to the `FileMigrationProvider`. - * @returns A function that accepts a `Kysely<Schema>` instance and returns the result of `useWithError(...)` which constructs a `Migrator` configured with the given `db` and a `FileMigrationProvider` that uses the captured `fs`, `path`, and the provided `migrationFolder`. + * @param migrations - A record of migration objects keyed by migration name. + * @returns A function that accepts a `Kysely<Schema>` instance and returns the result of `useWithError(...)` which constructs a `Migrator` configured with the given `db` and a `PassthroughMigrationProvider` using the provided migrations. * * @remarks * - The returned function does not run migrations; it only constructs the `Migrator` (wrapped in the `useWithError` error-handling helper). - * - `fs` and `path` are captured from the module scope and used by the underlying `FileMigrationProvider`. * * @example - * const getMigrator = kyselyMigrator('./migrations'); + * const getMigrator = kyselyMigrator({ '20230101_init': { up, down } }); * const migratorInstance = getMigrator(kyselyInstance); */
111-140: Documentation references outdated "migration folder" terminology.Line 116 mentions "migration folder" but the parameter is now a pre-loaded migrations record. The implementation logic is correct; only the documentation needs updating for consistency.
♻️ Proposed documentation fix
/** - * Creates an Effect that builds a migration helper object for a given migration folder. + * Creates an Effect that builds a migration helper object for a given migrations record. * * @template Schema - The database schema type used by the migrator. * - * @param migrationFolder - Path to the directory containing migration files. + * @param migrations - A record of migration objects keyed by migration name.
142-169: Documentation references outdated filesystem-based approach.Lines 152-158 describe a filesystem-based migration approach ("migrationFolder", "./migrations" directory), but the implementation now accepts a pre-loaded
migrationsrecord directly. The code correctly uses Effect-ts patterns.♻️ Proposed documentation fix
/** * Create a "live" migrator Effect for a specific SQL dialect. * * This factory returns an Effect that, when executed, will: * - instantiate a Kysely client configured for the provided dialect (via makeKyselyClient), * - obtain a database client from the dbClient service, - * - create a migrator that reads migration files from the package's ./migrations directory, + * - create a migrator using the provided migrations record, * - and provide the Kysely client service to the migrator. * * @typeParam Schema - The Kysely schema type describing your database shape. * @param dialect - The SQL dialect to configure the Kysely client for (e.g., "postgres", "sqlite"). - * @param migrationFolder - Filesystem path to the directory containing migration files. + * @param migrations - A record of migration objects keyed by migration name. * @returns An Effect that produces a configured migrator instance when run. The Effect may fail if the database client cannot be created, the Kysely client cannot be provided, or the migrations folder cannot be accessed/loaded. * * @remarks - * - The migrations folder path is resolved relative to this module's __dirname ("./migrations"). * - The returned Effect expects the runtime/environment to support the underlying Effect and service provisioning primitives used here.packages/@withstudiocms/sdk/src/migrator.ts (1)
48-62: Documentation references outdated "migrationFolder" terminology.Line 52 mentions "migrationFolder" but this function now uses an internal
migrationIndexrecord. The implementation correctly abstracts this away from the consumer, but the documentation should reflect this.♻️ Proposed documentation fix
/** * Creates a live migrator instance bound to the package's migration folder. * * This convenience factory forwards the provided dialect to `makeMigratorLive` - * and binds the module's default `migrationFolder`, producing a migrator that + * and binds the module's default migrations index, producing a migrator that * runs migrations from the package's built-in migration directory.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (17)
.changeset/brown-pots-rush.md.changeset/young-rabbits-ask.mdpackage.jsonpackages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/kysely/package.jsonpackages/@withstudiocms/kysely/src/core/migrator.tspackages/@withstudiocms/kysely/src/index.tspackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/kysely/test/core/migrator.test.tspackages/@withstudiocms/kysely/test/test-utils.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/scripts/create-migration.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/sdk/src/migrator.tspackages/studiocms/src/cli/migrator/index.ts
💤 Files with no reviewable changes (3)
- packages/@withstudiocms/kysely/test/test-utils.ts
- packages/@withstudiocms/kysely/src/index.ts
- packages/@withstudiocms/kysely/test/core/migrator.test.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Define interfaces for all data structures
Prefer type safety over convenience
Use Effect-ts patterns for async operations and error handling
Always handle potential null/undefined values in database interactions
Prefer type-safe database operations via @astrojs/db
Use Effect combinators consistently and avoid mixing raw Promise code with Effect-ts without proper interop
**/*.{ts,tsx}: Use strict TypeScript typing throughout the codebase
Follow existing patterns, use meaningful variable names, and comment complex logic
Files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/src/core/migrator.tspackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/sdk/src/migrator.ts
**/*.{ts,tsx,astro}
📄 CodeRabbit inference engine (.cursorrules)
**/*.{ts,tsx,astro}: Prefer Effect-ts for async workflows and error handling over raw Promise chains
Do not mix raw Promise chains with Effect-ts in the same flow; keep Effect-based error handling consistentPrefer Effect-ts for async and error handling (e.g., Effect.tryPromise, pipe, catchAll patterns)
Files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/src/core/migrator.tspackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/sdk/src/migrator.ts
package.json
📄 CodeRabbit inference engine (.cursorrules)
Target Node.js only in engines; do not suggest Bun or Deno
Include --remote for dev/build and database scripts (e.g., "astro build --remote", "astro db push --remote")
Files:
package.json
**/package.json
📄 CodeRabbit inference engine (GEMINI.md)
Target Node.js runtime only: set an engines.node field and avoid Bun/Deno-specific fields
Files:
package.jsonpackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
packages/studiocms/**
📄 CodeRabbit inference engine (.cursorrules)
Keep the core package code under packages/studiocms/
Files:
packages/studiocms/src/cli/migrator/index.ts
packages/**/package.json
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Plugins should manage their own dependencies and use peerDependencies appropriately to avoid conflicts
Files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
🧠 Learnings (27)
📓 Common learnings
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-08-25T23:27:00.892Z
Learning: Applies to packages/studiocms/src/i18n/translations/**/*.json : Store translation files under packages/studiocms/src/i18n/translations/
📚 Learning: 2025-08-25T23:27:00.892Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-08-25T23:27:00.892Z
Learning: Applies to packages/studiocms/src/i18n/index.ts : Keep i18n configuration in packages/studiocms/src/i18n/index.ts (exports t, etc.)
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/kysely/package.jsonpackages/@withstudiocms/sdk/src/migrator.ts
📚 Learning: 2025-08-25T23:25:59.062Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-25T23:25:59.062Z
Learning: Applies to packages/studiocms/src/i18n/index.ts : Keep i18n configuration in packages/studiocms/src/i18n/index.ts
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/package.jsonpackages/@withstudiocms/sdk/src/migrator.ts
📚 Learning: 2025-09-09T22:03:32.205Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 781
File: packages/studiocms/src/cli/init/steps/env.ts:276-293
Timestamp: 2025-09-09T22:03:32.205Z
Learning: In packages/studiocms/src/cli/init/steps/env.ts and similar clack-based Effect wrappers: mixing async/await with runEffect inside group calls is required due to the clack prompts package being wrapped in Effect but not being able to override internal functions. This is a justified technical exception to the general rule about avoiding raw Promise chains with Effect-ts.
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/src/migrator.ts
📚 Learning: 2025-12-09T02:18:13.493Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 1053
File: packages/studiocms/frontend/pages/[dashboard]/system-management.astro:9-30
Timestamp: 2025-12-09T02:18:13.493Z
Learning: In StudioCMS, Effect-ts is the recommended approach for async workflows and error handling, but pragmatic flexibility is acceptable for simpler cases (e.g., straightforward awaits in page files). Effect-ts should still be preferred for complex workflows, error-prone operations, and core library code.
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/studiocms/src/cli/migrator/index.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{ts,tsx} : Use Effect-ts patterns for async operations and error handling
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to db/config.@(ts|js) : Define database schema using Astro DB schema definitions
Applied to files:
packages/@studiocms/migrator/src/db/client.tspackages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/src/test-utils.ts
📚 Learning: 2025-09-24T05:48:08.255Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 845
File: packages/@studiocms/auth0/test/index.test.ts:1-3
Timestamp: 2025-09-24T05:48:08.255Z
Learning: In the withstudiocms/studiocms project, TypeScript is configured with "moduleResolution": "bundler", "verbatimModuleSyntax": true, and "type": "module". This requires using .js extensions in imports even when importing from .ts source files (e.g., '../src/index.js' for '../src/index.ts'). This is the correct pattern and should not be flagged as an error.
Applied to files:
packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/package.jsonpackages/@withstudiocms/sdk/src/migrator.ts
📚 Learning: 2025-09-24T05:48:08.255Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 845
File: packages/@studiocms/auth0/test/index.test.ts:1-3
Timestamp: 2025-09-24T05:48:08.255Z
Learning: In the withstudiocms/studiocms project, importing TypeScript files with .js extensions (e.g., '../src/index.js' for '../src/index.ts') is the correct pattern due to the tsconfig.json module resolution configuration. This allows proper ESM imports and should not be flagged as an error.
Applied to files:
packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-09-24T05:48:08.255Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 845
File: packages/@studiocms/auth0/test/index.test.ts:1-3
Timestamp: 2025-09-24T05:48:08.255Z
Learning: In the withstudiocms/studiocms project, importing TypeScript files with .js extensions (e.g., '../src/index.js' for '../src/index.ts') is the correct pattern due to the project's tsconfig.json module resolution configuration. This allows proper ESM imports and should not be flagged as an error.
Applied to files:
packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.tspackages/@withstudiocms/sdk/src/migrations/20251025T040912_init.tspackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.tspackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:27:00.892Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-08-25T23:27:00.892Z
Learning: Applies to package.json : Include --remote for dev/build and database scripts (e.g., "astro build --remote", "astro db push --remote")
Applied to files:
package.jsonpackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to pnpm-lock.yaml : Use pnpm as the package manager for development and scripts
Applied to files:
package.jsonpackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-06T00:45:30.196Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 667
File: packages/@studiocms/wysiwyg/package.json:74-76
Timestamp: 2025-08-06T00:45:30.196Z
Learning: In StudioCMS packages, the dist/ directory containing build artifacts (including compiled .astro files) is gitignored but gets created during the CI build process before publishing to npm. The build script pattern like "buildkit build 'src/**/*.{ts,astro,css,js}'" ensures .astro files are included in the build output, making wildcard exports like "./components/*": "./dist/components/*" valid for published packages even though dist/ doesn't exist in the source repository.
Applied to files:
package.jsonpackages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:25:59.062Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-25T23:25:59.062Z
Learning: Applies to .prototools : Specify Node.js and pnpm versions in .prototools
Applied to files:
package.json
📚 Learning: 2025-08-25T23:25:09.059Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .cursorrules:0-0
Timestamp: 2025-08-25T23:25:09.059Z
Learning: Applies to astro.config.mjs : In astro.config.mjs, include integrations db() and studioCMS()
Applied to files:
packages/studiocms/src/cli/migrator/index.ts
📚 Learning: 2025-08-25T23:25:59.062Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-25T23:25:59.062Z
Learning: Applies to astro.config.mjs : Include astrojs/db and studiocms() in the Astro integrations array
Applied to files:
packages/studiocms/src/cli/migrator/index.ts
📚 Learning: 2025-07-26T23:12:20.471Z
Learnt from: Adammatthiesen
Repo: withstudiocms/studiocms PR: 642
File: packages/studiocms/package.json:132-134
Timestamp: 2025-07-26T23:12:20.471Z
Learning: For Astro projects, wildcard exports in package.json for .astro files (like "./components/*", "./layouts/*") should point directly to source files (e.g., "./src/components/*") rather than using the typical TypeScript pattern with separate "types" and "default" fields, since Astro files don't have a compiled version that can be used directly and are imported as .astro files by consumers.
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{test,spec}.{ts,tsx} : Use proper TypeScript types in unit tests and mock external dependencies
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{ts,tsx} : Prefer type safety over convenience
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{ts,tsx} : Prefer type-safe database operations via astrojs/db
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/src/test-utils.tspackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:25:59.062Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-25T23:25:59.062Z
Learning: Applies to **/*.{ts,tsx} : Use strict TypeScript typing throughout the codebase
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:25:09.059Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .cursorrules:0-0
Timestamp: 2025-08-25T23:25:09.059Z
Learning: Applies to **/*.{ts,tsx,astro} : Prefer Effect-ts for async workflows and error handling over raw Promise chains
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{ts,tsx} : Use Effect combinators consistently and avoid mixing raw Promise code with Effect-ts without proper interop
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.jsonpackages/@withstudiocms/sdk/src/migrator.ts
📚 Learning: 2025-08-25T23:27:00.892Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-08-25T23:27:00.892Z
Learning: Applies to **/*.{ts,tsx,astro} : Prefer Effect-ts for async and error handling (e.g., Effect.tryPromise, pipe, catchAll patterns)
Applied to files:
packages/@withstudiocms/sdk/package.jsonpackages/@withstudiocms/kysely/package.json
📚 Learning: 2025-08-25T23:27:00.892Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-08-25T23:27:00.892Z
Learning: Applies to packages/studiocms/src/i18n/translations/**/*.json : Store translation files under packages/studiocms/src/i18n/translations/
Applied to files:
.changeset/young-rabbits-ask.md
📚 Learning: 2025-08-25T23:25:59.062Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-25T23:25:59.062Z
Learning: Applies to packages/studiocms/src/i18n/translations/*.json : Place translation files under packages/studiocms/src/i18n/translations/ as JSON files
Applied to files:
.changeset/young-rabbits-ask.md
📚 Learning: 2025-08-25T23:23:59.272Z
Learnt from: CR
Repo: withstudiocms/studiocms PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-25T23:23:59.272Z
Learning: Applies to **/*.{ts,tsx} : Define interfaces for all data structures
Applied to files:
packages/@withstudiocms/kysely/package.json
🔇 Additional comments (12)
.changeset/brown-pots-rush.md (1)
1-6: LGTM! Changeset properly documents the migration.The changeset correctly documents the patch updates for both packages and clearly states the import path change to
@withstudiocms/sdk/migrator.package.json (1)
34-34: LGTM! Script correctly updated to target SDK package.The
create-migrationscript now correctly references@withstudiocms/sdk, aligning with the migration of the migration system to the SDK package.packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts (2)
10-15: Import updates align with migration to scoped packages.The imports correctly reference the scoped package paths. This is consistent with the migration pattern used across all migration files.
228-272: Good practice marking deprecated tables.The schema properly marks tables as deprecated (lines 230, 248, 264) before removal, which provides a safe migration path for gradual deprecation.
packages/@withstudiocms/kysely/package.json (2)
81-81: The tsx removal is intentional and safe.The
create-migrationscript has been moved to the SDK package (packages/@withstudiocms/sdk/scripts/create-migration.ts), which retainstsxas a devDependency for this purpose. No other scripts or source files in the kysely package depend on tsx.
69-72: No breaking change found - the claim about removing "./schemas/*" export is unsupported.The codebase does not show any evidence of a
"./schemas/*"export ever existing. The current exports include"./schema"(singular) and"./utils/*", but git history shows no changes to a plural"./schemas/*"pattern. The search found zero imports of@withstudiocms/kysely/schemasand no schema JSON files in the source directory. The"./utils/*"export is already present and provides access to migrator utilities as intended.Likely an incorrect or invalid review comment.
packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts (1)
10-15: All migrator utility exports are correctly configured and available. The kysely package.json properly exports./utils/*pattern, andmigrator.tsexports bothsyncDatabaseSchemaandrollbackMigrationas const functions. TheTableDefinitiontype is also available viaexport * from './types.js'. The import path'@withstudiocms/kysely/utils/migrator'is valid and resolves correctly.packages/@studiocms/migrator/src/db/client.ts (1)
4-4: LGTM - Import path updated correctly.The import path has been updated to reference the migrator from the SDK package, aligning with the migration objectives.
packages/studiocms/src/cli/migrator/index.ts (1)
7-7: LGTM - Import path updated correctly.The import has been successfully migrated to the SDK package, maintaining consistency with the broader migration effort.
packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts (1)
14-19: LGTM - Import paths refactored to use scoped packages.The imports have been updated to use scoped package paths instead of relative imports, which improves maintainability and aligns with the migration to the SDK package structure.
packages/@withstudiocms/sdk/src/migrator.ts (2)
42-46: LGTM!The migration index uses top-level await to pre-load all migrations at module initialization. This is appropriate for an ES module package and ensures migrations are available synchronously when
getMigratorLiveis called. The auto-update comment for the create-migration script is helpful for maintainability.
63-74: LGTM!The
getMigratorLivefunction has a well-defined Effect-based return type that clearly documents the success type, error channel (MigratorError), and requirements (never). This follows Effect-ts patterns properly and provides good type safety for consumers. The delegation tomakeMigratorLivewith the internalmigrationIndexcleanly encapsulates the SDK's migrations.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Bundle ReportBundle size has no change ✅ Affected Assets, Files, and Routes:view changes for bundle: studiocms-blog-astro-bundle-server-esmAssets Changed:
view changes for bundle: studiocms-headless-astro-bundle-client-esmAssets Changed:
view changes for bundle: studiocms-blog-astro-bundle-client-esmAssets Changed:
view changes for bundle: studiocms-headless-astro-bundle-server-esmAssets Changed:
|
This pull request refactors the StudioCMS migration system by moving custom migration logic and migration files out of the
@withstudiocms/kyselypackage and into the@withstudiocms/sdkpackage. It updates imports and package scripts to reflect this change, removes migration-related code from@withstudiocms/kysely, and ensures that all migration operations now go through the SDK. This streamlines the codebase and clarifies package responsibilities.Migration system refactor:
@studiocms/migratorandstudiocmsare updated to use@withstudiocms/sdk/migratorinstead of@withstudiocms/kysely/migrator. (packages/@studiocms/migrator/src/db/client.ts,.changeset/brown-pots-rush.md,packages/studiocms/src/cli/migrator/index.ts) [1] [2] [3]@withstudiocms/kyselyto@withstudiocms/sdk, including updating all migration file imports and references. (packages/@withstudiocms/sdk/src/migrator.ts,packages/@withstudiocms/sdk/package.json, migration file renames and import updates) [1] [2] [3] [4] [5] [6] [7] [8]Package configuration and script updates:
create-migrationscript is removed from@withstudiocms/kyselyand added to@withstudiocms/sdk; the SDK package now exports the migrator entry point. (packages/@withstudiocms/kysely/package.json,packages/@withstudiocms/sdk/package.json) [1] [2] [3] [4]package.jsonis updated so thecreate-migrationcommand uses the SDK package instead of Kysely. (package.json)Test and utility cleanup:
@withstudiocms/kyselytest files, reflecting that migrations are no longer managed there. (packages/@withstudiocms/kysely/src/test-utils.ts,packages/@withstudiocms/kysely/test/core/migrator.test.ts,packages/@withstudiocms/kysely/test/test-utils.ts) [1] [2] [3] [4] [5] [6] [7]Exports and dependency adjustments:
packages/@withstudiocms/kysely/package.json) [1] [2]These changes ensure all migration logic is centralized in the SDK, simplifying package boundaries and future maintenance.
Summary by CodeRabbit
Refactor
Breaking Changes
✏️ Tip: You can customize this high-level summary in your review settings.