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

export const calendarMigrations: readonly Migration[] = [
  {
    id: '2026-04-18_calendar_initial',
    sql: `
      CREATE TABLE IF NOT EXISTS macsync.calendars (
        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,
        title         TEXT NOT NULL DEFAULT '',
        calendar_type TEXT NOT NULL DEFAULT 'local',
        color         TEXT NOT NULL DEFAULT '#888888',
        source        TEXT NOT NULL DEFAULT '',
        synced_at     TIMESTAMPTZ NOT NULL DEFAULT now(),
        created_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
        updated_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
        UNIQUE(device_id, external_id)
      );
      CREATE INDEX IF NOT EXISTS idx_calendars_device ON macsync.calendars(device_id);
    `,
  },
];
