import type { Migration } from '@/shared/db';

export const messageEmbeddingMigrations: readonly Migration[] = [
  {
    id: '2026-04-24_pgvector_extension',
    sql: `
      CREATE EXTENSION IF NOT EXISTS vector;
    `,
  },
  {
    id: '2026-04-24_message_embeddings_table',
    sql: `
      CREATE TABLE IF NOT EXISTS macsync.message_embeddings (
        message_id    UUID PRIMARY KEY REFERENCES macsync.messages(id) ON DELETE CASCADE,
        embedding     vector(768),
        model_version TEXT NOT NULL,
        created_at    TIMESTAMPTZ NOT NULL DEFAULT now()
      );

      CREATE INDEX IF NOT EXISTS idx_message_embeddings_hnsw
      ON macsync.message_embeddings
      USING hnsw (embedding vector_cosine_ops)
      WITH (m = 16, ef_construction = 64);
    `,
  },
];
