CREATE TABLE IF NOT EXISTS authjs_users (
  id TEXT PRIMARY KEY,
  name TEXT,
  email TEXT UNIQUE,
  "emailVerified" TIMESTAMPTZ,
  image TEXT
);

CREATE TABLE IF NOT EXISTS authjs_accounts (
  "userId" TEXT NOT NULL REFERENCES authjs_users(id) ON DELETE CASCADE,
  type TEXT NOT NULL,
  provider TEXT NOT NULL,
  "providerAccountId" TEXT NOT NULL,
  refresh_token TEXT,
  access_token TEXT,
  expires_at INTEGER,
  token_type TEXT,
  scope TEXT,
  id_token TEXT,
  session_state TEXT,
  PRIMARY KEY (provider, "providerAccountId")
);

CREATE TABLE IF NOT EXISTS authjs_sessions (
  "sessionToken" TEXT PRIMARY KEY,
  "userId" TEXT NOT NULL REFERENCES authjs_users(id) ON DELETE CASCADE,
  expires TIMESTAMPTZ NOT NULL
);

CREATE TABLE IF NOT EXISTS authjs_verification_token (
  identifier TEXT NOT NULL,
  token TEXT NOT NULL,
  expires TIMESTAMPTZ NOT NULL,
  PRIMARY KEY (identifier, token)
);

CREATE INDEX IF NOT EXISTS authjs_accounts_user_idx ON authjs_accounts("userId");
CREATE INDEX IF NOT EXISTS authjs_sessions_user_idx ON authjs_sessions("userId");

INSERT INTO kanban_card (card_id, title, description, status, priority, position)
VALUES
  ('card-seed-1', 'Wire up local sandbox', 'Boot the project and verify the preview stack.', 'doing', 'high', 1),
  ('card-seed-2', 'Polish board interactions', 'Tighten drag/drop and empty-state behavior.', 'todo', 'medium', 1)
ON CONFLICT DO NOTHING;
