@shapio/local 0.5.9 → 0.5.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/{advisoryLocks-ajVNBhfa.js → advisoryLocks-DGbxw3_E.js} +13 -13
- package/dist/advisoryLocks-DGbxw3_E.js.map +1 -0
- package/dist/errors-nQvt9bs7.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{migrator-CO5sXosL.js → migrator-BfVtncOo.js} +269 -148
- package/dist/migrator-BfVtncOo.js.map +1 -0
- package/package.json +4 -4
- package/dist/advisoryLocks-ajVNBhfa.js.map +0 -1
- package/dist/migrator-CO5sXosL.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrator-CO5sXosL.js","names":["up","down","withTimestamps","uuidPrimaryKey","up","down","up","down","up","down","up","down","withTimestamps","uuidPrimaryKey","up","down","withTimestamps","uuidPrimaryKey","up","down","PUBLIC_ROLE_ID","AUTHENTICATED_ROLE_ID","up","down","up","down","up","down","up","down","up","down","up","down","up","down","up","down","up","down","JOB_TYPE","IDEMPOTENCY_KEY","up","down","up","down","up","down","up","down","up","down","NIL_UUID","up","down","up","down","INDEX","BATCH","up","down","up","down","STATEMENTS","TABLES","up","down","up","down","up","down","bumpPermissionsVersion","up","down","INDEX","up","down","baseline","auditEventsSeq","modelsSiteScope","siteSeoSettings","entryHeadsEntryCreatedAt","systemVersionsRelease","up","down","up","down","up","down","up","down","baseline","auditEventsSeq","modelsSiteScope","siteSeoSettings","entryHeadsEntryCreatedAt","systemVersionsRelease","createPlatformTables","createAdminIdentity","createSystemSettings","createSchemaTables","createContentTables","createMediaTables","createPublishingTables","createAppUsers","createExtensionHookRuns","appAuthTokenVersionAndLoginCodePkce","addPublicationLogDiffIndexes","createUsageTables","createChangeSets","createEditorPresenceAndContentHealth","addChangesShipPermission","createSites","enqueueFieldIndexLayout","changeSetItemsSiteAndPreviewEntry","widenDeploymentProviders","createAssistRuns","auditEventsSeq","modelsSiteScope","siteSeoSettings","entryHeadsEntryCreatedAt","systemVersionsRelease"],"sources":["../../../apps/api/src/db/migrations/20261001120000_create_platform_tables.ts","../../../apps/api/src/db/migrations/20261001130000_create_admin_identity.ts","../../../apps/api/src/db/migrations/20261001130500_create_system_settings.ts","../../../apps/api/src/db/migrations/20261001140000_create_schema_tables.ts","../../../apps/api/src/db/migrations/20261001150000_create_content_tables.ts","../../../apps/api/src/db/migrations/20261001160000_create_media_tables.ts","../../../apps/api/src/db/migrations/20261001170000_create_publishing_tables.ts","../../../apps/api/src/db/migrations/20261001180000_create_app_users.ts","../../../apps/api/src/db/migrations/20261002120000_create_extension_hook_runs.ts","../../../apps/api/src/db/migrations/20261002130000_app_auth_token_version_and_login_code_pkce.ts","../../../apps/api/src/db/migrations/20261002180000_add_publication_log_diff_indexes.ts","../../../apps/api/src/db/migrations/20261002180100_create_usage_tables.ts","../../../apps/api/src/db/migrations/20261002180200_create_change_sets.ts","../../../apps/api/src/db/migrations/20261002190000_create_editor_presence_and_content_health.ts","../../../apps/api/src/db/migrations/20261003120000_add_changes_ship_permission.ts","../../../apps/api/src/db/migrations/20261003130000_create_sites.ts","../../../apps/api/src/db/migrations/20261003140200_enqueue_field_index_layout.ts","../../../apps/api/src/db/migrations/20261003140500_change_set_items_site_and_preview_entry.ts","../../../apps/api/src/db/migrations/20261003150000_widen_deployment_providers.ts","../../../apps/api/src/db/migrations/20261003160000_create_assist_runs.ts","../../../apps/api/src/db/migrations/20261003170000_audit_events_seq.ts","../../../apps/api/src/db/migrations/20261004120000_models_site_scope.ts","../../../apps/api/src/db/migrations/20261004130000_site_seo_settings.ts","../../../apps/api/src/db/migrations/20261005120000_entry_heads_entry_created_at.ts","../../../apps/api/src/db/migrations/20261006120000_system_versions_release.ts","../../../apps/api/src/db/migrations/mysql/0001_baseline.ts","../../../apps/api/src/db/migrations/mysql/20261003170000_audit_events_seq.ts","../../../apps/api/src/db/migrations/mysql/20261004120000_models_site_scope.ts","../../../apps/api/src/db/migrations/mysql/20261004130000_site_seo_settings.ts","../../../apps/api/src/db/migrations/mysql/20261005120000_entry_heads_entry_created_at.ts","../../../apps/api/src/db/migrations/mysql/index.ts","../../../apps/api/src/db/migrations/sqlite/0001_baseline.ts","../../../apps/api/src/db/migrations/sqlite/20261003170000_audit_events_seq.ts","../../../apps/api/src/db/migrations/sqlite/20261004120000_models_site_scope.ts","../../../apps/api/src/db/migrations/sqlite/20261004130000_site_seo_settings.ts","../../../apps/api/src/db/migrations/sqlite/20261005120000_entry_heads_entry_created_at.ts","../../../apps/api/src/db/migrations/sqlite/index.ts","../../../apps/api/src/db/migrations/index.ts","../../../apps/api/src/db/migrator.ts"],"sourcesContent":["import { sql, type Kysely } from 'kysely';\n\n/**\n * Foundation tables shared by every package: durable versions, the job queue, the transactional outbox\n * and the audit log. Statuses are text with CHECK constraints so new states need only a constraint change.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n // Single-row table. Durable version counters; caches compare against these on every request.\n await db.schema\n .createTable('system_versions')\n .addColumn('id', 'boolean', (col) =>\n col\n .primaryKey()\n .defaultTo(true)\n .check(sql`id`),\n )\n .addColumn('schema_version', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('permissions_version', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await sql`insert into system_versions default values`.execute(db);\n\n await db.schema\n .createTable('jobs')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('type', 'text', (col) => col.notNull())\n .addColumn('payload', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'running', 'succeeded', 'dead')`),\n )\n .addColumn('priority', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('run_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('attempts', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('max_attempts', 'integer', (col) =>\n col\n .notNull()\n .defaultTo(10)\n .check(sql`max_attempts > 0`),\n )\n .addColumn('idempotency_key', 'text')\n .addColumn('locked_by', 'text')\n .addColumn('locked_until', 'timestamptz')\n .addColumn('checkpoint', 'jsonb')\n .addColumn('result', 'jsonb')\n .addColumn('last_error', 'text')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('finished_at', 'timestamptz')\n .execute();\n await db.schema\n .createIndex('jobs_idempotency_key_uq')\n .on('jobs')\n .column('idempotency_key')\n .unique()\n .where(sql.ref('idempotency_key'), 'is not', null)\n .execute();\n // Claim order for runnable jobs. Expired leases are found through the running-status index.\n await db.schema\n .createIndex('jobs_pending_idx')\n .on('jobs')\n .columns(['priority desc', 'run_at'])\n .where(sql.ref('status'), '=', 'pending')\n .execute();\n await db.schema\n .createIndex('jobs_running_lease_idx')\n .on('jobs')\n .column('locked_until')\n .where(sql.ref('status'), '=', 'running')\n .execute();\n\n await db.schema\n .createTable('outbox_events')\n .addColumn('id', 'bigint', (col) => col.primaryKey().generatedAlwaysAsIdentity())\n .addColumn('event_id', 'uuid', (col) =>\n col\n .notNull()\n .unique()\n .defaultTo(sql`gen_random_uuid()`),\n )\n .addColumn('type', 'text', (col) => col.notNull())\n .addColumn('aggregate_type', 'text', (col) => col.notNull())\n .addColumn('aggregate_id', 'text', (col) => col.notNull())\n .addColumn('payload', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('dispatched_at', 'timestamptz')\n .addColumn('dispatch_attempts', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('last_dispatch_error', 'text')\n .execute();\n await db.schema\n .createIndex('outbox_events_undispatched_idx')\n .on('outbox_events')\n .column('id')\n .where(sql.ref('dispatched_at'), 'is', null)\n .execute();\n\n await db.schema\n .createTable('audit_events')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('occurred_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('actor_type', 'text', (col) =>\n col.notNull().check(sql`actor_type in ('admin', 'app_user', 'token', 'anonymous', 'system')`),\n )\n .addColumn('actor_id', 'text')\n .addColumn('action', 'text', (col) => col.notNull())\n .addColumn('target_type', 'text')\n .addColumn('target_id', 'text')\n .addColumn('outcome', 'text', (col) => col.notNull().check(sql`outcome in ('success', 'failure')`))\n .addColumn('request_id', 'text')\n .addColumn('ip', 'text')\n .addColumn('metadata', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n .execute();\n await db.schema\n .createIndex('audit_events_occurred_at_idx')\n .on('audit_events')\n .column('occurred_at desc')\n .execute();\n await db.schema\n .createIndex('audit_events_target_idx')\n .on('audit_events')\n .columns(['target_type', 'target_id', 'occurred_at desc'])\n .execute();\n await db.schema\n .createIndex('audit_events_actor_idx')\n .on('audit_events')\n .columns(['actor_type', 'actor_id', 'occurred_at desc'])\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('audit_events').execute();\n await db.schema.dropTable('outbox_events').execute();\n await db.schema.dropTable('jobs').execute();\n await db.schema.dropTable('system_versions').execute();\n};\n","import { sql, type CreateTableBuilder, type Kysely } from 'kysely';\n\n/**\n * Admin identity (package B, ADR 0005): admin users, roles and their permission grants, server-side\n * sessions, invitations, password resets, first-run setup tokens and API tokens. Every secret is stored\n * as a SHA-256 hash (tokens) or an argon2id hash (passwords), never in plain text.\n */\n\nconst withTimestamps = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`));\n\nconst uuidPrimaryKey = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table.addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`));\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('admin_users'))\n // Stored normalised (trimmed, lower case); the service normalises before every lookup.\n .addColumn('email', 'text', (col) => col.notNull().unique())\n .addColumn('name', 'text', (col) => col.notNull().defaultTo(''))\n .addColumn('password_hash', 'text', (col) => col.notNull())\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('active')\n .check(sql`status in ('active', 'disabled')`),\n )\n .addColumn('last_login_at', 'timestamptz')\n .addColumn('password_changed_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`)),\n ).execute();\n\n // `kind`: admin roles are held by admin users and admin-scope tokens; delivery roles only by delivery tokens.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('admin_roles'))\n .addColumn('key', 'text', (col) =>\n col\n .notNull()\n .unique()\n .check(sql`key ~ '^[a-z][a-z0-9-]{0,62}$'`),\n )\n .addColumn('name', 'text', (col) => col.notNull())\n .addColumn('description', 'text', (col) => col.notNull().defaultTo(''))\n .addColumn('kind', 'text', (col) =>\n col\n .notNull()\n .defaultTo('admin')\n .check(sql`kind in ('admin', 'delivery')`),\n )\n .addColumn('is_system', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ).execute();\n\n // One grant per (role, action, model). `model_id` null = every model (and is required for global\n // actions). `field_ids` null = every field the principal kind may see; otherwise only these stable IDs.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('admin_role_permissions'))\n .addColumn('role_id', 'uuid', (col) => col.notNull().references('admin_roles.id').onDelete('cascade'))\n .addColumn('action', 'text', (col) => col.notNull())\n .addColumn('model_id', 'text')\n .addColumn('condition', 'text', (col) => col.check(sql`condition in ('ownedByPrincipal')`))\n .addColumn('field_ids', sql`text[]`)\n .addUniqueConstraint('admin_role_permissions_grant_uq', ['role_id', 'action', 'model_id'], (uc) =>\n uc.nullsNotDistinct(),\n ),\n ).execute();\n\n await withTimestamps(\n db.schema\n .createTable('admin_user_roles')\n .addColumn('admin_user_id', 'uuid', (col) =>\n col.notNull().references('admin_users.id').onDelete('cascade'),\n )\n // Restrict: a role still held by someone cannot be deleted (the service reports a conflict first).\n .addColumn('role_id', 'uuid', (col) => col.notNull().references('admin_roles.id').onDelete('restrict'))\n .addPrimaryKeyConstraint('admin_user_roles_pk', ['admin_user_id', 'role_id']),\n ).execute();\n await db.schema.createIndex('admin_user_roles_role_idx').on('admin_user_roles').column('role_id').execute();\n\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('admin_sessions'))\n .addColumn('admin_user_id', 'uuid', (col) =>\n col.notNull().references('admin_users.id').onDelete('cascade'),\n )\n .addColumn('token_hash', 'text', (col) => col.notNull().unique())\n // Server-side CSRF secret bound to this session (@fastify/csrf-protection session mode).\n .addColumn('csrf_secret', 'text', (col) => col.notNull())\n .addColumn('ip', 'text')\n .addColumn('user_agent', 'text')\n .addColumn('last_seen_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('revoked_at', 'timestamptz')\n // Set when the user's privileges change; the next request gets a fresh session ID.\n .addColumn('rotation_required', 'boolean', (col) => col.notNull().defaultTo(false)),\n ).execute();\n await db.schema\n .createIndex('admin_sessions_user_idx')\n .on('admin_sessions')\n .column('admin_user_id')\n .where(sql.ref('revoked_at'), 'is', null)\n .execute();\n\n // The token hash is written when the email job runs, so the plain token never sits in the jobs table.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('admin_invitations'))\n .addColumn('email', 'text', (col) => col.notNull())\n .addColumn('role_ids', sql`uuid[]`, (col) => col.notNull().defaultTo(sql`'{}'::uuid[]`))\n .addColumn('token_hash', 'text', (col) => col.unique())\n .addColumn('invited_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('accepted_at', 'timestamptz')\n .addColumn('revoked_at', 'timestamptz'),\n ).execute();\n await db.schema\n .createIndex('admin_invitations_pending_email_idx')\n .on('admin_invitations')\n .column('email')\n .where(sql<boolean>`accepted_at is null and revoked_at is null`)\n .execute();\n\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('password_resets'))\n .addColumn('admin_user_id', 'uuid', (col) =>\n col.notNull().references('admin_users.id').onDelete('cascade'),\n )\n .addColumn('token_hash', 'text', (col) => col.unique())\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('used_at', 'timestamptz'),\n ).execute();\n await db.schema\n .createIndex('password_resets_user_idx')\n .on('password_resets')\n .column('admin_user_id')\n .execute();\n\n // A new token is issued (and the previous one superseded) on every boot while no admin exists.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('setup_tokens'))\n .addColumn('token_hash', 'text', (col) => col.notNull().unique())\n .addColumn('used_at', 'timestamptz')\n .addColumn('superseded_at', 'timestamptz'),\n ).execute();\n\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('api_tokens'))\n .addColumn('name', 'text', (col) => col.notNull())\n .addColumn('token_hash', 'text', (col) => col.notNull().unique())\n // First characters of the token, shown in lists so people can tell tokens apart.\n .addColumn('token_prefix', 'text', (col) => col.notNull())\n .addColumn('role_id', 'uuid', (col) => col.notNull().references('admin_roles.id').onDelete('restrict'))\n .addColumn('created_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('expires_at', 'timestamptz')\n .addColumn('last_used_at', 'timestamptz')\n .addColumn('revoked_at', 'timestamptz'),\n ).execute();\n await db.schema.createIndex('api_tokens_role_idx').on('api_tokens').column('role_id').execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('api_tokens').execute();\n await db.schema.dropTable('setup_tokens').execute();\n await db.schema.dropTable('password_resets').execute();\n await db.schema.dropTable('admin_invitations').execute();\n await db.schema.dropTable('admin_sessions').execute();\n await db.schema.dropTable('admin_user_roles').execute();\n await db.schema.dropTable('admin_role_permissions').execute();\n await db.schema.dropTable('admin_roles').execute();\n await db.schema.dropTable('admin_users').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Instance-wide key/value settings that must survive restarts and be shared by every instance, e.g. the\n * generated signing secret. General purpose: later packages add keys, not tables.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('system_settings')\n .addColumn('key', 'text', (col) => col.primaryKey())\n .addColumn('value', 'text', (col) => col.notNull())\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('system_settings').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Schema registry (package D, ADR 0002): models and components (one table, `kind` discriminator), immutable\n * schema revisions, the per-model active pointer, schema change jobs, locales and schema settings.\n * Model definitions are data: creating or changing a model never runs DDL (CONTRIBUTING.md rule 1).\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('models')\n .addColumn('id', 'uuid', (col) => col.primaryKey())\n .addColumn('kind', 'text', (col) =>\n col.notNull().check(sql`kind in ('collection', 'singleton', 'component')`),\n )\n // The API key of the active revision, denormalised so the database itself rejects two live\n // definitions with the same (case-folded) key even if two activations race.\n .addColumn('api_key', 'text', (col) => col.notNull())\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n // Soft delete: entries keep their model and reappear if the definition is applied again.\n .addColumn('deleted_at', 'timestamptz')\n .execute();\n await sql`create unique index models_api_key_uq on models (lower(api_key)) where deleted_at is null`.execute(\n db,\n );\n\n await db.schema\n .createTable('schema_revisions')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('model_id', 'uuid', (col) => col.notNull().references('models.id').onDelete('restrict'))\n .addColumn('version', 'integer', (col) => col.notNull().check(sql`version > 0`))\n .addColumn('definition', 'jsonb', (col) => col.notNull())\n // `sha256:<hex>` of the canonical serialization (@shapio/schema hashDefinition).\n .addColumn('hash', 'text', (col) => col.notNull())\n .addColumn('parent_revision_id', 'uuid', (col) => col.references('schema_revisions.id'))\n .addColumn('created_by_type', 'text', (col) => col.notNull())\n .addColumn('created_by_id', 'text')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addUniqueConstraint('schema_revisions_model_version_uq', ['model_id', 'version'])\n .execute();\n // Revisions are history: never rewritten.\n await sql`\n create function schema_revisions_immutable() returns trigger language plpgsql as $$\n begin\n raise exception 'schema_revisions rows are immutable';\n end;\n $$\n `.execute(db);\n await sql`\n create trigger schema_revisions_no_update before update on schema_revisions\n for each row execute function schema_revisions_immutable()\n `.execute(db);\n\n await db.schema\n .createTable('model_active_versions')\n .addColumn('model_id', 'uuid', (col) => col.primaryKey().references('models.id').onDelete('cascade'))\n .addColumn('revision_id', 'uuid', (col) => col.notNull().references('schema_revisions.id'))\n .addColumn('version', 'integer', (col) => col.notNull())\n // system_versions.schema_version right after this activation.\n .addColumn('schema_version', 'integer', (col) => col.notNull())\n .addColumn('activated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n\n await db.schema\n .createTable('schema_change_jobs')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('target_type', 'text', (col) => col.notNull().check(sql`target_type in ('model', 'locale')`))\n .addColumn('target_id', 'text', (col) => col.notNull())\n .addColumn('model_id', 'uuid', (col) => col.references('models.id'))\n .addColumn('from_revision_id', 'uuid', (col) => col.references('schema_revisions.id'))\n .addColumn('to_revision_id', 'uuid', (col) => col.references('schema_revisions.id'))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'running', 'activated', 'failed', 'cancelled')`),\n )\n .addColumn('plan', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n .addColumn('job_id', 'uuid', (col) => col.references('jobs.id').onDelete('set null'))\n .addColumn('error', 'jsonb')\n .addColumn('requested_by_type', 'text', (col) => col.notNull())\n .addColumn('requested_by_id', 'text')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('finished_at', 'timestamptz')\n .execute();\n // One change in flight per model or locale; a second one is refused until the first finishes.\n await sql`\n create unique index schema_change_jobs_in_flight_uq on schema_change_jobs (target_type, target_id)\n where status in ('pending', 'running')\n `.execute(db);\n await db.schema\n .createIndex('schema_change_jobs_model_idx')\n .on('schema_change_jobs')\n .columns(['model_id', 'created_at desc'])\n .execute();\n\n await db.schema\n .createTable('locales')\n .addColumn('code', 'text', (col) => col.primaryKey())\n .addColumn('label', 'text', (col) => col.notNull())\n .addColumn('is_default', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('fallbacks', sql`text[]`, (col) => col.notNull().defaultTo(sql`'{}'::text[]`))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await sql`create unique index locales_single_default_uq on locales (is_default) where is_default`.execute(\n db,\n );\n // Every instance starts with one locale so localized models work out of the box; it can be renamed.\n await sql`insert into locales (code, label, is_default) values ('en', 'English', true)`.execute(db);\n\n // Single row. `read_only` is the opt-in lock (ADR 0002): the admin UI cannot change models, only\n // `shapio schema apply` can. Never on by default.\n await db.schema\n .createTable('schema_settings')\n .addColumn('id', 'boolean', (col) =>\n col\n .primaryKey()\n .defaultTo(true)\n .check(sql`id`),\n )\n .addColumn('read_only', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('read_only_reason', 'text')\n .addColumn('updated_by_type', 'text')\n .addColumn('updated_by_id', 'text')\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await sql`insert into schema_settings default values`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('schema_settings').execute();\n await db.schema.dropTable('locales').execute();\n await db.schema.dropTable('schema_change_jobs').execute();\n await db.schema.dropTable('model_active_versions').execute();\n await db.schema.dropTable('schema_revisions').execute();\n await sql`drop function schema_revisions_immutable()`.execute(db);\n await db.schema.dropTable('models').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Content storage (package E, ADR 0001): entries, immutable content revisions, mutable heads (one per\n * entry, locale and state) with every content index, derived relation edges, the unique-value registry\n * and the publication log behind `?snapshot=N`. User content models never get tables of their own\n * (CONTRIBUTING.md rule 1): their values are JSONB keyed by stable field IDs.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('entries')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('model_id', 'uuid', (col) => col.notNull().references('models.id').onDelete('restrict'))\n // The app user who owns the entry (`ownedByPrincipal`). Package I adds the foreign key to app_users.\n .addColumn('owner_app_user_id', 'uuid')\n .addColumn('created_by_admin_id', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n // Soft delete: revisions stay as history; heads, edges and registry rows are removed.\n .addColumn('deleted_at', 'timestamptz')\n .execute();\n await sql`create index entries_model_idx on entries (model_id, created_at) where deleted_at is null`.execute(\n db,\n );\n await sql`create index entries_owner_idx on entries (owner_app_user_id) where owner_app_user_id is not null`.execute(\n db,\n );\n\n await db.schema\n .createTable('content_revisions')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('restrict'))\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('schema_revision_id', 'uuid', (col) => col.notNull().references('schema_revisions.id'))\n .addColumn('data', 'jsonb', (col) => col.notNull())\n // Why the revision exists: an explicit save, a publish of autosaved changes, a restore...\n .addColumn('reason', 'text', (col) =>\n col.notNull().check(sql`reason in ('create', 'save', 'publish', 'restore', 'duplicate', 'localize')`),\n )\n .addColumn('author_type', 'text', (col) => col.notNull())\n .addColumn('author_id', 'text')\n // Always a revision of the same entry and locale.\n .addColumn('parent_revision_id', 'uuid', (col) => col.references('content_revisions.id'))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n // The only index on history (ADR 0001): content indexes live on heads.\n await db.schema\n .createIndex('content_revisions_entry_idx')\n .on('content_revisions')\n .columns(['entry_id', 'locale', 'created_at'])\n .execute();\n // History is never rewritten. Deleting is allowed only for an explicit purge (a removed locale).\n await sql`\n create function content_revisions_immutable() returns trigger language plpgsql as $$\n begin\n raise exception 'content_revisions rows are immutable';\n end;\n $$\n `.execute(db);\n await sql`\n create trigger content_revisions_no_update before update on content_revisions\n for each row execute function content_revisions_immutable()\n `.execute(db);\n\n // Every head write takes the next value, so the schema planner can re-check \"heads changed after a\n // watermark\" at activation (ADR 0002, transitional write policy).\n await sql`create sequence entry_heads_change_seq as bigint`.execute(db);\n await db.schema\n .createTable('entry_heads')\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('cascade'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('state', 'text', (col) => col.notNull().check(sql`state in ('draft', 'published')`))\n .addColumn('revision_id', 'uuid', (col) => col.notNull().references('content_revisions.id'))\n .addColumn('data', 'jsonb', (col) => col.notNull())\n // Set when an autosave changed `data` since `revision_id` was written; cleared by the next revision.\n .addColumn('autosaved_at', 'timestamptz')\n // Optimistic concurrency token for editors (stale writes get 409).\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1))\n .addColumn('change_seq', 'bigint', (col) =>\n col.notNull().defaultTo(sql`nextval('entry_heads_change_seq')`),\n )\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addPrimaryKeyConstraint('entry_heads_pkey', ['entry_id', 'locale', 'state'])\n .execute();\n await sql`alter sequence entry_heads_change_seq owned by entry_heads.change_seq`.execute(db);\n // Serves `data @> {...}` only (scalar equality and containment filters).\n await sql`create index entry_heads_data_gin on entry_heads using gin (data jsonb_path_ops)`.execute(db);\n await db.schema\n .createIndex('entry_heads_model_locale_state_idx')\n .on('entry_heads')\n .columns(['model_id', 'locale', 'state'])\n .execute();\n await db.schema\n .createIndex('entry_heads_change_seq_idx')\n .on('entry_heads')\n .columns(['model_id', 'change_seq'])\n .execute();\n\n await db.schema\n .createTable('relation_edges')\n .addColumn('source_entry_id', 'uuid', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('state', 'text', (col) => col.notNull())\n .addColumn('field_id', 'uuid', (col) => col.notNull())\n // Order of the target among every value of this field in the head (document order).\n .addColumn('position', 'integer', (col) => col.notNull())\n .addColumn('target_entry_id', 'uuid', (col) => col.notNull().references('entries.id'))\n .addPrimaryKeyConstraint('relation_edges_pkey', [\n 'source_entry_id',\n 'locale',\n 'state',\n 'field_id',\n 'position',\n ])\n .addForeignKeyConstraint(\n 'relation_edges_head_fk',\n ['source_entry_id', 'locale', 'state'],\n 'entry_heads',\n ['entry_id', 'locale', 'state'],\n (constraint) => constraint.onDelete('cascade'),\n )\n .execute();\n await db.schema\n .createIndex('relation_edges_target_idx')\n .on('relation_edges')\n .columns(['target_entry_id', 'state'])\n .execute();\n\n await db.schema\n .createTable('unique_values')\n .addColumn('field_id', 'uuid', (col) => col.notNull())\n // The head's locale for localized fields; `*` for shared fields (every locale holds the same value).\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('state', 'text', (col) => col.notNull().check(sql`state in ('draft', 'published')`))\n // SHA-256 of the field's normalized value.\n .addColumn('value_hash', 'text', (col) => col.notNull())\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('cascade'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addPrimaryKeyConstraint('unique_values_pkey', ['field_id', 'locale', 'state', 'value_hash'])\n .execute();\n await db.schema.createIndex('unique_values_entry_idx').on('unique_values').column('entry_id').execute();\n\n // Single row: the last publication sequence number. Publishing increments it in the publishing\n // transaction, so the row lock orders publications by commit and a reader never sees N before N-1.\n await db.schema\n .createTable('publication_state')\n .addColumn('id', 'boolean', (col) =>\n col\n .primaryKey()\n .defaultTo(true)\n .check(sql`id`),\n )\n .addColumn('last_seq', 'bigint', (col) => col.notNull().defaultTo(0))\n .execute();\n await sql`insert into publication_state default values`.execute(db);\n\n // Which revision was live for (entry, locale) from one publication sequence number until another.\n await db.schema\n .createTable('publication_log')\n .addColumn('id', 'bigint', (col) => col.primaryKey().generatedAlwaysAsIdentity())\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('revision_id', 'uuid', (col) => col.notNull().references('content_revisions.id'))\n .addColumn('from_seq', 'bigint', (col) => col.notNull())\n // Null while the revision is still live.\n .addColumn('to_seq', 'bigint')\n .addColumn('published_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await sql`create unique index publication_log_open_uq on publication_log (entry_id, locale) where to_seq is null`.execute(\n db,\n );\n await db.schema\n .createIndex('publication_log_model_seq_idx')\n .on('publication_log')\n .columns(['model_id', 'from_seq'])\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('publication_log').execute();\n await db.schema.dropTable('publication_state').execute();\n await db.schema.dropTable('unique_values').execute();\n await db.schema.dropTable('relation_edges').execute();\n await db.schema.dropTable('entry_heads').execute();\n await db.schema.dropTable('content_revisions').execute();\n await sql`drop function content_revisions_immutable()`.execute(db);\n await db.schema.dropTable('entries').execute();\n};\n","import { sql, type CreateTableBuilder, type Kysely } from 'kysely';\n\n/**\n * Media library (package G): folders, assets, image variants, references from content and upload grants.\n * Bytes live in a storage driver (local disk or S3-compatible); rows record which driver and key hold\n * each object, so `shapio media migrate` can move assets one at a time while the server keeps serving.\n */\n\nconst withTimestamps = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`));\n\nconst uuidPrimaryKey = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table.addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`));\n\nconst STORAGE_DRIVER_CHECK = sql`storage_driver in ('local', 's3')`;\nconst VISIBILITY_CHECK = sql`visibility in ('public', 'private')`;\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('media_folders'))\n // Restrict: a folder with subfolders cannot be deleted (the service reports a conflict first).\n .addColumn('parent_id', 'uuid', (col) => col.references('media_folders.id').onDelete('restrict'))\n .addColumn('name', 'text', (col) => col.notNull().check(sql`length(name) between 1 and 255`))\n .addColumn('created_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ).execute();\n // Sibling names are unique, case-insensitively; root folders (parent_id null) are siblings too.\n await sql`create unique index media_folders_sibling_name_uq on media_folders\n (coalesce(parent_id, '00000000-0000-0000-0000-000000000000'::uuid), lower(name))`.execute(db);\n\n // `id` is assigned when the upload grant is issued, so the storage key can contain it before the row exists.\n // `status`: `processing` until the checksum, dimensions and variants job has run.\n await withTimestamps(\n db.schema\n .createTable('media_assets')\n .addColumn('id', 'uuid', (col) => col.primaryKey())\n .addColumn('folder_id', 'uuid', (col) => col.references('media_folders.id').onDelete('set null'))\n .addColumn('storage_driver', 'text', (col) => col.notNull().check(STORAGE_DRIVER_CHECK))\n .addColumn('storage_key', 'text', (col) => col.notNull())\n .addColumn('original_filename', 'text', (col) => col.notNull())\n .addColumn('mime_type', 'text', (col) => col.notNull())\n .addColumn('size_bytes', 'bigint', (col) => col.notNull())\n .addColumn('width', 'integer')\n .addColumn('height', 'integer')\n .addColumn('checksum_sha256', 'text')\n .addColumn('alt', 'text', (col) => col.notNull().defaultTo(''))\n .addColumn('caption', 'text', (col) => col.notNull().defaultTo(''))\n .addColumn('focal_x', 'real', (col) => col.check(sql`focal_x between 0 and 1`))\n .addColumn('focal_y', 'real', (col) => col.check(sql`focal_y between 0 and 1`))\n .addColumn('visibility', 'text', (col) => col.notNull().defaultTo('public').check(VISIBILITY_CHECK))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('processing')\n .check(sql`status in ('processing', 'ready', 'failed')`),\n )\n .addColumn('processing_error', 'text')\n .addColumn('created_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1))\n .addColumn('deleted_at', 'timestamptz')\n .addCheckConstraint('media_assets_focal_point_ck', sql`(focal_x is null) = (focal_y is null)`),\n ).execute();\n await db.schema\n .createIndex('media_assets_storage_key_uq')\n .on('media_assets')\n .column('storage_key')\n .unique()\n .execute();\n await db.schema\n .createIndex('media_assets_folder_idx')\n .on('media_assets')\n .columns(['folder_id', 'created_at', 'id'])\n .where(sql.ref('deleted_at'), 'is', null)\n .execute();\n await db.schema\n .createIndex('media_assets_created_idx')\n .on('media_assets')\n .columns(['created_at', 'id'])\n .where(sql.ref('deleted_at'), 'is', null)\n .execute();\n // `shapio media migrate` walks assets by driver.\n await db.schema\n .createIndex('media_assets_driver_idx')\n .on('media_assets')\n .columns(['storage_driver', 'id'])\n .execute();\n\n // Variants live on the same driver as their asset and move with it.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('media_variants'))\n .addColumn('asset_id', 'uuid', (col) => col.notNull().references('media_assets.id').onDelete('cascade'))\n .addColumn('name', 'text', (col) => col.notNull())\n .addColumn('width', 'integer')\n .addColumn('height', 'integer')\n .addColumn('format', 'text', (col) => col.notNull())\n .addColumn('mime_type', 'text', (col) => col.notNull())\n .addColumn('storage_key', 'text')\n .addColumn('size_bytes', 'bigint')\n .addColumn('checksum_sha256', 'text')\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'ready', 'failed')`),\n )\n .addColumn('error', 'text')\n .addUniqueConstraint('media_variants_asset_name_uq', ['asset_id', 'name']),\n ).execute();\n await db.schema\n .createIndex('media_variants_storage_key_uq')\n .on('media_variants')\n .column('storage_key')\n .unique()\n .execute();\n\n // Which entry heads use an asset (\"used in\", delete protection). Written by content saves (package E) in\n // the head-moving transaction; `model_id` is denormalised for display.\n await db.schema\n .createTable('media_references')\n .addColumn('asset_id', 'uuid', (col) => col.notNull().references('media_assets.id').onDelete('cascade'))\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('cascade'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addColumn('field_id', 'text', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('state', 'text', (col) => col.notNull().check(sql`state in ('draft', 'published')`))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addPrimaryKeyConstraint('media_references_pk', ['asset_id', 'entry_id', 'locale', 'state', 'field_id'])\n .execute();\n await db.schema\n .createIndex('media_references_entry_idx')\n .on('media_references')\n .columns(['entry_id', 'locale', 'state'])\n .execute();\n\n // One upload: the asset ID and storage key are fixed when the grant is issued; size and type are limits\n // the storage (presigned POST policy) or the upload route enforces, and confirm re-checks from the bytes.\n await db.schema\n .createTable('media_upload_grants')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('asset_id', 'uuid', (col) => col.notNull())\n .addColumn('kind', 'text', (col) => col.notNull().check(sql`kind in ('create', 'replace')`))\n .addColumn('storage_driver', 'text', (col) => col.notNull().check(STORAGE_DRIVER_CHECK))\n .addColumn('storage_key', 'text', (col) => col.notNull().unique())\n .addColumn('original_filename', 'text', (col) => col.notNull())\n .addColumn('declared_mime_type', 'text', (col) => col.notNull())\n .addColumn('max_size_bytes', 'bigint', (col) => col.notNull())\n .addColumn('folder_id', 'uuid')\n .addColumn('visibility', 'text', (col) => col.notNull().check(VISIBILITY_CHECK))\n .addColumn('created_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n // Who may confirm: the principal that asked for the grant (`admin:<id>` or `token:<id>`).\n .addColumn('created_by_principal', 'text', (col) => col.notNull())\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'consumed', 'rejected', 'expired')`),\n )\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('consumed_at', 'timestamptz')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('media_upload_grants').execute();\n await db.schema.dropTable('media_references').execute();\n await db.schema.dropTable('media_variants').execute();\n await db.schema.dropTable('media_assets').execute();\n await db.schema.dropTable('media_folders').execute();\n};\n","import { sql, type CreateTableBuilder, type Kysely } from 'kysely';\n\n/**\n * Publishing (package H): scheduled publications, releases, webhooks and their delivery log, deployment\n * connections and runs, and preview tokens. Secrets (webhook signing secrets, provider tokens) are stored\n * encrypted with a key derived from the instance signing secret; preview tokens are stored as hashes.\n */\n\nconst withTimestamps = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`));\n\nconst uuidPrimaryKey = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table.addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`));\n\nconst createdBy = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table.addColumn('created_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'));\n\nconst PUBLICATION_ACTION_CHECK = sql`action in ('publish', 'unpublish')`;\n\nconst createSchedulingTables = async (db: Kysely<unknown>) => {\n // One row per (entry, locale, action, time). The job that executes it checks and flips `status` in the\n // publishing transaction, so a retried job never publishes twice.\n await withTimestamps(\n createdBy(\n uuidPrimaryKey(db.schema.createTable('scheduled_publications'))\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('cascade'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('action', 'text', (col) => col.notNull().check(PUBLICATION_ACTION_CHECK))\n .addColumn('run_at', 'timestamptz', (col) => col.notNull())\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('scheduled')\n .check(sql`status in ('scheduled', 'done', 'failed', 'cancelled')`),\n )\n // An admin API token that scheduled it (CI); executed later with that token's role, if still live.\n .addColumn('created_by_token', 'uuid', (col) => col.references('api_tokens.id').onDelete('set null'))\n .addColumn('job_id', 'uuid')\n .addColumn('snapshot_seq', 'bigint')\n .addColumn('error', 'text')\n .addColumn('executed_at', 'timestamptz'),\n ),\n ).execute();\n await db.schema\n .createIndex('scheduled_publications_status_idx')\n .on('scheduled_publications')\n .columns(['status', 'run_at'])\n .execute();\n await db.schema\n .createIndex('scheduled_publications_entry_idx')\n .on('scheduled_publications')\n .columns(['entry_id', 'locale'])\n .execute();\n\n await withTimestamps(\n createdBy(\n uuidPrimaryKey(db.schema.createTable('releases'))\n .addColumn('name', 'text', (col) => col.notNull().check(sql`length(name) between 1 and 200`))\n .addColumn('description', 'text', (col) => col.notNull().defaultTo(''))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('draft')\n .check(sql`status in ('draft', 'scheduled', 'published', 'failed', 'cancelled')`),\n )\n .addColumn('scheduled_at', 'timestamptz')\n // The job that executes the schedule; a superseded job sees another ID and does nothing.\n .addColumn('schedule_job_id', 'uuid')\n .addColumn('scheduled_by', 'uuid', (col) => col.references('admin_users.id').onDelete('set null'))\n .addColumn('scheduled_by_token', 'uuid', (col) =>\n col.references('api_tokens.id').onDelete('set null'),\n )\n .addColumn('executed_at', 'timestamptz')\n .addColumn('snapshot_seq', 'bigint')\n .addColumn('error', 'text')\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ),\n ).execute();\n await db.schema\n .createIndex('releases_status_idx')\n .on('releases')\n .columns(['status', 'created_at'])\n .execute();\n\n await uuidPrimaryKey(db.schema.createTable('release_items'))\n .addColumn('release_id', 'uuid', (col) => col.notNull().references('releases.id').onDelete('cascade'))\n .addColumn('entry_id', 'uuid', (col) => col.notNull().references('entries.id').onDelete('cascade'))\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n .addColumn('locale', 'text', (col) => col.notNull())\n .addColumn('action', 'text', (col) => col.notNull().check(PUBLICATION_ACTION_CHECK))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'done', 'failed')`),\n )\n .addColumn('error', 'text')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addUniqueConstraint('release_items_entry_locale_uq', ['release_id', 'entry_id', 'locale'])\n .execute();\n};\n\nconst createWebhookTables = async (db: Kysely<unknown>) => {\n await withTimestamps(\n createdBy(\n uuidPrimaryKey(db.schema.createTable('webhooks'))\n .addColumn('name', 'text', (col) => col.notNull().check(sql`length(name) between 1 and 200`))\n .addColumn('url', 'text', (col) => col.notNull())\n // Event names or `prefix.*` patterns from the catalogue (webhooks/catalogue.ts).\n .addColumn('events', sql`text[]`, (col) => col.notNull().defaultTo(sql`'{}'::text[]`))\n .addColumn('enabled', 'boolean', (col) => col.notNull().defaultTo(true))\n .addColumn('secret_encrypted', 'text', (col) => col.notNull())\n .addColumn('allow_private_network', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('max_attempts', 'integer', (col) =>\n col\n .notNull()\n .defaultTo(8)\n .check(sql`max_attempts between 1 and 20`),\n )\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ),\n ).execute();\n\n // One row per (webhook, event). `payload` is the exact body sent, so every attempt signs the same bytes.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('webhook_deliveries'))\n .addColumn('webhook_id', 'uuid', (col) => col.notNull().references('webhooks.id').onDelete('cascade'))\n .addColumn('event_id', 'uuid')\n .addColumn('event_type', 'text', (col) => col.notNull())\n .addColumn('payload', 'jsonb', (col) => col.notNull())\n .addColumn('is_test', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('pending')\n .check(sql`status in ('pending', 'retrying', 'succeeded', 'dead')`),\n )\n .addColumn('attempts', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('last_response_status', 'integer')\n .addColumn('last_error', 'text')\n // Bounded summaries of each attempt (request headers without the signature, truncated response).\n .addColumn('attempt_log', 'jsonb', (col) => col.notNull().defaultTo(sql`'[]'::jsonb`))\n .addColumn('job_id', 'uuid')\n .addColumn('delivered_at', 'timestamptz'),\n ).execute();\n await db.schema\n .createIndex('webhook_deliveries_event_uq')\n .on('webhook_deliveries')\n .columns(['webhook_id', 'event_id'])\n .unique()\n .where(sql.ref('event_id'), 'is not', null)\n .execute();\n await db.schema\n .createIndex('webhook_deliveries_webhook_idx')\n .on('webhook_deliveries')\n .columns(['webhook_id', 'created_at desc'])\n .execute();\n};\n\nconst createDeploymentTables = async (db: Kysely<unknown>) => {\n await withTimestamps(\n createdBy(\n uuidPrimaryKey(db.schema.createTable('deployment_connections'))\n .addColumn('name', 'text', (col) => col.notNull().check(sql`length(name) between 1 and 200`))\n .addColumn('provider', 'text', (col) =>\n col.notNull().check(sql`provider in ('generic_webhook', 'cloudflare_pages', 'github')`),\n )\n // Non-secret provider settings (URL, account and project, repository and branch).\n .addColumn('settings', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n // Named secrets (signing secret, API token, deploy hook URL) as one encrypted JSON document.\n .addColumn('secrets_encrypted', 'text', (col) => col.notNull())\n // Secrets taken from the server environment: secret name → variable name, stored as-is.\n .addColumn('secret_env_refs', 'jsonb', (col) => col.notNull().defaultTo(sql`'{}'::jsonb`))\n // Preview tokens issued for this connection read with this delivery role's field grants.\n .addColumn('delivery_role_id', 'uuid', (col) => col.references('admin_roles.id').onDelete('set null'))\n .addColumn('preview_url_template', 'text')\n .addColumn('trigger_policy', sql`text[]`, (col) => col.notNull().defaultTo(sql`'{}'::text[]`))\n .addColumn('debounce_seconds', 'integer', (col) =>\n col\n .notNull()\n .defaultTo(10)\n .check(sql`debounce_seconds between 0 and 3600`),\n )\n .addColumn('allow_private_network', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('enabled', 'boolean', (col) => col.notNull().defaultTo(true))\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ),\n ).execute();\n\n // `status_rank` orders states (queued 0, triggered 1, building 2, unknown 3, deployed/failed 4); updates\n // only move it forward, so a late callback can never regress a run.\n await withTimestamps(\n createdBy(\n uuidPrimaryKey(db.schema.createTable('deployment_runs'))\n .addColumn('connection_id', 'uuid', (col) =>\n col.notNull().references('deployment_connections.id').onDelete('cascade'),\n )\n .addColumn('status', 'text', (col) =>\n col\n .notNull()\n .defaultTo('queued')\n .check(sql`status in ('queued', 'triggered', 'building', 'deployed', 'failed', 'unknown')`),\n )\n .addColumn('status_rank', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('trigger', 'text', (col) =>\n col.notNull().check(sql`trigger in ('publish', 'release', 'schema', 'manual', 'retry')`),\n )\n .addColumn('snapshot_seq', 'bigint')\n .addColumn('schema_version', 'integer')\n .addColumn('retry_of', 'uuid', (col) => col.references('deployment_runs.id').onDelete('set null'))\n .addColumn('provider_ref', 'text')\n .addColumn('log_url', 'text')\n .addColumn('site_url', 'text')\n .addColumn('error', 'text')\n .addColumn('timeline', 'jsonb', (col) => col.notNull().defaultTo(sql`'[]'::jsonb`))\n .addColumn('job_id', 'uuid')\n .addColumn('triggered_at', 'timestamptz')\n .addColumn('finished_at', 'timestamptz'),\n ),\n ).execute();\n // At most one queued run per connection: bursts of publishes coalesce into it.\n await db.schema\n .createIndex('deployment_runs_queued_uq')\n .on('deployment_runs')\n .column('connection_id')\n .unique()\n .where(sql.ref('status'), '=', 'queued')\n .execute();\n await db.schema\n .createIndex('deployment_runs_connection_idx')\n .on('deployment_runs')\n .columns(['connection_id', 'created_at desc'])\n .execute();\n};\n\nconst createPreviewTables = async (db: Kysely<unknown>) => {\n await uuidPrimaryKey(db.schema.createTable('preview_tokens'))\n .addColumn('token_hash', 'text', (col) => col.notNull().unique())\n .addColumn('token_prefix', 'text', (col) => col.notNull())\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n // Null: every entry of the model. Otherwise exactly this entry (and `locale`, when set).\n .addColumn('entry_id', 'uuid', (col) => col.references('entries.id').onDelete('cascade'))\n .addColumn('locale', 'text')\n .addColumn('connection_id', 'uuid', (col) =>\n col.references('deployment_connections.id').onDelete('set null'),\n )\n // Optional: preview exactly what this delivery role (the site's token) would see, within the creator's access.\n .addColumn('delivery_role_id', 'uuid', (col) => col.references('admin_roles.id').onDelete('set null'))\n // Preview reads are evaluated with the creator's current permissions; no creator, no preview.\n .addColumn('created_by', 'uuid', (col) => col.notNull().references('admin_users.id').onDelete('cascade'))\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('revoked_at', 'timestamptz')\n .addColumn('last_used_at', 'timestamptz')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await db.schema\n .createIndex('preview_tokens_entry_idx')\n .on('preview_tokens')\n .columns(['entry_id', 'created_at desc'])\n .execute();\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await createSchedulingTables(db);\n await createWebhookTables(db);\n await createDeploymentTables(db);\n await createPreviewTables(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('preview_tokens').execute();\n await db.schema.dropTable('deployment_runs').execute();\n await db.schema.dropTable('deployment_connections').execute();\n await db.schema.dropTable('webhook_deliveries').execute();\n await db.schema.dropTable('webhooks').execute();\n await db.schema.dropTable('release_items').execute();\n await db.schema.dropTable('releases').execute();\n await db.schema.dropTable('scheduled_publications').execute();\n};\n","import { sql, type CreateTableBuilder, type Kysely } from 'kysely';\n\n/**\n * App users (package I, ADR 0005): the end users of sites and apps built on Shapio, with their own roles\n * (`public` for anonymous callers, `authenticated` for every signed-in app user, plus custom roles), rotating\n * refresh tokens with reuse detection, OAuth identities, email confirmations, password resets and the\n * short-lived codes that hand an OAuth sign-in back to the app. Secrets are stored as SHA-256 hashes (tokens,\n * codes) or argon2id hashes (passwords), never in plain text.\n */\n\n/**\n * Stable IDs of the built-in app roles. The evaluator refers to them directly (permissions/appRoles.ts holds\n * the same values); a migration never imports application code, so they are repeated here.\n */\nconst PUBLIC_ROLE_ID = '00000000-0000-4000-a000-000000000001';\nconst AUTHENTICATED_ROLE_ID = '00000000-0000-4000-a000-000000000002';\n\nconst withTimestamps = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('updated_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`));\n\nconst uuidPrimaryKey = <T extends string, C extends string>(table: CreateTableBuilder<T, C>) =>\n table.addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`));\n\nconst createUsers = async (db: Kysely<unknown>) => {\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('app_users'))\n // Stored normalised (trimmed, lower case); uniqueness is also enforced case-insensitively below.\n .addColumn('email', 'text', (col) => col.notNull())\n .addColumn('name', 'text', (col) => col.notNull().defaultTo(''))\n // Null for accounts that only sign in with an OAuth provider.\n .addColumn('password_hash', 'text')\n .addColumn('confirmed_at', 'timestamptz')\n .addColumn('blocked_at', 'timestamptz')\n .addColumn('last_login_at', 'timestamptz')\n .addColumn('password_changed_at', 'timestamptz')\n // Soft delete: personal data is scrubbed, the row stays for audit and content ownership history.\n .addColumn('deleted_at', 'timestamptz'),\n ).execute();\n await sql`create unique index app_users_email_uq on app_users (lower(email)) where deleted_at is null`.execute(\n db,\n );\n await sql`create index app_users_created_idx on app_users (created_at desc, id desc) where deleted_at is null`.execute(\n db,\n );\n};\n\nconst createRoles = async (db: Kysely<unknown>) => {\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('app_roles'))\n .addColumn('key', 'text', (col) =>\n col\n .notNull()\n .unique()\n .check(sql`key ~ '^[a-z][a-z0-9-]{0,62}$'`),\n )\n .addColumn('name', 'text', (col) => col.notNull())\n .addColumn('description', 'text', (col) => col.notNull().defaultTo(''))\n // Built-in roles (public, authenticated) keep their key and name; their grants stay editable.\n .addColumn('is_system', 'boolean', (col) => col.notNull().defaultTo(false))\n .addColumn('version', 'integer', (col) => col.notNull().defaultTo(1)),\n ).execute();\n\n // Same grant shape as admin roles (permissions/policy.ts `Grant`), restricted to content actions.\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('app_role_permissions'))\n .addColumn('role_id', 'uuid', (col) => col.notNull().references('app_roles.id').onDelete('cascade'))\n .addColumn('action', 'text', (col) =>\n col.notNull().check(sql`action in ('read', 'create', 'update', 'delete', 'publish')`),\n )\n .addColumn('model_id', 'text')\n .addColumn('condition', 'text', (col) => col.check(sql`condition in ('ownedByPrincipal')`))\n .addColumn('field_ids', sql`text[]`)\n .addUniqueConstraint('app_role_permissions_grant_uq', ['role_id', 'action', 'model_id'], (uc) =>\n uc.nullsNotDistinct(),\n ),\n ).execute();\n\n await db.schema\n .createTable('app_user_roles')\n .addColumn('app_user_id', 'uuid', (col) => col.notNull().references('app_users.id').onDelete('cascade'))\n // Restrict: a role still held by someone cannot be deleted (the service reports a conflict first).\n .addColumn('role_id', 'uuid', (col) => col.notNull().references('app_roles.id').onDelete('restrict'))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addPrimaryKeyConstraint('app_user_roles_pk', ['app_user_id', 'role_id'])\n .execute();\n await db.schema.createIndex('app_user_roles_role_idx').on('app_user_roles').column('role_id').execute();\n\n await sql`\n insert into app_roles (id, key, name, description, is_system) values\n (${PUBLIC_ROLE_ID}, 'public', 'Public',\n 'Applies to every caller without a token. Grants nothing until you add permissions.', true),\n (${AUTHENTICATED_ROLE_ID}, 'authenticated', 'Authenticated',\n 'Held by every signed-in app user, in addition to their custom roles. Grants nothing until you add permissions.', true)\n `.execute(db);\n // Neither built-in role grants anything by default (brief §8): an admin enables delivery deliberately.\n};\n\nconst createCredentials = async (db: Kysely<unknown>) => {\n // One row per issued refresh token. A family is one sign-in; rotation adds a row to it and marks the\n // previous one used. Presenting a used token again revokes the whole family (reuse detection).\n await db.schema\n .createTable('app_refresh_tokens')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('app_user_id', 'uuid', (col) => col.notNull().references('app_users.id').onDelete('cascade'))\n .addColumn('family_id', 'uuid', (col) => col.notNull())\n .addColumn('token_hash', 'text', (col) => col.notNull().unique())\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('used_at', 'timestamptz')\n // A rotated token may be presented once more within a short grace (a client retrying a lost response);\n // it gets the same replacement. Set when that one retry is spent.\n .addColumn('reuse_grace_used_at', 'timestamptz')\n .addColumn('revoked_at', 'timestamptz')\n .addColumn('revoked_reason', 'text')\n .addColumn('ip', 'text')\n .addColumn('user_agent', 'text')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n await db.schema\n .createIndex('app_refresh_tokens_family_idx')\n .on('app_refresh_tokens')\n .column('family_id')\n .execute();\n await db.schema\n .createIndex('app_refresh_tokens_user_idx')\n .on('app_refresh_tokens')\n .column('app_user_id')\n .where(sql.ref('revoked_at'), 'is', null)\n .execute();\n\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable('app_oauth_accounts'))\n .addColumn('app_user_id', 'uuid', (col) => col.notNull().references('app_users.id').onDelete('cascade'))\n .addColumn('provider', 'text', (col) => col.notNull().check(sql`provider in ('google', 'github')`))\n .addColumn('provider_user_id', 'text', (col) => col.notNull())\n // The address the provider reported at the last sign-in (verified or not), for support.\n .addColumn('email', 'text')\n .addUniqueConstraint('app_oauth_accounts_identity_uq', ['provider', 'provider_user_id']),\n ).execute();\n await db.schema\n .createIndex('app_oauth_accounts_user_idx')\n .on('app_oauth_accounts')\n .column('app_user_id')\n .execute();\n\n // Token hashes are written when the email job runs, so the plain token never sits in the jobs table.\n for (const table of ['email_confirmations', 'app_password_resets'] as const) {\n await withTimestamps(\n uuidPrimaryKey(db.schema.createTable(table))\n .addColumn('app_user_id', 'uuid', (col) =>\n col.notNull().references('app_users.id').onDelete('cascade'),\n )\n .addColumn('email', 'text', (col) => col.notNull())\n .addColumn('token_hash', 'text', (col) => col.unique())\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('used_at', 'timestamptz'),\n ).execute();\n await db.schema.createIndex(`${table}_user_idx`).on(table).column('app_user_id').execute();\n }\n\n // One-time codes that hand an OAuth sign-in from the callback back to the app (exchanged for tokens).\n await db.schema\n .createTable('app_login_codes')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('app_user_id', 'uuid', (col) => col.notNull().references('app_users.id').onDelete('cascade'))\n .addColumn('code_hash', 'text', (col) => col.notNull().unique())\n .addColumn('expires_at', 'timestamptz', (col) => col.notNull())\n .addColumn('used_at', 'timestamptz')\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .execute();\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await createUsers(db);\n await createRoles(db);\n await createCredentials(db);\n // Package E recorded owners without a foreign key; app_users is new, so any earlier value is an orphan.\n await sql`update entries set owner_app_user_id = null where owner_app_user_id is not null`.execute(db);\n await sql`\n alter table entries add constraint entries_owner_app_user_fk\n foreign key (owner_app_user_id) references app_users (id) on delete set null\n `.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table entries drop constraint if exists entries_owner_app_user_fk`.execute(db);\n await db.schema.dropTable('app_login_codes').execute();\n await db.schema.dropTable('app_password_resets').execute();\n await db.schema.dropTable('email_confirmations').execute();\n await db.schema.dropTable('app_oauth_accounts').execute();\n await db.schema.dropTable('app_refresh_tokens').execute();\n await db.schema.dropTable('app_user_roles').execute();\n await db.schema.dropTable('app_role_permissions').execute();\n await db.schema.dropTable('app_roles').execute();\n await db.schema.dropTable('app_users').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Extension points (package K, ADR 0009): the ledger of post-commit lifecycle hooks (`afterCreate`,\n * `afterPublish`, ...) that have run. One row per (outbox event, hook name), written in the same transaction\n * as the hook's own database work, so a hook re-run after a worker crash finds its row and is skipped:\n * exactly once for everything the hook does through its transaction.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('extension_hook_runs')\n .addColumn('event_id', 'uuid', (col) => col.notNull())\n // `<model API key, model ID or *>.<event>`, as the hook is keyed in shapio.config.\n .addColumn('hook', 'text', (col) => col.notNull())\n .addColumn('job_id', 'uuid')\n .addColumn('completed_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addPrimaryKeyConstraint('extension_hook_runs_pkey', ['event_id', 'hook'])\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('extension_hook_runs').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * App users (ADR 0005):\n * - `app_users.token_version`: carried in every access token and bumped on logout, block, password change,\n * password reset and deletion, so the account's outstanding access tokens stop working on their next\n * request instead of living out their TTL.\n * - `app_login_codes.code_challenge`: the PKCE-style S256 challenge the app sent when it started the OAuth\n * sign-in; the one-time login code is only exchanged with the matching verifier. Codes live a minute, so\n * any pending ones (issued without a challenge) are dropped rather than given a placeholder.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .alterTable('app_users')\n .addColumn('token_version', 'integer', (col) => col.notNull().defaultTo(0))\n .execute();\n await sql`delete from app_login_codes`.execute(db);\n await db.schema\n .alterTable('app_login_codes')\n .addColumn('code_challenge', 'text', (col) => col.notNull())\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.alterTable('app_login_codes').dropColumn('code_challenge').execute();\n await db.schema.alterTable('app_users').dropColumn('token_version').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * The snapshot diff (repositories/snapshotDiff.ts) finds the (entry, locale) pairs whose live period opened\n * or closed between two publication sequence numbers, then reads each pair's live revision at both ends.\n * - `to_seq` range: periods that closed in the range (the open ones have no `to_seq` and are left out).\n * - `(entry_id, locale, from_seq)`: \"the row live at seq N\" is the latest row starting at or before N.\n * Periods that opened in the range use the existing `(model_id, from_seq)` index.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`create index publication_log_to_seq_idx on publication_log (to_seq) where to_seq is not null`.execute(\n db,\n );\n await db.schema\n .createIndex('publication_log_entry_locale_from_idx')\n .on('publication_log')\n .columns(['entry_id', 'locale', 'from_seq'])\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropIndex('publication_log_entry_locale_from_idx').execute();\n await db.schema.dropIndex('publication_log_to_seq_idx').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Field usage from delivery traffic (plan developer-face §5): daily counters written by the in-memory\n * aggregator (usage/aggregator.ts) in one multi-row upsert per flush, never per request. Counts only, no\n * payloads. `principal_key` is `token:<id>`, `app_users` or `anonymous`. Pruned by the retention job\n * after USAGE_RETENTION_DAYS.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('field_reads')\n .addColumn('day', 'date', (col) => col.notNull())\n .addColumn('model_id', 'uuid', (col) => col.notNull())\n // A stable field ID, or `<relation field ID>.<target field ID>` for a populated relation's field.\n .addColumn('field_path', 'text', (col) => col.notNull())\n .addColumn('principal_key', 'text', (col) => col.notNull())\n // `explicit`: the reader selected the field; `implicit`: it asked for the whole model.\n .addColumn('selection', 'text', (col) => col.notNull().check(sql`selection in ('explicit', 'implicit')`))\n .addColumn('reads', 'bigint', (col) => col.notNull().defaultTo(0))\n .addColumn('last_read_at', 'timestamptz', (col) => col.notNull())\n .addPrimaryKeyConstraint('field_reads_pkey', [\n 'day',\n 'model_id',\n 'field_path',\n 'principal_key',\n 'selection',\n ])\n .execute();\n await db.schema\n .createIndex('field_reads_model_day_idx')\n .on('field_reads')\n .columns(['model_id', 'day'])\n .execute();\n\n await db.schema\n .createTable('token_reads')\n .addColumn('day', 'date', (col) => col.notNull())\n .addColumn('principal_key', 'text', (col) => col.notNull())\n .addColumn('requests', 'bigint', (col) => col.notNull().defaultTo(0))\n // The last `?snapshot=N` (or GraphQL `snapshot`) this principal pinned that day; null = never pinned.\n .addColumn('last_snapshot', 'bigint')\n .addColumn('last_read_at', 'timestamptz', (col) => col.notNull())\n .addPrimaryKeyConstraint('token_reads_pkey', ['day', 'principal_key'])\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.dropTable('token_reads').execute();\n await db.schema.dropTable('field_reads').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Change sets (developer-face plan §5, ADR 0010): schema drafts and entry publications that ship as ONE\n * publication snapshot. Replaces releases (a clean rename: rows, permission strings, webhook event patterns,\n * deployment trigger policy and pending jobs move over; nothing keeps the old names).\n *\n * - `change_sets` / `change_set_items`: the set and its items (entry publications or schema drafts).\n * - `schema_drafts`: mutable proposed definitions; real (immutable) schema revisions are written at ship.\n * - `publication_snapshots`: one ledger row per publication sequence number (who, why, schema version),\n * backfilled for existing numbers as `legacy`.\n * - `schema_change_jobs.change_set_id` and `deployment_runs.change_set_id` link execution records to a set.\n */\n\nconst RELEASE_EVENT_RENAMES: ReadonlyArray<[string, string]> = [\n ['release.*', 'change_set.*'],\n ['release.scheduled', 'change_set.scheduled'],\n ['release.published', 'change_set.shipped'],\n ['release.failed', 'change_set.failed'],\n];\n\nconst createTables = async (db: Kysely<unknown>) => {\n await sql`\n create table change_sets (\n id uuid primary key default gen_random_uuid(),\n title text not null check (length(title) between 1 and 200),\n description text not null default '',\n status text not null default 'open'\n check (status in ('open', 'scheduled', 'shipping', 'shipped', 'failed', 'discarded')),\n ship_phase text check (ship_phase in ('preparing', 'activating')),\n source text not null default 'manual' check (source in ('manual', 'release', 'restore', 'builder')),\n restore_of_seq bigint,\n scheduled_for timestamptz,\n schedule_job_id uuid,\n scheduled_by uuid references admin_users(id) on delete set null,\n scheduled_by_token uuid references api_tokens(id) on delete set null,\n ship_job_id uuid,\n ship_mode text check (ship_mode in ('interactive', 'scheduled')),\n ship_requested_by uuid references admin_users(id) on delete set null,\n ship_requested_by_token uuid references api_tokens(id) on delete set null,\n acknowledge_breaking boolean not null default false,\n acknowledge_destructive boolean not null default false,\n deployment_connection_id uuid references deployment_connections(id) on delete set null,\n deployment_run_id uuid references deployment_runs(id) on delete set null,\n shipped_at timestamptz,\n shipped_seq bigint,\n schema_version_after integer,\n error jsonb,\n restore_report jsonb not null default '[]'::jsonb,\n created_by uuid references admin_users(id) on delete set null,\n created_by_token uuid references api_tokens(id) on delete set null,\n version integer not null default 1,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n )\n `.execute(db);\n await sql`create index change_sets_status_idx on change_sets (status, created_at desc)`.execute(db);\n\n await sql`\n create table schema_drafts (\n id uuid primary key default gen_random_uuid(),\n change_set_id uuid not null references change_sets(id) on delete cascade,\n definition_id uuid not null,\n kind text not null check (kind in ('collection', 'singleton', 'component')),\n api_key text not null,\n base_version integer,\n definition jsonb,\n version integer not null default 1,\n updated_by_type text not null,\n updated_by_id text,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now(),\n constraint schema_drafts_set_definition_uq unique (change_set_id, definition_id)\n )\n `.execute(db);\n await sql`create index schema_drafts_definition_idx on schema_drafts (definition_id)`.execute(db);\n\n await sql`\n create table change_set_items (\n id uuid primary key default gen_random_uuid(),\n change_set_id uuid not null references change_sets(id) on delete cascade,\n kind text not null check (kind in ('entry', 'schema')),\n position integer not null,\n entry_id uuid references entries(id) on delete cascade,\n model_id uuid,\n locale text,\n action text check (action in ('publish', 'unpublish')),\n source_revision_id uuid references content_revisions(id),\n schema_draft_id uuid references schema_drafts(id) on delete cascade,\n status text not null default 'pending' check (status in ('pending', 'done', 'failed')),\n error text,\n ship_state jsonb,\n created_at timestamptz not null default now(),\n constraint change_set_items_shape_check check (\n (kind = 'entry' and entry_id is not null and model_id is not null and locale is not null\n and action is not null and schema_draft_id is null)\n or (kind = 'schema' and schema_draft_id is not null and entry_id is null and source_revision_id is null)\n )\n )\n `.execute(db);\n await sql`\n create unique index change_set_items_entry_uq on change_set_items (change_set_id, entry_id, locale)\n where kind = 'entry'\n `.execute(db);\n await sql`create unique index change_set_items_draft_uq on change_set_items (schema_draft_id)`.execute(db);\n await sql`create index change_set_items_set_idx on change_set_items (change_set_id, position)`.execute(db);\n await sql`create index change_set_items_entry_idx on change_set_items (entry_id) where entry_id is not null`.execute(\n db,\n );\n\n await sql`\n create table publication_snapshots (\n seq bigint primary key,\n schema_version integer,\n source text not null,\n change_set_id uuid references change_sets(id) on delete set null,\n actor_type text,\n actor_id text,\n created_at timestamptz not null default now()\n )\n `.execute(db);\n await sql`create index publication_snapshots_change_set_idx on publication_snapshots (change_set_id)\n where change_set_id is not null`.execute(db);\n};\n\nconst linkExecutionRecords = async (db: Kysely<unknown>) => {\n await sql`alter table schema_change_jobs\n add column change_set_id uuid references change_sets(id) on delete set null`.execute(db);\n await sql`create index schema_change_jobs_change_set_idx on schema_change_jobs (change_set_id)\n where change_set_id is not null`.execute(db);\n await sql`alter table deployment_runs\n add column change_set_id uuid references change_sets(id) on delete set null`.execute(db);\n await sql`alter table deployment_runs drop constraint deployment_runs_trigger_check`.execute(db);\n await sql`update deployment_runs set trigger = 'change_set' where trigger = 'release'`.execute(db);\n await sql`alter table deployment_runs add constraint deployment_runs_trigger_check\n check (trigger in ('publish', 'change_set', 'schema', 'manual', 'retry'))`.execute(db);\n await sql`update deployment_connections\n set trigger_policy = array_replace(trigger_policy, 'release', 'change_set')`.execute(db);\n};\n\n/** Revisions written by activation-time value conversions (published heads roll to them in the log). */\nconst allowConversionRevisions = async (db: Kysely<unknown>) => {\n await sql`alter table content_revisions drop constraint content_revisions_reason_check`.execute(db);\n await sql`alter table content_revisions add constraint content_revisions_reason_check\n check (reason in ('create', 'save', 'publish', 'restore', 'duplicate', 'localize', 'conversion'))`.execute(\n db,\n );\n};\n\nconst backfillSnapshots = async (db: Kysely<unknown>) => {\n await sql`\n insert into publication_snapshots (seq, schema_version, source, created_at)\n select s, null, 'legacy',\n coalesce((select min(published_at) from publication_log where from_seq = s), now())\n from generate_series(1::bigint, (select last_seq from publication_state)) as s\n `.execute(db);\n};\n\nconst migrateReleases = async (db: Kysely<unknown>) => {\n await sql`\n insert into change_sets (id, title, description, status, source, scheduled_for, schedule_job_id,\n scheduled_by, scheduled_by_token, shipped_at, shipped_seq, error, created_by, version, created_at,\n updated_at)\n select id, name, description,\n case status when 'draft' then 'open' when 'published' then 'shipped' when 'cancelled' then 'discarded'\n else status end,\n 'release', scheduled_at, schedule_job_id, scheduled_by, scheduled_by_token, executed_at, snapshot_seq,\n case when error is null then null\n else jsonb_build_object('code', 'PUBLICATION_FAILED', 'message', error, 'itemId',\n (select ri.id from release_items ri where ri.release_id = releases.id and ri.status = 'failed' limit 1))\n end,\n created_by, version, created_at, updated_at\n from releases\n `.execute(db);\n await sql`\n insert into change_set_items (id, change_set_id, kind, position, entry_id, model_id, locale, action, status,\n error, created_at)\n select id, release_id, 'entry',\n row_number() over (partition by release_id order by created_at, id) - 1,\n entry_id, model_id, locale, action, status, error, created_at\n from release_items\n `.execute(db);\n // A scheduled release's pending job becomes the change set's ship job (same job ID, same schedule).\n await sql`\n update jobs set type = 'changeSet.ship',\n payload = jsonb_build_object('changeSetId', payload->>'releaseId', 'mode', 'scheduled')\n where type = 'publishing.release' and status in ('pending', 'running')\n `.execute(db);\n await sql`update admin_role_permissions set action = 'changes.manage' where action = 'releases.manage'`.execute(\n db,\n );\n for (const [from, to] of RELEASE_EVENT_RENAMES) {\n await sql`update webhooks set events = array_replace(events, ${from}, ${to})`.execute(db);\n }\n await sql`drop table release_items`.execute(db);\n await sql`drop table releases`.execute(db);\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await createTables(db);\n await linkExecutionRecords(db);\n await allowConversionRevisions(db);\n await backfillSnapshots(db);\n await migrateReleases(db);\n};\n\n/** Recreates releases from the change sets that hold only entry items; schema drafts and the ledger go. */\nconst restoreReleases = async (db: Kysely<unknown>) => {\n await sql`\n create table releases (\n id uuid primary key default gen_random_uuid(),\n name text not null check (length(name) between 1 and 200),\n description text not null default '',\n status text not null default 'draft'\n check (status in ('draft', 'scheduled', 'published', 'failed', 'cancelled')),\n scheduled_at timestamptz,\n schedule_job_id uuid,\n scheduled_by uuid references admin_users(id) on delete set null,\n scheduled_by_token uuid references api_tokens(id) on delete set null,\n executed_at timestamptz,\n snapshot_seq bigint,\n error text,\n version integer not null default 1,\n created_by uuid references admin_users(id) on delete set null,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n )\n `.execute(db);\n await sql`create index releases_status_idx on releases (status, created_at)`.execute(db);\n await sql`\n create table release_items (\n id uuid primary key default gen_random_uuid(),\n release_id uuid not null references releases(id) on delete cascade,\n entry_id uuid not null references entries(id) on delete cascade,\n model_id uuid not null,\n locale text not null,\n action text not null check (action in ('publish', 'unpublish')),\n status text not null default 'pending' check (status in ('pending', 'done', 'failed')),\n error text,\n created_at timestamptz not null default now(),\n constraint release_items_entry_locale_uq unique (release_id, entry_id, locale)\n )\n `.execute(db);\n await sql`\n insert into releases (id, name, description, status, scheduled_at, schedule_job_id, scheduled_by,\n scheduled_by_token, executed_at, snapshot_seq, error, version, created_by, created_at, updated_at)\n select id, title, description,\n case status when 'open' then 'draft' when 'shipped' then 'published' when 'discarded' then 'cancelled'\n when 'shipping' then 'draft' else status end,\n scheduled_for, schedule_job_id, scheduled_by, scheduled_by_token, shipped_at, shipped_seq,\n error->>'message', version, created_by, created_at, updated_at\n from change_sets cs\n where not exists (select 1 from change_set_items i where i.change_set_id = cs.id and i.kind = 'schema')\n `.execute(db);\n await sql`\n insert into release_items (id, release_id, entry_id, model_id, locale, action, status, error, created_at)\n select i.id, i.change_set_id, i.entry_id, i.model_id, i.locale, i.action, i.status, i.error, i.created_at\n from change_set_items i join releases r on r.id = i.change_set_id\n where i.kind = 'entry'\n `.execute(db);\n await sql`\n update jobs set type = 'publishing.release', payload = jsonb_build_object('releaseId', payload->>'changeSetId')\n where type = 'changeSet.ship' and status in ('pending', 'running')\n and (payload->>'changeSetId')::uuid in (select id from releases)\n `.execute(db);\n await sql`delete from jobs where type like 'changeSet.%' and status in ('pending', 'running')`.execute(db);\n await sql`update admin_role_permissions set action = 'releases.manage' where action = 'changes.manage'`.execute(\n db,\n );\n for (const [from, to] of RELEASE_EVENT_RENAMES) {\n await sql`update webhooks set events = array_replace(events, ${to}, ${from})`.execute(db);\n }\n // Events without a release equivalent are dropped from subscriptions.\n await sql`update webhooks set events = array_remove(array_remove(events, 'change_set.shipping'),\n 'change_set.discarded')`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await restoreReleases(db);\n // Revisions are immutable, so conversion revisions stay; the old check applies to new rows only.\n await sql`alter table content_revisions drop constraint content_revisions_reason_check`.execute(db);\n await sql`alter table content_revisions add constraint content_revisions_reason_check\n check (reason in ('create', 'save', 'publish', 'restore', 'duplicate', 'localize')) not valid`.execute(\n db,\n );\n await sql`update deployment_connections\n set trigger_policy = array_replace(trigger_policy, 'change_set', 'release')`.execute(db);\n await sql`alter table deployment_runs drop constraint deployment_runs_trigger_check`.execute(db);\n await sql`update deployment_runs set trigger = 'release' where trigger = 'change_set'`.execute(db);\n await sql`alter table deployment_runs add constraint deployment_runs_trigger_check\n check (trigger in ('publish', 'release', 'schema', 'manual', 'retry'))`.execute(db);\n await sql`alter table deployment_runs drop column change_set_id`.execute(db);\n await sql`alter table schema_change_jobs drop column change_set_id`.execute(db);\n await sql`drop table publication_snapshots`.execute(db);\n await sql`drop table change_set_items`.execute(db);\n await sql`drop table schema_drafts`.execute(db);\n await sql`drop table change_sets`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Editor experience (plan editor-experience §9):\n *\n * - `editor_presence`: who has an entry open, one row per browser tab, refreshed by a heartbeat and read\n * with a TTL. UNLOGGED: it is advisory and rebuilt within one heartbeat, so it skips the WAL and is\n * simply emptied after a crash. Correct across any number of server processes without NOTIFY.\n * - `content_health_findings`: open and recently resolved findings of the health rules per entry and\n * locale (`*` for the entry as a whole). An evaluation upserts what it found and resolves the rest.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`\n create unlogged table editor_presence (\n entry_id uuid not null,\n model_id uuid not null,\n admin_user_id uuid not null,\n tab_id text not null check (length(tab_id) between 1 and 64),\n locale text,\n started_at timestamptz not null default now(),\n last_seen_at timestamptz not null default now(),\n primary key (entry_id, admin_user_id, tab_id)\n )\n `.execute(db);\n await sql`create index editor_presence_model_idx on editor_presence (model_id, last_seen_at)`.execute(db);\n await sql`create index editor_presence_seen_idx on editor_presence (last_seen_at)`.execute(db);\n\n await sql`\n create table content_health_findings (\n id uuid primary key default gen_random_uuid(),\n entry_id uuid not null references entries(id) on delete cascade,\n model_id uuid not null,\n locale text not null,\n rule text not null,\n subject text not null default '',\n severity text not null check (severity in ('error', 'warning')),\n path text,\n details jsonb not null default '{}'::jsonb,\n first_seen_at timestamptz not null default now(),\n last_seen_at timestamptz not null default now(),\n resolved_at timestamptz,\n unique (entry_id, locale, rule, subject)\n )\n `.execute(db);\n await sql`create index content_health_findings_open_idx on content_health_findings (rule, last_seen_at desc, id)\n where resolved_at is null`.execute(db);\n await sql`create index content_health_findings_resolved_idx on content_health_findings (resolved_at)\n where resolved_at is not null`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`drop table content_health_findings`.execute(db);\n await sql`drop table editor_presence`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * `changes.ship` (agentic plan §I): shipping a change set (and scheduling a ship) becomes its own global\n * action, split from `changes.manage`, so a role can prepare change sets without being able to make them\n * live. Every role that holds `changes.manage` today keeps what it could do: it gets `changes.ship` too.\n * The permissions version moves only when grants changed, so running instances reload exactly then.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`\n with granted as (\n insert into admin_role_permissions (role_id, action, model_id, condition, field_ids)\n select role_id, 'changes.ship', null, null, null\n from admin_role_permissions\n where action = 'changes.manage' and model_id is null\n on conflict on constraint admin_role_permissions_grant_uq do nothing\n returning 1\n )\n update system_versions set permissions_version = permissions_version + 1, updated_at = now()\n where exists (select 1 from granted)\n `.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`\n with revoked as (\n delete from admin_role_permissions where action = 'changes.ship' returning 1\n )\n update system_versions set permissions_version = permissions_version + 1, updated_at = now()\n where exists (select 1 from revoked)\n `.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Sites (plan agentic-ecosystem §H, ADR 0011): one instance hosts many sites with one schema and one login.\n * A site owns its content, media, tokens, change sets, snapshots, app users and usage counters; models,\n * locales, admin users and roles stay instance-wide. Role assignments carry a site (null = every site).\n *\n * Every existing row moves to the primary site (fixed ID below, key `default`). Columns are added with a\n * constant default, which PostgreSQL records in the catalog without rewriting the table, and the default is\n * dropped straight after: from here on every insert must name its site. Copies of the entry's site (heads,\n * the publication log, unique values, findings, schedules, preview tokens) carry a composite foreign key to\n * `entries (id, site_id)`, so a copy can never disagree with its entry.\n *\n * `down` refuses while more than one site exists (merging sites would merge their snapshot ledgers and\n * uniqueness, and widen role assignments). With one site it is lossless.\n */\n\n/** The primary site every existing row belongs to. Repeated in constants/sites.ts (migrations never import app code). */\nconst PRIMARY_SITE_ID = '00000000-0000-4000-b000-000000000001';\nconst PUBLIC_ROLE_ID = '00000000-0000-4000-a000-000000000001';\nconst AUTHENTICATED_ROLE_ID = '00000000-0000-4000-a000-000000000002';\n\ntype OnDelete = 'restrict' | 'cascade' | 'set null';\n\n/** Tables whose rows always belong to one site, and what deleting a site does to them. */\nconst REQUIRED_SITE_TABLES: ReadonlyArray<[table: string, onDelete: OnDelete]> = [\n // Content and its derived rows: a site with content cannot be deleted.\n ['entries', 'restrict'],\n ['entry_heads', 'restrict'],\n ['unique_values', 'restrict'],\n ['publication_log', 'restrict'],\n ['scheduled_publications', 'restrict'],\n ['content_health_findings', 'restrict'],\n ['media_folders', 'restrict'],\n ['media_assets', 'restrict'],\n ['change_sets', 'restrict'],\n ['app_users', 'restrict'],\n ['app_user_roles', 'restrict'],\n ['app_oauth_accounts', 'restrict'],\n // Configuration and bookkeeping go with the (empty) site.\n ['publication_state', 'cascade'],\n ['publication_snapshots', 'cascade'],\n ['media_upload_grants', 'cascade'],\n ['preview_tokens', 'cascade'],\n ['deployment_connections', 'cascade'],\n ['field_reads', 'cascade'],\n ['token_reads', 'cascade'],\n];\n\n/** Null means \"every site\" (network): tokens, webhooks, role assignments; or \"not about a site\": history. */\nconst OPTIONAL_SITE_TABLES: ReadonlyArray<[table: string, onDelete: OnDelete]> = [\n ['api_tokens', 'cascade'],\n ['webhooks', 'cascade'],\n ['admin_user_roles', 'cascade'],\n ['outbox_events', 'set null'],\n ['audit_events', 'set null'],\n];\n\n/** Copies of the entry's site, tied to it by a composite foreign key. */\nconst ENTRY_SITE_COPIES: ReadonlyArray<[table: string, onDelete: OnDelete]> = [\n ['entry_heads', 'cascade'],\n ['unique_values', 'cascade'],\n ['publication_log', 'restrict'],\n ['scheduled_publications', 'cascade'],\n ['content_health_findings', 'cascade'],\n ['preview_tokens', 'cascade'],\n];\n\nconst createSites = async (db: Kysely<unknown>) => {\n await sql`\n create table sites (\n id uuid primary key default gen_random_uuid(),\n key text not null unique check (key ~ '^[a-z][a-z0-9-]{0,62}$'),\n name text not null check (length(name) between 1 and 200),\n is_primary boolean not null default false,\n version integer not null default 1,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n )\n `.execute(db);\n await sql`create unique index sites_single_primary_uq on sites (is_primary) where is_primary`.execute(db);\n await sql`insert into sites (id, key, name, is_primary) values (${PRIMARY_SITE_ID}, 'default', 'Default site', true)`.execute(\n db,\n );\n\n // Which app roles anonymous callers (`public`) and every signed-in app user (`authenticated`) hold on a\n // site. A new site binds nothing: deny by default (brief §8).\n await sql`\n create table site_app_roles (\n site_id uuid not null references sites(id) on delete cascade,\n audience text not null check (audience in ('public', 'authenticated')),\n role_id uuid not null references app_roles(id) on delete cascade,\n created_at timestamptz not null default now(),\n primary key (site_id, audience, role_id)\n )\n `.execute(db);\n await sql`create index site_app_roles_role_idx on site_app_roles (role_id)`.execute(db);\n await sql`\n insert into site_app_roles (site_id, audience, role_id) values\n (${PRIMARY_SITE_ID}, 'public', ${PUBLIC_ROLE_ID}),\n (${PRIMARY_SITE_ID}, 'authenticated', ${AUTHENTICATED_ROLE_ID})\n `.execute(db);\n};\n\nconst siteForeignKey = async (db: Kysely<unknown>, table: string, onDelete: OnDelete) => {\n const name = sql.id(`${table}_site_fk`);\n await sql`alter table ${sql.table(table)} add constraint ${name}\n foreign key (site_id) references sites(id) on delete ${sql.raw(onDelete)} not valid`.execute(db);\n await sql`alter table ${sql.table(table)} validate constraint ${name}`.execute(db);\n};\n\nconst addSiteColumns = async (db: Kysely<unknown>) => {\n for (const [table, onDelete] of REQUIRED_SITE_TABLES) {\n // A constant default is a catalog-only change (no table rewrite); dropping it makes inserts name a site.\n await sql`alter table ${sql.table(table)}\n add column site_id uuid not null default ${sql.lit(PRIMARY_SITE_ID)}::uuid`.execute(db);\n await sql`alter table ${sql.table(table)} alter column site_id drop default`.execute(db);\n await siteForeignKey(db, table, onDelete);\n }\n for (const [table, onDelete] of OPTIONAL_SITE_TABLES) {\n await sql`alter table ${sql.table(table)} add column site_id uuid`.execute(db);\n await siteForeignKey(db, table, onDelete);\n }\n // Delivery tokens always belong to a site; admin tokens stay network tokens (null), as they behave today.\n await sql`\n update api_tokens t set site_id = ${PRIMARY_SITE_ID}\n from admin_roles r where r.id = t.role_id and r.kind = 'delivery'\n `.execute(db);\n};\n\nconst tieCopiesToEntries = async (db: Kysely<unknown>) => {\n await sql`alter table entries add constraint entries_id_site_uq unique (id, site_id)`.execute(db);\n for (const [table, onDelete] of ENTRY_SITE_COPIES) {\n const name = sql.id(`${table}_entry_site_fk`);\n await sql`alter table ${sql.table(table)} add constraint ${name}\n foreign key (entry_id, site_id) references entries(id, site_id) on delete ${sql.raw(onDelete)} not valid`.execute(\n db,\n );\n await sql`alter table ${sql.table(table)} validate constraint ${name}`.execute(db);\n }\n};\n\nconst rekeyContent = async (db: Kysely<unknown>) => {\n await sql`drop index entries_model_idx`.execute(db);\n await sql`create index entries_model_idx on entries (site_id, model_id, created_at) where deleted_at is null`.execute(\n db,\n );\n await sql`drop index entry_heads_model_locale_state_idx`.execute(db);\n await sql`create index entry_heads_model_locale_state_idx on entry_heads (site_id, model_id, locale, state)`.execute(\n db,\n );\n // Uniqueness is per site: two sites may both have an article with the slug `hello`.\n await sql`alter table unique_values drop constraint unique_values_pkey`.execute(db);\n await sql`alter table unique_values add constraint unique_values_pkey\n primary key (site_id, field_id, locale, state, value_hash)`.execute(db);\n\n // One publication sequence per site: snapshot N of site A has nothing to do with snapshot N of site B.\n await sql`alter table publication_state drop constraint publication_state_pkey`.execute(db);\n await sql`alter table publication_state drop column id`.execute(db);\n await sql`alter table publication_state add constraint publication_state_pkey primary key (site_id)`.execute(\n db,\n );\n await sql`alter table publication_snapshots drop constraint publication_snapshots_pkey`.execute(db);\n await sql`alter table publication_snapshots add constraint publication_snapshots_pkey primary key (site_id, seq)`.execute(\n db,\n );\n await sql`drop index publication_log_to_seq_idx`.execute(db);\n await sql`create index publication_log_to_seq_idx on publication_log (site_id, to_seq) where to_seq is not null`.execute(\n db,\n );\n await sql`drop index publication_log_model_seq_idx`.execute(db);\n await sql`create index publication_log_model_seq_idx on publication_log (site_id, model_id, from_seq)`.execute(\n db,\n );\n\n await sql`create index scheduled_publications_site_idx on scheduled_publications (site_id, run_at)`.execute(\n db,\n );\n await sql`drop index content_health_findings_open_idx`.execute(db);\n await sql`create index content_health_findings_open_idx on content_health_findings\n (site_id, rule, last_seen_at desc, id) where resolved_at is null`.execute(db);\n await sql`drop index change_sets_status_idx`.execute(db);\n await sql`create index change_sets_status_idx on change_sets (site_id, status, created_at desc)`.execute(\n db,\n );\n};\n\nconst rekeyMedia = async (db: Kysely<unknown>) => {\n await sql`alter table media_folders add constraint media_folders_id_site_uq unique (id, site_id)`.execute(\n db,\n );\n await sql`drop index media_folders_sibling_name_uq`.execute(db);\n await sql`create unique index media_folders_sibling_name_uq on media_folders\n (site_id, coalesce(parent_id, '00000000-0000-0000-0000-000000000000'::uuid), lower(name))`.execute(db);\n // A folder's parent and an asset's folder are on the same site.\n await sql`alter table media_folders drop constraint media_folders_parent_id_fkey`.execute(db);\n await sql`alter table media_folders add constraint media_folders_parent_id_fkey\n foreign key (parent_id, site_id) references media_folders(id, site_id) on delete restrict`.execute(db);\n await sql`alter table media_assets drop constraint media_assets_folder_id_fkey`.execute(db);\n await sql`alter table media_assets add constraint media_assets_folder_id_fkey\n foreign key (folder_id, site_id) references media_folders(id, site_id) on delete set null (folder_id)`.execute(\n db,\n );\n await sql`drop index media_assets_created_idx`.execute(db);\n await sql`create index media_assets_created_idx on media_assets (site_id, created_at, id) where deleted_at is null`.execute(\n db,\n );\n};\n\nconst rekeyAppUsersAndUsage = async (db: Kysely<unknown>) => {\n await sql`drop index app_users_email_uq`.execute(db);\n await sql`create unique index app_users_email_uq on app_users (site_id, lower(email)) where deleted_at is null`.execute(\n db,\n );\n await sql`drop index app_users_created_idx`.execute(db);\n await sql`create index app_users_created_idx on app_users (site_id, created_at desc, id desc)\n where deleted_at is null`.execute(db);\n await sql`alter table app_oauth_accounts drop constraint app_oauth_accounts_identity_uq`.execute(db);\n await sql`alter table app_oauth_accounts add constraint app_oauth_accounts_identity_uq\n unique (site_id, provider, provider_user_id)`.execute(db);\n\n await sql`alter table field_reads drop constraint field_reads_pkey`.execute(db);\n await sql`alter table field_reads add constraint field_reads_pkey\n primary key (day, site_id, model_id, field_path, principal_key, selection)`.execute(db);\n await sql`alter table token_reads drop constraint token_reads_pkey`.execute(db);\n await sql`alter table token_reads add constraint token_reads_pkey primary key (day, site_id, principal_key)`.execute(\n db,\n );\n};\n\n/** A role is assigned on one site or on every site (null). */\nconst siteRoleAssignments = async (db: Kysely<unknown>) => {\n await sql`alter table admin_user_roles drop constraint admin_user_roles_pk`.execute(db);\n await sql`alter table admin_user_roles add column id uuid not null default gen_random_uuid()`.execute(db);\n await sql`alter table admin_user_roles add constraint admin_user_roles_pk primary key (id)`.execute(db);\n await sql`alter table admin_user_roles add constraint admin_user_roles_assignment_uq\n unique nulls not distinct (admin_user_id, role_id, site_id)`.execute(db);\n\n await sql`alter table admin_invitations\n add column role_assignments jsonb not null default '[]'::jsonb`.execute(db);\n await sql`\n update admin_invitations set role_assignments = coalesce(\n (select jsonb_agg(jsonb_build_object('roleId', r, 'siteId', null)) from unnest(role_ids) as r), '[]'::jsonb)\n `.execute(db);\n await sql`alter table admin_invitations drop column role_ids`.execute(db);\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await createSites(db);\n await addSiteColumns(db);\n await tieCopiesToEntries(db);\n await rekeyContent(db);\n await rekeyMedia(db);\n await rekeyAppUsersAndUsage(db);\n await siteRoleAssignments(db);\n};\n\nconst assertSingleSite = async (db: Kysely<unknown>) => {\n const { rows } = await sql<{ count: string }>`select count(*)::text as count from sites`.execute(db);\n if (Number(rows[0]?.count ?? 0) > 1) {\n throw new Error(\n 'Cannot roll back sites while more than one site exists: merging them would merge their snapshot ' +\n 'ledgers and uniqueness and widen role assignments. Delete the other sites first.',\n );\n }\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await assertSingleSite(db);\n\n await sql`alter table admin_invitations add column role_ids uuid[] not null default '{}'::uuid[]`.execute(\n db,\n );\n await sql`\n update admin_invitations set role_ids = coalesce(\n (select array_agg(distinct (a->>'roleId')::uuid) from jsonb_array_elements(role_assignments) as a), '{}'::uuid[])\n `.execute(db);\n await sql`alter table admin_invitations drop column role_assignments`.execute(db);\n // With one site, \"this site\" and \"every site\" are the same assignment.\n await sql`\n delete from admin_user_roles a using admin_user_roles b\n where a.admin_user_id = b.admin_user_id and a.role_id = b.role_id and a.id > b.id\n `.execute(db);\n await sql`alter table admin_user_roles drop constraint admin_user_roles_assignment_uq`.execute(db);\n await sql`alter table admin_user_roles drop constraint admin_user_roles_pk`.execute(db);\n await sql`alter table admin_user_roles drop column id`.execute(db);\n await sql`alter table admin_user_roles add constraint admin_user_roles_pk primary key (admin_user_id, role_id)`.execute(\n db,\n );\n\n await sql`alter table token_reads drop constraint token_reads_pkey`.execute(db);\n await sql`alter table token_reads add constraint token_reads_pkey primary key (day, principal_key)`.execute(\n db,\n );\n await sql`alter table field_reads drop constraint field_reads_pkey`.execute(db);\n await sql`alter table field_reads add constraint field_reads_pkey\n primary key (day, model_id, field_path, principal_key, selection)`.execute(db);\n await sql`alter table app_oauth_accounts drop constraint app_oauth_accounts_identity_uq`.execute(db);\n await sql`alter table app_oauth_accounts add constraint app_oauth_accounts_identity_uq\n unique (provider, provider_user_id)`.execute(db);\n await sql`drop index app_users_created_idx`.execute(db);\n await sql`create index app_users_created_idx on app_users (created_at desc, id desc) where deleted_at is null`.execute(\n db,\n );\n await sql`drop index app_users_email_uq`.execute(db);\n await sql`create unique index app_users_email_uq on app_users (lower(email)) where deleted_at is null`.execute(\n db,\n );\n\n await sql`drop index media_assets_created_idx`.execute(db);\n await sql`create index media_assets_created_idx on media_assets (created_at, id) where deleted_at is null`.execute(\n db,\n );\n await sql`alter table media_assets drop constraint media_assets_folder_id_fkey`.execute(db);\n await sql`alter table media_assets add constraint media_assets_folder_id_fkey\n foreign key (folder_id) references media_folders(id) on delete set null`.execute(db);\n await sql`alter table media_folders drop constraint media_folders_parent_id_fkey`.execute(db);\n await sql`alter table media_folders add constraint media_folders_parent_id_fkey\n foreign key (parent_id) references media_folders(id) on delete restrict`.execute(db);\n await sql`drop index media_folders_sibling_name_uq`.execute(db);\n await sql`create unique index media_folders_sibling_name_uq on media_folders\n (coalesce(parent_id, '00000000-0000-0000-0000-000000000000'::uuid), lower(name))`.execute(db);\n await sql`alter table media_folders drop constraint media_folders_id_site_uq`.execute(db);\n\n await sql`drop index change_sets_status_idx`.execute(db);\n await sql`create index change_sets_status_idx on change_sets (status, created_at desc)`.execute(db);\n await sql`drop index content_health_findings_open_idx`.execute(db);\n await sql`create index content_health_findings_open_idx on content_health_findings (rule, last_seen_at desc, id)\n where resolved_at is null`.execute(db);\n await sql`drop index scheduled_publications_site_idx`.execute(db);\n await sql`drop index publication_log_model_seq_idx`.execute(db);\n await sql`create index publication_log_model_seq_idx on publication_log (model_id, from_seq)`.execute(db);\n await sql`drop index publication_log_to_seq_idx`.execute(db);\n await sql`create index publication_log_to_seq_idx on publication_log (to_seq) where to_seq is not null`.execute(\n db,\n );\n await sql`alter table publication_snapshots drop constraint publication_snapshots_pkey`.execute(db);\n await sql`alter table publication_snapshots add constraint publication_snapshots_pkey primary key (seq)`.execute(\n db,\n );\n await sql`alter table publication_state drop constraint publication_state_pkey`.execute(db);\n await sql`alter table publication_state add column id boolean not null default true check (id)`.execute(db);\n await sql`alter table publication_state add constraint publication_state_pkey primary key (id)`.execute(db);\n await sql`alter table unique_values drop constraint unique_values_pkey`.execute(db);\n await sql`alter table unique_values add constraint unique_values_pkey\n primary key (field_id, locale, state, value_hash)`.execute(db);\n await sql`drop index entry_heads_model_locale_state_idx`.execute(db);\n await sql`create index entry_heads_model_locale_state_idx on entry_heads (model_id, locale, state)`.execute(\n db,\n );\n await sql`drop index entries_model_idx`.execute(db);\n await sql`create index entries_model_idx on entries (model_id, created_at) where deleted_at is null`.execute(\n db,\n );\n\n for (const [table] of ENTRY_SITE_COPIES) {\n await sql`alter table ${sql.table(table)} drop constraint ${sql.id(`${table}_entry_site_fk`)}`.execute(\n db,\n );\n }\n await sql`alter table entries drop constraint entries_id_site_uq`.execute(db);\n for (const [table] of [...REQUIRED_SITE_TABLES, ...OPTIONAL_SITE_TABLES]) {\n await sql`alter table ${sql.table(table)} drop column site_id`.execute(db);\n }\n await sql`drop table site_app_roles`.execute(db);\n await sql`drop table sites`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Field index layout v2 (sites plan §H): per-field expression indexes on `entry_heads` lead with `site_id`,\n * because every content query names its site. Building them is `CREATE INDEX CONCURRENTLY`, which cannot run\n * in a migration's transaction and may take a while, so this migration only enqueues the\n * `schema.fieldIndexLayout` job (schema/planner/indexLayout.ts), which rebuilds the indexes and drops the\n * old ones while the instance keeps serving. Nothing to rebuild (no field index yet, e.g. a new install):\n * no job.\n */\nconst JOB_TYPE = 'schema.fieldIndexLayout';\nconst IDEMPOTENCY_KEY = 'schema.fieldIndexLayout:v2';\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`\n insert into jobs (type, payload, max_attempts, idempotency_key)\n select ${JOB_TYPE}, '{}'::jsonb, 5, ${IDEMPOTENCY_KEY}\n where exists (\n select 1 from pg_catalog.pg_index i\n join pg_catalog.pg_class c on c.oid = i.indexrelid\n where i.indrelid = 'entry_heads'::regclass and c.relname like 'eh\\\\_%'\n )\n on conflict do nothing\n `.execute(db);\n};\n\n/** The layout job is idempotent; rolling back only forgets it if it has not run yet. */\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`delete from jobs where idempotency_key = ${IDEMPOTENCY_KEY} and status = 'pending'`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Sites, publishing (plan agentic-ecosystem §H, package G5).\n *\n * - `change_set_items.site_id`: a copy of the set's site, tied to the set and to the item's entry by\n * composite foreign keys, so a change set can never hold another site's entry (schema items have no entry;\n * their entry key is null and the entry foreign key does not apply).\n * - `preview_tokens.entry_id` becomes required: a preview token previews one entry of one site. Model-wide\n * tokens (short-lived by design) are deleted; whoever needs one opens the entry's preview again.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table change_sets add constraint change_sets_id_site_uq unique (id, site_id)`.execute(db);\n await sql`alter table change_set_items add column site_id uuid`.execute(db);\n await sql`\n update change_set_items i set site_id = s.site_id from change_sets s where s.id = i.change_set_id\n `.execute(db);\n await sql`alter table change_set_items alter column site_id set not null`.execute(db);\n await sql`alter table change_set_items add constraint change_set_items_set_site_fk\n foreign key (change_set_id, site_id) references change_sets(id, site_id) on delete cascade not valid`.execute(\n db,\n );\n await sql`alter table change_set_items validate constraint change_set_items_set_site_fk`.execute(db);\n await sql`alter table change_set_items add constraint change_set_items_entry_site_fk\n foreign key (entry_id, site_id) references entries(id, site_id) on delete cascade not valid`.execute(db);\n await sql`alter table change_set_items validate constraint change_set_items_entry_site_fk`.execute(db);\n\n await sql`delete from preview_tokens where entry_id is null`.execute(db);\n await sql`alter table preview_tokens alter column entry_id set not null`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table preview_tokens alter column entry_id drop not null`.execute(db);\n await sql`alter table change_set_items drop constraint change_set_items_entry_site_fk`.execute(db);\n await sql`alter table change_set_items drop constraint change_set_items_set_site_fk`.execute(db);\n await sql`alter table change_set_items drop column site_id`.execute(db);\n await sql`alter table change_sets drop constraint change_sets_id_site_uq`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Deploy adapters (plan agentic-ecosystem §B2): deployment connections may use the Vercel and Netlify\n * providers. The check is re-added NOT VALID and then validated, so existing rows are checked without\n * blocking writes for the scan.\n */\nconst WIDENED = sql`provider in ('generic_webhook', 'cloudflare_pages', 'vercel', 'netlify', 'github')`;\nconst ORIGINAL = sql`provider in ('generic_webhook', 'cloudflare_pages', 'github')`;\n\nconst replaceCheck = async (db: Kysely<unknown>, check: typeof WIDENED) => {\n await sql`alter table deployment_connections drop constraint deployment_connections_provider_check`.execute(\n db,\n );\n await sql`alter table deployment_connections add constraint deployment_connections_provider_check\n check (${check}) not valid`.execute(db);\n await sql`alter table deployment_connections validate constraint deployment_connections_provider_check`.execute(\n db,\n );\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await replaceCheck(db, WIDENED);\n};\n\n/** Refuses while Vercel or Netlify connections exist: a down migration never deletes user data. */\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const { rows } = await sql<{ count: string }>`\n select count(*)::text as count from deployment_connections where provider in ('vercel', 'netlify')\n `.execute(db);\n const count = Number(rows[0]?.count ?? 0);\n if (count > 0) {\n throw new Error(\n `Cannot roll back: ${count} deployment connection(s) use Vercel or Netlify. Delete them in the admin (Publishing → Deployments) first, then run the rollback again.`,\n );\n }\n await replaceCheck(db, ORIGINAL);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Editor assists (plan agentic-ecosystem §A0, §I): one `assist_runs` row per assist request (who, which\n * action, which model, token usage, duration, outcome). Never prompt or response text. Content-ops runs are\n * jobs: `job_id` points at the job whose result holds the proposals. Pruned by the retention job after\n * USAGE_RETENTION_DAYS. Change sets an assist run opens are marked `source = 'assist'`.\n */\nconst ACTIONS = sql`action in ('alt_text', 'summarize', 'translate', 'rewrite', 'schema_draft', 'content_ops')`;\nconst SOURCES_WIDENED = sql`source in ('manual', 'release', 'restore', 'builder', 'assist')`;\nconst SOURCES_ORIGINAL = sql`source in ('manual', 'release', 'restore', 'builder')`;\n\nconst replaceSourceCheck = async (db: Kysely<unknown>, check: typeof SOURCES_WIDENED) => {\n await sql`alter table change_sets drop constraint change_sets_source_check`.execute(db);\n await sql`alter table change_sets add constraint change_sets_source_check check (${check}) not valid`.execute(\n db,\n );\n await sql`alter table change_sets validate constraint change_sets_source_check`.execute(db);\n};\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .createTable('assist_runs')\n .addColumn('id', 'uuid', (col) => col.primaryKey().defaultTo(sql`gen_random_uuid()`))\n .addColumn('site_id', 'uuid', (col) => col.notNull().references('sites.id').onDelete('cascade'))\n // `admin` or `token` (the same actor types as audit events), and the admin user or token ID.\n .addColumn('actor_type', 'text', (col) => col.notNull())\n .addColumn('actor_id', 'text', (col) => col.notNull())\n .addColumn('action', 'text', (col) => col.notNull().check(ACTIONS))\n // The content-ops rule (`altMissing`, `localeMissing`); null for other actions.\n .addColumn('rule', 'text')\n .addColumn('provider', 'text', (col) => col.notNull())\n .addColumn('model', 'text', (col) => col.notNull())\n .addColumn('input_tokens', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('output_tokens', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('duration_ms', 'integer', (col) => col.notNull().defaultTo(0))\n .addColumn('status', 'text', (col) =>\n col.notNull().check(sql`status in ('queued', 'running', 'succeeded', 'failed')`),\n )\n .addColumn('error_code', 'text')\n .addColumn('job_id', 'uuid', (col) => col.references('jobs.id').onDelete('set null'))\n .addColumn('created_at', 'timestamptz', (col) => col.notNull().defaultTo(sql`now()`))\n .addColumn('finished_at', 'timestamptz')\n .execute();\n // Usage this month per site (status endpoint) and retention pruning by age.\n await db.schema\n .createIndex('assist_runs_site_created_idx')\n .on('assist_runs')\n .columns(['site_id', 'created_at'])\n .execute();\n await db.schema.createIndex('assist_runs_created_idx').on('assist_runs').column('created_at').execute();\n await replaceSourceCheck(db, SOURCES_WIDENED);\n};\n\n/** Refuses while change sets opened by assist exist: a down migration never deletes user data. */\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const { rows } = await sql<{ count: string }>`\n select count(*)::text as count from change_sets where source = 'assist'\n `.execute(db);\n const count = Number(rows[0]?.count ?? 0);\n if (count > 0) {\n throw new Error(\n `Cannot roll back: ${count} change set(s) were opened by assist. Discard and delete them first, then run the rollback again.`,\n );\n }\n await replaceSourceCheck(db, SOURCES_ORIGINAL);\n await db.schema.dropTable('assist_runs').execute();\n};\n","import type { Kysely } from 'kysely';\n\n/**\n * `audit_events.seq`: a monotonic tiebreaker after `occurred_at`, so events written in the same instant (one\n * transaction shares `now()`; SQLite and MySQL store milliseconds) list in the order they were written. The\n * UUID `id` is random and cannot order them. Adding an identity column rewrites the table once; existing rows\n * are numbered in the order the rewrite reads them. No index: the audit queries filter and sort by\n * `occurred_at` first, and `seq` only breaks ties.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema\n .alterTable('audit_events')\n .addColumn('seq', 'bigint', (col) => col.notNull().generatedAlwaysAsIdentity())\n .execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.alterTable('audit_events').dropColumn('seq').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Per-site schema (plan site-schema): a definition belongs to one site (`models.site_id`) or is shared by every\n * site (null, what every existing definition becomes). API IDs are unique per scope; whether a shared API ID\n * collides with a site's is the planner's rule (every view a change touches must stay valid), checked under\n * the schema lock. `schema_drafts.shared` says whether a change set's draft creates a shared definition; a\n * draft otherwise takes its change set's site. Nothing here runs DDL per model (CONTRIBUTING.md rule 1).\n *\n * `down` refuses while any definition belongs to a site: two sites may each have a `post`, which one index\n * over `lower(api_key)` cannot hold. Share or delete them first; then `down` is lossless.\n */\nconst NIL_UUID = '00000000-0000-0000-0000-000000000000';\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table models add column site_id uuid references sites (id)`.execute(db);\n await sql`create index models_site_idx on models (site_id)`.execute(db);\n await sql`drop index models_api_key_uq`.execute(db);\n await sql`\n create unique index models_api_key_uq on models (coalesce(site_id, ${sql.lit(NIL_UUID)}::uuid), lower(api_key))\n where deleted_at is null\n `.execute(db);\n await sql`alter table schema_drafts add column shared boolean not null default false`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const { rows } = await sql<{\n count: string;\n }>`select count(*)::text as count from models where site_id is not null`.execute(db);\n if (Number(rows[0]?.count ?? 0) > 0) {\n throw new Error(\n 'Cannot roll back per-site schema while definitions belong to a site: two sites may share an API ID. ' +\n 'Share or delete the site definitions first.',\n );\n }\n await sql`alter table schema_drafts drop column shared`.execute(db);\n await sql`drop index models_api_key_uq`.execute(db);\n await sql`create unique index models_api_key_uq on models (lower(api_key)) where deleted_at is null`.execute(\n db,\n );\n await sql`drop index models_site_idx`.execute(db);\n await sql`alter table models drop column site_id`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SEO defaults per site (plan seo-fields): `sites.seo_defaults` holds the site's default texts per locale, its\n * default social image and Twitter handle (`SeoDefaults` in @shapio/schema). Nullable, no default: a\n * catalog-only change, no table rewrite.\n *\n * `site.settings` is the site action that edits them. Every role that holds `publishing.manage` (everything\n * about what a site publishes) gets it; the built-in owner and admin roles get it from `ensureSystemRoles`.\n * The permissions version moves only when grants changed, so running instances reload exactly then.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table sites add column seo_defaults jsonb`.execute(db);\n await sql`\n with granted as (\n insert into admin_role_permissions (role_id, action, model_id, condition, field_ids)\n select role_id, 'site.settings', null, null, null\n from admin_role_permissions\n where action = 'publishing.manage' and model_id is null\n on conflict on constraint admin_role_permissions_grant_uq do nothing\n returning 1\n )\n update system_versions set permissions_version = permissions_version + 1, updated_at = now()\n where exists (select 1 from granted)\n `.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`\n with revoked as (\n delete from admin_role_permissions where action = 'site.settings' returning 1\n )\n update system_versions set permissions_version = permissions_version + 1, updated_at = now()\n where exists (select 1 from revoked)\n `.execute(db);\n await sql`alter table sites drop column seo_defaults`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * Delivery perf 2 (ADR 0001 amendment): the entry's `created_at` on each head (`entry_created_at`), so a list\n * in the default newest-first order walks `entry_heads_entry_order_idx` and stops at the page instead of\n * joining every matching head to `entries` and sorting them. `entries.created_at` never changes, and every head\n * insert copies it (repositories `entryHeads.insert`, `transferImport.insertHead`).\n *\n * The column is added nullable (a catalog-only change) and backfilled here in batches. The index is built\n * here on an empty table (a new install). With heads present it is built `CONCURRENTLY`, which cannot run\n * in a migration's transaction, by the `schema.entryOrderIndex` job this migration enqueues\n * (schema/planner/indexes.ts), so writes continue while it builds; queries are correct without it.\n */\nconst INDEX = 'entry_heads_entry_order_idx';\nconst JOB_TYPE = 'schema.entryOrderIndex';\nconst IDEMPOTENCY_KEY = 'schema.entryOrderIndex:v1';\nconst BATCH = 5000;\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table entry_heads add column entry_created_at timestamptz`.execute(db);\n for (;;) {\n const result = await sql`\n update entry_heads h set entry_created_at = e.created_at\n from entries e\n where e.id = h.entry_id and (h.entry_id, h.locale, h.state) in (\n select entry_id, locale, state from entry_heads where entry_created_at is null limit ${BATCH}\n )\n `.execute(db);\n if (Number(result.numAffectedRows ?? 0n) < BATCH) {\n break;\n }\n }\n const { rows } = await sql<{\n present: boolean;\n }>`select exists (select 1 from entry_heads) as present`.execute(db);\n if (rows[0]?.present) {\n await sql`\n insert into jobs (type, payload, max_attempts, idempotency_key)\n values (${JOB_TYPE}, '{}'::jsonb, 5, ${IDEMPOTENCY_KEY})\n on conflict do nothing\n `.execute(db);\n return;\n }\n await sql`\n create index ${sql.id(INDEX)} on entry_heads (site_id, model_id, state, entry_created_at desc, entry_id)\n `.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`delete from jobs where idempotency_key = ${IDEMPOTENCY_KEY} and status = 'pending'`.execute(db);\n await sql`drop index if exists ${sql.id(INDEX)}`.execute(db);\n await sql`alter table entry_heads drop column entry_created_at`.execute(db);\n};\n","import type { Kysely } from 'kysely';\n\n/**\n * In-process delivery (plan next-in-process §2): the Shapio release the server runs, written at every start\n * after migrating (`services/deliveryDescriptor.ts`). An in-process reader compares it with its own release on\n * every call and refuses to read across versions. Nullable: null until a server of this release starts.\n * Portable Kysely only, so every dialect runs this same module.\n */\nexport const dialectNeutral = true;\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.alterTable('system_versions').addColumn('release', 'text').execute();\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await db.schema.alterTable('system_versions').dropColumn('release').execute();\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * MySQL baseline: Shapio's whole system schema as of PostgreSQL migration\n * `20261003160000_create_assist_runs`, in one step, with the rows those migrations seed. Later migrations\n * follow the twin rule (`./index.ts`).\n *\n * Written from the migrated PostgreSQL catalog (types in `db/mysql/codec.ts`), then kept honest by\n * `test/mysqlBaseline.int.test.ts`, which migrates both databases and compares the logical schema and the\n * seeded rows. Differences that are deliberate:\n * - Tables default to `utf8mb4` with the binary `utf8mb4_0900_bin` collation (case-sensitive, NO PAD,\n * code point order); UUIDs are `CHAR(36)` ASCII with a case-insensitive collation, like PostgreSQL's uuid\n * input. Text in a key or index is `VARCHAR(n)` (`LONGTEXT` cannot be indexed whole); other text is\n * `LONGTEXT`.\n * - Partial unique indexes are unique indexes on `(case when <predicate> then <column> end)` key parts:\n * MySQL has no partial index, and a NULL key part never conflicts. Partial non-unique indexes are plain.\n * The three `NULLS NOT DISTINCT` constraints index `coalesce(column, '')`.\n * - `entry_heads_data_gin` (GIN, containment) has no MySQL equivalent and is left out.\n * - `entry_heads.change_seq` has no default: the MySQL plugin fills it from\n * `sequence_entry_heads_change_seq` (AUTO_INCREMENT, no lock held to commit). UUID keys default to\n * `uuid()` but the plugin fills them first (v4, known before the insert, for emulated RETURNING).\n * - `media_assets_folder_id_fkey` sets only `folder_id` to null on delete (PostgreSQL's column list),\n * which MySQL expresses as a trigger; immutability triggers signal SQLSTATE 45000. With binary logging\n * on, creating triggers needs SUPER or `log_bin_trust_function_creators = 1` (documentation/mysql.md).\n * - `editor_presence` is a plain table (UNLOGGED has no MySQL meaning).\n * - MySQL-only tables: `advisory_locks` (transaction-level advisory locks as row locks),\n * `notifications` (LISTEN/NOTIFY as a polled table), `sequence_entry_heads_change_seq`.\n * - Identity keys are `AUTO_INCREMENT`. MySQL creates an index for a foreign key no index covers.\n * MySQL runs DDL outside transactions: if the baseline fails part-way, drop the database's tables and\n * migrate again.\n */\nconst STATEMENTS: readonly string[] = [\n `create table \\`system_versions\\` (\n \\`id\\` tinyint(1) not null default 1,\n \\`schema_version\\` int not null default 0,\n \\`permissions_version\\` int not null default 0,\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`system_versions_pkey\\` primary key (\\`id\\`),\n constraint \\`system_versions_id_check\\` check (\\`id\\` = 1)\n)`,\n `create table \\`jobs\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`type\\` longtext not null,\n \\`payload\\` json not null default (json_object()),\n \\`status\\` longtext not null default ('pending'),\n \\`priority\\` int not null default 0,\n \\`run_at\\` datetime(6) not null default current_timestamp(6),\n \\`attempts\\` int not null default 0,\n \\`max_attempts\\` int not null default 10,\n \\`idempotency_key\\` varchar(512),\n \\`locked_by\\` longtext,\n \\`locked_until\\` datetime(6),\n \\`checkpoint\\` json,\n \\`result\\` json,\n \\`last_error\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`finished_at\\` datetime(6),\n constraint \\`jobs_pkey\\` primary key (\\`id\\`),\n constraint \\`jobs_max_attempts_check\\` check ((\\`max_attempts\\` > 0)),\n constraint \\`jobs_status_check\\` check ((\\`status\\` in ('pending', 'running', 'succeeded', 'dead')))\n)`,\n `create table \\`outbox_events\\` (\n \\`id\\` bigint not null auto_increment,\n \\`event_id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`type\\` longtext not null,\n \\`aggregate_type\\` longtext not null,\n \\`aggregate_id\\` longtext not null,\n \\`payload\\` json not null default (json_object()),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`dispatched_at\\` datetime(6),\n \\`dispatch_attempts\\` int not null default 0,\n \\`last_dispatch_error\\` longtext,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci,\n unique key \\`outbox_events_event_id_key\\` (\\`event_id\\`),\n constraint \\`outbox_events_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`audit_events\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`occurred_at\\` datetime(6) not null default current_timestamp(6),\n \\`actor_type\\` varchar(64) not null,\n \\`actor_id\\` varchar(255),\n \\`action\\` longtext not null,\n \\`target_type\\` varchar(64),\n \\`target_id\\` varchar(255),\n \\`outcome\\` longtext not null,\n \\`request_id\\` longtext,\n \\`ip\\` longtext,\n \\`metadata\\` json not null default (json_object()),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci,\n constraint \\`audit_events_pkey\\` primary key (\\`id\\`),\n constraint \\`audit_events_actor_type_check\\` check ((\\`actor_type\\` in ('admin', 'app_user', 'token', 'anonymous', 'system'))),\n constraint \\`audit_events_outcome_check\\` check ((\\`outcome\\` in ('success', 'failure')))\n)`,\n `create table \\`admin_users\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`email\\` varchar(255) not null,\n \\`name\\` longtext not null default (''),\n \\`password_hash\\` longtext not null,\n \\`status\\` longtext not null default ('active'),\n \\`last_login_at\\` datetime(6),\n \\`password_changed_at\\` datetime(6) not null default current_timestamp(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`admin_users_email_key\\` (\\`email\\`),\n constraint \\`admin_users_pkey\\` primary key (\\`id\\`),\n constraint \\`admin_users_status_check\\` check ((\\`status\\` in ('active', 'disabled')))\n)`,\n `create table \\`admin_roles\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`key\\` varchar(64) not null,\n \\`name\\` longtext not null,\n \\`description\\` longtext not null default (''),\n \\`kind\\` longtext not null default ('admin'),\n \\`is_system\\` tinyint(1) not null default 0,\n \\`version\\` int not null default 1,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`admin_roles_key_key\\` (\\`key\\`),\n constraint \\`admin_roles_pkey\\` primary key (\\`id\\`),\n constraint \\`admin_roles_key_check\\` check ((regexp_like(\\`key\\`, '^[a-z][a-z0-9-]{0,62}$', 'c'))),\n constraint \\`admin_roles_kind_check\\` check ((\\`kind\\` in ('admin', 'delivery')))\n)`,\n `create table \\`admin_role_permissions\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`action\\` varchar(64) not null,\n \\`model_id\\` varchar(255),\n \\`condition\\` longtext,\n \\`field_ids\\` json,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`admin_role_permissions_grant_uq\\` (\\`role_id\\`, \\`action\\`, (coalesce(\\`model_id\\`, ''))),\n constraint \\`admin_role_permissions_pkey\\` primary key (\\`id\\`),\n constraint \\`admin_role_permissions_condition_check\\` check ((\\`condition\\` = 'ownedByPrincipal'))\n)`,\n `create table \\`admin_user_roles\\` (\n \\`admin_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n unique key \\`admin_user_roles_assignment_uq\\` (\\`admin_user_id\\`, \\`role_id\\`, (coalesce(\\`site_id\\`, ''))),\n constraint \\`admin_user_roles_pk\\` primary key (\\`id\\`)\n)`,\n `create table \\`admin_sessions\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`admin_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`token_hash\\` varchar(128) not null,\n \\`csrf_secret\\` longtext not null,\n \\`ip\\` longtext,\n \\`user_agent\\` longtext,\n \\`last_seen_at\\` datetime(6) not null default current_timestamp(6),\n \\`expires_at\\` datetime(6) not null,\n \\`revoked_at\\` datetime(6),\n \\`rotation_required\\` tinyint(1) not null default 0,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`admin_sessions_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`admin_sessions_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`admin_invitations\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`email\\` varchar(255) not null,\n \\`token_hash\\` varchar(128),\n \\`invited_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`expires_at\\` datetime(6) not null,\n \\`accepted_at\\` datetime(6),\n \\`revoked_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`role_assignments\\` json not null default (json_array()),\n unique key \\`admin_invitations_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`admin_invitations_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`password_resets\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`admin_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`token_hash\\` varchar(128),\n \\`expires_at\\` datetime(6) not null,\n \\`used_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`password_resets_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`password_resets_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`setup_tokens\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`token_hash\\` varchar(128) not null,\n \\`used_at\\` datetime(6),\n \\`superseded_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`setup_tokens_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`setup_tokens_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`api_tokens\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`name\\` longtext not null,\n \\`token_hash\\` varchar(128) not null,\n \\`token_prefix\\` longtext not null,\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`expires_at\\` datetime(6),\n \\`last_used_at\\` datetime(6),\n \\`revoked_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci,\n unique key \\`api_tokens_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`api_tokens_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`system_settings\\` (\n \\`key\\` varchar(64) not null,\n \\`value\\` longtext not null,\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`system_settings_pkey\\` primary key (\\`key\\`)\n)`,\n `create table \\`models\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`kind\\` longtext not null,\n \\`api_key\\` varchar(255) not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`deleted_at\\` datetime(6),\n constraint \\`models_pkey\\` primary key (\\`id\\`),\n constraint \\`models_kind_check\\` check ((\\`kind\\` in ('collection', 'singleton', 'component')))\n)`,\n `create table \\`schema_revisions\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`version\\` int not null,\n \\`definition\\` json not null,\n \\`hash\\` longtext not null,\n \\`parent_revision_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_by_type\\` longtext not null,\n \\`created_by_id\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`schema_revisions_model_version_uq\\` (\\`model_id\\`, \\`version\\`),\n constraint \\`schema_revisions_pkey\\` primary key (\\`id\\`),\n constraint \\`schema_revisions_version_check\\` check ((\\`version\\` > 0))\n)`,\n `create table \\`model_active_versions\\` (\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`revision_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`version\\` int not null,\n \\`schema_version\\` int not null,\n \\`activated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`model_active_versions_pkey\\` primary key (\\`model_id\\`)\n)`,\n `create table \\`schema_change_jobs\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`target_type\\` varchar(64) not null,\n \\`target_id\\` varchar(255) not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`from_revision_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`to_revision_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`status\\` longtext not null default ('pending'),\n \\`plan\\` json not null default (json_object()),\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`error\\` json,\n \\`requested_by_type\\` longtext not null,\n \\`requested_by_id\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`finished_at\\` datetime(6),\n \\`change_set_id\\` char(36) character set ascii collate ascii_general_ci,\n constraint \\`schema_change_jobs_pkey\\` primary key (\\`id\\`),\n constraint \\`schema_change_jobs_status_check\\` check ((\\`status\\` in ('pending', 'running', 'activated', 'failed', 'cancelled'))),\n constraint \\`schema_change_jobs_target_type_check\\` check ((\\`target_type\\` in ('model', 'locale')))\n)`,\n `create table \\`locales\\` (\n \\`code\\` varchar(64) not null,\n \\`label\\` longtext not null,\n \\`is_default\\` tinyint(1) not null default 0,\n \\`fallbacks\\` json not null default (json_array()),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`locales_pkey\\` primary key (\\`code\\`)\n)`,\n `create table \\`schema_settings\\` (\n \\`id\\` tinyint(1) not null default 1,\n \\`read_only\\` tinyint(1) not null default 0,\n \\`read_only_reason\\` longtext,\n \\`updated_by_type\\` longtext,\n \\`updated_by_id\\` longtext,\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`schema_settings_pkey\\` primary key (\\`id\\`),\n constraint \\`schema_settings_id_check\\` check (\\`id\\` = 1)\n)`,\n `create table \\`entries\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`owner_app_user_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_by_admin_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`deleted_at\\` datetime(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`entries_id_site_uq\\` (\\`id\\`, \\`site_id\\`),\n constraint \\`entries_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`content_revisions\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`schema_revision_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`data\\` json not null,\n \\`reason\\` longtext not null,\n \\`author_type\\` longtext not null,\n \\`author_id\\` longtext,\n \\`parent_revision_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`content_revisions_pkey\\` primary key (\\`id\\`),\n constraint \\`content_revisions_reason_check\\` check ((\\`reason\\` in ('create', 'save', 'publish', 'restore', 'duplicate', 'localize', 'conversion')))\n)`,\n `create table \\`entry_heads\\` (\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`state\\` varchar(64) not null,\n \\`revision_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`data\\` json not null,\n \\`autosaved_at\\` datetime(6),\n \\`version\\` int not null default 1,\n \\`change_seq\\` bigint not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`entry_heads_pkey\\` primary key (\\`entry_id\\`, \\`locale\\`, \\`state\\`),\n constraint \\`entry_heads_state_check\\` check ((\\`state\\` in ('draft', 'published')))\n)`,\n `create table \\`relation_edges\\` (\n \\`source_entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`state\\` varchar(64) not null,\n \\`field_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`position\\` int not null,\n \\`target_entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`relation_edges_pkey\\` primary key (\\`source_entry_id\\`, \\`locale\\`, \\`state\\`, \\`field_id\\`, \\`position\\`)\n)`,\n `create table \\`unique_values\\` (\n \\`field_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`state\\` varchar(64) not null,\n \\`value_hash\\` varchar(128) not null,\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`unique_values_pkey\\` primary key (\\`site_id\\`, \\`field_id\\`, \\`locale\\`, \\`state\\`, \\`value_hash\\`),\n constraint \\`unique_values_state_check\\` check ((\\`state\\` in ('draft', 'published')))\n)`,\n `create table \\`publication_state\\` (\n \\`last_seq\\` bigint not null default 0,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`publication_state_pkey\\` primary key (\\`site_id\\`)\n)`,\n `create table \\`publication_log\\` (\n \\`id\\` bigint not null auto_increment,\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`revision_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`from_seq\\` bigint not null,\n \\`to_seq\\` bigint,\n \\`published_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`publication_log_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`media_folders\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`parent_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`name\\` varchar(255) not null,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`version\\` int not null default 1,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`media_folders_id_site_uq\\` (\\`id\\`, \\`site_id\\`),\n constraint \\`media_folders_pkey\\` primary key (\\`id\\`),\n constraint \\`media_folders_name_check\\` check (((char_length(\\`name\\`) >= 1) AND (char_length(\\`name\\`) <= 255)))\n)`,\n `create table \\`media_assets\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`folder_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`storage_driver\\` varchar(64) not null,\n \\`storage_key\\` varchar(768) not null,\n \\`original_filename\\` longtext not null,\n \\`mime_type\\` longtext not null,\n \\`size_bytes\\` bigint not null,\n \\`width\\` int,\n \\`height\\` int,\n \\`checksum_sha256\\` longtext,\n \\`alt\\` longtext not null default (''),\n \\`caption\\` longtext not null default (''),\n \\`focal_x\\` float,\n \\`focal_y\\` float,\n \\`visibility\\` longtext not null default ('public'),\n \\`status\\` longtext not null default ('processing'),\n \\`processing_error\\` longtext,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`version\\` int not null default 1,\n \\`deleted_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`media_assets_pkey\\` primary key (\\`id\\`),\n constraint \\`media_assets_focal_point_ck\\` check (((\\`focal_x\\` IS NULL) = (\\`focal_y\\` IS NULL))),\n constraint \\`media_assets_focal_x_check\\` check (((\\`focal_x\\` >= (0)) AND (\\`focal_x\\` <= (1)))),\n constraint \\`media_assets_focal_y_check\\` check (((\\`focal_y\\` >= (0)) AND (\\`focal_y\\` <= (1)))),\n constraint \\`media_assets_status_check\\` check ((\\`status\\` in ('processing', 'ready', 'failed'))),\n constraint \\`media_assets_storage_driver_check\\` check ((\\`storage_driver\\` in ('local', 's3'))),\n constraint \\`media_assets_visibility_check\\` check ((\\`visibility\\` in ('public', 'private')))\n)`,\n `create table \\`media_variants\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`asset_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`name\\` varchar(255) not null,\n \\`width\\` int,\n \\`height\\` int,\n \\`format\\` longtext not null,\n \\`mime_type\\` longtext not null,\n \\`storage_key\\` varchar(768),\n \\`size_bytes\\` bigint,\n \\`checksum_sha256\\` longtext,\n \\`status\\` longtext not null default ('pending'),\n \\`error\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`media_variants_asset_name_uq\\` (\\`asset_id\\`, \\`name\\`),\n constraint \\`media_variants_pkey\\` primary key (\\`id\\`),\n constraint \\`media_variants_status_check\\` check ((\\`status\\` in ('pending', 'ready', 'failed')))\n)`,\n `create table \\`media_references\\` (\n \\`asset_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`field_id\\` varchar(255) not null,\n \\`locale\\` varchar(64) not null,\n \\`state\\` varchar(64) not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`media_references_pk\\` primary key (\\`asset_id\\`, \\`entry_id\\`, \\`locale\\`, \\`state\\`, \\`field_id\\`),\n constraint \\`media_references_state_check\\` check ((\\`state\\` in ('draft', 'published')))\n)`,\n `create table \\`media_upload_grants\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`asset_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`kind\\` longtext not null,\n \\`storage_driver\\` longtext not null,\n \\`storage_key\\` varchar(768) not null,\n \\`original_filename\\` longtext not null,\n \\`declared_mime_type\\` longtext not null,\n \\`max_size_bytes\\` bigint not null,\n \\`folder_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`visibility\\` longtext not null,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_by_principal\\` longtext not null,\n \\`status\\` longtext not null default ('pending'),\n \\`expires_at\\` datetime(6) not null,\n \\`consumed_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`media_upload_grants_storage_key_key\\` (\\`storage_key\\`),\n constraint \\`media_upload_grants_pkey\\` primary key (\\`id\\`),\n constraint \\`media_upload_grants_kind_check\\` check ((\\`kind\\` in ('create', 'replace'))),\n constraint \\`media_upload_grants_status_check\\` check ((\\`status\\` in ('pending', 'consumed', 'rejected', 'expired'))),\n constraint \\`media_upload_grants_storage_driver_check\\` check ((\\`storage_driver\\` in ('local', 's3'))),\n constraint \\`media_upload_grants_visibility_check\\` check ((\\`visibility\\` in ('public', 'private')))\n)`,\n `create table \\`scheduled_publications\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`action\\` longtext not null,\n \\`run_at\\` datetime(6) not null,\n \\`status\\` varchar(64) not null default 'scheduled',\n \\`created_by_token\\` char(36) character set ascii collate ascii_general_ci,\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`snapshot_seq\\` bigint,\n \\`error\\` longtext,\n \\`executed_at\\` datetime(6),\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`scheduled_publications_pkey\\` primary key (\\`id\\`),\n constraint \\`scheduled_publications_action_check\\` check ((\\`action\\` in ('publish', 'unpublish'))),\n constraint \\`scheduled_publications_status_check\\` check ((\\`status\\` in ('scheduled', 'done', 'failed', 'cancelled')))\n)`,\n `create table \\`webhooks\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`name\\` longtext not null,\n \\`url\\` longtext not null,\n \\`events\\` json not null default (json_array()),\n \\`enabled\\` tinyint(1) not null default 1,\n \\`secret_encrypted\\` longtext not null,\n \\`allow_private_network\\` tinyint(1) not null default 0,\n \\`max_attempts\\` int not null default 8,\n \\`version\\` int not null default 1,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci,\n constraint \\`webhooks_pkey\\` primary key (\\`id\\`),\n constraint \\`webhooks_max_attempts_check\\` check (((\\`max_attempts\\` >= 1) AND (\\`max_attempts\\` <= 20))),\n constraint \\`webhooks_name_check\\` check (((char_length(\\`name\\`) >= 1) AND (char_length(\\`name\\`) <= 200)))\n)`,\n `create table \\`webhook_deliveries\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`webhook_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`event_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`event_type\\` longtext not null,\n \\`payload\\` json not null,\n \\`is_test\\` tinyint(1) not null default 0,\n \\`status\\` longtext not null default ('pending'),\n \\`attempts\\` int not null default 0,\n \\`last_response_status\\` int,\n \\`last_error\\` longtext,\n \\`attempt_log\\` json not null default (json_array()),\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`delivered_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`webhook_deliveries_pkey\\` primary key (\\`id\\`),\n constraint \\`webhook_deliveries_status_check\\` check ((\\`status\\` in ('pending', 'retrying', 'succeeded', 'dead')))\n)`,\n `create table \\`deployment_connections\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`name\\` longtext not null,\n \\`provider\\` longtext not null,\n \\`settings\\` json not null default (json_object()),\n \\`secrets_encrypted\\` longtext not null,\n \\`secret_env_refs\\` json not null default (json_object()),\n \\`delivery_role_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`preview_url_template\\` longtext,\n \\`trigger_policy\\` json not null default (json_array()),\n \\`debounce_seconds\\` int not null default 10,\n \\`allow_private_network\\` tinyint(1) not null default 0,\n \\`enabled\\` tinyint(1) not null default 1,\n \\`version\\` int not null default 1,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`deployment_connections_pkey\\` primary key (\\`id\\`),\n constraint \\`deployment_connections_debounce_seconds_check\\` check (((\\`debounce_seconds\\` >= 0) AND (\\`debounce_seconds\\` <= 3600))),\n constraint \\`deployment_connections_name_check\\` check (((char_length(\\`name\\`) >= 1) AND (char_length(\\`name\\`) <= 200))),\n constraint \\`deployment_connections_provider_check\\` check ((\\`provider\\` in ('generic_webhook', 'cloudflare_pages', 'vercel', 'netlify', 'github')))\n)`,\n `create table \\`deployment_runs\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`connection_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`status\\` longtext not null default ('queued'),\n \\`status_rank\\` int not null default 0,\n \\`trigger\\` longtext not null,\n \\`snapshot_seq\\` bigint,\n \\`schema_version\\` int,\n \\`retry_of\\` char(36) character set ascii collate ascii_general_ci,\n \\`provider_ref\\` longtext,\n \\`log_url\\` longtext,\n \\`site_url\\` longtext,\n \\`error\\` longtext,\n \\`timeline\\` json not null default (json_array()),\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`triggered_at\\` datetime(6),\n \\`finished_at\\` datetime(6),\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`change_set_id\\` char(36) character set ascii collate ascii_general_ci,\n constraint \\`deployment_runs_pkey\\` primary key (\\`id\\`),\n constraint \\`deployment_runs_status_check\\` check ((\\`status\\` in ('queued', 'triggered', 'building', 'deployed', 'failed', 'unknown'))),\n constraint \\`deployment_runs_trigger_check\\` check ((\\`trigger\\` in ('publish', 'change_set', 'schema', 'manual', 'retry')))\n)`,\n `create table \\`preview_tokens\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`token_hash\\` varchar(128) not null,\n \\`token_prefix\\` longtext not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` longtext,\n \\`connection_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`delivery_role_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`expires_at\\` datetime(6) not null,\n \\`revoked_at\\` datetime(6),\n \\`last_used_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`preview_tokens_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`preview_tokens_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`app_users\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`email\\` varchar(255) not null,\n \\`name\\` longtext not null default (''),\n \\`password_hash\\` longtext,\n \\`confirmed_at\\` datetime(6),\n \\`blocked_at\\` datetime(6),\n \\`last_login_at\\` datetime(6),\n \\`password_changed_at\\` datetime(6),\n \\`deleted_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`token_version\\` int not null default 0,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`app_users_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`app_roles\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`key\\` varchar(64) not null,\n \\`name\\` longtext not null,\n \\`description\\` longtext not null default (''),\n \\`is_system\\` tinyint(1) not null default 0,\n \\`version\\` int not null default 1,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`app_roles_key_key\\` (\\`key\\`),\n constraint \\`app_roles_pkey\\` primary key (\\`id\\`),\n constraint \\`app_roles_key_check\\` check ((regexp_like(\\`key\\`, '^[a-z][a-z0-9-]{0,62}$', 'c')))\n)`,\n `create table \\`app_role_permissions\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`action\\` varchar(64) not null,\n \\`model_id\\` varchar(255),\n \\`condition\\` longtext,\n \\`field_ids\\` json,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`app_role_permissions_grant_uq\\` (\\`role_id\\`, \\`action\\`, (coalesce(\\`model_id\\`, ''))),\n constraint \\`app_role_permissions_pkey\\` primary key (\\`id\\`),\n constraint \\`app_role_permissions_action_check\\` check ((\\`action\\` in ('read', 'create', 'update', 'delete', 'publish'))),\n constraint \\`app_role_permissions_condition_check\\` check ((\\`condition\\` = 'ownedByPrincipal'))\n)`,\n `create table \\`app_user_roles\\` (\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`app_user_roles_pk\\` primary key (\\`app_user_id\\`, \\`role_id\\`)\n)`,\n `create table \\`app_refresh_tokens\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`family_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`token_hash\\` varchar(128) not null,\n \\`expires_at\\` datetime(6) not null,\n \\`used_at\\` datetime(6),\n \\`reuse_grace_used_at\\` datetime(6),\n \\`revoked_at\\` datetime(6),\n \\`revoked_reason\\` longtext,\n \\`ip\\` longtext,\n \\`user_agent\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`app_refresh_tokens_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`app_refresh_tokens_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`app_oauth_accounts\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`provider\\` varchar(64) not null,\n \\`provider_user_id\\` varchar(255) not null,\n \\`email\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`app_oauth_accounts_identity_uq\\` (\\`site_id\\`, \\`provider\\`, \\`provider_user_id\\`),\n constraint \\`app_oauth_accounts_pkey\\` primary key (\\`id\\`),\n constraint \\`app_oauth_accounts_provider_check\\` check ((\\`provider\\` in ('google', 'github')))\n)`,\n `create table \\`email_confirmations\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`email\\` longtext not null,\n \\`token_hash\\` varchar(128),\n \\`expires_at\\` datetime(6) not null,\n \\`used_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`email_confirmations_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`email_confirmations_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`app_password_resets\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`email\\` longtext not null,\n \\`token_hash\\` varchar(128),\n \\`expires_at\\` datetime(6) not null,\n \\`used_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`app_password_resets_token_hash_key\\` (\\`token_hash\\`),\n constraint \\`app_password_resets_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`app_login_codes\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`app_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`code_hash\\` varchar(128) not null,\n \\`expires_at\\` datetime(6) not null,\n \\`used_at\\` datetime(6),\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`code_challenge\\` longtext not null,\n unique key \\`app_login_codes_code_hash_key\\` (\\`code_hash\\`),\n constraint \\`app_login_codes_pkey\\` primary key (\\`id\\`)\n)`,\n `create table \\`extension_hook_runs\\` (\n \\`event_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`hook\\` varchar(255) not null,\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`completed_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`extension_hook_runs_pkey\\` primary key (\\`event_id\\`, \\`hook\\`)\n)`,\n `create table \\`field_reads\\` (\n \\`day\\` date not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`field_path\\` varchar(400) not null,\n \\`principal_key\\` varchar(255) not null,\n \\`selection\\` varchar(64) not null,\n \\`reads\\` bigint not null default 0,\n \\`last_read_at\\` datetime(6) not null,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`field_reads_pkey\\` primary key (\\`day\\`, \\`site_id\\`, \\`model_id\\`, \\`field_path\\`, \\`principal_key\\`, \\`selection\\`),\n constraint \\`field_reads_selection_check\\` check ((\\`selection\\` in ('explicit', 'implicit')))\n)`,\n `create table \\`token_reads\\` (\n \\`day\\` date not null,\n \\`principal_key\\` varchar(255) not null,\n \\`requests\\` bigint not null default 0,\n \\`last_snapshot\\` bigint,\n \\`last_read_at\\` datetime(6) not null,\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`token_reads_pkey\\` primary key (\\`day\\`, \\`site_id\\`, \\`principal_key\\`)\n)`,\n `create table \\`change_sets\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`title\\` longtext not null,\n \\`description\\` longtext not null default (''),\n \\`status\\` varchar(64) not null default 'open',\n \\`ship_phase\\` longtext,\n \\`source\\` longtext not null default ('manual'),\n \\`restore_of_seq\\` bigint,\n \\`scheduled_for\\` datetime(6),\n \\`schedule_job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`scheduled_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`scheduled_by_token\\` char(36) character set ascii collate ascii_general_ci,\n \\`ship_job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`ship_mode\\` longtext,\n \\`ship_requested_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`ship_requested_by_token\\` char(36) character set ascii collate ascii_general_ci,\n \\`acknowledge_breaking\\` tinyint(1) not null default 0,\n \\`acknowledge_destructive\\` tinyint(1) not null default 0,\n \\`deployment_connection_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`deployment_run_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`shipped_at\\` datetime(6),\n \\`shipped_seq\\` bigint,\n \\`schema_version_after\\` int,\n \\`error\\` json,\n \\`restore_report\\` json not null default (json_array()),\n \\`created_by\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_by_token\\` char(36) character set ascii collate ascii_general_ci,\n \\`version\\` int not null default 1,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`change_sets_id_site_uq\\` (\\`id\\`, \\`site_id\\`),\n constraint \\`change_sets_pkey\\` primary key (\\`id\\`),\n constraint \\`change_sets_ship_mode_check\\` check ((\\`ship_mode\\` in ('interactive', 'scheduled'))),\n constraint \\`change_sets_ship_phase_check\\` check ((\\`ship_phase\\` in ('preparing', 'activating'))),\n constraint \\`change_sets_source_check\\` check ((\\`source\\` in ('manual', 'release', 'restore', 'builder', 'assist'))),\n constraint \\`change_sets_status_check\\` check ((\\`status\\` in ('open', 'scheduled', 'shipping', 'shipped', 'failed', 'discarded'))),\n constraint \\`change_sets_title_check\\` check (((char_length(\\`title\\`) >= 1) AND (char_length(\\`title\\`) <= 200)))\n)`,\n `create table \\`schema_drafts\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`change_set_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`definition_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`kind\\` longtext not null,\n \\`api_key\\` longtext not null,\n \\`base_version\\` int,\n \\`definition\\` json,\n \\`version\\` int not null default 1,\n \\`updated_by_type\\` longtext not null,\n \\`updated_by_id\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`schema_drafts_set_definition_uq\\` (\\`change_set_id\\`, \\`definition_id\\`),\n constraint \\`schema_drafts_pkey\\` primary key (\\`id\\`),\n constraint \\`schema_drafts_kind_check\\` check ((\\`kind\\` in ('collection', 'singleton', 'component')))\n)`,\n `create table \\`change_set_items\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`change_set_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`kind\\` longtext not null,\n \\`position\\` int not null,\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`locale\\` varchar(64),\n \\`action\\` longtext,\n \\`source_revision_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`schema_draft_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`status\\` longtext not null default ('pending'),\n \\`error\\` longtext,\n \\`ship_state\\` json,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`change_set_items_pkey\\` primary key (\\`id\\`),\n constraint \\`change_set_items_action_check\\` check ((\\`action\\` in ('publish', 'unpublish'))),\n constraint \\`change_set_items_kind_check\\` check ((\\`kind\\` in ('entry', 'schema'))),\n constraint \\`change_set_items_shape_check\\` check ((((\\`kind\\` = 'entry') AND (\\`entry_id\\` IS NOT NULL) AND (\\`model_id\\` IS NOT NULL) AND (\\`locale\\` IS NOT NULL) AND (\\`action\\` IS NOT NULL) AND (\\`schema_draft_id\\` IS NULL)) OR ((\\`kind\\` = 'schema') AND (\\`schema_draft_id\\` IS NOT NULL) AND (\\`entry_id\\` IS NULL) AND (\\`source_revision_id\\` IS NULL)))),\n constraint \\`change_set_items_status_check\\` check ((\\`status\\` in ('pending', 'done', 'failed')))\n)`,\n `create table \\`publication_snapshots\\` (\n \\`seq\\` bigint not null,\n \\`schema_version\\` int,\n \\`source\\` longtext not null,\n \\`change_set_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`actor_type\\` longtext,\n \\`actor_id\\` longtext,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n constraint \\`publication_snapshots_pkey\\` primary key (\\`site_id\\`, \\`seq\\`)\n)`,\n `create table \\`editor_presence\\` (\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`admin_user_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`tab_id\\` varchar(64) not null,\n \\`locale\\` longtext,\n \\`started_at\\` datetime(6) not null default current_timestamp(6),\n \\`last_seen_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`editor_presence_pkey\\` primary key (\\`entry_id\\`, \\`admin_user_id\\`, \\`tab_id\\`),\n constraint \\`editor_presence_tab_id_check\\` check (((char_length(\\`tab_id\\`) >= 1) AND (char_length(\\`tab_id\\`) <= 64)))\n)`,\n `create table \\`content_health_findings\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`entry_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`model_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`locale\\` varchar(64) not null,\n \\`rule\\` varchar(255) not null,\n \\`subject\\` varchar(255) not null default '',\n \\`severity\\` longtext not null,\n \\`path\\` longtext,\n \\`details\\` json not null default (json_object()),\n \\`first_seen_at\\` datetime(6) not null default current_timestamp(6),\n \\`last_seen_at\\` datetime(6) not null default current_timestamp(6),\n \\`resolved_at\\` datetime(6),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n unique key \\`content_health_findings_entry_id_locale_rule_subject_key\\` (\\`entry_id\\`, \\`locale\\`, \\`rule\\`, \\`subject\\`),\n constraint \\`content_health_findings_pkey\\` primary key (\\`id\\`),\n constraint \\`content_health_findings_severity_check\\` check ((\\`severity\\` in ('error', 'warning')))\n)`,\n `create table \\`sites\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`key\\` varchar(64) not null,\n \\`name\\` longtext not null,\n \\`is_primary\\` tinyint(1) not null default 0,\n \\`version\\` int not null default 1,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`updated_at\\` datetime(6) not null default current_timestamp(6),\n unique key \\`sites_key_key\\` (\\`key\\`),\n constraint \\`sites_pkey\\` primary key (\\`id\\`),\n constraint \\`sites_key_check\\` check ((regexp_like(\\`key\\`, '^[a-z][a-z0-9-]{0,62}$', 'c'))),\n constraint \\`sites_name_check\\` check (((char_length(\\`name\\`) >= 1) AND (char_length(\\`name\\`) <= 200)))\n)`,\n `create table \\`site_app_roles\\` (\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`audience\\` varchar(64) not null,\n \\`role_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`site_app_roles_pkey\\` primary key (\\`site_id\\`, \\`audience\\`, \\`role_id\\`),\n constraint \\`site_app_roles_audience_check\\` check ((\\`audience\\` in ('public', 'authenticated')))\n)`,\n `create table \\`assist_runs\\` (\n \\`id\\` char(36) character set ascii collate ascii_general_ci not null default (uuid()),\n \\`site_id\\` char(36) character set ascii collate ascii_general_ci not null,\n \\`actor_type\\` longtext not null,\n \\`actor_id\\` longtext not null,\n \\`action\\` longtext not null,\n \\`rule\\` longtext,\n \\`provider\\` longtext not null,\n \\`model\\` longtext not null,\n \\`input_tokens\\` int not null default 0,\n \\`output_tokens\\` int not null default 0,\n \\`duration_ms\\` int not null default 0,\n \\`status\\` longtext not null,\n \\`error_code\\` longtext,\n \\`job_id\\` char(36) character set ascii collate ascii_general_ci,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n \\`finished_at\\` datetime(6),\n constraint \\`assist_runs_pkey\\` primary key (\\`id\\`),\n constraint \\`assist_runs_action_check\\` check ((\\`action\\` in ('alt_text', 'summarize', 'translate', 'rewrite', 'schema_draft', 'content_ops'))),\n constraint \\`assist_runs_status_check\\` check ((\\`status\\` in ('queued', 'running', 'succeeded', 'failed')))\n)`,\n `alter table \\`outbox_events\\` add constraint \\`outbox_events_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete set null`,\n `alter table \\`audit_events\\` add constraint \\`audit_events_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete set null`,\n `alter table \\`admin_role_permissions\\` add constraint \\`admin_role_permissions_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`admin_roles\\` (\\`id\\`) on delete cascade`,\n `alter table \\`admin_user_roles\\` add constraint \\`admin_user_roles_admin_user_id_fkey\\` foreign key (\\`admin_user_id\\`) references \\`admin_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`admin_user_roles\\` add constraint \\`admin_user_roles_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`admin_roles\\` (\\`id\\`) on delete restrict`,\n `alter table \\`admin_user_roles\\` add constraint \\`admin_user_roles_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`admin_sessions\\` add constraint \\`admin_sessions_admin_user_id_fkey\\` foreign key (\\`admin_user_id\\`) references \\`admin_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`admin_invitations\\` add constraint \\`admin_invitations_invited_by_fkey\\` foreign key (\\`invited_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`password_resets\\` add constraint \\`password_resets_admin_user_id_fkey\\` foreign key (\\`admin_user_id\\`) references \\`admin_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`api_tokens\\` add constraint \\`api_tokens_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`api_tokens\\` add constraint \\`api_tokens_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`admin_roles\\` (\\`id\\`) on delete restrict`,\n `alter table \\`api_tokens\\` add constraint \\`api_tokens_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`schema_revisions\\` add constraint \\`schema_revisions_model_id_fkey\\` foreign key (\\`model_id\\`) references \\`models\\` (\\`id\\`) on delete restrict`,\n `alter table \\`schema_revisions\\` add constraint \\`schema_revisions_parent_revision_id_fkey\\` foreign key (\\`parent_revision_id\\`) references \\`schema_revisions\\` (\\`id\\`)`,\n `alter table \\`model_active_versions\\` add constraint \\`model_active_versions_model_id_fkey\\` foreign key (\\`model_id\\`) references \\`models\\` (\\`id\\`) on delete cascade`,\n `alter table \\`model_active_versions\\` add constraint \\`model_active_versions_revision_id_fkey\\` foreign key (\\`revision_id\\`) references \\`schema_revisions\\` (\\`id\\`)`,\n `alter table \\`schema_change_jobs\\` add constraint \\`schema_change_jobs_change_set_id_fkey\\` foreign key (\\`change_set_id\\`) references \\`change_sets\\` (\\`id\\`) on delete set null`,\n `alter table \\`schema_change_jobs\\` add constraint \\`schema_change_jobs_from_revision_id_fkey\\` foreign key (\\`from_revision_id\\`) references \\`schema_revisions\\` (\\`id\\`)`,\n `alter table \\`schema_change_jobs\\` add constraint \\`schema_change_jobs_job_id_fkey\\` foreign key (\\`job_id\\`) references \\`jobs\\` (\\`id\\`) on delete set null`,\n `alter table \\`schema_change_jobs\\` add constraint \\`schema_change_jobs_model_id_fkey\\` foreign key (\\`model_id\\`) references \\`models\\` (\\`id\\`)`,\n `alter table \\`schema_change_jobs\\` add constraint \\`schema_change_jobs_to_revision_id_fkey\\` foreign key (\\`to_revision_id\\`) references \\`schema_revisions\\` (\\`id\\`)`,\n `alter table \\`entries\\` add constraint \\`entries_created_by_admin_id_fkey\\` foreign key (\\`created_by_admin_id\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`entries\\` add constraint \\`entries_model_id_fkey\\` foreign key (\\`model_id\\`) references \\`models\\` (\\`id\\`) on delete restrict`,\n `alter table \\`entries\\` add constraint \\`entries_owner_app_user_fk\\` foreign key (\\`owner_app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`entries\\` add constraint \\`entries_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`content_revisions\\` add constraint \\`content_revisions_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete restrict`,\n `alter table \\`content_revisions\\` add constraint \\`content_revisions_parent_revision_id_fkey\\` foreign key (\\`parent_revision_id\\`) references \\`content_revisions\\` (\\`id\\`)`,\n `alter table \\`content_revisions\\` add constraint \\`content_revisions_schema_revision_id_fkey\\` foreign key (\\`schema_revision_id\\`) references \\`schema_revisions\\` (\\`id\\`)`,\n `alter table \\`entry_heads\\` add constraint \\`entry_heads_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`entry_heads\\` add constraint \\`entry_heads_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`entry_heads\\` add constraint \\`entry_heads_revision_id_fkey\\` foreign key (\\`revision_id\\`) references \\`content_revisions\\` (\\`id\\`)`,\n `alter table \\`entry_heads\\` add constraint \\`entry_heads_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`relation_edges\\` add constraint \\`relation_edges_head_fk\\` foreign key (\\`source_entry_id\\`, \\`locale\\`, \\`state\\`) references \\`entry_heads\\` (\\`entry_id\\`, \\`locale\\`, \\`state\\`) on delete cascade`,\n `alter table \\`relation_edges\\` add constraint \\`relation_edges_target_entry_id_fkey\\` foreign key (\\`target_entry_id\\`) references \\`entries\\` (\\`id\\`)`,\n `alter table \\`unique_values\\` add constraint \\`unique_values_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`unique_values\\` add constraint \\`unique_values_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`unique_values\\` add constraint \\`unique_values_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`publication_state\\` add constraint \\`publication_state_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`publication_log\\` add constraint \\`publication_log_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`)`,\n `alter table \\`publication_log\\` add constraint \\`publication_log_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete restrict`,\n `alter table \\`publication_log\\` add constraint \\`publication_log_revision_id_fkey\\` foreign key (\\`revision_id\\`) references \\`content_revisions\\` (\\`id\\`)`,\n `alter table \\`publication_log\\` add constraint \\`publication_log_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`media_folders\\` add constraint \\`media_folders_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`media_folders\\` add constraint \\`media_folders_parent_id_fkey\\` foreign key (\\`parent_id\\`, \\`site_id\\`) references \\`media_folders\\` (\\`id\\`, \\`site_id\\`) on delete restrict`,\n `alter table \\`media_folders\\` add constraint \\`media_folders_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`media_assets\\` add constraint \\`media_assets_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`media_assets\\` add constraint \\`media_assets_folder_id_fkey\\` foreign key (\\`folder_id\\`, \\`site_id\\`) references \\`media_folders\\` (\\`id\\`, \\`site_id\\`)`,\n `alter table \\`media_assets\\` add constraint \\`media_assets_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`media_variants\\` add constraint \\`media_variants_asset_id_fkey\\` foreign key (\\`asset_id\\`) references \\`media_assets\\` (\\`id\\`) on delete cascade`,\n `alter table \\`media_references\\` add constraint \\`media_references_asset_id_fkey\\` foreign key (\\`asset_id\\`) references \\`media_assets\\` (\\`id\\`) on delete cascade`,\n `alter table \\`media_references\\` add constraint \\`media_references_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`media_upload_grants\\` add constraint \\`media_upload_grants_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`media_upload_grants\\` add constraint \\`media_upload_grants_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`scheduled_publications\\` add constraint \\`scheduled_publications_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`scheduled_publications\\` add constraint \\`scheduled_publications_created_by_token_fkey\\` foreign key (\\`created_by_token\\`) references \\`api_tokens\\` (\\`id\\`) on delete set null`,\n `alter table \\`scheduled_publications\\` add constraint \\`scheduled_publications_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`scheduled_publications\\` add constraint \\`scheduled_publications_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`scheduled_publications\\` add constraint \\`scheduled_publications_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`webhooks\\` add constraint \\`webhooks_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`webhooks\\` add constraint \\`webhooks_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`webhook_deliveries\\` add constraint \\`webhook_deliveries_webhook_id_fkey\\` foreign key (\\`webhook_id\\`) references \\`webhooks\\` (\\`id\\`) on delete cascade`,\n `alter table \\`deployment_connections\\` add constraint \\`deployment_connections_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`deployment_connections\\` add constraint \\`deployment_connections_delivery_role_id_fkey\\` foreign key (\\`delivery_role_id\\`) references \\`admin_roles\\` (\\`id\\`) on delete set null`,\n `alter table \\`deployment_connections\\` add constraint \\`deployment_connections_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`deployment_runs\\` add constraint \\`deployment_runs_change_set_id_fkey\\` foreign key (\\`change_set_id\\`) references \\`change_sets\\` (\\`id\\`) on delete set null`,\n `alter table \\`deployment_runs\\` add constraint \\`deployment_runs_connection_id_fkey\\` foreign key (\\`connection_id\\`) references \\`deployment_connections\\` (\\`id\\`) on delete cascade`,\n `alter table \\`deployment_runs\\` add constraint \\`deployment_runs_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`deployment_runs\\` add constraint \\`deployment_runs_retry_of_fkey\\` foreign key (\\`retry_of\\`) references \\`deployment_runs\\` (\\`id\\`) on delete set null`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_connection_id_fkey\\` foreign key (\\`connection_id\\`) references \\`deployment_connections\\` (\\`id\\`) on delete set null`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_delivery_role_id_fkey\\` foreign key (\\`delivery_role_id\\`) references \\`admin_roles\\` (\\`id\\`) on delete set null`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`preview_tokens\\` add constraint \\`preview_tokens_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_users\\` add constraint \\`app_users_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`app_role_permissions\\` add constraint \\`app_role_permissions_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`app_roles\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_user_roles\\` add constraint \\`app_user_roles_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_user_roles\\` add constraint \\`app_user_roles_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`app_roles\\` (\\`id\\`) on delete restrict`,\n `alter table \\`app_user_roles\\` add constraint \\`app_user_roles_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`app_refresh_tokens\\` add constraint \\`app_refresh_tokens_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_oauth_accounts\\` add constraint \\`app_oauth_accounts_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_oauth_accounts\\` add constraint \\`app_oauth_accounts_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`email_confirmations\\` add constraint \\`email_confirmations_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_password_resets\\` add constraint \\`app_password_resets_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`app_login_codes\\` add constraint \\`app_login_codes_app_user_id_fkey\\` foreign key (\\`app_user_id\\`) references \\`app_users\\` (\\`id\\`) on delete cascade`,\n `alter table \\`field_reads\\` add constraint \\`field_reads_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`token_reads\\` add constraint \\`token_reads_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_created_by_fkey\\` foreign key (\\`created_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_created_by_token_fkey\\` foreign key (\\`created_by_token\\`) references \\`api_tokens\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_deployment_connection_id_fkey\\` foreign key (\\`deployment_connection_id\\`) references \\`deployment_connections\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_deployment_run_id_fkey\\` foreign key (\\`deployment_run_id\\`) references \\`deployment_runs\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_scheduled_by_fkey\\` foreign key (\\`scheduled_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_scheduled_by_token_fkey\\` foreign key (\\`scheduled_by_token\\`) references \\`api_tokens\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_ship_requested_by_fkey\\` foreign key (\\`ship_requested_by\\`) references \\`admin_users\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_ship_requested_by_token_fkey\\` foreign key (\\`ship_requested_by_token\\`) references \\`api_tokens\\` (\\`id\\`) on delete set null`,\n `alter table \\`change_sets\\` add constraint \\`change_sets_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`schema_drafts\\` add constraint \\`schema_drafts_change_set_id_fkey\\` foreign key (\\`change_set_id\\`) references \\`change_sets\\` (\\`id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_change_set_id_fkey\\` foreign key (\\`change_set_id\\`) references \\`change_sets\\` (\\`id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_schema_draft_id_fkey\\` foreign key (\\`schema_draft_id\\`) references \\`schema_drafts\\` (\\`id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_set_site_fk\\` foreign key (\\`change_set_id\\`, \\`site_id\\`) references \\`change_sets\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`change_set_items\\` add constraint \\`change_set_items_source_revision_id_fkey\\` foreign key (\\`source_revision_id\\`) references \\`content_revisions\\` (\\`id\\`)`,\n `alter table \\`publication_snapshots\\` add constraint \\`publication_snapshots_change_set_id_fkey\\` foreign key (\\`change_set_id\\`) references \\`change_sets\\` (\\`id\\`) on delete set null`,\n `alter table \\`publication_snapshots\\` add constraint \\`publication_snapshots_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`content_health_findings\\` add constraint \\`content_health_findings_entry_id_fkey\\` foreign key (\\`entry_id\\`) references \\`entries\\` (\\`id\\`) on delete cascade`,\n `alter table \\`content_health_findings\\` add constraint \\`content_health_findings_entry_site_fk\\` foreign key (\\`entry_id\\`, \\`site_id\\`) references \\`entries\\` (\\`id\\`, \\`site_id\\`) on delete cascade`,\n `alter table \\`content_health_findings\\` add constraint \\`content_health_findings_site_fk\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete restrict`,\n `alter table \\`site_app_roles\\` add constraint \\`site_app_roles_role_id_fkey\\` foreign key (\\`role_id\\`) references \\`app_roles\\` (\\`id\\`) on delete cascade`,\n `alter table \\`site_app_roles\\` add constraint \\`site_app_roles_site_id_fkey\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `alter table \\`assist_runs\\` add constraint \\`assist_runs_job_id_fkey\\` foreign key (\\`job_id\\`) references \\`jobs\\` (\\`id\\`) on delete set null`,\n `alter table \\`assist_runs\\` add constraint \\`assist_runs_site_id_fkey\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`) on delete cascade`,\n `create index \\`admin_invitations_pending_email_idx\\` on \\`admin_invitations\\` (\\`email\\`)`,\n `create index \\`admin_sessions_user_idx\\` on \\`admin_sessions\\` (\\`admin_user_id\\`)`,\n `create index \\`admin_user_roles_role_idx\\` on \\`admin_user_roles\\` (\\`role_id\\`)`,\n `create index \\`api_tokens_role_idx\\` on \\`api_tokens\\` (\\`role_id\\`)`,\n `create index \\`app_oauth_accounts_user_idx\\` on \\`app_oauth_accounts\\` (\\`app_user_id\\`)`,\n `create index \\`app_password_resets_user_idx\\` on \\`app_password_resets\\` (\\`app_user_id\\`)`,\n `create index \\`app_refresh_tokens_family_idx\\` on \\`app_refresh_tokens\\` (\\`family_id\\`)`,\n `create index \\`app_refresh_tokens_user_idx\\` on \\`app_refresh_tokens\\` (\\`app_user_id\\`)`,\n `create index \\`app_user_roles_role_idx\\` on \\`app_user_roles\\` (\\`role_id\\`)`,\n `create index \\`app_users_created_idx\\` on \\`app_users\\` (\\`site_id\\`, \\`created_at\\` desc, \\`id\\` desc)`,\n `create unique index \\`app_users_email_uq\\` on \\`app_users\\` ((case when (\\`deleted_at\\` IS NULL) then \\`site_id\\` end), (case when (\\`deleted_at\\` IS NULL) then lower(\\`email\\`) end))`,\n `create index \\`assist_runs_created_idx\\` on \\`assist_runs\\` (\\`created_at\\`)`,\n `create index \\`assist_runs_site_created_idx\\` on \\`assist_runs\\` (\\`site_id\\`, \\`created_at\\`)`,\n `create index \\`audit_events_actor_idx\\` on \\`audit_events\\` (\\`actor_type\\`, \\`actor_id\\`, \\`occurred_at\\` desc)`,\n `create index \\`audit_events_occurred_at_idx\\` on \\`audit_events\\` (\\`occurred_at\\` desc)`,\n `create index \\`audit_events_target_idx\\` on \\`audit_events\\` (\\`target_type\\`, \\`target_id\\`, \\`occurred_at\\` desc)`,\n `create unique index \\`change_set_items_draft_uq\\` on \\`change_set_items\\` (\\`schema_draft_id\\`)`,\n `create index \\`change_set_items_entry_idx\\` on \\`change_set_items\\` (\\`entry_id\\`)`,\n `create unique index \\`change_set_items_entry_uq\\` on \\`change_set_items\\` ((case when (\\`kind\\` = 'entry') then \\`change_set_id\\` end), (case when (\\`kind\\` = 'entry') then \\`entry_id\\` end), (case when (\\`kind\\` = 'entry') then \\`locale\\` end))`,\n `create index \\`change_set_items_set_idx\\` on \\`change_set_items\\` (\\`change_set_id\\`, \\`position\\`)`,\n `create index \\`change_sets_status_idx\\` on \\`change_sets\\` (\\`site_id\\`, \\`status\\`, \\`created_at\\` desc)`,\n `create index \\`content_health_findings_open_idx\\` on \\`content_health_findings\\` (\\`site_id\\`, \\`rule\\`, \\`last_seen_at\\` desc, \\`id\\`)`,\n `create index \\`content_health_findings_resolved_idx\\` on \\`content_health_findings\\` (\\`resolved_at\\`)`,\n `create index \\`content_revisions_entry_idx\\` on \\`content_revisions\\` (\\`entry_id\\`, \\`locale\\`, \\`created_at\\`)`,\n `create index \\`deployment_runs_connection_idx\\` on \\`deployment_runs\\` (\\`connection_id\\`, \\`created_at\\` desc)`,\n `create unique index \\`deployment_runs_queued_uq\\` on \\`deployment_runs\\` ((case when (\\`status\\` = 'queued') then \\`connection_id\\` end))`,\n `create index \\`editor_presence_model_idx\\` on \\`editor_presence\\` (\\`model_id\\`, \\`last_seen_at\\`)`,\n `create index \\`editor_presence_seen_idx\\` on \\`editor_presence\\` (\\`last_seen_at\\`)`,\n `create index \\`email_confirmations_user_idx\\` on \\`email_confirmations\\` (\\`app_user_id\\`)`,\n `create index \\`entries_model_idx\\` on \\`entries\\` (\\`site_id\\`, \\`model_id\\`, \\`created_at\\`)`,\n `create index \\`entries_owner_idx\\` on \\`entries\\` (\\`owner_app_user_id\\`)`,\n `create index \\`entry_heads_change_seq_idx\\` on \\`entry_heads\\` (\\`model_id\\`, \\`change_seq\\`)`,\n `create index \\`entry_heads_model_locale_state_idx\\` on \\`entry_heads\\` (\\`site_id\\`, \\`model_id\\`, \\`locale\\`, \\`state\\`)`,\n `create index \\`field_reads_model_day_idx\\` on \\`field_reads\\` (\\`model_id\\`, \\`day\\`)`,\n `create unique index \\`jobs_idempotency_key_uq\\` on \\`jobs\\` (\\`idempotency_key\\`)`,\n `create index \\`jobs_pending_idx\\` on \\`jobs\\` (\\`priority\\` desc, \\`run_at\\`)`,\n `create index \\`jobs_running_lease_idx\\` on \\`jobs\\` (\\`locked_until\\`)`,\n `create unique index \\`locales_single_default_uq\\` on \\`locales\\` ((case when \\`is_default\\` then \\`is_default\\` end))`,\n `create index \\`media_assets_created_idx\\` on \\`media_assets\\` (\\`site_id\\`, \\`created_at\\`, \\`id\\`)`,\n `create index \\`media_assets_driver_idx\\` on \\`media_assets\\` (\\`storage_driver\\`, \\`id\\`)`,\n `create index \\`media_assets_folder_idx\\` on \\`media_assets\\` (\\`folder_id\\`, \\`created_at\\`, \\`id\\`)`,\n `create unique index \\`media_assets_storage_key_uq\\` on \\`media_assets\\` (\\`storage_key\\`)`,\n `create unique index \\`media_folders_sibling_name_uq\\` on \\`media_folders\\` (\\`site_id\\`, (COALESCE(\\`parent_id\\`, '00000000-0000-0000-0000-000000000000')), (lower(\\`name\\`)))`,\n `create index \\`media_references_entry_idx\\` on \\`media_references\\` (\\`entry_id\\`, \\`locale\\`, \\`state\\`)`,\n `create unique index \\`media_variants_storage_key_uq\\` on \\`media_variants\\` (\\`storage_key\\`)`,\n `create unique index \\`models_api_key_uq\\` on \\`models\\` ((case when (\\`deleted_at\\` IS NULL) then lower(\\`api_key\\`) end))`,\n `create index \\`outbox_events_undispatched_idx\\` on \\`outbox_events\\` (\\`id\\`)`,\n `create index \\`password_resets_user_idx\\` on \\`password_resets\\` (\\`admin_user_id\\`)`,\n `create index \\`preview_tokens_entry_idx\\` on \\`preview_tokens\\` (\\`entry_id\\`, \\`created_at\\` desc)`,\n `create index \\`publication_log_entry_locale_from_idx\\` on \\`publication_log\\` (\\`entry_id\\`, \\`locale\\`, \\`from_seq\\`)`,\n `create index \\`publication_log_model_seq_idx\\` on \\`publication_log\\` (\\`site_id\\`, \\`model_id\\`, \\`from_seq\\`)`,\n `create unique index \\`publication_log_open_uq\\` on \\`publication_log\\` ((case when (\\`to_seq\\` IS NULL) then \\`entry_id\\` end), (case when (\\`to_seq\\` IS NULL) then \\`locale\\` end))`,\n `create index \\`publication_log_to_seq_idx\\` on \\`publication_log\\` (\\`site_id\\`, \\`to_seq\\`)`,\n `create index \\`publication_snapshots_change_set_idx\\` on \\`publication_snapshots\\` (\\`change_set_id\\`)`,\n `create index \\`relation_edges_target_idx\\` on \\`relation_edges\\` (\\`target_entry_id\\`, \\`state\\`)`,\n `create index \\`scheduled_publications_entry_idx\\` on \\`scheduled_publications\\` (\\`entry_id\\`, \\`locale\\`)`,\n `create index \\`scheduled_publications_site_idx\\` on \\`scheduled_publications\\` (\\`site_id\\`, \\`run_at\\`)`,\n `create index \\`scheduled_publications_status_idx\\` on \\`scheduled_publications\\` (\\`status\\`, \\`run_at\\`)`,\n `create index \\`schema_change_jobs_change_set_idx\\` on \\`schema_change_jobs\\` (\\`change_set_id\\`)`,\n `create unique index \\`schema_change_jobs_in_flight_uq\\` on \\`schema_change_jobs\\` ((case when (\\`status\\` in ('pending', 'running')) then \\`target_type\\` end), (case when (\\`status\\` in ('pending', 'running')) then \\`target_id\\` end))`,\n `create index \\`schema_change_jobs_model_idx\\` on \\`schema_change_jobs\\` (\\`model_id\\`, \\`created_at\\` desc)`,\n `create index \\`schema_drafts_definition_idx\\` on \\`schema_drafts\\` (\\`definition_id\\`)`,\n `create index \\`site_app_roles_role_idx\\` on \\`site_app_roles\\` (\\`role_id\\`)`,\n `create unique index \\`sites_single_primary_uq\\` on \\`sites\\` ((case when \\`is_primary\\` then \\`is_primary\\` end))`,\n `create index \\`unique_values_entry_idx\\` on \\`unique_values\\` (\\`entry_id\\`)`,\n `create unique index \\`webhook_deliveries_event_uq\\` on \\`webhook_deliveries\\` (\\`webhook_id\\`, \\`event_id\\`)`,\n `create index \\`webhook_deliveries_webhook_idx\\` on \\`webhook_deliveries\\` (\\`webhook_id\\`, \\`created_at\\` desc)`,\n `create table \\`advisory_locks\\` (\n \\`namespace\\` int not null,\n \\`lock_key\\` int not null,\n constraint \\`advisory_locks_pkey\\` primary key (\\`namespace\\`, \\`lock_key\\`)\n)`,\n `create table \\`notifications\\` (\n \\`id\\` bigint not null auto_increment,\n \\`channel\\` varchar(64) not null,\n \\`payload\\` longtext not null,\n \\`created_at\\` datetime(6) not null default current_timestamp(6),\n constraint \\`notifications_pkey\\` primary key (\\`id\\`)\n)`,\n `create index \\`notifications_created_idx\\` on \\`notifications\\` (\\`created_at\\`)`,\n `create table \\`sequence_entry_heads_change_seq\\` (\n \\`value\\` bigint not null auto_increment,\n constraint \\`sequence_entry_heads_change_seq_pkey\\` primary key (\\`value\\`)\n)`,\n `create trigger \\`media_assets_folder_id_fkey_set_null\\` before delete on \\`media_folders\\` for each row\n update \\`media_assets\\` set \\`folder_id\\` = null where \\`folder_id\\` = old.\\`id\\` and \\`site_id\\` = old.\\`site_id\\``,\n `create trigger \\`schema_revisions_no_update\\` before update on \\`schema_revisions\\` for each row\n signal sqlstate '45000' set message_text = 'schema_revisions rows are immutable'`,\n `create trigger \\`content_revisions_no_update\\` before update on \\`content_revisions\\` for each row\n signal sqlstate '45000' set message_text = 'content_revisions rows are immutable'`,\n `insert into \\`system_versions\\` () values ()`,\n `insert into \\`schema_settings\\` () values ()`,\n `insert into \\`locales\\` (\\`code\\`, \\`label\\`, \\`is_default\\`) values ('en', 'English', 1)`,\n `insert into \\`sites\\` (\\`id\\`, \\`key\\`, \\`name\\`, \\`is_primary\\`) values ('00000000-0000-4000-b000-000000000001', 'default', 'Default site', 1)`,\n `insert into \\`publication_state\\` (\\`site_id\\`, \\`last_seq\\`) values ('00000000-0000-4000-b000-000000000001', 0)`,\n `insert into \\`app_roles\\` (\\`id\\`, \\`key\\`, \\`name\\`, \\`description\\`, \\`is_system\\`) values\n ('00000000-0000-4000-a000-000000000001', 'public', 'Public', 'Applies to every caller without a token. Grants nothing until you add permissions.', 1),\n ('00000000-0000-4000-a000-000000000002', 'authenticated', 'Authenticated', 'Held by every signed-in app user, in addition to their custom roles. Grants nothing until you add permissions.', 1)`,\n `insert into \\`site_app_roles\\` (\\`site_id\\`, \\`audience\\`, \\`role_id\\`) values\n ('00000000-0000-4000-b000-000000000001', 'public', '00000000-0000-4000-a000-000000000001'),\n ('00000000-0000-4000-b000-000000000001', 'authenticated', '00000000-0000-4000-a000-000000000002')`,\n];\n\nconst TABLES: readonly string[] = [\n 'system_versions',\n 'jobs',\n 'outbox_events',\n 'audit_events',\n 'admin_users',\n 'admin_roles',\n 'admin_role_permissions',\n 'admin_user_roles',\n 'admin_sessions',\n 'admin_invitations',\n 'password_resets',\n 'setup_tokens',\n 'api_tokens',\n 'system_settings',\n 'models',\n 'schema_revisions',\n 'model_active_versions',\n 'schema_change_jobs',\n 'locales',\n 'schema_settings',\n 'entries',\n 'content_revisions',\n 'entry_heads',\n 'relation_edges',\n 'unique_values',\n 'publication_state',\n 'publication_log',\n 'media_folders',\n 'media_assets',\n 'media_variants',\n 'media_references',\n 'media_upload_grants',\n 'scheduled_publications',\n 'webhooks',\n 'webhook_deliveries',\n 'deployment_connections',\n 'deployment_runs',\n 'preview_tokens',\n 'app_users',\n 'app_roles',\n 'app_role_permissions',\n 'app_user_roles',\n 'app_refresh_tokens',\n 'app_oauth_accounts',\n 'email_confirmations',\n 'app_password_resets',\n 'app_login_codes',\n 'extension_hook_runs',\n 'field_reads',\n 'token_reads',\n 'change_sets',\n 'schema_drafts',\n 'change_set_items',\n 'publication_snapshots',\n 'editor_presence',\n 'content_health_findings',\n 'sites',\n 'site_app_roles',\n 'assist_runs',\n 'advisory_locks',\n 'notifications',\n 'sequence_entry_heads_change_seq',\n];\n\n/** Runs the statements on one connection, where `foreign_key_checks` is off (tables reference in cycles). */\nconst withoutForeignKeyChecks = async (db: Kysely<unknown>, statements: readonly string[]) =>\n db.connection().execute(async (connection) => {\n await sql`set foreign_key_checks = 0`.execute(connection);\n try {\n for (const statement of statements) {\n await sql.raw(statement).execute(connection);\n }\n } finally {\n await sql`set foreign_key_checks = 1`.execute(connection);\n }\n });\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => withoutForeignKeyChecks(db, STATEMENTS);\n\nexport const down = async (db: Kysely<unknown>): Promise<void> =>\n withoutForeignKeyChecks(\n db,\n [...TABLES].reverse().map((table) => `drop table if exists \\`${table}\\``),\n );\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * MySQL twin of `../20261003170000_audit_events_seq.ts`: `seq` is `AUTO_INCREMENT`, which InnoDB only allows\n * on an indexed column, hence `audit_events_seq_key` (MySQL only; PostgreSQL and SQLite need no index for a\n * tiebreaker). Existing rows are numbered in primary-key order. `db/mysql/tables.ts` lists `seq` as the\n * table's identity, so an insert's emulated RETURNING finds its row by `LAST_INSERT_ID()`.\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \\`audit_events\\`\n add column \\`seq\\` bigint not null auto_increment,\n add unique key \\`audit_events_seq_key\\` (\\`seq\\`)`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \\`audit_events\\` drop column \\`seq\\``.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * MySQL twin of `../20261004120000_models_site_scope.ts`. The per-scope API ID key uses functional key parts,\n * like the baseline: `coalesce(site_id, '')` for the scope (MySQL has no `NULLS NOT DISTINCT`) and the\n * case-folded API ID of live rows only (a deleted row's part is NULL, and NULLs never collide).\n */\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \\`models\\` add column \\`site_id\\` char(36) character set ascii collate ascii_general_ci`.execute(\n db,\n );\n await sql`create index \\`models_site_idx\\` on \\`models\\` (\\`site_id\\`)`.execute(db);\n await sql`alter table \\`models\\` add constraint \\`models_site_id_fkey\\` foreign key (\\`site_id\\`) references \\`sites\\` (\\`id\\`)`.execute(\n db,\n );\n await sql`drop index \\`models_api_key_uq\\` on \\`models\\``.execute(db);\n await sql`create unique index \\`models_api_key_uq\\` on \\`models\\`\n ((coalesce(\\`site_id\\`, '')), (case when (\\`deleted_at\\` IS NULL) then lower(\\`api_key\\`) end))`.execute(\n db,\n );\n await sql`alter table \\`schema_drafts\\` add column \\`shared\\` tinyint(1) not null default 0`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const { rows } = await sql<{\n count: number;\n }>`select count(*) as count from \\`models\\` where \\`site_id\\` is not null`.execute(db);\n if (Number(rows[0]?.count ?? 0) > 0) {\n throw new Error(\n 'Cannot roll back per-site schema while definitions belong to a site: two sites may share an API ID. ' +\n 'Share or delete the site definitions first.',\n );\n }\n await sql`alter table \\`schema_drafts\\` drop column \\`shared\\``.execute(db);\n await sql`drop index \\`models_api_key_uq\\` on \\`models\\``.execute(db);\n await sql`create unique index \\`models_api_key_uq\\` on \\`models\\`\n ((case when (\\`deleted_at\\` IS NULL) then lower(\\`api_key\\`) end))`.execute(db);\n await sql`alter table \\`models\\` drop foreign key \\`models_site_id_fkey\\``.execute(db);\n await sql`drop index \\`models_site_idx\\` on \\`models\\``.execute(db);\n await sql`alter table \\`models\\` drop column \\`site_id\\``.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * MySQL twin of `../20261004130000_site_seo_settings.ts`. `insert ignore` stands in for `on conflict do\n * nothing` (the grant's unique key); the permissions version moves only when a grant was added or removed.\n */\nconst bumpPermissionsVersion = (db: Kysely<unknown>) =>\n sql`update \\`system_versions\\` set \\`permissions_version\\` = \\`permissions_version\\` + 1,\n \\`updated_at\\` = current_timestamp(6)`.execute(db);\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \\`sites\\` add column \\`seo_defaults\\` json`.execute(db);\n const granted = await sql`\n insert ignore into \\`admin_role_permissions\\` (\\`id\\`, \\`role_id\\`, \\`action\\`, \\`model_id\\`, \\`condition\\`, \\`field_ids\\`)\n select uuid(), \\`role_id\\`, 'site.settings', null, null, null\n from \\`admin_role_permissions\\`\n where \\`action\\` = 'publishing.manage' and \\`model_id\\` is null\n `.execute(db);\n if (Number(granted.numAffectedRows ?? 0) > 0) {\n await bumpPermissionsVersion(db);\n }\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const revoked =\n await sql`delete from \\`admin_role_permissions\\` where \\`action\\` = 'site.settings'`.execute(db);\n if (Number(revoked.numAffectedRows ?? 0) > 0) {\n await bumpPermissionsVersion(db);\n }\n await sql`alter table \\`sites\\` drop column \\`seo_defaults\\``.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * MySQL twin of `../20261005120000_entry_heads_entry_created_at.ts`. The column is added `ALGORITHM=INSTANT`\n * and backfilled in batches; the index is built online (`ALGORITHM=INPLACE, LOCK=NONE`), so writes continue.\n * It is one more index of `entry_heads`, which is why `MYSQL_MAX_FIELD_INDEXES` (db/limits.ts) went down by one.\n */\nconst INDEX = 'entry_heads_entry_order_idx';\nconst BATCH = 5000;\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \\`entry_heads\\` add column \\`entry_created_at\\` datetime(6), algorithm=instant`.execute(\n db,\n );\n for (;;) {\n const result = await sql`update \\`entry_heads\\` set \\`entry_created_at\\` = (\n select e.\\`created_at\\` from \\`entries\\` e where e.\\`id\\` = \\`entry_heads\\`.\\`entry_id\\`\n ) where \\`entry_created_at\\` is null limit ${sql.lit(BATCH)}`.execute(db);\n if (Number(result.numAffectedRows ?? 0n) < BATCH) {\n break;\n }\n }\n await sql`create index ${sql.id(INDEX)} on \\`entry_heads\\`\n (\\`site_id\\`, \\`model_id\\`, \\`state\\`, \\`entry_created_at\\` desc, \\`entry_id\\`) algorithm=inplace lock=none`.execute(\n db,\n );\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`drop index ${sql.id(INDEX)} on \\`entry_heads\\``.execute(db);\n await sql`alter table \\`entry_heads\\` drop column \\`entry_created_at\\``.execute(db);\n};\n","import type { Migration } from 'kysely/migration';\nimport * as systemVersionsRelease from '../20261006120000_system_versions_release.js';\nimport * as baseline from './0001_baseline.js';\nimport * as auditEventsSeq from './20261003170000_audit_events_seq.js';\nimport * as modelsSiteScope from './20261004120000_models_site_scope.js';\nimport * as siteSeoSettings from './20261004130000_site_seo_settings.js';\nimport * as entryHeadsEntryCreatedAt from './20261005120000_entry_heads_entry_created_at.js';\n\n/**\n * MySQL migrations. `0001_baseline` creates the schema the PostgreSQL migrations up to and including\n * `MYSQL_BASELINE_COVERS` build. Every later migration follows the twin rule (CONTRIBUTING.md): it exists\n * under the same name in every list, either as a MySQL twin in this folder or, when it only uses portable\n * Kysely (`export const dialectNeutral = true`), as the very same module. `../twins.test.ts` enforces it.\n */\nexport const MYSQL_BASELINE_COVERS = '20261003160000_create_assist_runs';\n\nexport const MYSQL_MIGRATIONS: Readonly<Record<string, Migration>> = {\n '0001_baseline': baseline,\n '20261003170000_audit_events_seq': auditEventsSeq,\n '20261004120000_models_site_scope': modelsSiteScope,\n '20261004130000_site_seo_settings': siteSeoSettings,\n '20261005120000_entry_heads_entry_created_at': entryHeadsEntryCreatedAt,\n '20261006120000_system_versions_release': systemVersionsRelease,\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SQLite baseline: Shapio's whole system schema as of PostgreSQL migration\n * `20261003160000_create_assist_runs`, in one step, with the rows those migrations seed. Later migrations\n * follow the twin rule (`./index.ts`).\n *\n * Written from the migrated PostgreSQL catalog with the type mapping in `db/sqlite/codec.ts`, then kept\n * honest by `test/sqliteBaseline.int.test.ts`, which migrates both databases and compares the logical\n * schema (tables, columns, nullability, defaults, keys, foreign keys, indexes, seed rows). Differences that\n * are deliberate:\n * - UNIQUE constraints are named unique indexes (SQLite only names those in its errors); the three\n * `NULLS NOT DISTINCT` ones index `coalesce(column, '')` (`db/sqlite/nullsNotDistinct.ts`).\n * - `entry_heads_data_gin` (GIN, containment queries) has no SQLite equivalent and is left out.\n * - The `entry_heads_change_seq` sequence is a row in `sequences`, advanced by `shapio_nextval()`.\n * - `media_assets_folder_id_fkey` sets only `folder_id` to null on delete (PostgreSQL's column list), which\n * SQLite expresses as a trigger.\n * - `editor_presence` is a plain table (UNLOGGED has no SQLite meaning); the immutability triggers raise.\n * - Identity keys (`outbox_events.id`, `publication_log.id`) are `integer primary key autoincrement`.\n * Defaults call functions Shapio registers on every connection (`db/sqlite/functions.ts`).\n */\nconst STATEMENTS: readonly string[] = [\n `create table \"system_versions\" (\n \"id\" integer_boolean not null default 1,\n \"schema_version\" integer not null default 0,\n \"permissions_version\" integer not null default 0,\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"system_versions_id_check\" CHECK (id),\n constraint \"system_versions_pkey\" primary key (id)\n )`,\n `create table \"jobs\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"type\" text not null,\n \"payload\" text_jsonb not null default ('{}'),\n \"status\" text not null default ('pending'),\n \"priority\" integer not null default 0,\n \"run_at\" text_timestamptz not null default (shapio_now()),\n \"attempts\" integer not null default 0,\n \"max_attempts\" integer not null default 10,\n \"idempotency_key\" text,\n \"locked_by\" text,\n \"locked_until\" text_timestamptz,\n \"checkpoint\" text_jsonb,\n \"result\" text_jsonb,\n \"last_error\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"finished_at\" text_timestamptz,\n constraint \"jobs_max_attempts_check\" CHECK ((max_attempts > 0)),\n constraint \"jobs_status_check\" CHECK ((status IN ('pending', 'running', 'succeeded', 'dead'))),\n constraint \"jobs_pkey\" primary key (id)\n )`,\n `create table \"outbox_events\" (\n \"id\" integer primary key autoincrement,\n \"event_id\" text_uuid not null default (gen_random_uuid()),\n \"type\" text not null,\n \"aggregate_type\" text not null,\n \"aggregate_id\" text not null,\n \"payload\" text_jsonb not null default ('{}'),\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"dispatched_at\" text_timestamptz,\n \"dispatch_attempts\" integer not null default 0,\n \"last_dispatch_error\" text,\n \"site_id\" text_uuid,\n constraint \"outbox_events_site_fk\" foreign key (site_id) references sites (id) on delete set null\n )`,\n `create unique index \"outbox_events_event_id_key\" on \"outbox_events\" (event_id)`,\n `create table \"audit_events\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"occurred_at\" text_timestamptz not null default (shapio_now()),\n \"actor_type\" text not null,\n \"actor_id\" text,\n \"action\" text not null,\n \"target_type\" text,\n \"target_id\" text,\n \"outcome\" text not null,\n \"request_id\" text,\n \"ip\" text,\n \"metadata\" text_jsonb not null default ('{}'),\n \"site_id\" text_uuid,\n constraint \"audit_events_actor_type_check\" CHECK ((actor_type IN ('admin', 'app_user', 'token', 'anonymous', 'system'))),\n constraint \"audit_events_outcome_check\" CHECK ((outcome IN ('success', 'failure'))),\n constraint \"audit_events_site_fk\" foreign key (site_id) references sites (id) on delete set null,\n constraint \"audit_events_pkey\" primary key (id)\n )`,\n `create table \"admin_users\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"email\" text not null,\n \"name\" text not null default (''),\n \"password_hash\" text not null,\n \"status\" text not null default ('active'),\n \"last_login_at\" text_timestamptz,\n \"password_changed_at\" text_timestamptz not null default (shapio_now()),\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"admin_users_status_check\" CHECK ((status IN ('active', 'disabled'))),\n constraint \"admin_users_pkey\" primary key (id)\n )`,\n `create unique index \"admin_users_email_key\" on \"admin_users\" (email)`,\n `create table \"admin_roles\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"key\" text not null,\n \"name\" text not null,\n \"description\" text not null default (''),\n \"kind\" text not null default ('admin'),\n \"is_system\" integer_boolean not null default 0,\n \"version\" integer not null default 1,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"admin_roles_key_check\" CHECK ((key REGEXP '^[a-z][a-z0-9-]{0,62}$')),\n constraint \"admin_roles_kind_check\" CHECK ((kind IN ('admin', 'delivery'))),\n constraint \"admin_roles_pkey\" primary key (id)\n )`,\n `create unique index \"admin_roles_key_key\" on \"admin_roles\" (key)`,\n `create table \"admin_role_permissions\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"role_id\" text_uuid not null,\n \"action\" text not null,\n \"model_id\" text,\n \"condition\" text,\n \"field_ids\" text_array,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"admin_role_permissions_condition_check\" CHECK ((condition = 'ownedByPrincipal')),\n constraint \"admin_role_permissions_role_id_fkey\" foreign key (role_id) references admin_roles (id) on delete cascade,\n constraint \"admin_role_permissions_pkey\" primary key (id)\n )`,\n `create unique index \"admin_role_permissions_grant_uq\" on \"admin_role_permissions\" (role_id, action, coalesce(model_id, ''))`,\n `create table \"admin_user_roles\" (\n \"admin_user_id\" text_uuid not null,\n \"role_id\" text_uuid not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid,\n \"id\" text_uuid not null default (gen_random_uuid()),\n constraint \"admin_user_roles_admin_user_id_fkey\" foreign key (admin_user_id) references admin_users (id) on delete cascade,\n constraint \"admin_user_roles_role_id_fkey\" foreign key (role_id) references admin_roles (id) on delete restrict,\n constraint \"admin_user_roles_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"admin_user_roles_pk\" primary key (id)\n )`,\n `create unique index \"admin_user_roles_assignment_uq\" on \"admin_user_roles\" (admin_user_id, role_id, coalesce(site_id, ''))`,\n `create table \"admin_sessions\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"admin_user_id\" text_uuid not null,\n \"token_hash\" text not null,\n \"csrf_secret\" text not null,\n \"ip\" text,\n \"user_agent\" text,\n \"last_seen_at\" text_timestamptz not null default (shapio_now()),\n \"expires_at\" text_timestamptz not null,\n \"revoked_at\" text_timestamptz,\n \"rotation_required\" integer_boolean not null default 0,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"admin_sessions_admin_user_id_fkey\" foreign key (admin_user_id) references admin_users (id) on delete cascade,\n constraint \"admin_sessions_pkey\" primary key (id)\n )`,\n `create unique index \"admin_sessions_token_hash_key\" on \"admin_sessions\" (token_hash)`,\n `create table \"admin_invitations\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"email\" text not null,\n \"token_hash\" text,\n \"invited_by\" text_uuid,\n \"expires_at\" text_timestamptz not null,\n \"accepted_at\" text_timestamptz,\n \"revoked_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"role_assignments\" text_jsonb not null default ('[]'),\n constraint \"admin_invitations_invited_by_fkey\" foreign key (invited_by) references admin_users (id) on delete set null,\n constraint \"admin_invitations_pkey\" primary key (id)\n )`,\n `create unique index \"admin_invitations_token_hash_key\" on \"admin_invitations\" (token_hash)`,\n `create table \"password_resets\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"admin_user_id\" text_uuid not null,\n \"token_hash\" text,\n \"expires_at\" text_timestamptz not null,\n \"used_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"password_resets_admin_user_id_fkey\" foreign key (admin_user_id) references admin_users (id) on delete cascade,\n constraint \"password_resets_pkey\" primary key (id)\n )`,\n `create unique index \"password_resets_token_hash_key\" on \"password_resets\" (token_hash)`,\n `create table \"setup_tokens\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"token_hash\" text not null,\n \"used_at\" text_timestamptz,\n \"superseded_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"setup_tokens_pkey\" primary key (id)\n )`,\n `create unique index \"setup_tokens_token_hash_key\" on \"setup_tokens\" (token_hash)`,\n `create table \"api_tokens\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"name\" text not null,\n \"token_hash\" text not null,\n \"token_prefix\" text not null,\n \"role_id\" text_uuid not null,\n \"created_by\" text_uuid,\n \"expires_at\" text_timestamptz,\n \"last_used_at\" text_timestamptz,\n \"revoked_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid,\n constraint \"api_tokens_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"api_tokens_role_id_fkey\" foreign key (role_id) references admin_roles (id) on delete restrict,\n constraint \"api_tokens_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"api_tokens_pkey\" primary key (id)\n )`,\n `create unique index \"api_tokens_token_hash_key\" on \"api_tokens\" (token_hash)`,\n `create table \"system_settings\" (\n \"key\" text not null,\n \"value\" text not null,\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"system_settings_pkey\" primary key (key)\n )`,\n `create table \"models\" (\n \"id\" text_uuid not null,\n \"kind\" text not null,\n \"api_key\" text not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"deleted_at\" text_timestamptz,\n constraint \"models_kind_check\" CHECK ((kind IN ('collection', 'singleton', 'component'))),\n constraint \"models_pkey\" primary key (id)\n )`,\n `create table \"schema_revisions\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"model_id\" text_uuid not null,\n \"version\" integer not null,\n \"definition\" text_jsonb not null,\n \"hash\" text not null,\n \"parent_revision_id\" text_uuid,\n \"created_by_type\" text not null,\n \"created_by_id\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n constraint \"schema_revisions_version_check\" CHECK ((version > 0)),\n constraint \"schema_revisions_model_id_fkey\" foreign key (model_id) references models (id) on delete restrict,\n constraint \"schema_revisions_parent_revision_id_fkey\" foreign key (parent_revision_id) references schema_revisions (id),\n constraint \"schema_revisions_pkey\" primary key (id)\n )`,\n `create unique index \"schema_revisions_model_version_uq\" on \"schema_revisions\" (model_id, version)`,\n `create table \"model_active_versions\" (\n \"model_id\" text_uuid not null,\n \"revision_id\" text_uuid not null,\n \"version\" integer not null,\n \"schema_version\" integer not null,\n \"activated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"model_active_versions_model_id_fkey\" foreign key (model_id) references models (id) on delete cascade,\n constraint \"model_active_versions_revision_id_fkey\" foreign key (revision_id) references schema_revisions (id),\n constraint \"model_active_versions_pkey\" primary key (model_id)\n )`,\n `create table \"schema_change_jobs\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"target_type\" text not null,\n \"target_id\" text not null,\n \"model_id\" text_uuid,\n \"from_revision_id\" text_uuid,\n \"to_revision_id\" text_uuid,\n \"status\" text not null default ('pending'),\n \"plan\" text_jsonb not null default ('{}'),\n \"job_id\" text_uuid,\n \"error\" text_jsonb,\n \"requested_by_type\" text not null,\n \"requested_by_id\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"finished_at\" text_timestamptz,\n \"change_set_id\" text_uuid,\n constraint \"schema_change_jobs_status_check\" CHECK ((status IN ('pending', 'running', 'activated', 'failed', 'cancelled'))),\n constraint \"schema_change_jobs_target_type_check\" CHECK ((target_type IN ('model', 'locale'))),\n constraint \"schema_change_jobs_change_set_id_fkey\" foreign key (change_set_id) references change_sets (id) on delete set null,\n constraint \"schema_change_jobs_from_revision_id_fkey\" foreign key (from_revision_id) references schema_revisions (id),\n constraint \"schema_change_jobs_job_id_fkey\" foreign key (job_id) references jobs (id) on delete set null,\n constraint \"schema_change_jobs_model_id_fkey\" foreign key (model_id) references models (id),\n constraint \"schema_change_jobs_to_revision_id_fkey\" foreign key (to_revision_id) references schema_revisions (id),\n constraint \"schema_change_jobs_pkey\" primary key (id)\n )`,\n `create table \"locales\" (\n \"code\" text not null,\n \"label\" text not null,\n \"is_default\" integer_boolean not null default 0,\n \"fallbacks\" text_array not null default ('[]'),\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"locales_pkey\" primary key (code)\n )`,\n `create table \"schema_settings\" (\n \"id\" integer_boolean not null default 1,\n \"read_only\" integer_boolean not null default 0,\n \"read_only_reason\" text,\n \"updated_by_type\" text,\n \"updated_by_id\" text,\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"schema_settings_id_check\" CHECK (id),\n constraint \"schema_settings_pkey\" primary key (id)\n )`,\n `create table \"entries\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"model_id\" text_uuid not null,\n \"owner_app_user_id\" text_uuid,\n \"created_by_admin_id\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"deleted_at\" text_timestamptz,\n \"site_id\" text_uuid not null,\n constraint \"entries_created_by_admin_id_fkey\" foreign key (created_by_admin_id) references admin_users (id) on delete set null,\n constraint \"entries_model_id_fkey\" foreign key (model_id) references models (id) on delete restrict,\n constraint \"entries_owner_app_user_fk\" foreign key (owner_app_user_id) references app_users (id) on delete set null,\n constraint \"entries_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"entries_pkey\" primary key (id)\n )`,\n `create unique index \"entries_id_site_uq\" on \"entries\" (id, site_id)`,\n `create table \"content_revisions\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"entry_id\" text_uuid not null,\n \"locale\" text not null,\n \"schema_revision_id\" text_uuid not null,\n \"data\" text_jsonb not null,\n \"reason\" text not null,\n \"author_type\" text not null,\n \"author_id\" text,\n \"parent_revision_id\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n constraint \"content_revisions_reason_check\" CHECK ((reason IN ('create', 'save', 'publish', 'restore', 'duplicate', 'localize', 'conversion'))),\n constraint \"content_revisions_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete restrict,\n constraint \"content_revisions_parent_revision_id_fkey\" foreign key (parent_revision_id) references content_revisions (id),\n constraint \"content_revisions_schema_revision_id_fkey\" foreign key (schema_revision_id) references schema_revisions (id),\n constraint \"content_revisions_pkey\" primary key (id)\n )`,\n `create table \"entry_heads\" (\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"locale\" text not null,\n \"state\" text not null,\n \"revision_id\" text_uuid not null,\n \"data\" text_jsonb not null,\n \"autosaved_at\" text_timestamptz,\n \"version\" integer not null default 1,\n \"change_seq\" bigint not null default (shapio_nextval('entry_heads_change_seq')),\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"entry_heads_state_check\" CHECK ((state IN ('draft', 'published'))),\n constraint \"entry_heads_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"entry_heads_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"entry_heads_revision_id_fkey\" foreign key (revision_id) references content_revisions (id),\n constraint \"entry_heads_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"entry_heads_pkey\" primary key (entry_id, locale, state)\n )`,\n `create table \"relation_edges\" (\n \"source_entry_id\" text_uuid not null,\n \"locale\" text not null,\n \"state\" text not null,\n \"field_id\" text_uuid not null,\n \"position\" integer not null,\n \"target_entry_id\" text_uuid not null,\n constraint \"relation_edges_head_fk\" foreign key (source_entry_id, locale, state) references entry_heads (entry_id, locale, state) on delete cascade,\n constraint \"relation_edges_target_entry_id_fkey\" foreign key (target_entry_id) references entries (id),\n constraint \"relation_edges_pkey\" primary key (source_entry_id, locale, state, field_id, \"position\")\n )`,\n `create table \"unique_values\" (\n \"field_id\" text_uuid not null,\n \"locale\" text not null,\n \"state\" text not null,\n \"value_hash\" text not null,\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"site_id\" text_uuid not null,\n constraint \"unique_values_state_check\" CHECK ((state IN ('draft', 'published'))),\n constraint \"unique_values_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"unique_values_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"unique_values_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"unique_values_pkey\" primary key (site_id, field_id, locale, state, value_hash)\n )`,\n `create table \"publication_state\" (\n \"last_seq\" bigint not null default 0,\n \"site_id\" text_uuid not null,\n constraint \"publication_state_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"publication_state_pkey\" primary key (site_id)\n )`,\n `create table \"publication_log\" (\n \"id\" integer primary key autoincrement,\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"locale\" text not null,\n \"revision_id\" text_uuid not null,\n \"from_seq\" bigint not null,\n \"to_seq\" bigint,\n \"published_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"publication_log_entry_id_fkey\" foreign key (entry_id) references entries (id),\n constraint \"publication_log_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete restrict,\n constraint \"publication_log_revision_id_fkey\" foreign key (revision_id) references content_revisions (id),\n constraint \"publication_log_site_fk\" foreign key (site_id) references sites (id) on delete restrict\n )`,\n `create table \"media_folders\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"parent_id\" text_uuid,\n \"name\" text not null,\n \"created_by\" text_uuid,\n \"version\" integer not null default 1,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"media_folders_name_check\" CHECK (((length(name) >= 1) AND (length(name) <= 255))),\n constraint \"media_folders_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"media_folders_parent_id_fkey\" foreign key (parent_id, site_id) references media_folders (id, site_id) on delete restrict,\n constraint \"media_folders_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"media_folders_pkey\" primary key (id)\n )`,\n `create unique index \"media_folders_id_site_uq\" on \"media_folders\" (id, site_id)`,\n `create table \"media_assets\" (\n \"id\" text_uuid not null,\n \"folder_id\" text_uuid,\n \"storage_driver\" text not null,\n \"storage_key\" text not null,\n \"original_filename\" text not null,\n \"mime_type\" text not null,\n \"size_bytes\" bigint not null,\n \"width\" integer,\n \"height\" integer,\n \"checksum_sha256\" text,\n \"alt\" text not null default (''),\n \"caption\" text not null default (''),\n \"focal_x\" real,\n \"focal_y\" real,\n \"visibility\" text not null default ('public'),\n \"status\" text not null default ('processing'),\n \"processing_error\" text,\n \"created_by\" text_uuid,\n \"version\" integer not null default 1,\n \"deleted_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"media_assets_focal_point_ck\" CHECK (((focal_x IS NULL) = (focal_y IS NULL))),\n constraint \"media_assets_focal_x_check\" CHECK (((focal_x >= 0) AND (focal_x <= 1))),\n constraint \"media_assets_focal_y_check\" CHECK (((focal_y >= 0) AND (focal_y <= 1))),\n constraint \"media_assets_status_check\" CHECK ((status IN ('processing', 'ready', 'failed'))),\n constraint \"media_assets_storage_driver_check\" CHECK ((storage_driver IN ('local', 's3'))),\n constraint \"media_assets_visibility_check\" CHECK ((visibility IN ('public', 'private'))),\n constraint \"media_assets_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"media_assets_folder_id_fkey\" foreign key (folder_id, site_id) references media_folders (id, site_id),\n constraint \"media_assets_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"media_assets_pkey\" primary key (id)\n )`,\n `create table \"media_variants\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"asset_id\" text_uuid not null,\n \"name\" text not null,\n \"width\" integer,\n \"height\" integer,\n \"format\" text not null,\n \"mime_type\" text not null,\n \"storage_key\" text,\n \"size_bytes\" bigint,\n \"checksum_sha256\" text,\n \"status\" text not null default ('pending'),\n \"error\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"media_variants_status_check\" CHECK ((status IN ('pending', 'ready', 'failed'))),\n constraint \"media_variants_asset_id_fkey\" foreign key (asset_id) references media_assets (id) on delete cascade,\n constraint \"media_variants_pkey\" primary key (id)\n )`,\n `create unique index \"media_variants_asset_name_uq\" on \"media_variants\" (asset_id, name)`,\n `create table \"media_references\" (\n \"asset_id\" text_uuid not null,\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"field_id\" text not null,\n \"locale\" text not null,\n \"state\" text not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n constraint \"media_references_state_check\" CHECK ((state IN ('draft', 'published'))),\n constraint \"media_references_asset_id_fkey\" foreign key (asset_id) references media_assets (id) on delete cascade,\n constraint \"media_references_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"media_references_pk\" primary key (asset_id, entry_id, locale, state, field_id)\n )`,\n `create table \"media_upload_grants\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"asset_id\" text_uuid not null,\n \"kind\" text not null,\n \"storage_driver\" text not null,\n \"storage_key\" text not null,\n \"original_filename\" text not null,\n \"declared_mime_type\" text not null,\n \"max_size_bytes\" bigint not null,\n \"folder_id\" text_uuid,\n \"visibility\" text not null,\n \"created_by\" text_uuid,\n \"created_by_principal\" text not null,\n \"status\" text not null default ('pending'),\n \"expires_at\" text_timestamptz not null,\n \"consumed_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"media_upload_grants_kind_check\" CHECK ((kind IN ('create', 'replace'))),\n constraint \"media_upload_grants_status_check\" CHECK ((status IN ('pending', 'consumed', 'rejected', 'expired'))),\n constraint \"media_upload_grants_storage_driver_check\" CHECK ((storage_driver IN ('local', 's3'))),\n constraint \"media_upload_grants_visibility_check\" CHECK ((visibility IN ('public', 'private'))),\n constraint \"media_upload_grants_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"media_upload_grants_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"media_upload_grants_pkey\" primary key (id)\n )`,\n `create unique index \"media_upload_grants_storage_key_key\" on \"media_upload_grants\" (storage_key)`,\n `create table \"scheduled_publications\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"locale\" text not null,\n \"action\" text not null,\n \"run_at\" text_timestamptz not null,\n \"status\" text not null default ('scheduled'),\n \"created_by_token\" text_uuid,\n \"job_id\" text_uuid,\n \"snapshot_seq\" bigint,\n \"error\" text,\n \"executed_at\" text_timestamptz,\n \"created_by\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"scheduled_publications_action_check\" CHECK ((action IN ('publish', 'unpublish'))),\n constraint \"scheduled_publications_status_check\" CHECK ((status IN ('scheduled', 'done', 'failed', 'cancelled'))),\n constraint \"scheduled_publications_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"scheduled_publications_created_by_token_fkey\" foreign key (created_by_token) references api_tokens (id) on delete set null,\n constraint \"scheduled_publications_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"scheduled_publications_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"scheduled_publications_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"scheduled_publications_pkey\" primary key (id)\n )`,\n `create table \"webhooks\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"name\" text not null,\n \"url\" text not null,\n \"events\" text_array not null default ('[]'),\n \"enabled\" integer_boolean not null default 1,\n \"secret_encrypted\" text not null,\n \"allow_private_network\" integer_boolean not null default 0,\n \"max_attempts\" integer not null default 8,\n \"version\" integer not null default 1,\n \"created_by\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid,\n constraint \"webhooks_max_attempts_check\" CHECK (((max_attempts >= 1) AND (max_attempts <= 20))),\n constraint \"webhooks_name_check\" CHECK (((length(name) >= 1) AND (length(name) <= 200))),\n constraint \"webhooks_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"webhooks_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"webhooks_pkey\" primary key (id)\n )`,\n `create table \"webhook_deliveries\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"webhook_id\" text_uuid not null,\n \"event_id\" text_uuid,\n \"event_type\" text not null,\n \"payload\" text_jsonb not null,\n \"is_test\" integer_boolean not null default 0,\n \"status\" text not null default ('pending'),\n \"attempts\" integer not null default 0,\n \"last_response_status\" integer,\n \"last_error\" text,\n \"attempt_log\" text_jsonb not null default ('[]'),\n \"job_id\" text_uuid,\n \"delivered_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"webhook_deliveries_status_check\" CHECK ((status IN ('pending', 'retrying', 'succeeded', 'dead'))),\n constraint \"webhook_deliveries_webhook_id_fkey\" foreign key (webhook_id) references webhooks (id) on delete cascade,\n constraint \"webhook_deliveries_pkey\" primary key (id)\n )`,\n `create table \"deployment_connections\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"name\" text not null,\n \"provider\" text not null,\n \"settings\" text_jsonb not null default ('{}'),\n \"secrets_encrypted\" text not null,\n \"secret_env_refs\" text_jsonb not null default ('{}'),\n \"delivery_role_id\" text_uuid,\n \"preview_url_template\" text,\n \"trigger_policy\" text_array not null default ('[]'),\n \"debounce_seconds\" integer not null default 10,\n \"allow_private_network\" integer_boolean not null default 0,\n \"enabled\" integer_boolean not null default 1,\n \"version\" integer not null default 1,\n \"created_by\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"deployment_connections_debounce_seconds_check\" CHECK (((debounce_seconds >= 0) AND (debounce_seconds <= 3600))),\n constraint \"deployment_connections_name_check\" CHECK (((length(name) >= 1) AND (length(name) <= 200))),\n constraint \"deployment_connections_provider_check\" CHECK ((provider IN ('generic_webhook', 'cloudflare_pages', 'vercel', 'netlify', 'github'))),\n constraint \"deployment_connections_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"deployment_connections_delivery_role_id_fkey\" foreign key (delivery_role_id) references admin_roles (id) on delete set null,\n constraint \"deployment_connections_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"deployment_connections_pkey\" primary key (id)\n )`,\n `create table \"deployment_runs\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"connection_id\" text_uuid not null,\n \"status\" text not null default ('queued'),\n \"status_rank\" integer not null default 0,\n \"trigger\" text not null,\n \"snapshot_seq\" bigint,\n \"schema_version\" integer,\n \"retry_of\" text_uuid,\n \"provider_ref\" text,\n \"log_url\" text,\n \"site_url\" text,\n \"error\" text,\n \"timeline\" text_jsonb not null default ('[]'),\n \"job_id\" text_uuid,\n \"triggered_at\" text_timestamptz,\n \"finished_at\" text_timestamptz,\n \"created_by\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"change_set_id\" text_uuid,\n constraint \"deployment_runs_status_check\" CHECK ((status IN ('queued', 'triggered', 'building', 'deployed', 'failed', 'unknown'))),\n constraint \"deployment_runs_trigger_check\" CHECK ((trigger IN ('publish', 'change_set', 'schema', 'manual', 'retry'))),\n constraint \"deployment_runs_change_set_id_fkey\" foreign key (change_set_id) references change_sets (id) on delete set null,\n constraint \"deployment_runs_connection_id_fkey\" foreign key (connection_id) references deployment_connections (id) on delete cascade,\n constraint \"deployment_runs_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"deployment_runs_retry_of_fkey\" foreign key (retry_of) references deployment_runs (id) on delete set null,\n constraint \"deployment_runs_pkey\" primary key (id)\n )`,\n `create table \"preview_tokens\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"token_hash\" text not null,\n \"token_prefix\" text not null,\n \"model_id\" text_uuid not null,\n \"entry_id\" text_uuid not null,\n \"locale\" text,\n \"connection_id\" text_uuid,\n \"delivery_role_id\" text_uuid,\n \"created_by\" text_uuid not null,\n \"expires_at\" text_timestamptz not null,\n \"revoked_at\" text_timestamptz,\n \"last_used_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"preview_tokens_connection_id_fkey\" foreign key (connection_id) references deployment_connections (id) on delete set null,\n constraint \"preview_tokens_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete cascade,\n constraint \"preview_tokens_delivery_role_id_fkey\" foreign key (delivery_role_id) references admin_roles (id) on delete set null,\n constraint \"preview_tokens_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"preview_tokens_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"preview_tokens_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"preview_tokens_pkey\" primary key (id)\n )`,\n `create unique index \"preview_tokens_token_hash_key\" on \"preview_tokens\" (token_hash)`,\n `create table \"app_users\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"email\" text not null,\n \"name\" text not null default (''),\n \"password_hash\" text,\n \"confirmed_at\" text_timestamptz,\n \"blocked_at\" text_timestamptz,\n \"last_login_at\" text_timestamptz,\n \"password_changed_at\" text_timestamptz,\n \"deleted_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"token_version\" integer not null default 0,\n \"site_id\" text_uuid not null,\n constraint \"app_users_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"app_users_pkey\" primary key (id)\n )`,\n `create table \"app_roles\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"key\" text not null,\n \"name\" text not null,\n \"description\" text not null default (''),\n \"is_system\" integer_boolean not null default 0,\n \"version\" integer not null default 1,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"app_roles_key_check\" CHECK ((key REGEXP '^[a-z][a-z0-9-]{0,62}$')),\n constraint \"app_roles_pkey\" primary key (id)\n )`,\n `create unique index \"app_roles_key_key\" on \"app_roles\" (key)`,\n `create table \"app_role_permissions\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"role_id\" text_uuid not null,\n \"action\" text not null,\n \"model_id\" text,\n \"condition\" text,\n \"field_ids\" text_array,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"app_role_permissions_action_check\" CHECK ((action IN ('read', 'create', 'update', 'delete', 'publish'))),\n constraint \"app_role_permissions_condition_check\" CHECK ((condition = 'ownedByPrincipal')),\n constraint \"app_role_permissions_role_id_fkey\" foreign key (role_id) references app_roles (id) on delete cascade,\n constraint \"app_role_permissions_pkey\" primary key (id)\n )`,\n `create unique index \"app_role_permissions_grant_uq\" on \"app_role_permissions\" (role_id, action, coalesce(model_id, ''))`,\n `create table \"app_user_roles\" (\n \"app_user_id\" text_uuid not null,\n \"role_id\" text_uuid not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"app_user_roles_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"app_user_roles_role_id_fkey\" foreign key (role_id) references app_roles (id) on delete restrict,\n constraint \"app_user_roles_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"app_user_roles_pk\" primary key (app_user_id, role_id)\n )`,\n `create table \"app_refresh_tokens\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"app_user_id\" text_uuid not null,\n \"family_id\" text_uuid not null,\n \"token_hash\" text not null,\n \"expires_at\" text_timestamptz not null,\n \"used_at\" text_timestamptz,\n \"reuse_grace_used_at\" text_timestamptz,\n \"revoked_at\" text_timestamptz,\n \"revoked_reason\" text,\n \"ip\" text,\n \"user_agent\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n constraint \"app_refresh_tokens_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"app_refresh_tokens_pkey\" primary key (id)\n )`,\n `create unique index \"app_refresh_tokens_token_hash_key\" on \"app_refresh_tokens\" (token_hash)`,\n `create table \"app_oauth_accounts\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"app_user_id\" text_uuid not null,\n \"provider\" text not null,\n \"provider_user_id\" text not null,\n \"email\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"app_oauth_accounts_provider_check\" CHECK ((provider IN ('google', 'github'))),\n constraint \"app_oauth_accounts_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"app_oauth_accounts_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"app_oauth_accounts_pkey\" primary key (id)\n )`,\n `create unique index \"app_oauth_accounts_identity_uq\" on \"app_oauth_accounts\" (site_id, provider, provider_user_id)`,\n `create table \"email_confirmations\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"app_user_id\" text_uuid not null,\n \"email\" text not null,\n \"token_hash\" text,\n \"expires_at\" text_timestamptz not null,\n \"used_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"email_confirmations_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"email_confirmations_pkey\" primary key (id)\n )`,\n `create unique index \"email_confirmations_token_hash_key\" on \"email_confirmations\" (token_hash)`,\n `create table \"app_password_resets\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"app_user_id\" text_uuid not null,\n \"email\" text not null,\n \"token_hash\" text,\n \"expires_at\" text_timestamptz not null,\n \"used_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"app_password_resets_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"app_password_resets_pkey\" primary key (id)\n )`,\n `create unique index \"app_password_resets_token_hash_key\" on \"app_password_resets\" (token_hash)`,\n `create table \"app_login_codes\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"app_user_id\" text_uuid not null,\n \"code_hash\" text not null,\n \"expires_at\" text_timestamptz not null,\n \"used_at\" text_timestamptz,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"code_challenge\" text not null,\n constraint \"app_login_codes_app_user_id_fkey\" foreign key (app_user_id) references app_users (id) on delete cascade,\n constraint \"app_login_codes_pkey\" primary key (id)\n )`,\n `create unique index \"app_login_codes_code_hash_key\" on \"app_login_codes\" (code_hash)`,\n `create table \"extension_hook_runs\" (\n \"event_id\" text_uuid not null,\n \"hook\" text not null,\n \"job_id\" text_uuid,\n \"completed_at\" text_timestamptz not null default (shapio_now()),\n constraint \"extension_hook_runs_pkey\" primary key (event_id, hook)\n )`,\n `create table \"field_reads\" (\n \"day\" text_date not null,\n \"model_id\" text_uuid not null,\n \"field_path\" text not null,\n \"principal_key\" text not null,\n \"selection\" text not null,\n \"reads\" bigint not null default 0,\n \"last_read_at\" text_timestamptz not null,\n \"site_id\" text_uuid not null,\n constraint \"field_reads_selection_check\" CHECK ((selection IN ('explicit', 'implicit'))),\n constraint \"field_reads_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"field_reads_pkey\" primary key (day, site_id, model_id, field_path, principal_key, selection)\n )`,\n `create table \"token_reads\" (\n \"day\" text_date not null,\n \"principal_key\" text not null,\n \"requests\" bigint not null default 0,\n \"last_snapshot\" bigint,\n \"last_read_at\" text_timestamptz not null,\n \"site_id\" text_uuid not null,\n constraint \"token_reads_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"token_reads_pkey\" primary key (day, site_id, principal_key)\n )`,\n `create table \"change_sets\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"title\" text not null,\n \"description\" text not null default (''),\n \"status\" text not null default ('open'),\n \"ship_phase\" text,\n \"source\" text not null default ('manual'),\n \"restore_of_seq\" bigint,\n \"scheduled_for\" text_timestamptz,\n \"schedule_job_id\" text_uuid,\n \"scheduled_by\" text_uuid,\n \"scheduled_by_token\" text_uuid,\n \"ship_job_id\" text_uuid,\n \"ship_mode\" text,\n \"ship_requested_by\" text_uuid,\n \"ship_requested_by_token\" text_uuid,\n \"acknowledge_breaking\" integer_boolean not null default 0,\n \"acknowledge_destructive\" integer_boolean not null default 0,\n \"deployment_connection_id\" text_uuid,\n \"deployment_run_id\" text_uuid,\n \"shipped_at\" text_timestamptz,\n \"shipped_seq\" bigint,\n \"schema_version_after\" integer,\n \"error\" text_jsonb,\n \"restore_report\" text_jsonb not null default ('[]'),\n \"created_by\" text_uuid,\n \"created_by_token\" text_uuid,\n \"version\" integer not null default 1,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"change_sets_ship_mode_check\" CHECK ((ship_mode IN ('interactive', 'scheduled'))),\n constraint \"change_sets_ship_phase_check\" CHECK ((ship_phase IN ('preparing', 'activating'))),\n constraint \"change_sets_source_check\" CHECK ((source IN ('manual', 'release', 'restore', 'builder', 'assist'))),\n constraint \"change_sets_status_check\" CHECK ((status IN ('open', 'scheduled', 'shipping', 'shipped', 'failed', 'discarded'))),\n constraint \"change_sets_title_check\" CHECK (((length(title) >= 1) AND (length(title) <= 200))),\n constraint \"change_sets_created_by_fkey\" foreign key (created_by) references admin_users (id) on delete set null,\n constraint \"change_sets_created_by_token_fkey\" foreign key (created_by_token) references api_tokens (id) on delete set null,\n constraint \"change_sets_deployment_connection_id_fkey\" foreign key (deployment_connection_id) references deployment_connections (id) on delete set null,\n constraint \"change_sets_deployment_run_id_fkey\" foreign key (deployment_run_id) references deployment_runs (id) on delete set null,\n constraint \"change_sets_scheduled_by_fkey\" foreign key (scheduled_by) references admin_users (id) on delete set null,\n constraint \"change_sets_scheduled_by_token_fkey\" foreign key (scheduled_by_token) references api_tokens (id) on delete set null,\n constraint \"change_sets_ship_requested_by_fkey\" foreign key (ship_requested_by) references admin_users (id) on delete set null,\n constraint \"change_sets_ship_requested_by_token_fkey\" foreign key (ship_requested_by_token) references api_tokens (id) on delete set null,\n constraint \"change_sets_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"change_sets_pkey\" primary key (id)\n )`,\n `create unique index \"change_sets_id_site_uq\" on \"change_sets\" (id, site_id)`,\n `create table \"schema_drafts\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"change_set_id\" text_uuid not null,\n \"definition_id\" text_uuid not null,\n \"kind\" text not null,\n \"api_key\" text not null,\n \"base_version\" integer,\n \"definition\" text_jsonb,\n \"version\" integer not null default 1,\n \"updated_by_type\" text not null,\n \"updated_by_id\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"schema_drafts_kind_check\" CHECK ((kind IN ('collection', 'singleton', 'component'))),\n constraint \"schema_drafts_change_set_id_fkey\" foreign key (change_set_id) references change_sets (id) on delete cascade,\n constraint \"schema_drafts_pkey\" primary key (id)\n )`,\n `create unique index \"schema_drafts_set_definition_uq\" on \"schema_drafts\" (change_set_id, definition_id)`,\n `create table \"change_set_items\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"change_set_id\" text_uuid not null,\n \"kind\" text not null,\n \"position\" integer not null,\n \"entry_id\" text_uuid,\n \"model_id\" text_uuid,\n \"locale\" text,\n \"action\" text,\n \"source_revision_id\" text_uuid,\n \"schema_draft_id\" text_uuid,\n \"status\" text not null default ('pending'),\n \"error\" text,\n \"ship_state\" text_jsonb,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"change_set_items_action_check\" CHECK ((action IN ('publish', 'unpublish'))),\n constraint \"change_set_items_kind_check\" CHECK ((kind IN ('entry', 'schema'))),\n constraint \"change_set_items_shape_check\" CHECK ((((kind = 'entry') AND (entry_id IS NOT NULL) AND (model_id IS NOT NULL) AND (locale IS NOT NULL) AND (action IS NOT NULL) AND (schema_draft_id IS NULL)) OR ((kind = 'schema') AND (schema_draft_id IS NOT NULL) AND (entry_id IS NULL) AND (source_revision_id IS NULL)))),\n constraint \"change_set_items_status_check\" CHECK ((status IN ('pending', 'done', 'failed'))),\n constraint \"change_set_items_change_set_id_fkey\" foreign key (change_set_id) references change_sets (id) on delete cascade,\n constraint \"change_set_items_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"change_set_items_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"change_set_items_schema_draft_id_fkey\" foreign key (schema_draft_id) references schema_drafts (id) on delete cascade,\n constraint \"change_set_items_set_site_fk\" foreign key (change_set_id, site_id) references change_sets (id, site_id) on delete cascade,\n constraint \"change_set_items_source_revision_id_fkey\" foreign key (source_revision_id) references content_revisions (id),\n constraint \"change_set_items_pkey\" primary key (id)\n )`,\n `create table \"publication_snapshots\" (\n \"seq\" bigint not null,\n \"schema_version\" integer,\n \"source\" text not null,\n \"change_set_id\" text_uuid,\n \"actor_type\" text,\n \"actor_id\" text,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"site_id\" text_uuid not null,\n constraint \"publication_snapshots_change_set_id_fkey\" foreign key (change_set_id) references change_sets (id) on delete set null,\n constraint \"publication_snapshots_site_fk\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"publication_snapshots_pkey\" primary key (site_id, seq)\n )`,\n `create table \"editor_presence\" (\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"admin_user_id\" text_uuid not null,\n \"tab_id\" text not null,\n \"locale\" text,\n \"started_at\" text_timestamptz not null default (shapio_now()),\n \"last_seen_at\" text_timestamptz not null default (shapio_now()),\n constraint \"editor_presence_tab_id_check\" CHECK (((length(tab_id) >= 1) AND (length(tab_id) <= 64))),\n constraint \"editor_presence_pkey\" primary key (entry_id, admin_user_id, tab_id)\n )`,\n `create table \"content_health_findings\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"entry_id\" text_uuid not null,\n \"model_id\" text_uuid not null,\n \"locale\" text not null,\n \"rule\" text not null,\n \"subject\" text not null default (''),\n \"severity\" text not null,\n \"path\" text,\n \"details\" text_jsonb not null default ('{}'),\n \"first_seen_at\" text_timestamptz not null default (shapio_now()),\n \"last_seen_at\" text_timestamptz not null default (shapio_now()),\n \"resolved_at\" text_timestamptz,\n \"site_id\" text_uuid not null,\n constraint \"content_health_findings_severity_check\" CHECK ((severity IN ('error', 'warning'))),\n constraint \"content_health_findings_entry_id_fkey\" foreign key (entry_id) references entries (id) on delete cascade,\n constraint \"content_health_findings_entry_site_fk\" foreign key (entry_id, site_id) references entries (id, site_id) on delete cascade,\n constraint \"content_health_findings_site_fk\" foreign key (site_id) references sites (id) on delete restrict,\n constraint \"content_health_findings_pkey\" primary key (id)\n )`,\n `create unique index \"content_health_findings_entry_id_locale_rule_subject_key\" on \"content_health_findings\" (entry_id, locale, rule, subject)`,\n `create table \"sites\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"key\" text not null,\n \"name\" text not null,\n \"is_primary\" integer_boolean not null default 0,\n \"version\" integer not null default 1,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n constraint \"sites_key_check\" CHECK ((key REGEXP '^[a-z][a-z0-9-]{0,62}$')),\n constraint \"sites_name_check\" CHECK (((length(name) >= 1) AND (length(name) <= 200))),\n constraint \"sites_pkey\" primary key (id)\n )`,\n `create unique index \"sites_key_key\" on \"sites\" (key)`,\n `create table \"site_app_roles\" (\n \"site_id\" text_uuid not null,\n \"audience\" text not null,\n \"role_id\" text_uuid not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n constraint \"site_app_roles_audience_check\" CHECK ((audience IN ('public', 'authenticated'))),\n constraint \"site_app_roles_role_id_fkey\" foreign key (role_id) references app_roles (id) on delete cascade,\n constraint \"site_app_roles_site_id_fkey\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"site_app_roles_pkey\" primary key (site_id, audience, role_id)\n )`,\n `create table \"assist_runs\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"site_id\" text_uuid not null,\n \"actor_type\" text not null,\n \"actor_id\" text not null,\n \"action\" text not null,\n \"rule\" text,\n \"provider\" text not null,\n \"model\" text not null,\n \"input_tokens\" integer not null default 0,\n \"output_tokens\" integer not null default 0,\n \"duration_ms\" integer not null default 0,\n \"status\" text not null,\n \"error_code\" text,\n \"job_id\" text_uuid,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"finished_at\" text_timestamptz,\n constraint \"assist_runs_action_check\" CHECK ((action IN ('alt_text', 'summarize', 'translate', 'rewrite', 'schema_draft', 'content_ops'))),\n constraint \"assist_runs_status_check\" CHECK ((status IN ('queued', 'running', 'succeeded', 'failed'))),\n constraint \"assist_runs_job_id_fkey\" foreign key (job_id) references jobs (id) on delete set null,\n constraint \"assist_runs_site_id_fkey\" foreign key (site_id) references sites (id) on delete cascade,\n constraint \"assist_runs_pkey\" primary key (id)\n )`,\n `create index \"admin_invitations_pending_email_idx\" on \"admin_invitations\" (email) where ((accepted_at IS NULL) AND (revoked_at IS NULL))`,\n `create index \"admin_sessions_user_idx\" on \"admin_sessions\" (admin_user_id) where (revoked_at IS NULL)`,\n `create index \"admin_user_roles_role_idx\" on \"admin_user_roles\" (role_id)`,\n `create index \"api_tokens_role_idx\" on \"api_tokens\" (role_id)`,\n `create index \"app_oauth_accounts_user_idx\" on \"app_oauth_accounts\" (app_user_id)`,\n `create index \"app_password_resets_user_idx\" on \"app_password_resets\" (app_user_id)`,\n `create index \"app_refresh_tokens_family_idx\" on \"app_refresh_tokens\" (family_id)`,\n `create index \"app_refresh_tokens_user_idx\" on \"app_refresh_tokens\" (app_user_id) where (revoked_at IS NULL)`,\n `create index \"app_user_roles_role_idx\" on \"app_user_roles\" (role_id)`,\n `create index \"app_users_created_idx\" on \"app_users\" (site_id, created_at DESC, id DESC) where (deleted_at IS NULL)`,\n `create unique index \"app_users_email_uq\" on \"app_users\" (site_id, lower(email)) where (deleted_at IS NULL)`,\n `create index \"assist_runs_created_idx\" on \"assist_runs\" (created_at)`,\n `create index \"assist_runs_site_created_idx\" on \"assist_runs\" (site_id, created_at)`,\n `create index \"audit_events_actor_idx\" on \"audit_events\" (actor_type, actor_id, occurred_at DESC)`,\n `create index \"audit_events_occurred_at_idx\" on \"audit_events\" (occurred_at DESC)`,\n `create index \"audit_events_target_idx\" on \"audit_events\" (target_type, target_id, occurred_at DESC)`,\n `create unique index \"change_set_items_draft_uq\" on \"change_set_items\" (schema_draft_id)`,\n `create index \"change_set_items_entry_idx\" on \"change_set_items\" (entry_id) where (entry_id IS NOT NULL)`,\n `create unique index \"change_set_items_entry_uq\" on \"change_set_items\" (change_set_id, entry_id, locale) where (kind = 'entry')`,\n `create index \"change_set_items_set_idx\" on \"change_set_items\" (change_set_id, position)`,\n `create index \"change_sets_status_idx\" on \"change_sets\" (site_id, status, created_at DESC)`,\n `create index \"content_health_findings_open_idx\" on \"content_health_findings\" (site_id, rule, last_seen_at DESC, id) where (resolved_at IS NULL)`,\n `create index \"content_health_findings_resolved_idx\" on \"content_health_findings\" (resolved_at) where (resolved_at IS NOT NULL)`,\n `create index \"content_revisions_entry_idx\" on \"content_revisions\" (entry_id, locale, created_at)`,\n `create index \"deployment_runs_connection_idx\" on \"deployment_runs\" (connection_id, created_at DESC)`,\n `create unique index \"deployment_runs_queued_uq\" on \"deployment_runs\" (connection_id) where (status = 'queued')`,\n `create index \"editor_presence_model_idx\" on \"editor_presence\" (model_id, last_seen_at)`,\n `create index \"editor_presence_seen_idx\" on \"editor_presence\" (last_seen_at)`,\n `create index \"email_confirmations_user_idx\" on \"email_confirmations\" (app_user_id)`,\n `create index \"entries_model_idx\" on \"entries\" (site_id, model_id, created_at) where (deleted_at IS NULL)`,\n `create index \"entries_owner_idx\" on \"entries\" (owner_app_user_id) where (owner_app_user_id IS NOT NULL)`,\n `create index \"entry_heads_change_seq_idx\" on \"entry_heads\" (model_id, change_seq)`,\n `create index \"entry_heads_model_locale_state_idx\" on \"entry_heads\" (site_id, model_id, locale, state)`,\n `create index \"field_reads_model_day_idx\" on \"field_reads\" (model_id, day)`,\n `create unique index \"jobs_idempotency_key_uq\" on \"jobs\" (idempotency_key) where (idempotency_key IS NOT NULL)`,\n `create index \"jobs_pending_idx\" on \"jobs\" (priority DESC, run_at) where (status = 'pending')`,\n `create index \"jobs_running_lease_idx\" on \"jobs\" (locked_until) where (status = 'running')`,\n `create unique index \"locales_single_default_uq\" on \"locales\" (is_default) where is_default`,\n `create index \"media_assets_created_idx\" on \"media_assets\" (site_id, created_at, id) where (deleted_at IS NULL)`,\n `create index \"media_assets_driver_idx\" on \"media_assets\" (storage_driver, id)`,\n `create index \"media_assets_folder_idx\" on \"media_assets\" (folder_id, created_at, id) where (deleted_at IS NULL)`,\n `create unique index \"media_assets_storage_key_uq\" on \"media_assets\" (storage_key)`,\n `create unique index \"media_folders_sibling_name_uq\" on \"media_folders\" (site_id, COALESCE(parent_id, '00000000-0000-0000-0000-000000000000'), lower(name))`,\n `create index \"media_references_entry_idx\" on \"media_references\" (entry_id, locale, state)`,\n `create unique index \"media_variants_storage_key_uq\" on \"media_variants\" (storage_key)`,\n `create unique index \"models_api_key_uq\" on \"models\" (lower(api_key)) where (deleted_at IS NULL)`,\n `create index \"outbox_events_undispatched_idx\" on \"outbox_events\" (id) where (dispatched_at IS NULL)`,\n `create index \"password_resets_user_idx\" on \"password_resets\" (admin_user_id)`,\n `create index \"preview_tokens_entry_idx\" on \"preview_tokens\" (entry_id, created_at DESC)`,\n `create index \"publication_log_entry_locale_from_idx\" on \"publication_log\" (entry_id, locale, from_seq)`,\n `create index \"publication_log_model_seq_idx\" on \"publication_log\" (site_id, model_id, from_seq)`,\n `create unique index \"publication_log_open_uq\" on \"publication_log\" (entry_id, locale) where (to_seq IS NULL)`,\n `create index \"publication_log_to_seq_idx\" on \"publication_log\" (site_id, to_seq) where (to_seq IS NOT NULL)`,\n `create index \"publication_snapshots_change_set_idx\" on \"publication_snapshots\" (change_set_id) where (change_set_id IS NOT NULL)`,\n `create index \"relation_edges_target_idx\" on \"relation_edges\" (target_entry_id, state)`,\n `create index \"scheduled_publications_entry_idx\" on \"scheduled_publications\" (entry_id, locale)`,\n `create index \"scheduled_publications_site_idx\" on \"scheduled_publications\" (site_id, run_at)`,\n `create index \"scheduled_publications_status_idx\" on \"scheduled_publications\" (status, run_at)`,\n `create index \"schema_change_jobs_change_set_idx\" on \"schema_change_jobs\" (change_set_id) where (change_set_id IS NOT NULL)`,\n `create unique index \"schema_change_jobs_in_flight_uq\" on \"schema_change_jobs\" (target_type, target_id) where (status IN ('pending', 'running'))`,\n `create index \"schema_change_jobs_model_idx\" on \"schema_change_jobs\" (model_id, created_at DESC)`,\n `create index \"schema_drafts_definition_idx\" on \"schema_drafts\" (definition_id)`,\n `create index \"site_app_roles_role_idx\" on \"site_app_roles\" (role_id)`,\n `create unique index \"sites_single_primary_uq\" on \"sites\" (is_primary) where is_primary`,\n `create index \"unique_values_entry_idx\" on \"unique_values\" (entry_id)`,\n `create unique index \"webhook_deliveries_event_uq\" on \"webhook_deliveries\" (webhook_id, event_id) where (event_id IS NOT NULL)`,\n `create index \"webhook_deliveries_webhook_idx\" on \"webhook_deliveries\" (webhook_id, created_at DESC)`,\n `create trigger \"media_assets_folder_id_fkey_set_null\" before delete on \"media_folders\" for each row begin update \"media_assets\" set folder_id = null where folder_id = old.id and site_id = old.site_id; end`,\n `create table \"sequences\" (\n \"name\" text primary key,\n \"value\" integer not null default 0\n )`,\n `insert into \"sequences\" (name, value) values ('entry_heads_change_seq', 0)`,\n `create trigger \"schema_revisions_no_update\" before update on \"schema_revisions\" for each row begin select raise(abort, 'schema_revisions rows are immutable'); end`,\n `create trigger \"content_revisions_no_update\" before update on \"content_revisions\" for each row begin select raise(abort, 'content_revisions rows are immutable'); end`,\n `insert into system_versions default values`,\n `insert into schema_settings default values`,\n `insert into locales (code, label, is_default) values ('en', 'English', 1)`,\n `insert into sites (id, key, name, is_primary) values ('00000000-0000-4000-b000-000000000001', 'default', 'Default site', 1)`,\n `insert into publication_state (site_id, last_seq) values ('00000000-0000-4000-b000-000000000001', 0)`,\n `insert into app_roles (id, key, name, description, is_system) values\n ('00000000-0000-4000-a000-000000000001', 'public', 'Public', 'Applies to every caller without a token. Grants nothing until you add permissions.', 1),\n ('00000000-0000-4000-a000-000000000002', 'authenticated', 'Authenticated', 'Held by every signed-in app user, in addition to their custom roles. Grants nothing until you add permissions.', 1)`,\n `insert into site_app_roles (site_id, audience, role_id) values\n ('00000000-0000-4000-b000-000000000001', 'public', '00000000-0000-4000-a000-000000000001'),\n ('00000000-0000-4000-b000-000000000001', 'authenticated', '00000000-0000-4000-a000-000000000002')`,\n];\n\nconst TABLES: readonly string[] = [\n 'system_versions',\n 'jobs',\n 'outbox_events',\n 'audit_events',\n 'admin_users',\n 'admin_roles',\n 'admin_role_permissions',\n 'admin_user_roles',\n 'admin_sessions',\n 'admin_invitations',\n 'password_resets',\n 'setup_tokens',\n 'api_tokens',\n 'system_settings',\n 'models',\n 'schema_revisions',\n 'model_active_versions',\n 'schema_change_jobs',\n 'locales',\n 'schema_settings',\n 'entries',\n 'content_revisions',\n 'entry_heads',\n 'relation_edges',\n 'unique_values',\n 'publication_state',\n 'publication_log',\n 'media_folders',\n 'media_assets',\n 'media_variants',\n 'media_references',\n 'media_upload_grants',\n 'scheduled_publications',\n 'webhooks',\n 'webhook_deliveries',\n 'deployment_connections',\n 'deployment_runs',\n 'preview_tokens',\n 'app_users',\n 'app_roles',\n 'app_role_permissions',\n 'app_user_roles',\n 'app_refresh_tokens',\n 'app_oauth_accounts',\n 'email_confirmations',\n 'app_password_resets',\n 'app_login_codes',\n 'extension_hook_runs',\n 'field_reads',\n 'token_reads',\n 'change_sets',\n 'schema_drafts',\n 'change_set_items',\n 'publication_snapshots',\n 'editor_presence',\n 'content_health_findings',\n 'sites',\n 'site_app_roles',\n 'assist_runs',\n 'sequences',\n];\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n for (const statement of STATEMENTS) {\n await sql.raw(statement).execute(db);\n }\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n // Foreign keys reference in cycles; checking them at commit lets the tables drop in any order.\n await sql`pragma defer_foreign_keys = on`.execute(db);\n for (const table of [...TABLES].reverse()) {\n await sql.raw(`drop table if exists \"${table}\"`).execute(db);\n }\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SQLite twin of `../20261003170000_audit_events_seq.ts`. SQLite cannot add a column whose default calls a\n * function, so the table is rebuilt: the old one is renamed aside, the new one takes `seq` from the\n * `audit_events_seq` row in `sequences` (like `entry_heads.change_seq`), and the rows are copied in\n * `(occurred_at, id)` order so existing events are numbered oldest first. Nothing references `audit_events`.\n */\nconst COLUMNS = [\n 'id',\n 'occurred_at',\n 'actor_type',\n 'actor_id',\n 'action',\n 'target_type',\n 'target_id',\n 'outcome',\n 'request_id',\n 'ip',\n 'metadata',\n 'site_id',\n] as const;\n\nconst INDEXES = [\n `create index \"audit_events_actor_idx\" on \"audit_events\" (actor_type, actor_id, occurred_at DESC)`,\n `create index \"audit_events_occurred_at_idx\" on \"audit_events\" (occurred_at DESC)`,\n `create index \"audit_events_target_idx\" on \"audit_events\" (target_type, target_id, occurred_at DESC)`,\n];\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`insert into \"sequences\" (name, value) values ('audit_events_seq', 0)`.execute(db);\n await sql`alter table \"audit_events\" rename to \"audit_events_before_seq\"`.execute(db);\n await sql`create table \"audit_events\" (\n \"id\" text_uuid not null default (gen_random_uuid()),\n \"occurred_at\" text_timestamptz not null default (shapio_now()),\n \"actor_type\" text not null,\n \"actor_id\" text,\n \"action\" text not null,\n \"target_type\" text,\n \"target_id\" text,\n \"outcome\" text not null,\n \"request_id\" text,\n \"ip\" text,\n \"metadata\" text_jsonb not null default ('{}'),\n \"site_id\" text_uuid,\n \"seq\" bigint not null default (shapio_nextval('audit_events_seq')),\n constraint \"audit_events_actor_type_check\" CHECK ((actor_type IN ('admin', 'app_user', 'token', 'anonymous', 'system'))),\n constraint \"audit_events_outcome_check\" CHECK ((outcome IN ('success', 'failure'))),\n constraint \"audit_events_site_fk\" foreign key (site_id) references sites (id) on delete set null,\n constraint \"audit_events_pkey\" primary key (id)\n )`.execute(db);\n const columns = sql.join(COLUMNS.map((column) => sql.ref(column)));\n // Each copied row takes its `seq` from the column default, in the SELECT's order.\n await sql`insert into \"audit_events\" (${columns})\n select ${columns} from \"audit_events_before_seq\" order by occurred_at, id`.execute(db);\n await sql`drop table \"audit_events_before_seq\"`.execute(db);\n for (const statement of INDEXES) {\n await sql.raw(statement).execute(db);\n }\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \"audit_events\" drop column \"seq\"`.execute(db);\n await sql`delete from \"sequences\" where name = 'audit_events_seq'`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SQLite twin of `../20261004120000_models_site_scope.ts`. `down` rebuilds `models` without `site_id`\n * (SQLite cannot drop a column that carries a foreign key). With `legacy_alter_table` on, renaming the old\n * table aside leaves the references of `schema_revisions`, `model_active_versions`, `schema_change_jobs` and\n * `entries` pointing at the name `models`, which the rebuilt table then takes; dropping the renamed table\n * deletes nothing they reference.\n */\nconst NIL_UUID = '00000000-0000-0000-0000-000000000000';\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \"models\" add column \"site_id\" text_uuid references sites (id)`.execute(db);\n await sql`create index \"models_site_idx\" on \"models\" (site_id)`.execute(db);\n await sql`drop index \"models_api_key_uq\"`.execute(db);\n await sql`\n create unique index \"models_api_key_uq\" on \"models\" (coalesce(site_id, ${sql.lit(NIL_UUID)}), lower(api_key))\n where (deleted_at IS NULL)\n `.execute(db);\n await sql`alter table \"schema_drafts\" add column \"shared\" integer_boolean not null default 0`.execute(db);\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const { rows } = await sql<{\n count: number;\n }>`select count(*) as count from \"models\" where site_id is not null`.execute(db);\n if (Number(rows[0]?.count ?? 0) > 0) {\n throw new Error(\n 'Cannot roll back per-site schema while definitions belong to a site: two sites may share an API ID. ' +\n 'Share or delete the site definitions first.',\n );\n }\n await sql`alter table \"schema_drafts\" drop column \"shared\"`.execute(db);\n await sql`pragma legacy_alter_table = on`.execute(db);\n await sql`alter table \"models\" rename to \"models_before_site_scope\"`.execute(db);\n await sql`create table \"models\" (\n \"id\" text_uuid not null,\n \"kind\" text not null,\n \"api_key\" text not null,\n \"created_at\" text_timestamptz not null default (shapio_now()),\n \"updated_at\" text_timestamptz not null default (shapio_now()),\n \"deleted_at\" text_timestamptz,\n constraint \"models_kind_check\" CHECK ((kind IN ('collection', 'singleton', 'component'))),\n constraint \"models_pkey\" primary key (id)\n )`.execute(db);\n await sql`insert into \"models\" (id, kind, api_key, created_at, updated_at, deleted_at)\n select id, kind, api_key, created_at, updated_at, deleted_at from \"models_before_site_scope\"`.execute(db);\n await sql`drop table \"models_before_site_scope\"`.execute(db);\n await sql`pragma legacy_alter_table = off`.execute(db);\n await sql`create unique index \"models_api_key_uq\" on \"models\" (lower(api_key)) where (deleted_at IS NULL)`.execute(\n db,\n );\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SQLite twin of `../20261004130000_site_seo_settings.ts`. `insert or ignore` stands in for `on conflict do\n * nothing` (the grant's unique index); the permissions version moves only when a grant was added or removed.\n */\nconst bumpPermissionsVersion = (db: Kysely<unknown>) =>\n sql`update \"system_versions\" set permissions_version = permissions_version + 1, updated_at = shapio_now()`.execute(\n db,\n );\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \"sites\" add column \"seo_defaults\" text_jsonb`.execute(db);\n const granted = await sql`\n insert or ignore into \"admin_role_permissions\" (role_id, action, model_id, condition, field_ids)\n select role_id, 'site.settings', null, null, null\n from \"admin_role_permissions\"\n where action = 'publishing.manage' and model_id is null\n `.execute(db);\n if (Number(granted.numAffectedRows ?? 0) > 0) {\n await bumpPermissionsVersion(db);\n }\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n const revoked = await sql`delete from \"admin_role_permissions\" where action = 'site.settings'`.execute(db);\n if (Number(revoked.numAffectedRows ?? 0) > 0) {\n await bumpPermissionsVersion(db);\n }\n await sql`alter table \"sites\" drop column \"seo_defaults\"`.execute(db);\n};\n","import { sql, type Kysely } from 'kysely';\n\n/**\n * SQLite twin of `../20261005120000_entry_heads_entry_created_at.ts`. One process holds the write lock, so\n * the backfill is one statement and the index is built here (a plain `CREATE INDEX`; writers wait for it, the\n * documented single-process limitation of ADR 0001, \"D2: as built\").\n */\nconst INDEX = 'entry_heads_entry_order_idx';\n\nexport const up = async (db: Kysely<unknown>): Promise<void> => {\n await sql`alter table \"entry_heads\" add column \"entry_created_at\" text_timestamptz`.execute(db);\n await sql`update \"entry_heads\" set entry_created_at = (\n select e.created_at from \"entries\" e where e.id = \"entry_heads\".entry_id\n ) where entry_created_at is null`.execute(db);\n await sql`create index ${sql.id(INDEX)} on \"entry_heads\" (site_id, model_id, state, entry_created_at desc, entry_id)`.execute(\n db,\n );\n};\n\nexport const down = async (db: Kysely<unknown>): Promise<void> => {\n await sql`drop index if exists ${sql.id(INDEX)}`.execute(db);\n await sql`alter table \"entry_heads\" drop column \"entry_created_at\"`.execute(db);\n};\n","import type { Migration } from 'kysely/migration';\nimport * as systemVersionsRelease from '../20261006120000_system_versions_release.js';\nimport * as baseline from './0001_baseline.js';\nimport * as auditEventsSeq from './20261003170000_audit_events_seq.js';\nimport * as modelsSiteScope from './20261004120000_models_site_scope.js';\nimport * as siteSeoSettings from './20261004130000_site_seo_settings.js';\nimport * as entryHeadsEntryCreatedAt from './20261005120000_entry_heads_entry_created_at.js';\n\n/**\n * SQLite migrations. `0001_baseline` creates the schema the PostgreSQL migrations up to and including\n * `SQLITE_BASELINE_COVERS` build. Every later migration follows the twin rule (CONTRIBUTING.md): it exists\n * under the same name in both lists, either as a SQLite twin in this folder or, when it only uses portable\n * Kysely (`export const dialectNeutral = true`), as the very same module. `twins.test.ts` enforces it.\n */\nexport const SQLITE_BASELINE_COVERS = '20261003160000_create_assist_runs';\n\nexport const SQLITE_MIGRATIONS: Readonly<Record<string, Migration>> = {\n '0001_baseline': baseline,\n '20261003170000_audit_events_seq': auditEventsSeq,\n '20261004120000_models_site_scope': modelsSiteScope,\n '20261004130000_site_seo_settings': siteSeoSettings,\n '20261005120000_entry_heads_entry_created_at': entryHeadsEntryCreatedAt,\n '20261006120000_system_versions_release': systemVersionsRelease,\n};\n","import type { Migration, MigrationProvider } from 'kysely/migration';\nimport type { DialectName } from '../dialect.js';\nimport * as createPlatformTables from './20261001120000_create_platform_tables.js';\nimport * as createAdminIdentity from './20261001130000_create_admin_identity.js';\nimport * as createSystemSettings from './20261001130500_create_system_settings.js';\nimport * as createSchemaTables from './20261001140000_create_schema_tables.js';\nimport * as createContentTables from './20261001150000_create_content_tables.js';\nimport * as createMediaTables from './20261001160000_create_media_tables.js';\nimport * as createPublishingTables from './20261001170000_create_publishing_tables.js';\nimport * as createAppUsers from './20261001180000_create_app_users.js';\nimport * as createExtensionHookRuns from './20261002120000_create_extension_hook_runs.js';\nimport * as appAuthTokenVersionAndLoginCodePkce from './20261002130000_app_auth_token_version_and_login_code_pkce.js';\nimport * as addPublicationLogDiffIndexes from './20261002180000_add_publication_log_diff_indexes.js';\nimport * as createUsageTables from './20261002180100_create_usage_tables.js';\nimport * as createChangeSets from './20261002180200_create_change_sets.js';\nimport * as createEditorPresenceAndContentHealth from './20261002190000_create_editor_presence_and_content_health.js';\nimport * as addChangesShipPermission from './20261003120000_add_changes_ship_permission.js';\nimport * as createSites from './20261003130000_create_sites.js';\nimport * as enqueueFieldIndexLayout from './20261003140200_enqueue_field_index_layout.js';\nimport * as changeSetItemsSiteAndPreviewEntry from './20261003140500_change_set_items_site_and_preview_entry.js';\nimport * as widenDeploymentProviders from './20261003150000_widen_deployment_providers.js';\nimport * as createAssistRuns from './20261003160000_create_assist_runs.js';\nimport * as auditEventsSeq from './20261003170000_audit_events_seq.js';\nimport * as modelsSiteScope from './20261004120000_models_site_scope.js';\nimport * as siteSeoSettings from './20261004130000_site_seo_settings.js';\nimport * as entryHeadsEntryCreatedAt from './20261005120000_entry_heads_entry_created_at.js';\nimport * as systemVersionsRelease from './20261006120000_system_versions_release.js';\nimport { MYSQL_MIGRATIONS } from './mysql/index.js';\nimport { SQLITE_MIGRATIONS } from './sqlite/index.js';\n\n/**\n * Every migration, listed explicitly. A static list works when the server is bundled for npm, where\n * directory scanning would not. Names must keep the `YYYYMMDDHHMMSS_description` order; the migrator\n * rejects out-of-order additions. Timestamps are assigned when a migration merges.\n */\nexport const MIGRATIONS: Readonly<Record<string, Migration>> = {\n '20261001120000_create_platform_tables': createPlatformTables,\n '20261001130000_create_admin_identity': createAdminIdentity,\n '20261001130500_create_system_settings': createSystemSettings,\n '20261001140000_create_schema_tables': createSchemaTables,\n '20261001150000_create_content_tables': createContentTables,\n '20261001160000_create_media_tables': createMediaTables,\n '20261001170000_create_publishing_tables': createPublishingTables,\n '20261001180000_create_app_users': createAppUsers,\n '20261002120000_create_extension_hook_runs': createExtensionHookRuns,\n '20261002130000_app_auth_token_version_and_login_code_pkce': appAuthTokenVersionAndLoginCodePkce,\n '20261002180000_add_publication_log_diff_indexes': addPublicationLogDiffIndexes,\n '20261002180100_create_usage_tables': createUsageTables,\n '20261002180200_create_change_sets': createChangeSets,\n '20261002190000_create_editor_presence_and_content_health': createEditorPresenceAndContentHealth,\n '20261003120000_add_changes_ship_permission': addChangesShipPermission,\n '20261003130000_create_sites': createSites,\n '20261003140200_enqueue_field_index_layout': enqueueFieldIndexLayout,\n '20261003140500_change_set_items_site_and_preview_entry': changeSetItemsSiteAndPreviewEntry,\n '20261003150000_widen_deployment_providers': widenDeploymentProviders,\n '20261003160000_create_assist_runs': createAssistRuns,\n '20261003170000_audit_events_seq': auditEventsSeq,\n '20261004120000_models_site_scope': modelsSiteScope,\n '20261004130000_site_seo_settings': siteSeoSettings,\n '20261005120000_entry_heads_entry_created_at': entryHeadsEntryCreatedAt,\n '20261006120000_system_versions_release': systemVersionsRelease,\n};\n\nexport const staticMigrationProvider: MigrationProvider = {\n getMigrations: () => Promise.resolve({ ...MIGRATIONS }),\n};\n\n/** SQLite's list: its baseline, then the twins of later migrations (`./sqlite/index.ts`). */\nexport const sqliteMigrationProvider: MigrationProvider = {\n getMigrations: () => Promise.resolve({ ...SQLITE_MIGRATIONS }),\n};\n\n/** MySQL's list: its baseline, then the twins of later migrations (`./mysql/index.ts`). */\nexport const mysqlMigrationProvider: MigrationProvider = {\n getMigrations: () => Promise.resolve({ ...MYSQL_MIGRATIONS }),\n};\n\nconst PROVIDERS: Readonly<Record<DialectName, MigrationProvider>> = {\n postgres: staticMigrationProvider,\n sqlite: sqliteMigrationProvider,\n mysql: mysqlMigrationProvider,\n};\n\nexport const migrationProviderFor = (dialect: DialectName): MigrationProvider => PROVIDERS[dialect];\n","import type { Kysely } from 'kysely';\nimport { Migrator, type MigrationResult } from 'kysely/migration';\nimport { LOCK_NAMESPACE, MIGRATION_LOCK_KEY } from '../constants/lockKeys.js';\nimport { withSessionAdvisoryLock } from './advisoryLocks.js';\nimport { migrationProviderFor } from './migrations/index.js';\nimport { mysqlMigrationHint } from './mysql/errors.js';\nimport { mysqlDriverOf } from './mysql/index.js';\nimport { sqliteDriverOf } from './sqlite/index.js';\nimport type { DB } from './types.js';\n\ntype MigrationLogger = {\n info: (obj: object, msg: string) => void;\n};\n\nexport class MigrationError extends Error {\n readonly results: readonly MigrationResult[];\n\n constructor(message: string, results: readonly MigrationResult[], options?: ErrorOptions) {\n super(message, options);\n this.name = 'MigrationError';\n this.results = results;\n }\n}\n\nconst dialectOfHandle = (db: Kysely<DB>) => {\n if (sqliteDriverOf(db)) {\n return 'sqlite';\n }\n return mysqlDriverOf(db) ? 'mysql' : 'postgres';\n};\n\n/**\n * Migrations must stay in order; out-of-order additions are rejected (see build plan §2). The list depends\n * on the handle's dialect (SQLite and MySQL start from a baseline).\n */\nexport const createMigrator = (db: Kysely<DB>): Migrator =>\n new Migrator({\n db,\n provider: migrationProviderFor(dialectOfHandle(db)),\n allowUnorderedMigrations: false,\n });\n\n/**\n * Runs pending migrations under a session advisory lock so concurrent instances starting together\n * migrate exactly once; the others wait, then find nothing to do.\n */\nconst runMigrations = (db: Kysely<DB>, log: MigrationLogger): Promise<MigrationResult[]> =>\n withSessionAdvisoryLock(db, LOCK_NAMESPACE.migrations, MIGRATION_LOCK_KEY, async () => {\n const { error, results = [] } = await createMigrator(db).migrateToLatest();\n for (const result of results) {\n log.info({ migration: result.migrationName, status: result.status }, 'migration');\n }\n if (error) {\n const hint = mysqlMigrationHint(error);\n throw new MigrationError(\n hint ? `Database migration failed: ${hint}` : 'Database migration failed',\n results,\n {\n cause: error,\n },\n );\n }\n return results;\n });\n\n/**\n * Runs pending migrations (see `runMigrations`), then refreshes SQLite's planner statistics: new tables and\n * indexes have none yet (`sqlite/driver.ts`).\n */\nexport const migrateToLatest = async (db: Kysely<DB>, log: MigrationLogger): Promise<MigrationResult[]> => {\n const results = await runMigrations(db, log);\n await sqliteDriverOf(db)?.optimizeStatistics('full');\n return results;\n};\n\n/** Names of migrations known to this build that have not run against the database. */\nexport const getPendingMigrations = async (db: Kysely<DB>): Promise<string[]> => {\n const migrations = await createMigrator(db).getMigrations();\n return migrations.filter((migration) => migration.executedAt === undefined).map((m) => m.name);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAaA,QAAK,OAAO,OAAuC;CAE9D,MAAM,GAAG,OACN,YAAY,iBAAiB,CAAC,CAC9B,UAAU,MAAM,YAAY,QAC3B,IACG,WAAW,CAAC,CACZ,UAAU,IAAI,CAAC,CACf,MAAM,GAAG,IAAI,CAClB,CAAC,CACA,UAAU,kBAAkB,YAAY,QAAQ,IAAI,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAC3E,UAAU,uBAAuB,YAAY,QAAQ,IAAI,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAChF,UAAU,cAAc,gBAAgB,QAAQ,IAAI,QAAQ,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC,CACpF,QAAQ;CACX,MAAM,GAAG,6CAA6C,QAAQ,EAAE;CAEhE,MAAM,GAAG,OACN,YAAY,MAAM,CAAC,CACnB,UAAU,MAAM,SAAS,QAAQ,IAAI,WAAW,CAAC,CAAC,UAAU,GAAG,mBAAmB,CAAC,CAAC,CACpF,UAAU,QAAQ,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACjD,UAAU,WAAW,UAAU,QAAQ,IAAI,QAAQ,CAAC,CAAC,UAAU,GAAG,aAAa,CAAC,CAAC,CACjF,UAAU,UAAU,SAAS,QAC5B,IACG,QAAQ,CAAC,CACT,UAAU,SAAS,CAAC,CACpB,MAAM,GA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;;;;;;;;;;;;;;;CAmBA;;;;;;;;;;;;;;;;;;;;;;;CAuBA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBA;;;;;;;;;;;;;;;;;;CAkBA;;;;;;;;;;;;;;;;CAgBA;;;;;;;;;;;;;CAaA;;;;;;;;;;;;;;CAcA;;;;;;;CAOA;;;;;;;;;;;;;;;;CAgBA;;;;;;;;;;;;;CAaA;;;;;;;;;;;;CAYA;;;;;;;;;;;;CAYA;;;;;;;;;;;CAWA;;;;;;;CAOA;;;;;;;;;;;;CAYA;;;;;;;;;CASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCA;;;;;;;;;;;;;;;;;CAiBA;;;;;;;;;;;;;;;;;;;;;;CAsBA;;;;;;;;;;;CAWA;;;;;;;;;;;CAWA;;;;;;;;;;;;;;;;;;CAkBA;;;;;;;;;;;;;CAaA;;;;;;;;CAQA;;;;;;;;;;;;;;;;;;;;;CAqBA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAKA;;;;;;;CAOA;CACA;;;;CAIA;;CAEA;;CAEA;;CAEA;CACA;CACA;CACA;CACA;CACA;;;CAGA;;;AAGF;AAEA,MAAMC,WAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,0BAA0B,OAAO,IAAqB,eAC1D,GAAG,WAAW,CAAC,CAAC,QAAQ,OAAO,eAAe;CAC5C,MAAM,GAAG,6BAA6B,QAAQ,UAAU;CACxD,IAAI;EACF,KAAK,MAAM,aAAa,YACtB,MAAM,IAAI,IAAI,SAAS,CAAC,CAAC,QAAQ,UAAU;CAE/C,UAAU;EACR,MAAM,GAAG,6BAA6B,QAAQ,UAAU;CAC1D;AACF,CAAC;AAEH,MAAaC,OAAK,OAAO,OAAuC,wBAAwB,IAAIF,YAAU;AAEtG,MAAaG,SAAO,OAAO,OACzB,wBACE,IACA,CAAC,GAAGF,QAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,UAAU,0BAA0B,MAAM,GAAG,CAC1E;;;;;;;;;;;;;ACnqCF,MAAaG,OAAK,OAAO,OAAuC;CAC9D,MAAM,GAAG;;uDAE4C,QAAQ,EAAE;AACjE;AAEA,MAAa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;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;CAIA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAGA;;;AAGF;AAEA,MAAM,SAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAaC,OAAK,OAAO,OAAuC;CAC9D,KAAK,MAAM,aAAa,YACtB,MAAM,IAAI,IAAI,SAAS,CAAC,CAAC,QAAQ,EAAE;AAEvC;AAEA,MAAaC,SAAO,OAAO,OAAuC;CAEhE,MAAM,GAAG,iCAAiC,QAAQ,EAAE;CACpD,KAAK,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,GACtC,MAAM,IAAI,IAAI,yBAAyB,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;AAE/D;;;;;;;;;;;;;AC/nCA,MAAM,UAAU;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,UAAU;CACd;CACA;CACA;AACF;AAEA,MAAaC,OAAK,OAAO,OAAuC;CAC9D,MAAM,GAAG,uEAAuE,QAAQ,EAAE;CAC1F,MAAM,GAAG,iEAAiE,QAAQ,EAAE;CACpF,MAAM,GAAG;;;;;;;;;;;;;;;;;;KAkBN,QAAQ,EAAE;CACb,MAAM,UAAU,IAAI,KAAK,QAAQ,KAAK,WAAW,IAAI,IAAI,MAAM,CAAC,CAAC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