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

export const deviceMigrations: readonly Migration[] = [
  {
    id: '2026-04-18_icloud_schema',
    sql: `
      CREATE SCHEMA IF NOT EXISTS macsync;
    `,
  },
  {
    id: '2026-04-18_device_initial',
    sql: `
      CREATE TABLE IF NOT EXISTS macsync.devices (
        id            UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        name          TEXT NOT NULL,
        token         TEXT NOT NULL UNIQUE,
        platform      TEXT NOT NULL DEFAULT 'macos',
        hardware_id   TEXT UNIQUE,
        registered_at TIMESTAMPTZ NOT NULL DEFAULT now(),
        last_seen_at  TIMESTAMPTZ,
        revoked_at    TIMESTAMPTZ,
        created_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
        updated_at    TIMESTAMPTZ NOT NULL DEFAULT now()
      );
      CREATE INDEX IF NOT EXISTS idx_devices_token ON macsync.devices(token);
      CREATE INDEX IF NOT EXISTS idx_devices_hardware_id ON macsync.devices(hardware_id);
    `,
  },
];
