CREATE TABLE osint.assets (
  id TEXT PRIMARY KEY,
  level_id TEXT NOT NULL REFERENCES osint.levels(id) ON DELETE CASCADE,
  original_name TEXT NOT NULL,
  mime_type TEXT NOT NULL,
  byte_size BIGINT NOT NULL CHECK (byte_size >= 0),
  content BYTEA NOT NULL,
  checksum_sha256 TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX assets_level_idx ON osint.assets(level_id, created_at);

ALTER TABLE osint.widgets
  ADD COLUMN asset_id TEXT REFERENCES osint.assets(id) ON DELETE SET NULL;

COMMENT ON TABLE osint.assets IS 'Uploaded source files used by database-backed document widgets';
