CREATE TABLE issue_media (
    id         BIGSERIAL PRIMARY KEY,
    issue_id   BIGINT NOT NULL REFERENCES issues(id) ON DELETE CASCADE,
    uploader_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    file_path  TEXT NOT NULL,
    mime_type  TEXT NOT NULL,
    file_size  BIGINT NOT NULL,
    uploaded_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_issue_media_issue ON issue_media(issue_id);

INSERT INTO permissions (module, action, scope, description)
VALUES ('issue', 'upload_media', FALSE, 'Soruna medya ekle')
ON CONFLICT (module, action, scope) DO NOTHING;
