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

export const noteMigrations: readonly Migration[] = [
  {
    id: '2026-05-13_note_initial',
    sql: `
      CREATE TABLE IF NOT EXISTS macsync.notes (
        id            UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        device_id     UUID NOT NULL REFERENCES macsync.devices(id) ON DELETE CASCADE,
        external_id   TEXT NOT NULL,
        folder        TEXT,
        name          TEXT,
        body          TEXT,
        modified_at   TIMESTAMPTZ,
        synced_at     TIMESTAMPTZ NOT NULL DEFAULT now(),
        UNIQUE(device_id, external_id)
      );
      CREATE INDEX IF NOT EXISTS idx_notes_device ON macsync.notes(device_id);
      CREATE INDEX IF NOT EXISTS idx_notes_folder ON macsync.notes(folder);
    `,
  },
];
