Skip to content

feat(migrations): Move StudioCMS Migration system from kysely package to sdk package#1153

Merged
Adammatthiesen merged 7 commits intomainfrom
adam/move-migrations
Jan 7, 2026
Merged

feat(migrations): Move StudioCMS Migration system from kysely package to sdk package#1153
Adammatthiesen merged 7 commits intomainfrom
adam/move-migrations

Conversation

@Adammatthiesen
Copy link
Member

@Adammatthiesen Adammatthiesen commented Jan 7, 2026

This pull request refactors the StudioCMS migration system by moving custom migration logic and migration files out of the @withstudiocms/kysely package and into the @withstudiocms/sdk package. 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:

  • Migrator imports in @studiocms/migrator and studiocms are updated to use @withstudiocms/sdk/migrator instead 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]
  • Custom migration files and migrator implementation are moved from @withstudiocms/kysely to @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:

  • The create-migration script is removed from @withstudiocms/kysely and 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]
  • The root package.json is updated so the create-migration command uses the SDK package instead of Kysely. (package.json)

Test and utility cleanup:

  • Migration-related test utilities and migration directory configuration are removed from @withstudiocms/kysely test 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:

  • Migrator and migration-related exports are removed from Kysely, and utility exports are updated. (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

    • Migration tooling and utilities were reorganized and moved between packages.
    • Migration-related imports and scripts updated to use the new package layout.
  • Breaking Changes

    • Migrator now lives in the SDK package; Kysely no longer exposes migrator.
    • Migrator API surface and script targets have changed; update integrations accordingly.

✏️ Tip: You can customize this high-level summary in your review settings.

…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-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 9a0271d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@studiocms/migrator Patch
studiocms Patch
@withstudiocms/kysely Patch
@withstudiocms/sdk Patch
@studiocms/auth0 Patch
@studiocms/blog Patch
@studiocms/cloudinary-image-service Patch
@studiocms/devapps Patch
@studiocms/discord Patch
@studiocms/github Patch
@studiocms/google Patch
@studiocms/html Patch
@studiocms/markdoc Patch
@studiocms/md Patch
@studiocms/mdx Patch
@studiocms/s3-storage Patch
@studiocms/wysiwyg Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Custom migration functionality is moved from @withstudiocms/kysely into @withstudiocms/sdk: scripts, exports, and migrator code were updated accordingly; migrator APIs were renamed and getMigratorLive now exposes an Effect-based typed API; migration files and CLI references now import from the SDK package.

Changes

Cohort / File(s) Summary
Changeset entries
\.changeset/brown-pots-rush.md, \.changeset/young-rabbits-ask.md
Added patch release notes reflecting migration of custom migrations from @withstudiocms/kysely to @withstudiocms/sdk.
Root script
package.json
create-migration script filter changed from @withstudiocms/kysely@withstudiocms/sdk.
Kysely package manifest
packages/@withstudiocms/kysely/package.json
Removed create-migration script and ./migrator export; replaced ./schemas/* export with ./utils/*; removed tsx devDependency.
SDK package manifest
packages/@withstudiocms/sdk/package.json
Added create-migration script, new ./migrator export (types + default), and added tsx devDependency.
Migrator implementation (kysely)
packages/@withstudiocms/kysely/src/core/migrator.ts
Renamed parameter migrationFoldermigrations across kyselyMigrator, makeMigrator, and makeMigratorLive signatures and usages.
Kysely public surface & test utils
packages/@withstudiocms/kysely/src/index.ts, packages/@withstudiocms/kysely/src/test-utils.ts
Removed migrator-related comment; removed getMigratorLive import and migrator-related options/API from test utilities (no migrationsDir or getMigrator).
Kysely tests removed/updated
packages/@withstudiocms/kysely/test/core/migrator.test.ts, packages/@withstudiocms/kysely/test/test-utils.ts
Deleted migrator core tests and removed migration folder resolution from test helpers.
SDK migrator export & API
packages/@withstudiocms/sdk/src/migrator.ts
Reworked imports to scoped packages; dynamic migration loader simplified; getMigratorLive now returns a strongly-typed Effect-based API (toLatest, up, down, status) with explicit error typing.
SDK migration files
packages/@withstudiocms/sdk/src/migrations/... (20251025T040912_init.ts, 20251130T150847_drop_deprecated.ts, 20251221T002125_url-mapping.ts)
Updated imports to use @withstudiocms/kysely/... scoped paths for Kysely types and migrator utilities.
Migrator consumers / CLI
packages/@studiocms/migrator/src/db/client.ts, packages/studiocms/src/cli/migrator/index.ts
Switched imports of getMigratorLive from @withstudiocms/kysely/migrator@withstudiocms/sdk/migrator.

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[]
Loading

Notes:

  • New/changed interactions: migrator loader returns module objects (not only up/down); getMigratorLive exposes an Effect-based API and typed error model.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: moving the StudioCMS migration system from kysely to sdk package, and follows the conventional commit format with appropriate scope.
Linked Issues check ✅ Passed All objectives from issue #1147 are fully implemented: migrator moved from @withstudiocms/kysely to @withstudiocms/sdk, imports updated in @studiocms/migrator and studiocms, and migration code centralized in SDK.
Out of Scope Changes check ✅ Passed All changes are directly related to the migration objective. Parameter renaming (migrationFolder to migrations) and test file removals support the refactoring without introducing unrelated functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch adam/move-migrations

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2ef10b and 9a0271d.

📒 Files selected for processing (2)
  • .changeset/young-rabbits-ask.md
  • packages/@withstudiocms/kysely/src/test-utils.ts
💤 Files with no reviewable changes (1)
  • packages/@withstudiocms/kysely/src/test-utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/young-rabbits-ask.md

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.

@codecov
Copy link

codecov bot commented Jan 7, 2026

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 7, 2026

studiocms

npm i https://pkg.pr.new/withstudiocms/studiocms@1153

@studiocms/auth0

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/auth0@1153

@studiocms/blog

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/blog@1153

@studiocms/cloudinary-image-service

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/cloudinary-image-service@1153

@studiocms/devapps

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/devapps@1153

@studiocms/discord

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/discord@1153

@studiocms/github

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/github@1153

@studiocms/google

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/google@1153

@studiocms/html

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/html@1153

@studiocms/markdoc

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/markdoc@1153

@studiocms/md

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/md@1153

@studiocms/mdx

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/mdx@1153

@studiocms/migrator

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/migrator@1153

@studiocms/s3-storage

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/s3-storage@1153

@studiocms/wysiwyg

npm i https://pkg.pr.new/withstudiocms/studiocms/@studiocms/wysiwyg@1153

@withstudiocms/auth-kit

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/auth-kit@1153

@withstudiocms/component-registry

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/component-registry@1153

@withstudiocms/effect

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/effect@1153

@withstudiocms/internal_helpers

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/internal_helpers@1153

@withstudiocms/kysely

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/kysely@1153

@withstudiocms/sdk

npm i https://pkg.pr.new/withstudiocms/studiocms/@withstudiocms/sdk@1153

commit: 9a0271d

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Allure Test Report for this PR:

Allure Report | History

@Adammatthiesen Adammatthiesen marked this pull request as ready for review January 7, 2026 12:35
@Adammatthiesen Adammatthiesen requested a review from a team as a code owner January 7, 2026 12:35
Copy link
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

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 the engines.node field to specify Node.js runtime support.

Per coding guidelines, set an engines.node field 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:

  1. Removing the getMigrator references from the documentation examples
  2. 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:

  1. Removing the commented code entirely
  2. 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 getMigrator method, 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 migrationFolder and describes it as a "Filesystem path to the directory containing migration files," but the parameter is now migrations: 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 migrations record 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 migrationIndex record. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 25e6fc0 and d2ef10b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • .changeset/brown-pots-rush.md
  • .changeset/young-rabbits-ask.md
  • package.json
  • packages/@studiocms/migrator/src/db/client.ts
  • packages/@withstudiocms/kysely/package.json
  • packages/@withstudiocms/kysely/src/core/migrator.ts
  • packages/@withstudiocms/kysely/src/index.ts
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@withstudiocms/kysely/test/core/migrator.test.ts
  • packages/@withstudiocms/kysely/test/test-utils.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/scripts/create-migration.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/sdk/src/migrator.ts
  • packages/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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/kysely/src/core/migrator.ts
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@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 consistent

Prefer Effect-ts for async and error handling (e.g., Effect.tryPromise, pipe, catchAll patterns)

Files:

  • packages/@studiocms/migrator/src/db/client.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/kysely/src/core/migrator.ts
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@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.json
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.json
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@withstudiocms/kysely/package.json
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/kysely/package.json
  • packages/@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.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@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.ts
  • packages/studiocms/src/cli/migrator/index.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251130T150847_drop_deprecated.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@withstudiocms/kysely/package.json
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@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.ts
  • packages/@withstudiocms/sdk/src/migrations/20251025T040912_init.ts
  • packages/@withstudiocms/sdk/package.json
  • packages/@withstudiocms/sdk/src/migrations/20251221T002125_url-mapping.ts
  • packages/@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.json
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.json
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.json
  • packages/@withstudiocms/sdk/package.json
  • packages/@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.json
  • packages/@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.json
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@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.json
  • packages/@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.json
  • packages/@withstudiocms/kysely/src/test-utils.ts
  • packages/@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.json
  • packages/@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.json
  • packages/@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.json
  • packages/@withstudiocms/kysely/package.json
  • packages/@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.json
  • packages/@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-migration script 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-migration script has been moved to the SDK package (packages/@withstudiocms/sdk/scripts/create-migration.ts), which retains tsx as 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/schemas and 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, and migrator.ts exports both syncDatabaseSchema and rollbackMigration as const functions. The TableDefinition type is also available via export * 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 getMigratorLive is called. The auto-update comment for the create-migration script is helpful for maintainability.


63-74: LGTM!

The getMigratorLive function 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 to makeMigratorLive with the internal migrationIndex cleanly encapsulates the SDK's migrations.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jan 7, 2026

Bundle Report

Bundle size has no change ✅

Affected Assets, Files, and Routes:

view changes for bundle: studiocms-blog-astro-bundle-server-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
manifest_ooBRoH9o.mjs (New) 3.53kB 3.53kB 100.0% 🚀
manifest_BvebQjt3.mjs (Deleted) -3.53kB 0 bytes -100.0% 🗑️
view changes for bundle: studiocms-headless-astro-bundle-client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
_astro/EditPage.*.CdKT2Dmg.js (New) 1.78kB 1.78kB 100.0% 🚀
_astro/CreatePage.*.B4yF0bqj.js (New) 1.74kB 1.74kB 100.0% 🚀
_astro/EditPage.*.CMhQseSe.js (Deleted) -1.78kB 0 bytes -100.0% 🗑️
_astro/CreatePage.*.CRbPqDvI.js (Deleted) -1.74kB 0 bytes -100.0% 🗑️
view changes for bundle: studiocms-blog-astro-bundle-client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
_astro/EditPage.*.CdKT2Dmg.js (New) 1.78kB 1.78kB 100.0% 🚀
_astro/CreatePage.*.B4yF0bqj.js (New) 1.74kB 1.74kB 100.0% 🚀
_astro/EditPage.*.CecGpUsZ.js (New) 1.34kB 1.34kB 100.0% 🚀
_astro/CreatePage.*.COa1PUAk.js (New) 1.31kB 1.31kB 100.0% 🚀
_astro/ConfigForm.*.DlS_bALP.js (New) 1.2kB 1.2kB 100.0% 🚀
_astro/DashboardLayout.*.CmzJV5Lc.js (New) 457 bytes 457 bytes 100.0% 🚀
_astro/EditPage.*.CMhQseSe.js (Deleted) -1.78kB 0 bytes -100.0% 🗑️
_astro/CreatePage.*.CRbPqDvI.js (Deleted) -1.74kB 0 bytes -100.0% 🗑️
_astro/EditPage.*.C29dcWn7.js (Deleted) -1.34kB 0 bytes -100.0% 🗑️
_astro/CreatePage.*.C7a-zQWp.js (Deleted) -1.31kB 0 bytes -100.0% 🗑️
_astro/ConfigForm.*.D9Wmr8_6.js (Deleted) -1.2kB 0 bytes -100.0% 🗑️
_astro/DashboardLayout.*.Ck8xGCgY.js (Deleted) -457 bytes 0 bytes -100.0% 🗑️
view changes for bundle: studiocms-headless-astro-bundle-server-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
manifest_BRItcnS_.mjs (New) 3.53kB 3.53kB 100.0% 🚀
manifest_-_TX5YHm.mjs (Deleted) -3.53kB 0 bytes -100.0% 🗑️

@Adammatthiesen Adammatthiesen merged commit 0435b82 into main Jan 7, 2026
31 checks passed
@Adammatthiesen Adammatthiesen deleted the adam/move-migrations branch January 7, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate custom migrations to the StudioCMS SDK package

3 participants

Comments