CREATE TABLE dumps (
    id TEXT PRIMARY KEY,
    kind TEXT NOT NULL,
    title TEXT NOT NULL,
    comment TEXT,
    user_id TEXT NOT NULL,
    created_at TEXT NOT NULL,
    url TEXT,
    rich_content TEXT,
    file_name TEXT,
    file_mime TEXT,
    file_size INTEGER,
    vote_count INTEGER NOT NULL DEFAULT 0,
    FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE users (
  id TEXT PRIMARY KEY,
  username TEXT UNIQUE NOT NULL,
  password_hash TEXT NOT NULL,
  is_admin INTEGER NOT NULL DEFAULT 0,
  created_at TEXT NOT NULL,
  avatar_mime TEXT
);

CREATE TABLE votes (
  dump_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  created_at TEXT NOT NULL,
  PRIMARY KEY (dump_id, user_id),
  FOREIGN KEY (dump_id) REFERENCES dumps(id) ON DELETE CASCADE,
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
