create temporary table __crank_v2_context ( had_mcp_ledger boolean not null ) on commit drop; insert into __crank_v2_context (had_mcp_ledger) values (to_regclass(format('%I.%I', current_schema(), '__crank_mcp_migrations')) is not null); create table __crank_migrations ( version bigint primary key, name text not null unique, checksum text not null, phase text not null, compatibility text not null, applied_at timestamptz not null default now() ); create table __crank_migration_legacy_audit ( source text not null, source_version bigint not null, source_checksum text not null, imported_at timestamptz not null default now(), primary key (source, source_version) ); insert into __crank_migrations (version, name, checksum, phase, compatibility) values ( 1, 'community-baseline-v1', 'crank-community-baseline-v1', 'expand', 'legacy-baseline' ); insert into __crank_migration_legacy_audit (source, source_version, source_checksum) values ('core', 1, 'crank-community-baseline-v1'); create table if not exists __crank_mcp_migrations ( version integer primary key, checksum text not null, applied_at timestamptz not null default now() ); create table if not exists mcp_transport_sessions ( id text primary key, protocol_version text not null, initialized boolean not null default false, supports_elicitation boolean not null default false, workspace_slug text not null, agent_slug text not null, created_at timestamptz not null, updated_at timestamptz not null, expires_at timestamptz null ); alter table mcp_transport_sessions add column if not exists supports_elicitation boolean not null default false; alter table mcp_transport_sessions add column if not exists expires_at timestamptz null; create index if not exists mcp_transport_sessions_workspace_agent_idx on mcp_transport_sessions(workspace_slug, agent_slug, updated_at desc); create index if not exists mcp_transport_sessions_expires_at_idx on mcp_transport_sessions(expires_at) where expires_at is not null; insert into __crank_mcp_migrations (version, checksum) values (1, 'mcp-transport-sessions-v1') on conflict (version) do nothing; insert into __crank_migration_legacy_audit (source, source_version, source_checksum) select 'mcp-session', 1, 'mcp-transport-sessions-v1' from __crank_v2_context where had_mcp_ledger; create table if not exists __crank_ext_migrations ( extension_name text not null, version integer not null, checksum text null, applied_at timestamptz not null default now(), primary key (extension_name, version) ); alter table __crank_ext_migrations add column if not exists checksum text null;