/** * SQL schema definitions for context storage adapters. * * Provides DDL strings for both Postgres and SQLite that define the * conversations and messages tables with proper ordering and cascade deletes. */ /** * Postgres DDL for the conversations table. * Uses JSONB for metadata and TIMESTAMPTZ for timestamps. */ export declare const POSTGRES_CONVERSATIONS_DDL = "\nCREATE TABLE IF NOT EXISTS conversations (\n id TEXT PRIMARY KEY,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n metadata JSONB NOT NULL DEFAULT '{}'::jsonb\n);\n\nCREATE INDEX IF NOT EXISTS idx_conversations_created_at ON conversations (created_at);\nCREATE INDEX IF NOT EXISTS idx_conversations_updated_at ON conversations (updated_at);\n"; /** * Postgres DDL for the messages table. * Uses composite primary key on (conversation_id, sequence) for ordering. * Cascade deletes when parent conversation is removed. */ export declare const POSTGRES_MESSAGES_DDL = "\nCREATE TABLE IF NOT EXISTS messages (\n conversation_id TEXT NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,\n sequence INTEGER NOT NULL,\n payload JSONB NOT NULL,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n PRIMARY KEY (conversation_id, sequence)\n);\n\nCREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages (conversation_id);\n"; /** * Combined Postgres DDL for both tables. */ export declare const POSTGRES_SCHEMA_DDL = "\n\nCREATE TABLE IF NOT EXISTS conversations (\n id TEXT PRIMARY KEY,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n metadata JSONB NOT NULL DEFAULT '{}'::jsonb\n);\n\nCREATE INDEX IF NOT EXISTS idx_conversations_created_at ON conversations (created_at);\nCREATE INDEX IF NOT EXISTS idx_conversations_updated_at ON conversations (updated_at);\n\n\nCREATE TABLE IF NOT EXISTS messages (\n conversation_id TEXT NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,\n sequence INTEGER NOT NULL,\n payload JSONB NOT NULL,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n PRIMARY KEY (conversation_id, sequence)\n);\n\nCREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages (conversation_id);\n\n"; /** * SQLite DDL for the conversations table. * Uses TEXT for JSON storage (SQLite lacks native JSON type in DDL). * Timestamps stored as ISO 8601 strings. */ export declare const SQLITE_CONVERSATIONS_DDL = "\nCREATE TABLE IF NOT EXISTS conversations (\n id TEXT PRIMARY KEY,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n metadata TEXT NOT NULL DEFAULT '{}'\n);\n\nCREATE INDEX IF NOT EXISTS idx_conversations_created_at ON conversations (created_at);\nCREATE INDEX IF NOT EXISTS idx_conversations_updated_at ON conversations (updated_at);\n"; /** * SQLite DDL for the messages table. * Uses composite primary key on (conversation_id, sequence) for ordering. * Cascade deletes require PRAGMA foreign_keys = ON at runtime. */ export declare const SQLITE_MESSAGES_DDL = "\nCREATE TABLE IF NOT EXISTS messages (\n conversation_id TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n payload TEXT NOT NULL,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n PRIMARY KEY (conversation_id, sequence),\n FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages (conversation_id);\n"; /** * Combined SQLite DDL for both tables. */ export declare const SQLITE_SCHEMA_DDL = "\n\nCREATE TABLE IF NOT EXISTS conversations (\n id TEXT PRIMARY KEY,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n metadata TEXT NOT NULL DEFAULT '{}'\n);\n\nCREATE INDEX IF NOT EXISTS idx_conversations_created_at ON conversations (created_at);\nCREATE INDEX IF NOT EXISTS idx_conversations_updated_at ON conversations (updated_at);\n\n\nCREATE TABLE IF NOT EXISTS messages (\n conversation_id TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n payload TEXT NOT NULL,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n PRIMARY KEY (conversation_id, sequence),\n FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages (conversation_id);\n\n"; /** * Get the appropriate schema DDL for a database type. */ export declare function getSchemaFor(dbType: 'postgres' | 'sqlite'): string; /** * Get the conversations table DDL for a database type. */ export declare function getConversationsDDL(dbType: 'postgres' | 'sqlite'): string; /** * Get the messages table DDL for a database type. */ export declare function getMessagesDDL(dbType: 'postgres' | 'sqlite'): string; //# sourceMappingURL=schema.d.ts.map