@umec/core 0.1.0-alpha.10 → 0.1.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -508,17 +508,18 @@ async function runMigrate(options) {
508
508
  }
509
509
  if (options.repair) {
510
510
  for (const upgrade of CORE_UPGRADES) {
511
- const needed = dryRun ? true : await upgrade.canApply(options.executor);
512
- if (!needed) continue;
513
- print(`upgrade ${upgrade.name} (${upgrade.fromVersion} \u2192 ${upgrade.toVersion})`);
514
- if (dryRun) {
511
+ const legacyPresent = dryRun ? true : await upgrade.canApply(options.executor);
512
+ if (legacyPresent) {
513
+ print(`upgrade ${upgrade.name} (${upgrade.fromVersion} \u2192 ${upgrade.toVersion})`);
514
+ if (dryRun) {
515
+ applied.push(upgrade.name);
516
+ continue;
517
+ }
518
+ await upgrade.apply(options.executor);
519
+ await recordMigration(options.executor, upgrade.name, `upgrade:${upgrade.name}`, "upgrade", now);
515
520
  applied.push(upgrade.name);
516
- continue;
521
+ alreadyByName.set(upgrade.name, { name: upgrade.name, checksum: `upgrade:${upgrade.name}`, kind: "upgrade" });
517
522
  }
518
- await upgrade.apply(options.executor);
519
- await recordMigration(options.executor, upgrade.name, `upgrade:${upgrade.name}`, "upgrade", now);
520
- applied.push(upgrade.name);
521
- alreadyByName.set(upgrade.name, { name: upgrade.name, checksum: `upgrade:${upgrade.name}`, kind: "upgrade" });
522
523
  for (const supersededName of ["0002_orders.sql", "0005_orders_tracking.sql"]) {
523
524
  const superseded = coreMigrations.find((migration) => migration.name === supersededName);
524
525
  if (!superseded) {
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli/index.ts","../src/cli/doctor.ts","../schema/upgrades/v2-to-v6.ts","../src/cli/checksum.ts","../src/cli/extend.ts","../src/cli/migrate.ts","../src/cli/wrangler.ts","../src/cli/executor.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { loadSnapshotJson } from \"../db/catalog.js\";\nimport type { SchemaSnapshot } from \"../db/snapshot.js\";\nimport { findPackageRoot } from \"../package-root.js\";\nimport { runDoctor } from \"./doctor.js\";\nimport { runExtend } from \"./extend.js\";\nimport { coreVersionFromPackage, runMigrate, type MigrateOptions } from \"./migrate.js\";\nimport { createWranglerExecutor, readD1DatabaseName, type RunCommand } from \"./wrangler.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\n\nexport type CliIo = {\n cwd?: string;\n stdout?: (message: string) => void;\n stderr?: (message: string) => void;\n executor?: MigrationExecutor;\n runCommand?: RunCommand;\n};\n\nexport function parseArgs(argv: string[]): {\n command: string | null;\n flags: Record<string, string | boolean>;\n} {\n const flags: Record<string, string | boolean> = {};\n let command: string | null = null;\n for (let i = 0; i < argv.length; i += 1) {\n const arg = argv[i];\n if (!arg) continue;\n if (arg.startsWith(\"--\")) {\n const eq = arg.indexOf(\"=\");\n if (eq > 0) {\n flags[arg.slice(2, eq)] = arg.slice(eq + 1);\n continue;\n }\n const name = arg.slice(2);\n const next = argv[i + 1];\n if (next && !next.startsWith(\"--\") && name !== \"dry-run\" && name !== \"adopt\" && name !== \"repair\" && name !== \"remote\" && name !== \"local\") {\n flags[name] = next;\n i += 1;\n } else {\n flags[name] = true;\n }\n continue;\n }\n if (!command) command = arg;\n }\n return { command, flags };\n}\n\nfunction usage(): string {\n return `Usage:\n umec migrate [--dry-run] [--local|--remote] [--adopt] [--repair] [--database NAME]\n umec doctor [--local|--remote] [--database NAME]\n umec extend [--key NAME] [--type boolean|string|number]`;\n}\n\nexport async function runCli(argv: string[], io: CliIo = {}): Promise<number> {\n const cwd = io.cwd ?? process.cwd();\n const stdout = io.stdout ?? ((message) => console.log(message));\n const stderr = io.stderr ?? ((message) => console.error(message));\n const { command, flags } = parseArgs(argv);\n\n if (!command || command === \"help\" || flags.help) {\n stdout(usage());\n return command ? 0 : 1;\n }\n\n const snapshot = loadSnapshotJson() as SchemaSnapshot;\n const remote = flags.remote === true;\n const database = typeof flags.database === \"string\" ? flags.database : readD1DatabaseName(cwd);\n\n const executor =\n io.executor ??\n (command === \"extend\" || (command === \"migrate\" && flags[\"dry-run\"] === true)\n ? undefined\n : database\n ? createWranglerExecutor({ cwd, database, remote, runCommand: io.runCommand })\n : undefined);\n\n if (command === \"migrate\") {\n if (flags[\"dry-run\"] === true && !io.executor) {\n const migrations = (await import(\"../db/catalog.js\")).listCoreMigrations();\n stdout(\"dry-run (no D1 connection)\");\n stdout(\"ensure umec_schema_version / umec_migrations\");\n for (const migration of migrations) stdout(`apply core/${migration.name}`);\n stdout(`would set umec_schema_version.version = ${snapshot.version}`);\n return 0;\n }\n if (!executor) {\n stderr(\"wrangler.jsonc の d1_databases[0].database_name が見つかりません。--database を指定してください。\");\n return 1;\n }\n const options: MigrateOptions = {\n cwd,\n executor,\n snapshot,\n dryRun: flags[\"dry-run\"] === true,\n adopt: flags.adopt === true,\n repair: flags.repair === true,\n coreVersion: coreVersionFromPackage(),\n print: stdout,\n };\n const result = await runMigrate(options);\n for (const warning of result.warnings) stdout(`warn: ${warning}`);\n if (result.error) stderr(result.error);\n return result.exitCode;\n }\n\n if (command === \"doctor\") {\n const result = await runDoctor({\n cwd,\n executor,\n snapshot,\n print: stdout,\n });\n return result.exitCode;\n }\n\n if (command === \"extend\") {\n const result = runExtend({\n cwd,\n key: typeof flags.key === \"string\" ? flags.key : undefined,\n type: typeof flags.type === \"string\" ? flags.type : undefined,\n print: stdout,\n });\n if (result.error) stderr(result.error);\n return result.exitCode;\n }\n\n stderr(usage());\n return 1;\n}\n\nfunction isDirectRun(): boolean {\n const invoked = process.argv[1];\n if (!invoked) return false;\n return /(?:^|[\\\\/])cli(?:\\.js)?$/.test(invoked) || invoked.includes(`${join(\"dist\", \"cli\")}`);\n}\n\nif (isDirectRun()) {\n const pkg = JSON.parse(readFileSync(join(findPackageRoot(), \"package.json\"), \"utf8\")) as { version: string };\n if (process.argv.includes(\"--version\") || process.argv.includes(\"-V\")) {\n console.log(pkg.version);\n process.exit(0);\n }\n runCli(process.argv.slice(2)).then(\n (code) => process.exit(code),\n (error) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n },\n );\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { upgradeV2toV6 } from \"../../schema/upgrades/v2-to-v6.js\";\nimport { currentSchemaVersion, listCoreMigrations } from \"../db/catalog.js\";\nimport { classifyDrift } from \"../db/drift.js\";\nimport { introspectSnapshot } from \"../db/introspect.js\";\nimport type { SchemaSnapshot } from \"../db/snapshot.js\";\nimport { sha256File } from \"./checksum.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\nimport type { Printer } from \"./migrate.js\";\n\nexport type DoctorOptions = {\n cwd: string;\n executor?: MigrationExecutor;\n snapshot: SchemaSnapshot;\n print?: Printer;\n};\n\nexport type DoctorResult = {\n exitCode: number;\n lines: string[];\n};\n\nexport async function runDoctor(options: DoctorOptions): Promise<DoctorResult> {\n const print = options.print ?? (() => {});\n const lines: string[] = [];\n const installed = currentSchemaVersion();\n let exitCode = 0;\n\n const say = (line: string) => {\n lines.push(line);\n print(line);\n };\n\n say(`installed schema version: ${installed}`);\n\n if (!options.executor) {\n say(\"no database executor; offline checks only\");\n } else {\n try {\n const version = await options.executor.first<{ version: number; core_version: string }>(\n \"SELECT version, core_version FROM umec_schema_version WHERE id = 1\",\n );\n if (!version) {\n say(\"umec_schema_version: missing (run umec migrate)\");\n } else {\n say(`database schema version: ${version.version} (core ${version.core_version})`);\n if (version.version > installed) {\n exitCode = 1;\n say(\n `DB は schema v${version.version}。インストール中の @umec/core は v${installed} までしか知らない。戻すには wrangler d1 time-travel restore --bookmark=<記録済み> のあと同じ core バージョンを入れ直すこと。down migration は無い。`,\n );\n }\n }\n } catch {\n say(\"umec_schema_version: unreadable (run umec migrate)\");\n }\n\n const actual = await introspectViaExecutor(options.executor, options.snapshot.version);\n const drift = classifyDrift(options.snapshot, actual);\n for (const finding of drift.compatible) say(`warn: ${finding.message}`);\n for (const finding of drift.incompatible) {\n exitCode = 1;\n say(`error: ${finding.message}`);\n }\n if (await upgradeV2toV6.canApply(options.executor)) {\n exitCode = 1;\n say(\"error: orders は event_id PK の旧スキーマです。umec migrate --repair を実行してください。\");\n }\n\n const applied = await options.executor.all<{ name: string; checksum: string }>(\n \"SELECT name, checksum FROM umec_migrations\",\n ).catch(() => []);\n const appliedByName = new Map(applied.map((row) => [row.name, row.checksum]));\n for (const migration of listCoreMigrations()) {\n const expected = sha256File(migration.path);\n const got = appliedByName.get(migration.name);\n if (got && got !== expected) {\n exitCode = 1;\n say(`error: checksum mismatch ${migration.name}`);\n }\n }\n }\n\n const extensionsPath = join(options.cwd, \"src/config/extensions.ts\");\n if (!existsSync(extensionsPath)) {\n say(\"warn: src/config/extensions.ts がありません。拡張は umec extend で extras_json に足してください。\");\n }\n\n return { exitCode, lines };\n}\n\nasync function introspectViaExecutor(executor: MigrationExecutor, version: number) {\n const db = {\n prepare(query: string) {\n return {\n bind(...values: unknown[]) {\n this._params = values;\n return this;\n },\n _params: [] as unknown[],\n async first<T>() {\n return executor.first<T>(query, this._params);\n },\n async all<T>() {\n return { results: await executor.all<T>(query, this._params) };\n },\n async run() {\n const result = await executor.run(query, this._params);\n return { meta: { changes: result.changes } };\n },\n };\n },\n async batch() {\n return [];\n },\n };\n return introspectSnapshot(db, version);\n}\n","import type { UpgradeExecutor, UpgradeModule } from \"./types.js\";\n\nexport const UPGRADE_PAGE_SIZE = 500;\n\nexport const LEGACY_0002_SQL = `CREATE TABLE IF NOT EXISTS orders (\n event_id TEXT PRIMARY KEY NOT NULL,\n session_id TEXT NOT NULL,\n amount_total INTEGER NOT NULL,\n currency TEXT NOT NULL,\n customer_email TEXT NOT NULL,\n run_id TEXT,\n created_at INTEGER NOT NULL\n);\n`;\n\nexport const V6_ORDERS_DDL = `CREATE TABLE orders_new (\n id TEXT PRIMARY KEY,\n email TEXT NOT NULL,\n name TEXT,\n phone TEXT,\n items_json TEXT NOT NULL,\n amount INTEGER NOT NULL,\n shipping INTEGER,\n address_json TEXT,\n payment_intent TEXT,\n custom_fields_json TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n run_id TEXT,\n email_status TEXT CHECK (email_status IN ('sent', 'failed')),\n created_at INTEGER NOT NULL,\n shipped_at INTEGER,\n tracking_number TEXT,\n carrier TEXT CHECK (carrier IN ('yamato', 'sagawa', 'japanpost', 'other') OR carrier IS NULL)\n)`;\n\ntype LegacyOrderRow = {\n event_id: string;\n session_id?: string | null;\n amount_total?: number | null;\n amount?: number | null;\n customer_email?: string | null;\n email?: string | null;\n name?: string | null;\n phone?: string | null;\n items_json?: string | null;\n shipping?: number | null;\n address_json?: string | null;\n payment_intent?: string | null;\n custom_fields_json?: string | null;\n status?: string | null;\n run_id?: string | null;\n email_status?: string | null;\n created_at: number;\n shipped_at?: number | null;\n tracking_number?: string | null;\n carrier?: string | null;\n};\n\ntype TableInfoRow = {\n name: string;\n pk: number;\n};\n\nfunction asString(value: unknown, fallback = \"\"): string {\n return typeof value === \"string\" ? value : fallback;\n}\n\nfunction asNullableString(value: unknown): string | null {\n return typeof value === \"string\" ? value : null;\n}\n\nfunction asNumber(value: unknown, fallback = 0): number {\n return typeof value === \"number\" && Number.isFinite(value) ? value : fallback;\n}\n\nfunction asNullableNumber(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n}\n\nexport async function detectLegacyOrdersPk(db: UpgradeExecutor): Promise<boolean> {\n const columns = await db.all<TableInfoRow>(\"PRAGMA table_info(orders)\");\n if (columns.length === 0) return false;\n const eventId = columns.find((column) => column.name === \"event_id\");\n return eventId != null && eventId.pk === 1;\n}\n\nexport function mapLegacyOrder(row: LegacyOrderRow): {\n id: string;\n email: string;\n name: string | null;\n phone: string | null;\n items_json: string;\n amount: number;\n shipping: number | null;\n address_json: string | null;\n payment_intent: string | null;\n custom_fields_json: string | null;\n status: string;\n run_id: string | null;\n email_status: string | null;\n created_at: number;\n shipped_at: number | null;\n tracking_number: string | null;\n carrier: string | null;\n} {\n const sessionId = asNullableString(row.session_id);\n const eventId = asString(row.event_id);\n return {\n id: sessionId && sessionId.length > 0 ? sessionId : eventId,\n email: asString(row.customer_email ?? row.email),\n name: asNullableString(row.name),\n phone: asNullableString(row.phone),\n items_json: asNullableString(row.items_json) ?? \"[]\",\n amount: asNumber(row.amount_total ?? row.amount),\n shipping: asNullableNumber(row.shipping),\n address_json: asNullableString(row.address_json),\n payment_intent: asNullableString(row.payment_intent),\n custom_fields_json: asNullableString(row.custom_fields_json),\n status: asNullableString(row.status) ?? \"pending\",\n run_id: asNullableString(row.run_id),\n email_status: asNullableString(row.email_status),\n created_at: asNumber(row.created_at),\n shipped_at: asNullableNumber(row.shipped_at),\n tracking_number: asNullableString(row.tracking_number),\n carrier: asNullableString(row.carrier),\n };\n}\n\nexport async function applyV2toV6(db: UpgradeExecutor): Promise<void> {\n if (!(await detectLegacyOrdersPk(db))) {\n throw new Error(\"v2-to-v6: orders.event_id primary key not found; refuse to rebuild\");\n }\n\n await db.exec(\"DROP TABLE IF EXISTS orders_new\");\n await db.exec(V6_ORDERS_DDL);\n\n let cursor: string | null = null;\n for (;;) {\n const pageSql = cursor\n ? \"SELECT * FROM orders WHERE event_id > ? ORDER BY event_id LIMIT ?\"\n : \"SELECT * FROM orders ORDER BY event_id LIMIT ?\";\n const pageParams = cursor ? [cursor, UPGRADE_PAGE_SIZE] : [UPGRADE_PAGE_SIZE];\n const rows: LegacyOrderRow[] = await db.all<LegacyOrderRow>(pageSql, pageParams);\n if (rows.length === 0) break;\n\n for (const row of rows) {\n const mapped = mapLegacyOrder(row);\n await db.run(\n `INSERT INTO orders_new (\n id, email, name, phone, items_json, amount, shipping, address_json,\n payment_intent, custom_fields_json, status, run_id, email_status,\n created_at, shipped_at, tracking_number, carrier\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n [\n mapped.id,\n mapped.email,\n mapped.name,\n mapped.phone,\n mapped.items_json,\n mapped.amount,\n mapped.shipping,\n mapped.address_json,\n mapped.payment_intent,\n mapped.custom_fields_json,\n mapped.status,\n mapped.run_id,\n mapped.email_status,\n mapped.created_at,\n mapped.shipped_at,\n mapped.tracking_number,\n mapped.carrier,\n ],\n );\n }\n\n const last: LegacyOrderRow | undefined = rows[rows.length - 1];\n if (!last) break;\n cursor = last.event_id;\n if (rows.length < UPGRADE_PAGE_SIZE) break;\n }\n\n const oldCount = await db.first<{ n: number }>(\"SELECT COUNT(*) AS n FROM orders\");\n const newCount = await db.first<{ n: number }>(\"SELECT COUNT(*) AS n FROM orders_new\");\n const expected = oldCount?.n ?? -1;\n const copied = newCount?.n ?? -2;\n if (expected !== copied) {\n throw new Error(\n `v2-to-v6: COUNT mismatch orders=${expected} orders_new=${copied}. DROP skipped. Restore from Time Travel bookmark.`,\n );\n }\n\n await db.exec(\"DROP TABLE orders\");\n await db.exec(\"ALTER TABLE orders_new RENAME TO orders\");\n await db.exec(\"CREATE INDEX IF NOT EXISTS orders_payment_intent_idx ON orders(payment_intent)\");\n}\n\nexport const upgradeV2toV6: UpgradeModule = {\n name: \"v2-to-v6\",\n fromVersion: 2,\n toVersion: 6,\n description: \"Rebuild orders from event_id PK (v2) to id PK (v6)\",\n replacesChecksums: [\"ca6ec5c885f715a3ae65a7101787d66750ed831370dc2ecde0636cfc3cf83e24\"],\n canApply: detectLegacyOrdersPk,\n apply: applyV2toV6,\n};\n","import { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\n\nexport function sha256Bytes(contents: Buffer | string): string {\n return createHash(\"sha256\").update(contents).digest(\"hex\");\n}\n\nexport function sha256File(path: string): string {\n return sha256Bytes(readFileSync(path));\n}\n\nexport function loadFrozenChecksums(path: string): Record<string, string> {\n return JSON.parse(readFileSync(path, \"utf8\")) as Record<string, string>;\n}\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Printer } from \"./migrate.js\";\n\nconst EXTENSION_TYPES = {\n boolean: \"z.boolean().optional()\",\n string: \"z.string().optional()\",\n number: \"z.number().optional()\",\n} as const;\n\nexport type ExtendType = keyof typeof EXTENSION_TYPES;\n\nexport type ExtendOptions = {\n cwd: string;\n key?: string;\n type?: string;\n print?: Printer;\n};\n\nconst STUB = `import { z } from \"zod\";\n\nexport const orderExtensionSchema = z.object({\n});\n\nexport type OrderExtension = z.infer<typeof orderExtensionSchema>;\n`;\n\nfunction isExtendType(value: string): value is ExtendType {\n return value in EXTENSION_TYPES;\n}\n\nexport function runExtend(options: ExtendOptions): { exitCode: number; path: string; error?: string } {\n const print = options.print ?? (() => {});\n const path = join(options.cwd, \"src/config/extensions.ts\");\n mkdirSync(dirname(path), { recursive: true });\n\n if (!existsSync(path)) {\n writeFileSync(path, STUB);\n print(`created ${path}`);\n }\n\n const key = options.key;\n if (!key) {\n print(\"拡張は orders.extras_json に Zod で足す。orders を ALTER しないこと。\");\n print(`編集ファイル: ${path}`);\n return { exitCode: 0, path };\n }\n\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {\n return { exitCode: 1, path, error: `invalid extras key: ${key}` };\n }\n\n const typeName = options.type ?? \"string\";\n if (!isExtendType(typeName)) {\n return { exitCode: 1, path, error: `unsupported type ${typeName} (boolean|string|number)` };\n }\n\n let source = readFileSync(path, \"utf8\");\n if (new RegExp(`\\\\b${key}:`).test(source)) {\n print(`${key} already exists in ${path}`);\n return { exitCode: 0, path };\n }\n\n if (!source.includes(\"orderExtensionSchema\")) {\n return { exitCode: 1, path, error: \"orderExtensionSchema not found in extensions.ts\" };\n }\n\n source = source.replace(\n /export const orderExtensionSchema = z\\.object\\(\\{\\n/,\n `export const orderExtensionSchema = z.object({\\n ${key}: ${EXTENSION_TYPES[typeName]},\\n`,\n );\n writeFileSync(path, source);\n print(`added ${key}: ${typeName} to extras_json via ${path}`);\n print(\"orders テーブルを ALTER しないこと。予約列 extras_json だけを使う。\");\n return { exitCode: 0, path };\n}\n","import { readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { upgradeV2toV6 } from \"../../schema/upgrades/v2-to-v6.js\";\nimport type { UpgradeModule } from \"../../schema/upgrades/types.js\";\nimport { currentSchemaVersion, listCoreMigrations } from \"../db/catalog.js\";\nimport { classifyDrift, type DriftFinding } from \"../db/drift.js\";\nimport { introspectSnapshot } from \"../db/introspect.js\";\nimport { TRACKING_TABLES_SQL } from \"../db/schema-version.js\";\nimport { CORE_TABLES, type SchemaSnapshot } from \"../db/snapshot.js\";\nimport { sha256File } from \"./checksum.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\nimport { findPackageRoot } from \"../package-root.js\";\n\nexport const CORE_UPGRADES: UpgradeModule[] = [upgradeV2toV6];\n\nexport type Printer = (message: string) => void;\n\nexport type MigrateOptions = {\n cwd: string;\n executor: MigrationExecutor;\n snapshot: SchemaSnapshot;\n dryRun?: boolean;\n adopt?: boolean;\n repair?: boolean;\n coreVersion: string;\n now?: number;\n print?: Printer;\n};\n\nexport type MigrateResult = {\n exitCode: number;\n applied: string[];\n warnings: string[];\n error?: string;\n bookmark?: string | null;\n};\n\ntype AppliedRow = { name: string; checksum: string; kind: string };\n\nasync function ensureTracking(executor: MigrationExecutor, dryRun: boolean, print: Printer): Promise<void> {\n print(\"ensure umec_schema_version / umec_migrations\");\n if (dryRun) return;\n await executor.applySql(TRACKING_TABLES_SQL);\n}\n\nasync function readApplied(executor: MigrationExecutor): Promise<AppliedRow[]> {\n try {\n return await executor.all<AppliedRow>(\"SELECT name, checksum, kind FROM umec_migrations\");\n } catch {\n return [];\n }\n}\n\nasync function readVersion(executor: MigrationExecutor): Promise<number | null> {\n try {\n const row = await executor.first<{ version: number }>(\n \"SELECT version FROM umec_schema_version WHERE id = 1\",\n );\n return row?.version ?? null;\n } catch {\n return null;\n }\n}\n\nasync function recordMigration(\n executor: MigrationExecutor,\n name: string,\n checksum: string,\n kind: \"sql\" | \"upgrade\",\n now: number,\n): Promise<void> {\n await executor.run(\n `INSERT INTO umec_migrations (name, checksum, kind, applied_at) VALUES (?, ?, ?, ?)\n ON CONFLICT(name) DO UPDATE SET checksum = excluded.checksum, kind = excluded.kind, applied_at = excluded.applied_at`,\n [name, checksum, kind, now],\n );\n}\n\nasync function writeVersion(\n executor: MigrationExecutor,\n version: number,\n coreVersion: string,\n now: number,\n bookmark: string | null,\n): Promise<void> {\n await executor.run(\n `INSERT INTO umec_schema_version (id, version, core_version, applied_at, time_travel_bookmark)\n VALUES (1, ?, ?, ?, ?)\n ON CONFLICT(id) DO UPDATE SET\n version = excluded.version,\n core_version = excluded.core_version,\n applied_at = excluded.applied_at,\n time_travel_bookmark = excluded.time_travel_bookmark`,\n [version, coreVersion, now, bookmark],\n );\n}\n\nfunction listLocalMigrations(cwd: string): { name: string; path: string; sql: string }[] {\n const dir = join(cwd, \"migrations\", \"local\");\n try {\n return readdirSync(dir)\n .filter((name) => name.endsWith(\".sql\"))\n .sort()\n .map((name) => ({\n name: `local/${name}`,\n path: join(dir, name),\n sql: readFileSync(join(dir, name), \"utf8\"),\n }));\n } catch {\n return [];\n }\n}\n\nasync function adoptD1History(\n executor: MigrationExecutor,\n now: number,\n print: Printer,\n): Promise<{ adopted: string[]; warnings: string[] }> {\n const warnings: string[] = [];\n let names: string[] = [];\n try {\n const rows = await executor.all<{ name: string }>(\"SELECT name FROM d1_migrations\");\n names = rows.map((row) => row.name);\n } catch {\n throw new Error(\"d1_migrations が見つかりません。--adopt は wrangler 管理下の既存 D1 向けです。\");\n }\n\n const core = listCoreMigrations();\n const byFile = new Map(core.map((migration) => [migration.name, migration]));\n const adopted: string[] = [];\n const legacy = await upgradeV2toV6.canApply(executor);\n\n for (const rawName of names) {\n const fileName = rawName.split(\"/\").pop() ?? rawName;\n const migration = byFile.get(fileName);\n if (!migration) {\n warnings.push(`d1_migrations の ${rawName} は core に無いのでスキップ`);\n continue;\n }\n const checksum =\n fileName === \"0002_orders.sql\" && legacy\n ? (upgradeV2toV6.replacesChecksums[0] ?? sha256File(migration.path))\n : sha256File(migration.path);\n await recordMigration(executor, migration.name, checksum, \"sql\", now);\n adopted.push(migration.name);\n print(`adopt ${migration.name}`);\n }\n\n return { adopted, warnings };\n}\n\nasync function snapshotFromExecutor(\n executor: MigrationExecutor,\n version: number,\n): Promise<SchemaSnapshot> {\n const db = {\n prepare(query: string) {\n return {\n bind(...values: unknown[]) {\n this._params = values;\n return this;\n },\n _params: [] as unknown[],\n async first<T>() {\n return executor.first<T>(query, this._params);\n },\n async all<T>() {\n const results = await executor.all<T>(query, this._params);\n return { results };\n },\n async run() {\n const result = await executor.run(query, this._params);\n return { meta: { changes: result.changes } };\n },\n };\n },\n async batch() {\n return [];\n },\n };\n return introspectSnapshot(db, version);\n}\n\nexport async function runMigrate(options: MigrateOptions): Promise<MigrateResult> {\n const print = options.print ?? (() => {});\n const dryRun = options.dryRun === true;\n const now = options.now ?? Date.now();\n const applied: string[] = [];\n const warnings: string[] = [];\n const installedVersion = currentSchemaVersion();\n\n try {\n await ensureTracking(options.executor, dryRun, print);\n\n const dbVersion = dryRun ? null : await readVersion(options.executor);\n if (dbVersion != null && dbVersion > installedVersion) {\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `DB は schema v${dbVersion}。インストール中の @umec/core は v${installedVersion} までしか知らない。戻すには wrangler d1 time-travel restore --bookmark=<記録済み> のあと同じ core バージョンを入れ直すこと。down migration は無い。`,\n };\n }\n\n if (options.adopt) {\n print(\"adopt d1_migrations → umec_migrations\");\n if (dryRun) {\n return { exitCode: 0, applied: [\"--adopt\"], warnings };\n }\n const result = await adoptD1History(options.executor, now, print);\n applied.push(...result.adopted);\n warnings.push(...result.warnings);\n const bookmark = await options.executor.captureBookmark();\n const maxAdopted = result.adopted.reduce((max, name) => Math.max(max, Number(name.slice(0, 4)) || 0), 0);\n await writeVersion(options.executor, maxAdopted, options.coreVersion, now, bookmark);\n return { exitCode: 0, applied, warnings, bookmark };\n }\n\n if (!dryRun) {\n const actual = await snapshotFromExecutor(options.executor, options.snapshot.version);\n const fresh = CORE_TABLES.every((table) => !actual.tables[table]);\n if (!fresh) {\n const alreadyForDrift = await readApplied(options.executor);\n const pendingSql = listCoreMigrations()\n .filter((migration) => !alreadyForDrift.some((row) => row.name === migration.name))\n .map((migration) => migration.sql)\n .join(\"\\n\");\n const drift = classifyDrift(options.snapshot, actual);\n for (const finding of drift.compatible) {\n warnings.push(finding.message);\n print(`warn: ${finding.message}`);\n }\n const blocking = drift.incompatible.filter((finding) => !pendingMigrationFixes(pendingSql, finding));\n const repairable = options.repair && (await upgradeV2toV6.canApply(options.executor));\n if (blocking.length > 0 && !repairable) {\n const details = blocking.map((finding) => finding.message).join(\"; \");\n const hint = (await upgradeV2toV6.canApply(options.executor))\n ? \" umec migrate --repair で v2-to-v6 を提案できます。\"\n : \"\";\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `非互換 drift のため migrate を拒否: ${details}.${hint}`,\n };\n }\n }\n }\n\n const already = dryRun ? [] : await readApplied(options.executor);\n const alreadyByName = new Map(already.map((row) => [row.name, row]));\n const coreMigrations = listCoreMigrations();\n\n for (const migration of coreMigrations) {\n const currentHash = sha256File(migration.path);\n const recorded = alreadyByName.get(migration.name);\n if (recorded && recorded.checksum !== currentHash) {\n const knownLegacy = CORE_UPGRADES.some((upgrade) => upgrade.replacesChecksums.includes(recorded.checksum));\n const canRepair = options.repair && knownLegacy && (await upgradeV2toV6.canApply(options.executor));\n if (!canRepair) {\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `公開済み migration ${migration.name} の checksum が食い違っています。in-place 改変は禁止です。${knownLegacy ? \"umec migrate --repair を使ってください。\" : \"\"}`,\n };\n }\n }\n }\n\n let bookmark: string | null = null;\n if (!dryRun) {\n bookmark = await options.executor.captureBookmark();\n print(bookmark ? `time-travel bookmark ${bookmark}` : \"time-travel bookmark unavailable\");\n }\n\n if (options.repair) {\n for (const upgrade of CORE_UPGRADES) {\n const needed = dryRun ? true : await upgrade.canApply(options.executor);\n if (!needed) continue;\n print(`upgrade ${upgrade.name} (${upgrade.fromVersion} → ${upgrade.toVersion})`);\n if (dryRun) {\n applied.push(upgrade.name);\n continue;\n }\n await upgrade.apply(options.executor);\n await recordMigration(options.executor, upgrade.name, `upgrade:${upgrade.name}`, \"upgrade\", now);\n applied.push(upgrade.name);\n alreadyByName.set(upgrade.name, { name: upgrade.name, checksum: `upgrade:${upgrade.name}`, kind: \"upgrade\" });\n // upgradeV2toV6 bakes 0002 (PK rebuild) and 0005 (tracking_number/carrier\n // ALTER) into a single orders_new DDL (V6_ORDERS_DDL). Both must be marked\n // applied — in the DB *and* in alreadyByName, which the normal loop below\n // reads from — so it doesn't re-run 0005's ALTER against columns that\n // already exist. Do not add anything else here:\n // - 0003/0004/0006 create unrelated tables (IF NOT EXISTS) that\n // V6_ORDERS_DDL never touches — they still need to run normally.\n // - 0007 (extras_json) postdates this upgrade's toVersion (6) and is\n // NOT part of V6_ORDERS_DDL — it must also still run normally.\n // (real remote-D1 repro: runrun 2026-08-19)\n for (const supersededName of [\"0002_orders.sql\", \"0005_orders_tracking.sql\"]) {\n const superseded = coreMigrations.find((migration) => migration.name === supersededName);\n if (!superseded) {\n throw new Error(`upgradeV2toV6 supersedes unknown migration ${supersededName} — schema/migrations/ drifted`);\n }\n const checksum = sha256File(superseded.path);\n await recordMigration(options.executor, superseded.name, checksum, \"sql\", now);\n alreadyByName.set(superseded.name, { name: superseded.name, checksum, kind: \"sql\" });\n }\n }\n }\n\n for (const migration of coreMigrations) {\n if (alreadyByName.get(migration.name)?.checksum === sha256File(migration.path)) continue;\n if (alreadyByName.has(migration.name) && !options.repair) continue;\n print(`apply core/${migration.name}`);\n if (dryRun) {\n applied.push(migration.name);\n continue;\n }\n await options.executor.applySql(migration.sql);\n await recordMigration(options.executor, migration.name, sha256File(migration.path), \"sql\", now);\n applied.push(migration.name);\n }\n\n for (const local of listLocalMigrations(options.cwd)) {\n const hash = sha256File(local.path);\n if (alreadyByName.get(local.name)?.checksum === hash) continue;\n print(`apply ${local.name}`);\n if (dryRun) {\n applied.push(local.name);\n continue;\n }\n await options.executor.applySql(local.sql);\n await recordMigration(options.executor, local.name, hash, \"sql\", now);\n applied.push(local.name);\n }\n\n if (!dryRun) {\n await writeVersion(options.executor, installedVersion, options.coreVersion, now, bookmark);\n } else {\n print(`would set umec_schema_version.version = ${installedVersion}`);\n }\n\n return { exitCode: 0, applied, warnings, bookmark };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { exitCode: 1, applied, warnings, error: message };\n }\n}\n\nexport function pendingMigrationFixes(pendingSql: string, finding: DriftFinding): boolean {\n if (finding.message.includes(`required table \"${finding.table}\" is missing`)) {\n return new RegExp(`CREATE TABLE(?: IF NOT EXISTS)?\\\\s+${finding.table}\\\\b`, \"i\").test(pendingSql);\n }\n const missingColumn = finding.message.match(/required column \"([^.\"]+)\\.([^\"]+)\" is missing/);\n if (missingColumn?.[1] && missingColumn[2]) {\n // Scope to the owning table — an unrelated ALTER TABLE elsewhere in pendingSql\n // that happens to ADD COLUMN the same name must not count as a fix (qoder\n // review, 2026-08-20: \"inventory.sku\" could be false-matched by an unrelated\n // \"ALTER TABLE orders ADD COLUMN sku\").\n const [, table, column] = missingColumn;\n return new RegExp(`ALTER TABLE\\\\s+${table}\\\\s+ADD COLUMN\\\\s+${column}\\\\b`, \"i\").test(pendingSql);\n }\n return false;\n}\n\nexport function coreVersionFromPackage(root = findPackageRoot()): string {\n const pkg = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")) as { version: string };\n return pkg.version;\n}\n","import { spawn } from \"node:child_process\";\nimport { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { bindSql, type MigrationExecutor } from \"./executor.js\";\n\nexport type WranglerRunResult = {\n code: number;\n stdout: string;\n stderr: string;\n};\n\nexport type RunCommand = (command: string, args: string[], cwd: string) => Promise<WranglerRunResult>;\n\nexport function defaultRunCommand(command: string, args: string[], cwd: string): Promise<WranglerRunResult> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, { cwd, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout.on(\"data\", (chunk: Buffer) => {\n stdout += chunk.toString();\n });\n child.stderr.on(\"data\", (chunk: Buffer) => {\n stderr += chunk.toString();\n });\n child.on(\"error\", reject);\n child.on(\"close\", (code) => {\n resolve({ code: code ?? 1, stdout, stderr });\n });\n });\n}\n\nexport function parseJsonc(text: string): unknown {\n const stripped = text.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\").replace(/^\\s*\\/\\/.*$/gm, \"\");\n return JSON.parse(stripped);\n}\n\nexport function readD1DatabaseName(cwd: string, override?: string): string | null {\n if (override) return override;\n const path = join(cwd, \"wrangler.jsonc\");\n try {\n const parsed = parseJsonc(readFileSync(path, \"utf8\")) as {\n d1_databases?: Array<{ database_name?: string }>;\n };\n return parsed.d1_databases?.[0]?.database_name ?? null;\n } catch {\n return null;\n }\n}\n\nfunction parseExecuteJson(stdout: string): { results: unknown[]; changes: number } {\n const trimmed = stdout.trim();\n if (!trimmed) return { results: [], changes: 0 };\n const start = trimmed.indexOf(\"[\");\n const objStart = trimmed.indexOf(\"{\");\n const cut =\n start >= 0 && (objStart < 0 || start < objStart)\n ? trimmed.slice(start)\n : objStart >= 0\n ? trimmed.slice(objStart)\n : trimmed;\n const parsed: unknown = JSON.parse(cut);\n const rows = Array.isArray(parsed) ? parsed : [parsed];\n const first = rows[0] as { results?: unknown[]; meta?: { changes?: number } } | undefined;\n return {\n results: first?.results ?? [],\n changes: first?.meta?.changes ?? 0,\n };\n}\n\nexport function createWranglerExecutor(options: {\n cwd: string;\n database: string;\n remote: boolean;\n runCommand?: RunCommand;\n}): MigrationExecutor {\n const runCommand = options.runCommand ?? defaultRunCommand;\n const location = options.remote ? \"--remote\" : \"--local\";\n\n const execute = async (sql: string) => {\n const result = await runCommand(\n \"wrangler\",\n [\"d1\", \"execute\", options.database, location, \"--json\", \"--command\", sql],\n options.cwd,\n );\n if (result.code !== 0) {\n throw new Error(result.stderr || result.stdout || `wrangler d1 execute failed (${result.code})`);\n }\n return parseExecuteJson(result.stdout);\n };\n\n return {\n async exec(sql: string) {\n await execute(sql);\n },\n async applySql(sql: string) {\n const { splitSqlStatements } = await import(\"../db/sql.js\");\n for (const statement of splitSqlStatements(sql)) {\n await execute(statement);\n }\n },\n async all<T>(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return result.results as T[];\n },\n async first<T>(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return (result.results[0] as T | undefined) ?? null;\n },\n async run(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return { changes: result.changes };\n },\n async captureBookmark() {\n const result = await runCommand(\n \"wrangler\",\n [\"d1\", \"time-travel\", \"info\", options.database, \"--json\"],\n options.cwd,\n );\n if (result.code !== 0) return null;\n try {\n const parsed = JSON.parse(result.stdout) as { bookmark?: string };\n return parsed.bookmark ?? null;\n } catch {\n return null;\n }\n },\n };\n}\n","import type { UpgradeExecutor } from \"../../schema/upgrades/types.js\";\nimport type { ShopDatabase } from \"../db/d1.js\";\nimport { splitSqlStatements } from \"../db/sql.js\";\n\nexport type MigrationExecutor = UpgradeExecutor & {\n applySql(sql: string): Promise<void>;\n captureBookmark(): Promise<string | null>;\n};\n\nexport function sqlLiteral(value: unknown): string {\n if (value === null || value === undefined) return \"NULL\";\n if (typeof value === \"boolean\") return value ? \"1\" : \"0\";\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n if (typeof value === \"string\") return `'${value.replaceAll(\"'\", \"''\")}'`;\n throw new Error(`Unsupported SQL bind: ${typeof value}`);\n}\n\nexport function bindSql(sql: string, params: unknown[] = []): string {\n let index = 0;\n return sql.replaceAll(\"?\", () => {\n if (index >= params.length) throw new Error(\"Not enough SQL bind parameters\");\n return sqlLiteral(params[index++]);\n });\n}\n\nexport function executorFromDatabase(\n db: ShopDatabase,\n captureBookmark: () => Promise<string | null> = async () => null,\n): MigrationExecutor {\n return {\n async exec(sql: string) {\n await db.prepare(sql).run();\n },\n async applySql(sql: string) {\n for (const statement of splitSqlStatements(sql)) {\n await db.prepare(statement).run();\n }\n },\n async all<T>(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n const result = await statement.all<T>();\n return result.results ?? [];\n },\n async first<T>(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n return statement.first<T>();\n },\n async run(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n const result = await statement.run();\n return { changes: result.meta.changes };\n },\n captureBookmark,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,QAAAC,aAAY;;;ACDrB,SAAS,kBAAkB;AAC3B,SAAS,YAAY;;;ACCd,IAAM,oBAAoB;AAa1B,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgD7B,SAAS,SAAS,OAAgB,WAAW,IAAY;AACvD,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,iBAAiB,OAA+B;AACvD,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,SAAS,OAAgB,WAAW,GAAW;AACtD,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,SAAS,iBAAiB,OAA+B;AACvD,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,eAAsB,qBAAqB,IAAuC;AAChF,QAAM,UAAU,MAAM,GAAG,IAAkB,2BAA2B;AACtE,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,QA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IACT,CAAC;AACD,QAAI,OAAO,MAAO,QAAO,OAAO,KAAK;AACrC,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,MAAM,CAAC;AACd,SAAO;AACT;AAEA,SAAS,cAAuB;AAC9B,QAAM,UAAU,QAAQ,KAAK,CAAC;AAC9B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,2BAA2B,KAAK,OAAO,KAAK,QAAQ,SAAS,GAAGC,MAAK,QAAQ,KAAK,CAAC,EAAE;AAC9F;AAEA,IAAI,YAAY,GAAG;AACjB,QAAM,MAAM,KAAK,MAAMC,cAAaD,MAAK,gBAAgB,GAAG,cAAc,GAAG,MAAM,CAAC;AACpF,MAAI,QAAQ,KAAK,SAAS,WAAW,KAAK,QAAQ,KAAK,SAAS,IAAI,GAAG;AACrE,YAAQ,IAAI,IAAI,OAAO;AACvB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACA,SAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE;AAAA,IAC5B,CAAC,SAAS,QAAQ,KAAK,IAAI;AAAA,IAC3B,CAAC,UAAU;AACT,cAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAC5D,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;","names":["readFileSync","join","existsSync","readFileSync","join","readFileSync","join","join","readFileSync","bookmark","readFileSync","join","join","readFileSync","splitSqlStatements","join","readFileSync"]}
1
+ {"version":3,"sources":["../src/cli/index.ts","../src/cli/doctor.ts","../schema/upgrades/v2-to-v6.ts","../src/cli/checksum.ts","../src/cli/extend.ts","../src/cli/migrate.ts","../src/cli/wrangler.ts","../src/cli/executor.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { loadSnapshotJson } from \"../db/catalog.js\";\nimport type { SchemaSnapshot } from \"../db/snapshot.js\";\nimport { findPackageRoot } from \"../package-root.js\";\nimport { runDoctor } from \"./doctor.js\";\nimport { runExtend } from \"./extend.js\";\nimport { coreVersionFromPackage, runMigrate, type MigrateOptions } from \"./migrate.js\";\nimport { createWranglerExecutor, readD1DatabaseName, type RunCommand } from \"./wrangler.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\n\nexport type CliIo = {\n cwd?: string;\n stdout?: (message: string) => void;\n stderr?: (message: string) => void;\n executor?: MigrationExecutor;\n runCommand?: RunCommand;\n};\n\nexport function parseArgs(argv: string[]): {\n command: string | null;\n flags: Record<string, string | boolean>;\n} {\n const flags: Record<string, string | boolean> = {};\n let command: string | null = null;\n for (let i = 0; i < argv.length; i += 1) {\n const arg = argv[i];\n if (!arg) continue;\n if (arg.startsWith(\"--\")) {\n const eq = arg.indexOf(\"=\");\n if (eq > 0) {\n flags[arg.slice(2, eq)] = arg.slice(eq + 1);\n continue;\n }\n const name = arg.slice(2);\n const next = argv[i + 1];\n if (next && !next.startsWith(\"--\") && name !== \"dry-run\" && name !== \"adopt\" && name !== \"repair\" && name !== \"remote\" && name !== \"local\") {\n flags[name] = next;\n i += 1;\n } else {\n flags[name] = true;\n }\n continue;\n }\n if (!command) command = arg;\n }\n return { command, flags };\n}\n\nfunction usage(): string {\n return `Usage:\n umec migrate [--dry-run] [--local|--remote] [--adopt] [--repair] [--database NAME]\n umec doctor [--local|--remote] [--database NAME]\n umec extend [--key NAME] [--type boolean|string|number]`;\n}\n\nexport async function runCli(argv: string[], io: CliIo = {}): Promise<number> {\n const cwd = io.cwd ?? process.cwd();\n const stdout = io.stdout ?? ((message) => console.log(message));\n const stderr = io.stderr ?? ((message) => console.error(message));\n const { command, flags } = parseArgs(argv);\n\n if (!command || command === \"help\" || flags.help) {\n stdout(usage());\n return command ? 0 : 1;\n }\n\n const snapshot = loadSnapshotJson() as SchemaSnapshot;\n const remote = flags.remote === true;\n const database = typeof flags.database === \"string\" ? flags.database : readD1DatabaseName(cwd);\n\n const executor =\n io.executor ??\n (command === \"extend\" || (command === \"migrate\" && flags[\"dry-run\"] === true)\n ? undefined\n : database\n ? createWranglerExecutor({ cwd, database, remote, runCommand: io.runCommand })\n : undefined);\n\n if (command === \"migrate\") {\n if (flags[\"dry-run\"] === true && !io.executor) {\n const migrations = (await import(\"../db/catalog.js\")).listCoreMigrations();\n stdout(\"dry-run (no D1 connection)\");\n stdout(\"ensure umec_schema_version / umec_migrations\");\n for (const migration of migrations) stdout(`apply core/${migration.name}`);\n stdout(`would set umec_schema_version.version = ${snapshot.version}`);\n return 0;\n }\n if (!executor) {\n stderr(\"wrangler.jsonc の d1_databases[0].database_name が見つかりません。--database を指定してください。\");\n return 1;\n }\n const options: MigrateOptions = {\n cwd,\n executor,\n snapshot,\n dryRun: flags[\"dry-run\"] === true,\n adopt: flags.adopt === true,\n repair: flags.repair === true,\n coreVersion: coreVersionFromPackage(),\n print: stdout,\n };\n const result = await runMigrate(options);\n for (const warning of result.warnings) stdout(`warn: ${warning}`);\n if (result.error) stderr(result.error);\n return result.exitCode;\n }\n\n if (command === \"doctor\") {\n const result = await runDoctor({\n cwd,\n executor,\n snapshot,\n print: stdout,\n });\n return result.exitCode;\n }\n\n if (command === \"extend\") {\n const result = runExtend({\n cwd,\n key: typeof flags.key === \"string\" ? flags.key : undefined,\n type: typeof flags.type === \"string\" ? flags.type : undefined,\n print: stdout,\n });\n if (result.error) stderr(result.error);\n return result.exitCode;\n }\n\n stderr(usage());\n return 1;\n}\n\nfunction isDirectRun(): boolean {\n const invoked = process.argv[1];\n if (!invoked) return false;\n return /(?:^|[\\\\/])cli(?:\\.js)?$/.test(invoked) || invoked.includes(`${join(\"dist\", \"cli\")}`);\n}\n\nif (isDirectRun()) {\n const pkg = JSON.parse(readFileSync(join(findPackageRoot(), \"package.json\"), \"utf8\")) as { version: string };\n if (process.argv.includes(\"--version\") || process.argv.includes(\"-V\")) {\n console.log(pkg.version);\n process.exit(0);\n }\n runCli(process.argv.slice(2)).then(\n (code) => process.exit(code),\n (error) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n },\n );\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { upgradeV2toV6 } from \"../../schema/upgrades/v2-to-v6.js\";\nimport { currentSchemaVersion, listCoreMigrations } from \"../db/catalog.js\";\nimport { classifyDrift } from \"../db/drift.js\";\nimport { introspectSnapshot } from \"../db/introspect.js\";\nimport type { SchemaSnapshot } from \"../db/snapshot.js\";\nimport { sha256File } from \"./checksum.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\nimport type { Printer } from \"./migrate.js\";\n\nexport type DoctorOptions = {\n cwd: string;\n executor?: MigrationExecutor;\n snapshot: SchemaSnapshot;\n print?: Printer;\n};\n\nexport type DoctorResult = {\n exitCode: number;\n lines: string[];\n};\n\nexport async function runDoctor(options: DoctorOptions): Promise<DoctorResult> {\n const print = options.print ?? (() => {});\n const lines: string[] = [];\n const installed = currentSchemaVersion();\n let exitCode = 0;\n\n const say = (line: string) => {\n lines.push(line);\n print(line);\n };\n\n say(`installed schema version: ${installed}`);\n\n if (!options.executor) {\n say(\"no database executor; offline checks only\");\n } else {\n try {\n const version = await options.executor.first<{ version: number; core_version: string }>(\n \"SELECT version, core_version FROM umec_schema_version WHERE id = 1\",\n );\n if (!version) {\n say(\"umec_schema_version: missing (run umec migrate)\");\n } else {\n say(`database schema version: ${version.version} (core ${version.core_version})`);\n if (version.version > installed) {\n exitCode = 1;\n say(\n `DB は schema v${version.version}。インストール中の @umec/core は v${installed} までしか知らない。戻すには wrangler d1 time-travel restore --bookmark=<記録済み> のあと同じ core バージョンを入れ直すこと。down migration は無い。`,\n );\n }\n }\n } catch {\n say(\"umec_schema_version: unreadable (run umec migrate)\");\n }\n\n const actual = await introspectViaExecutor(options.executor, options.snapshot.version);\n const drift = classifyDrift(options.snapshot, actual);\n for (const finding of drift.compatible) say(`warn: ${finding.message}`);\n for (const finding of drift.incompatible) {\n exitCode = 1;\n say(`error: ${finding.message}`);\n }\n if (await upgradeV2toV6.canApply(options.executor)) {\n exitCode = 1;\n say(\"error: orders は event_id PK の旧スキーマです。umec migrate --repair を実行してください。\");\n }\n\n const applied = await options.executor.all<{ name: string; checksum: string }>(\n \"SELECT name, checksum FROM umec_migrations\",\n ).catch(() => []);\n const appliedByName = new Map(applied.map((row) => [row.name, row.checksum]));\n for (const migration of listCoreMigrations()) {\n const expected = sha256File(migration.path);\n const got = appliedByName.get(migration.name);\n if (got && got !== expected) {\n exitCode = 1;\n say(`error: checksum mismatch ${migration.name}`);\n }\n }\n }\n\n const extensionsPath = join(options.cwd, \"src/config/extensions.ts\");\n if (!existsSync(extensionsPath)) {\n say(\"warn: src/config/extensions.ts がありません。拡張は umec extend で extras_json に足してください。\");\n }\n\n return { exitCode, lines };\n}\n\nasync function introspectViaExecutor(executor: MigrationExecutor, version: number) {\n const db = {\n prepare(query: string) {\n return {\n bind(...values: unknown[]) {\n this._params = values;\n return this;\n },\n _params: [] as unknown[],\n async first<T>() {\n return executor.first<T>(query, this._params);\n },\n async all<T>() {\n return { results: await executor.all<T>(query, this._params) };\n },\n async run() {\n const result = await executor.run(query, this._params);\n return { meta: { changes: result.changes } };\n },\n };\n },\n async batch() {\n return [];\n },\n };\n return introspectSnapshot(db, version);\n}\n","import type { UpgradeExecutor, UpgradeModule } from \"./types.js\";\n\nexport const UPGRADE_PAGE_SIZE = 500;\n\nexport const LEGACY_0002_SQL = `CREATE TABLE IF NOT EXISTS orders (\n event_id TEXT PRIMARY KEY NOT NULL,\n session_id TEXT NOT NULL,\n amount_total INTEGER NOT NULL,\n currency TEXT NOT NULL,\n customer_email TEXT NOT NULL,\n run_id TEXT,\n created_at INTEGER NOT NULL\n);\n`;\n\nexport const V6_ORDERS_DDL = `CREATE TABLE orders_new (\n id TEXT PRIMARY KEY,\n email TEXT NOT NULL,\n name TEXT,\n phone TEXT,\n items_json TEXT NOT NULL,\n amount INTEGER NOT NULL,\n shipping INTEGER,\n address_json TEXT,\n payment_intent TEXT,\n custom_fields_json TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n run_id TEXT,\n email_status TEXT CHECK (email_status IN ('sent', 'failed')),\n created_at INTEGER NOT NULL,\n shipped_at INTEGER,\n tracking_number TEXT,\n carrier TEXT CHECK (carrier IN ('yamato', 'sagawa', 'japanpost', 'other') OR carrier IS NULL)\n)`;\n\ntype LegacyOrderRow = {\n event_id: string;\n session_id?: string | null;\n amount_total?: number | null;\n amount?: number | null;\n customer_email?: string | null;\n email?: string | null;\n name?: string | null;\n phone?: string | null;\n items_json?: string | null;\n shipping?: number | null;\n address_json?: string | null;\n payment_intent?: string | null;\n custom_fields_json?: string | null;\n status?: string | null;\n run_id?: string | null;\n email_status?: string | null;\n created_at: number;\n shipped_at?: number | null;\n tracking_number?: string | null;\n carrier?: string | null;\n};\n\ntype TableInfoRow = {\n name: string;\n pk: number;\n};\n\nfunction asString(value: unknown, fallback = \"\"): string {\n return typeof value === \"string\" ? value : fallback;\n}\n\nfunction asNullableString(value: unknown): string | null {\n return typeof value === \"string\" ? value : null;\n}\n\nfunction asNumber(value: unknown, fallback = 0): number {\n return typeof value === \"number\" && Number.isFinite(value) ? value : fallback;\n}\n\nfunction asNullableNumber(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n}\n\nexport async function detectLegacyOrdersPk(db: UpgradeExecutor): Promise<boolean> {\n const columns = await db.all<TableInfoRow>(\"PRAGMA table_info(orders)\");\n if (columns.length === 0) return false;\n const eventId = columns.find((column) => column.name === \"event_id\");\n return eventId != null && eventId.pk === 1;\n}\n\nexport function mapLegacyOrder(row: LegacyOrderRow): {\n id: string;\n email: string;\n name: string | null;\n phone: string | null;\n items_json: string;\n amount: number;\n shipping: number | null;\n address_json: string | null;\n payment_intent: string | null;\n custom_fields_json: string | null;\n status: string;\n run_id: string | null;\n email_status: string | null;\n created_at: number;\n shipped_at: number | null;\n tracking_number: string | null;\n carrier: string | null;\n} {\n const sessionId = asNullableString(row.session_id);\n const eventId = asString(row.event_id);\n return {\n id: sessionId && sessionId.length > 0 ? sessionId : eventId,\n email: asString(row.customer_email ?? row.email),\n name: asNullableString(row.name),\n phone: asNullableString(row.phone),\n items_json: asNullableString(row.items_json) ?? \"[]\",\n amount: asNumber(row.amount_total ?? row.amount),\n shipping: asNullableNumber(row.shipping),\n address_json: asNullableString(row.address_json),\n payment_intent: asNullableString(row.payment_intent),\n custom_fields_json: asNullableString(row.custom_fields_json),\n status: asNullableString(row.status) ?? \"pending\",\n run_id: asNullableString(row.run_id),\n email_status: asNullableString(row.email_status),\n created_at: asNumber(row.created_at),\n shipped_at: asNullableNumber(row.shipped_at),\n tracking_number: asNullableString(row.tracking_number),\n carrier: asNullableString(row.carrier),\n };\n}\n\nexport async function applyV2toV6(db: UpgradeExecutor): Promise<void> {\n if (!(await detectLegacyOrdersPk(db))) {\n throw new Error(\"v2-to-v6: orders.event_id primary key not found; refuse to rebuild\");\n }\n\n await db.exec(\"DROP TABLE IF EXISTS orders_new\");\n await db.exec(V6_ORDERS_DDL);\n\n let cursor: string | null = null;\n for (;;) {\n const pageSql = cursor\n ? \"SELECT * FROM orders WHERE event_id > ? ORDER BY event_id LIMIT ?\"\n : \"SELECT * FROM orders ORDER BY event_id LIMIT ?\";\n const pageParams = cursor ? [cursor, UPGRADE_PAGE_SIZE] : [UPGRADE_PAGE_SIZE];\n const rows: LegacyOrderRow[] = await db.all<LegacyOrderRow>(pageSql, pageParams);\n if (rows.length === 0) break;\n\n for (const row of rows) {\n const mapped = mapLegacyOrder(row);\n await db.run(\n `INSERT INTO orders_new (\n id, email, name, phone, items_json, amount, shipping, address_json,\n payment_intent, custom_fields_json, status, run_id, email_status,\n created_at, shipped_at, tracking_number, carrier\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n [\n mapped.id,\n mapped.email,\n mapped.name,\n mapped.phone,\n mapped.items_json,\n mapped.amount,\n mapped.shipping,\n mapped.address_json,\n mapped.payment_intent,\n mapped.custom_fields_json,\n mapped.status,\n mapped.run_id,\n mapped.email_status,\n mapped.created_at,\n mapped.shipped_at,\n mapped.tracking_number,\n mapped.carrier,\n ],\n );\n }\n\n const last: LegacyOrderRow | undefined = rows[rows.length - 1];\n if (!last) break;\n cursor = last.event_id;\n if (rows.length < UPGRADE_PAGE_SIZE) break;\n }\n\n const oldCount = await db.first<{ n: number }>(\"SELECT COUNT(*) AS n FROM orders\");\n const newCount = await db.first<{ n: number }>(\"SELECT COUNT(*) AS n FROM orders_new\");\n const expected = oldCount?.n ?? -1;\n const copied = newCount?.n ?? -2;\n if (expected !== copied) {\n throw new Error(\n `v2-to-v6: COUNT mismatch orders=${expected} orders_new=${copied}. DROP skipped. Restore from Time Travel bookmark.`,\n );\n }\n\n await db.exec(\"DROP TABLE orders\");\n await db.exec(\"ALTER TABLE orders_new RENAME TO orders\");\n await db.exec(\"CREATE INDEX IF NOT EXISTS orders_payment_intent_idx ON orders(payment_intent)\");\n}\n\nexport const upgradeV2toV6: UpgradeModule = {\n name: \"v2-to-v6\",\n fromVersion: 2,\n toVersion: 6,\n description: \"Rebuild orders from event_id PK (v2) to id PK (v6)\",\n replacesChecksums: [\"ca6ec5c885f715a3ae65a7101787d66750ed831370dc2ecde0636cfc3cf83e24\"],\n canApply: detectLegacyOrdersPk,\n apply: applyV2toV6,\n};\n","import { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\n\nexport function sha256Bytes(contents: Buffer | string): string {\n return createHash(\"sha256\").update(contents).digest(\"hex\");\n}\n\nexport function sha256File(path: string): string {\n return sha256Bytes(readFileSync(path));\n}\n\nexport function loadFrozenChecksums(path: string): Record<string, string> {\n return JSON.parse(readFileSync(path, \"utf8\")) as Record<string, string>;\n}\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Printer } from \"./migrate.js\";\n\nconst EXTENSION_TYPES = {\n boolean: \"z.boolean().optional()\",\n string: \"z.string().optional()\",\n number: \"z.number().optional()\",\n} as const;\n\nexport type ExtendType = keyof typeof EXTENSION_TYPES;\n\nexport type ExtendOptions = {\n cwd: string;\n key?: string;\n type?: string;\n print?: Printer;\n};\n\nconst STUB = `import { z } from \"zod\";\n\nexport const orderExtensionSchema = z.object({\n});\n\nexport type OrderExtension = z.infer<typeof orderExtensionSchema>;\n`;\n\nfunction isExtendType(value: string): value is ExtendType {\n return value in EXTENSION_TYPES;\n}\n\nexport function runExtend(options: ExtendOptions): { exitCode: number; path: string; error?: string } {\n const print = options.print ?? (() => {});\n const path = join(options.cwd, \"src/config/extensions.ts\");\n mkdirSync(dirname(path), { recursive: true });\n\n if (!existsSync(path)) {\n writeFileSync(path, STUB);\n print(`created ${path}`);\n }\n\n const key = options.key;\n if (!key) {\n print(\"拡張は orders.extras_json に Zod で足す。orders を ALTER しないこと。\");\n print(`編集ファイル: ${path}`);\n return { exitCode: 0, path };\n }\n\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {\n return { exitCode: 1, path, error: `invalid extras key: ${key}` };\n }\n\n const typeName = options.type ?? \"string\";\n if (!isExtendType(typeName)) {\n return { exitCode: 1, path, error: `unsupported type ${typeName} (boolean|string|number)` };\n }\n\n let source = readFileSync(path, \"utf8\");\n if (new RegExp(`\\\\b${key}:`).test(source)) {\n print(`${key} already exists in ${path}`);\n return { exitCode: 0, path };\n }\n\n if (!source.includes(\"orderExtensionSchema\")) {\n return { exitCode: 1, path, error: \"orderExtensionSchema not found in extensions.ts\" };\n }\n\n source = source.replace(\n /export const orderExtensionSchema = z\\.object\\(\\{\\n/,\n `export const orderExtensionSchema = z.object({\\n ${key}: ${EXTENSION_TYPES[typeName]},\\n`,\n );\n writeFileSync(path, source);\n print(`added ${key}: ${typeName} to extras_json via ${path}`);\n print(\"orders テーブルを ALTER しないこと。予約列 extras_json だけを使う。\");\n return { exitCode: 0, path };\n}\n","import { readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { upgradeV2toV6 } from \"../../schema/upgrades/v2-to-v6.js\";\nimport type { UpgradeModule } from \"../../schema/upgrades/types.js\";\nimport { currentSchemaVersion, listCoreMigrations } from \"../db/catalog.js\";\nimport { classifyDrift, type DriftFinding } from \"../db/drift.js\";\nimport { introspectSnapshot } from \"../db/introspect.js\";\nimport { TRACKING_TABLES_SQL } from \"../db/schema-version.js\";\nimport { CORE_TABLES, type SchemaSnapshot } from \"../db/snapshot.js\";\nimport { sha256File } from \"./checksum.js\";\nimport type { MigrationExecutor } from \"./executor.js\";\nimport { findPackageRoot } from \"../package-root.js\";\n\nexport const CORE_UPGRADES: UpgradeModule[] = [upgradeV2toV6];\n\nexport type Printer = (message: string) => void;\n\nexport type MigrateOptions = {\n cwd: string;\n executor: MigrationExecutor;\n snapshot: SchemaSnapshot;\n dryRun?: boolean;\n adopt?: boolean;\n repair?: boolean;\n coreVersion: string;\n now?: number;\n print?: Printer;\n};\n\nexport type MigrateResult = {\n exitCode: number;\n applied: string[];\n warnings: string[];\n error?: string;\n bookmark?: string | null;\n};\n\ntype AppliedRow = { name: string; checksum: string; kind: string };\n\nasync function ensureTracking(executor: MigrationExecutor, dryRun: boolean, print: Printer): Promise<void> {\n print(\"ensure umec_schema_version / umec_migrations\");\n if (dryRun) return;\n await executor.applySql(TRACKING_TABLES_SQL);\n}\n\nasync function readApplied(executor: MigrationExecutor): Promise<AppliedRow[]> {\n try {\n return await executor.all<AppliedRow>(\"SELECT name, checksum, kind FROM umec_migrations\");\n } catch {\n return [];\n }\n}\n\nasync function readVersion(executor: MigrationExecutor): Promise<number | null> {\n try {\n const row = await executor.first<{ version: number }>(\n \"SELECT version FROM umec_schema_version WHERE id = 1\",\n );\n return row?.version ?? null;\n } catch {\n return null;\n }\n}\n\nasync function recordMigration(\n executor: MigrationExecutor,\n name: string,\n checksum: string,\n kind: \"sql\" | \"upgrade\",\n now: number,\n): Promise<void> {\n await executor.run(\n `INSERT INTO umec_migrations (name, checksum, kind, applied_at) VALUES (?, ?, ?, ?)\n ON CONFLICT(name) DO UPDATE SET checksum = excluded.checksum, kind = excluded.kind, applied_at = excluded.applied_at`,\n [name, checksum, kind, now],\n );\n}\n\nasync function writeVersion(\n executor: MigrationExecutor,\n version: number,\n coreVersion: string,\n now: number,\n bookmark: string | null,\n): Promise<void> {\n await executor.run(\n `INSERT INTO umec_schema_version (id, version, core_version, applied_at, time_travel_bookmark)\n VALUES (1, ?, ?, ?, ?)\n ON CONFLICT(id) DO UPDATE SET\n version = excluded.version,\n core_version = excluded.core_version,\n applied_at = excluded.applied_at,\n time_travel_bookmark = excluded.time_travel_bookmark`,\n [version, coreVersion, now, bookmark],\n );\n}\n\nfunction listLocalMigrations(cwd: string): { name: string; path: string; sql: string }[] {\n const dir = join(cwd, \"migrations\", \"local\");\n try {\n return readdirSync(dir)\n .filter((name) => name.endsWith(\".sql\"))\n .sort()\n .map((name) => ({\n name: `local/${name}`,\n path: join(dir, name),\n sql: readFileSync(join(dir, name), \"utf8\"),\n }));\n } catch {\n return [];\n }\n}\n\nasync function adoptD1History(\n executor: MigrationExecutor,\n now: number,\n print: Printer,\n): Promise<{ adopted: string[]; warnings: string[] }> {\n const warnings: string[] = [];\n let names: string[] = [];\n try {\n const rows = await executor.all<{ name: string }>(\"SELECT name FROM d1_migrations\");\n names = rows.map((row) => row.name);\n } catch {\n throw new Error(\"d1_migrations が見つかりません。--adopt は wrangler 管理下の既存 D1 向けです。\");\n }\n\n const core = listCoreMigrations();\n const byFile = new Map(core.map((migration) => [migration.name, migration]));\n const adopted: string[] = [];\n const legacy = await upgradeV2toV6.canApply(executor);\n\n for (const rawName of names) {\n const fileName = rawName.split(\"/\").pop() ?? rawName;\n const migration = byFile.get(fileName);\n if (!migration) {\n warnings.push(`d1_migrations の ${rawName} は core に無いのでスキップ`);\n continue;\n }\n const checksum =\n fileName === \"0002_orders.sql\" && legacy\n ? (upgradeV2toV6.replacesChecksums[0] ?? sha256File(migration.path))\n : sha256File(migration.path);\n await recordMigration(executor, migration.name, checksum, \"sql\", now);\n adopted.push(migration.name);\n print(`adopt ${migration.name}`);\n }\n\n return { adopted, warnings };\n}\n\nasync function snapshotFromExecutor(\n executor: MigrationExecutor,\n version: number,\n): Promise<SchemaSnapshot> {\n const db = {\n prepare(query: string) {\n return {\n bind(...values: unknown[]) {\n this._params = values;\n return this;\n },\n _params: [] as unknown[],\n async first<T>() {\n return executor.first<T>(query, this._params);\n },\n async all<T>() {\n const results = await executor.all<T>(query, this._params);\n return { results };\n },\n async run() {\n const result = await executor.run(query, this._params);\n return { meta: { changes: result.changes } };\n },\n };\n },\n async batch() {\n return [];\n },\n };\n return introspectSnapshot(db, version);\n}\n\nexport async function runMigrate(options: MigrateOptions): Promise<MigrateResult> {\n const print = options.print ?? (() => {});\n const dryRun = options.dryRun === true;\n const now = options.now ?? Date.now();\n const applied: string[] = [];\n const warnings: string[] = [];\n const installedVersion = currentSchemaVersion();\n\n try {\n await ensureTracking(options.executor, dryRun, print);\n\n const dbVersion = dryRun ? null : await readVersion(options.executor);\n if (dbVersion != null && dbVersion > installedVersion) {\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `DB は schema v${dbVersion}。インストール中の @umec/core は v${installedVersion} までしか知らない。戻すには wrangler d1 time-travel restore --bookmark=<記録済み> のあと同じ core バージョンを入れ直すこと。down migration は無い。`,\n };\n }\n\n if (options.adopt) {\n print(\"adopt d1_migrations → umec_migrations\");\n if (dryRun) {\n return { exitCode: 0, applied: [\"--adopt\"], warnings };\n }\n const result = await adoptD1History(options.executor, now, print);\n applied.push(...result.adopted);\n warnings.push(...result.warnings);\n const bookmark = await options.executor.captureBookmark();\n const maxAdopted = result.adopted.reduce((max, name) => Math.max(max, Number(name.slice(0, 4)) || 0), 0);\n await writeVersion(options.executor, maxAdopted, options.coreVersion, now, bookmark);\n return { exitCode: 0, applied, warnings, bookmark };\n }\n\n if (!dryRun) {\n const actual = await snapshotFromExecutor(options.executor, options.snapshot.version);\n const fresh = CORE_TABLES.every((table) => !actual.tables[table]);\n if (!fresh) {\n const alreadyForDrift = await readApplied(options.executor);\n const pendingSql = listCoreMigrations()\n .filter((migration) => !alreadyForDrift.some((row) => row.name === migration.name))\n .map((migration) => migration.sql)\n .join(\"\\n\");\n const drift = classifyDrift(options.snapshot, actual);\n for (const finding of drift.compatible) {\n warnings.push(finding.message);\n print(`warn: ${finding.message}`);\n }\n const blocking = drift.incompatible.filter((finding) => !pendingMigrationFixes(pendingSql, finding));\n const repairable = options.repair && (await upgradeV2toV6.canApply(options.executor));\n if (blocking.length > 0 && !repairable) {\n const details = blocking.map((finding) => finding.message).join(\"; \");\n const hint = (await upgradeV2toV6.canApply(options.executor))\n ? \" umec migrate --repair で v2-to-v6 を提案できます。\"\n : \"\";\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `非互換 drift のため migrate を拒否: ${details}.${hint}`,\n };\n }\n }\n }\n\n const already = dryRun ? [] : await readApplied(options.executor);\n const alreadyByName = new Map(already.map((row) => [row.name, row]));\n const coreMigrations = listCoreMigrations();\n\n for (const migration of coreMigrations) {\n const currentHash = sha256File(migration.path);\n const recorded = alreadyByName.get(migration.name);\n if (recorded && recorded.checksum !== currentHash) {\n const knownLegacy = CORE_UPGRADES.some((upgrade) => upgrade.replacesChecksums.includes(recorded.checksum));\n const canRepair = options.repair && knownLegacy && (await upgradeV2toV6.canApply(options.executor));\n if (!canRepair) {\n return {\n exitCode: 1,\n applied,\n warnings,\n error: `公開済み migration ${migration.name} の checksum が食い違っています。in-place 改変は禁止です。${knownLegacy ? \"umec migrate --repair を使ってください。\" : \"\"}`,\n };\n }\n }\n }\n\n let bookmark: string | null = null;\n if (!dryRun) {\n bookmark = await options.executor.captureBookmark();\n print(bookmark ? `time-travel bookmark ${bookmark}` : \"time-travel bookmark unavailable\");\n }\n\n if (options.repair) {\n for (const upgrade of CORE_UPGRADES) {\n const legacyPresent = dryRun ? true : await upgrade.canApply(options.executor);\n if (legacyPresent) {\n print(`upgrade ${upgrade.name} (${upgrade.fromVersion} → ${upgrade.toVersion})`);\n if (dryRun) {\n applied.push(upgrade.name);\n continue;\n }\n await upgrade.apply(options.executor);\n await recordMigration(options.executor, upgrade.name, `upgrade:${upgrade.name}`, \"upgrade\", now);\n applied.push(upgrade.name);\n alreadyByName.set(upgrade.name, { name: upgrade.name, checksum: `upgrade:${upgrade.name}`, kind: \"upgrade\" });\n }\n // dryRun is always true here only via the legacyPresent branch above,\n // which already `continue`s — so reaching this point means dryRun is\n // false and we have a real executor to write through.\n // upgradeV2toV6 bakes 0002 (PK rebuild) and 0005 (tracking_number/carrier\n // ALTER) into a single orders_new DDL (V6_ORDERS_DDL). Both must be marked\n // applied — in the DB *and* in alreadyByName, which the normal loop below\n // reads from — so it doesn't re-run 0005's ALTER against columns that\n // already exist.\n //\n // This runs whenever orders is no longer in the legacy shape — which is\n // true either because we just fixed it above, or because a *previous*\n // repair attempt already ran the DDL but was interrupted (crashed,\n // network error, core updated mid-retry) before recording 0005. Gating\n // this only on `legacyPresent` (the original design) misses that second\n // case: canApply() reads the live schema, sees orders is already\n // rebuilt, reports false, and the whole block — including the supersede\n // bookkeeping — gets skipped, leaving 0005 permanently unrecorded even\n // though its effect is already live. The normal loop below then tries\n // to re-run 0005's ALTER forever (real remote-D1 repro, 2026-08-19: a\n // retry after a failed repair reproduced the original bug via this\n // path). recordMigration() is an upsert with the migration's real\n // checksum, so calling it here when nothing was actually missing is a\n // harmless no-op.\n //\n // Do not add 0003/0004/0006 here — they create unrelated tables\n // (IF NOT EXISTS) that V6_ORDERS_DDL never touches and still need to\n // run normally. Same for 0007 (extras_json): it postdates this\n // upgrade's toVersion (6) and isn't part of V6_ORDERS_DDL.\n for (const supersededName of [\"0002_orders.sql\", \"0005_orders_tracking.sql\"]) {\n const superseded = coreMigrations.find((migration) => migration.name === supersededName);\n if (!superseded) {\n throw new Error(`upgradeV2toV6 supersedes unknown migration ${supersededName} — schema/migrations/ drifted`);\n }\n const checksum = sha256File(superseded.path);\n await recordMigration(options.executor, superseded.name, checksum, \"sql\", now);\n alreadyByName.set(superseded.name, { name: superseded.name, checksum, kind: \"sql\" });\n }\n }\n }\n\n for (const migration of coreMigrations) {\n if (alreadyByName.get(migration.name)?.checksum === sha256File(migration.path)) continue;\n if (alreadyByName.has(migration.name) && !options.repair) continue;\n print(`apply core/${migration.name}`);\n if (dryRun) {\n applied.push(migration.name);\n continue;\n }\n await options.executor.applySql(migration.sql);\n await recordMigration(options.executor, migration.name, sha256File(migration.path), \"sql\", now);\n applied.push(migration.name);\n }\n\n for (const local of listLocalMigrations(options.cwd)) {\n const hash = sha256File(local.path);\n if (alreadyByName.get(local.name)?.checksum === hash) continue;\n print(`apply ${local.name}`);\n if (dryRun) {\n applied.push(local.name);\n continue;\n }\n await options.executor.applySql(local.sql);\n await recordMigration(options.executor, local.name, hash, \"sql\", now);\n applied.push(local.name);\n }\n\n if (!dryRun) {\n await writeVersion(options.executor, installedVersion, options.coreVersion, now, bookmark);\n } else {\n print(`would set umec_schema_version.version = ${installedVersion}`);\n }\n\n return { exitCode: 0, applied, warnings, bookmark };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return { exitCode: 1, applied, warnings, error: message };\n }\n}\n\nexport function pendingMigrationFixes(pendingSql: string, finding: DriftFinding): boolean {\n if (finding.message.includes(`required table \"${finding.table}\" is missing`)) {\n return new RegExp(`CREATE TABLE(?: IF NOT EXISTS)?\\\\s+${finding.table}\\\\b`, \"i\").test(pendingSql);\n }\n const missingColumn = finding.message.match(/required column \"([^.\"]+)\\.([^\"]+)\" is missing/);\n if (missingColumn?.[1] && missingColumn[2]) {\n // Scope to the owning table — an unrelated ALTER TABLE elsewhere in pendingSql\n // that happens to ADD COLUMN the same name must not count as a fix\n // (a finding for \"inventory.sku\" could otherwise be false-matched by an\n // unrelated \"ALTER TABLE orders ADD COLUMN sku\").\n const [, table, column] = missingColumn;\n return new RegExp(`ALTER TABLE\\\\s+${table}\\\\s+ADD COLUMN\\\\s+${column}\\\\b`, \"i\").test(pendingSql);\n }\n return false;\n}\n\nexport function coreVersionFromPackage(root = findPackageRoot()): string {\n const pkg = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")) as { version: string };\n return pkg.version;\n}\n","import { spawn } from \"node:child_process\";\nimport { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { bindSql, type MigrationExecutor } from \"./executor.js\";\n\nexport type WranglerRunResult = {\n code: number;\n stdout: string;\n stderr: string;\n};\n\nexport type RunCommand = (command: string, args: string[], cwd: string) => Promise<WranglerRunResult>;\n\nexport function defaultRunCommand(command: string, args: string[], cwd: string): Promise<WranglerRunResult> {\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, { cwd, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout.on(\"data\", (chunk: Buffer) => {\n stdout += chunk.toString();\n });\n child.stderr.on(\"data\", (chunk: Buffer) => {\n stderr += chunk.toString();\n });\n child.on(\"error\", reject);\n child.on(\"close\", (code) => {\n resolve({ code: code ?? 1, stdout, stderr });\n });\n });\n}\n\nexport function parseJsonc(text: string): unknown {\n const stripped = text.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\").replace(/^\\s*\\/\\/.*$/gm, \"\");\n return JSON.parse(stripped);\n}\n\nexport function readD1DatabaseName(cwd: string, override?: string): string | null {\n if (override) return override;\n const path = join(cwd, \"wrangler.jsonc\");\n try {\n const parsed = parseJsonc(readFileSync(path, \"utf8\")) as {\n d1_databases?: Array<{ database_name?: string }>;\n };\n return parsed.d1_databases?.[0]?.database_name ?? null;\n } catch {\n return null;\n }\n}\n\nfunction parseExecuteJson(stdout: string): { results: unknown[]; changes: number } {\n const trimmed = stdout.trim();\n if (!trimmed) return { results: [], changes: 0 };\n const start = trimmed.indexOf(\"[\");\n const objStart = trimmed.indexOf(\"{\");\n const cut =\n start >= 0 && (objStart < 0 || start < objStart)\n ? trimmed.slice(start)\n : objStart >= 0\n ? trimmed.slice(objStart)\n : trimmed;\n const parsed: unknown = JSON.parse(cut);\n const rows = Array.isArray(parsed) ? parsed : [parsed];\n const first = rows[0] as { results?: unknown[]; meta?: { changes?: number } } | undefined;\n return {\n results: first?.results ?? [],\n changes: first?.meta?.changes ?? 0,\n };\n}\n\nexport function createWranglerExecutor(options: {\n cwd: string;\n database: string;\n remote: boolean;\n runCommand?: RunCommand;\n}): MigrationExecutor {\n const runCommand = options.runCommand ?? defaultRunCommand;\n const location = options.remote ? \"--remote\" : \"--local\";\n\n const execute = async (sql: string) => {\n const result = await runCommand(\n \"wrangler\",\n [\"d1\", \"execute\", options.database, location, \"--json\", \"--command\", sql],\n options.cwd,\n );\n if (result.code !== 0) {\n throw new Error(result.stderr || result.stdout || `wrangler d1 execute failed (${result.code})`);\n }\n return parseExecuteJson(result.stdout);\n };\n\n return {\n async exec(sql: string) {\n await execute(sql);\n },\n async applySql(sql: string) {\n const { splitSqlStatements } = await import(\"../db/sql.js\");\n for (const statement of splitSqlStatements(sql)) {\n await execute(statement);\n }\n },\n async all<T>(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return result.results as T[];\n },\n async first<T>(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return (result.results[0] as T | undefined) ?? null;\n },\n async run(sql: string, params: unknown[] = []) {\n const result = await execute(bindSql(sql, params));\n return { changes: result.changes };\n },\n async captureBookmark() {\n const result = await runCommand(\n \"wrangler\",\n [\"d1\", \"time-travel\", \"info\", options.database, \"--json\"],\n options.cwd,\n );\n if (result.code !== 0) return null;\n try {\n const parsed = JSON.parse(result.stdout) as { bookmark?: string };\n return parsed.bookmark ?? null;\n } catch {\n return null;\n }\n },\n };\n}\n","import type { UpgradeExecutor } from \"../../schema/upgrades/types.js\";\nimport type { ShopDatabase } from \"../db/d1.js\";\nimport { splitSqlStatements } from \"../db/sql.js\";\n\nexport type MigrationExecutor = UpgradeExecutor & {\n applySql(sql: string): Promise<void>;\n captureBookmark(): Promise<string | null>;\n};\n\nexport function sqlLiteral(value: unknown): string {\n if (value === null || value === undefined) return \"NULL\";\n if (typeof value === \"boolean\") return value ? \"1\" : \"0\";\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n if (typeof value === \"string\") return `'${value.replaceAll(\"'\", \"''\")}'`;\n throw new Error(`Unsupported SQL bind: ${typeof value}`);\n}\n\nexport function bindSql(sql: string, params: unknown[] = []): string {\n let index = 0;\n return sql.replaceAll(\"?\", () => {\n if (index >= params.length) throw new Error(\"Not enough SQL bind parameters\");\n return sqlLiteral(params[index++]);\n });\n}\n\nexport function executorFromDatabase(\n db: ShopDatabase,\n captureBookmark: () => Promise<string | null> = async () => null,\n): MigrationExecutor {\n return {\n async exec(sql: string) {\n await db.prepare(sql).run();\n },\n async applySql(sql: string) {\n for (const statement of splitSqlStatements(sql)) {\n await db.prepare(statement).run();\n }\n },\n async all<T>(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n const result = await statement.all<T>();\n return result.results ?? [];\n },\n async first<T>(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n return statement.first<T>();\n },\n async run(sql: string, params: unknown[] = []) {\n const statement = db.prepare(sql);\n if (params.length > 0) statement.bind(...params);\n const result = await statement.run();\n return { changes: result.meta.changes };\n },\n captureBookmark,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,QAAAC,aAAY;;;ACDrB,SAAS,kBAAkB;AAC3B,SAAS,YAAY;;;ACCd,IAAM,oBAAoB;AAa1B,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgD7B,SAAS,SAAS,OAAgB,WAAW,IAAY;AACvD,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,iBAAiB,OAA+B;AACvD,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,SAAS,OAAgB,WAAW,GAAW;AAC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AAU;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AACD,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,YAAY,UAAU;AACxB,UAAM,SAAS,UAAU;AAAA,MACvB;AAAA,MACA,KAAK,OAAO,MAAM,QAAQ,WAAW,MAAM,MAAM;AAAA,MACjD,MAAM,OAAO,MAAM,SAAS,WAAW,MAAM,OAAO;AAAA,MACpD,OAAO;AAAA,IACT,CAAC;AACD,QAAI,OAAO,MAAO,QAAO,OAAO,KAAK;AACrC,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,MAAM,CAAC;AACd,SAAO;AACT;AAEA,SAAS,cAAuB;AAC9B,QAAM,UAAU,QAAQ,KAAK,CAAC;AAC9B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,2BAA2B,KAAK,OAAO,KAAK,QAAQ,SAAS,GAAGC,MAAK,QAAQ,KAAK,CAAC,EAAE;AAC9F;AAEA,IAAI,YAAY,GAAG;AACjB,QAAM,MAAM,KAAK,MAAMC,cAAaD,MAAK,gBAAgB,GAAG,cAAc,GAAG,MAAM,CAAC;AACpF,MAAI,QAAQ,KAAK,SAAS,WAAW,KAAK,QAAQ,KAAK,SAAS,IAAI,GAAG;AACrE,YAAQ,IAAI,IAAI,OAAO;AACvB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACA,SAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE;AAAA,IAC5B,CAAC,SAAS,QAAQ,KAAK,IAAI;AAAA,IAC3B,CAAC,UAAU;AACT,cAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAC5D,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;","names":["readFileSync","join","existsSync","readFileSync","join","readFileSync","join","join","readFileSync","bookmark","readFileSync","join","join","readFileSync","splitSqlStatements","join","readFileSync"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umec/core",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.11",
4
4
  "description": "Headless EC logic for umec — config schema and shared handlers",
5
5
  "type": "module",
6
6
  "license": "MIT",