orchardcore-data-migration

Creates OrchardCore DataMigration classes for content definitions, index tables, and schema versioning.

8.2k|2.6k|Updated Nov 19, 2014
One-click install
npx skills add https://github.com/OrchardCMS/OrchardCore --skill orchardcore-data-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: orchardcore-data-migration
Source: https://github.com/OrchardCMS/OrchardCore/tree/main/.agents/skills/orchardcore-data-migration
Command: npx skills add https://github.com/OrchardCMS/OrchardCore --skill orchardcore-data-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing OrchardCore data migrations requires following a strict version-chain convention (CreateAsync plus sequential UpdateFromXAsync methods), and mistakes like renumbering shipped methods or omitting column lengths break tenant upgrades across database providers. This Skill guides you through the correct patterns so migrations run reliably on fresh installs and upgrades.

Core Features & Use Cases

  • Version-chain guidance: Explains how the migration runner stores version numbers per tenant and why CreateAsync must return the latest version while UpdateFromX methods are never renumbered.
  • Schema and content definition operations: Covers altering content types and parts with IContentDefinitionManager, creating and altering SQL index tables with SchemaBuilder, patching existing content items via paged YesSql queries, and running recipe migrations.
  • Provider-specific handling: Documents workarounds for SQLite's inability to drop columns, MySQL index key-length limits, and safe index dropping with try/catch guards.
  • Use Case: You need to add a new column to an existing LinkFieldIndex table in a shipped module. The Skill directs you to append a new UpdateFromXAsync method using SchemaBuilder.AlterIndexTableAsync, bump the CreateAsync return value, and register the migration with AddDataMigration in Startup.cs.

Quick Start

Ask the assistant to create an OrchardCore data migration that adds a new content part and registers it in the module's Startup.cs.

Frequently Asked Questions about orchardcore-data-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a data migration in OrchardCore?

Create a class inheriting DataMigration with a CreateAsync method that defines your schema and returns the latest version number. Register it in the module's Startup.cs with services.AddDataMigration<Migrations>(), and OrchardCore runs it automatically per tenant on startup.

How do I add an UpdateFromX migration step in OrchardCore?

Append a new UpdateFromXAsync method where X matches the version stored from the previous step, and have it return X+1. Never edit or renumber already-shipped methods, since existing tenants store the old version numbers and renumbering breaks their upgrade path.

Why does my OrchardCore migration fail on SQLite?

SQLite cannot drop columns, so AlterIndexTableAsync calls that drop or rebuild columns throw exceptions. Wrap those operations in try/catch blocks and log a warning, as shown in the standard OrchardCore module migrations.

How do I patch existing content items in an OrchardCore migration?

Query ContentItem through ContentItemIndex ordered by DocumentId, process items in paged batches, mutate the Content as a JsonObject, and call SaveAsync plus FlushAsync per page. Place this logic in an UpdateFromX method, never in CreateAsync, since fresh installs have no data.

What string column length should I use in OrchardCore index tables?

Always set an explicit length with .WithLength(n) or mark the column .Unlimited(), because unlengthed string columns default inconsistently across providers. Standard lengths are 26 for ContentItemId and ContentItemVersionId, with ContentItemIndex.Max*Size constants for type and part names.