Files
artifactapi/migrations/0005_cargo_index.sql
T
unkin-agent ce8026d46e
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
Guard cargo publishes against name and version collisions
- serialise publishes per crate with an advisory lock in one transaction
- add a unique index on normalised name and version without build metadata
- validate versions as strict SemVer 2.0 and reject an empty .crate
- renumber the migration to 0005
2026-10-17 12:43:44 +11:00

20 lines
830 B
SQL

-- Local cargo registries: one sparse-index line per published crate version.
-- line holds the index JSON minus yanked, which flips on yank/unyank.
CREATE TABLE IF NOT EXISTS cargo_index (
id BIGSERIAL PRIMARY KEY,
repo_name TEXT NOT NULL,
file_path TEXT NOT NULL,
name TEXT NOT NULL,
version TEXT NOT NULL,
line TEXT NOT NULL,
yanked BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(repo_name, file_path)
);
CREATE INDEX IF NOT EXISTS idx_cargo_index_repo_name ON cargo_index(repo_name, lower(name));
-- Cargo treats names equal up to case and -/_, and versions equal up to build metadata.
CREATE UNIQUE INDEX IF NOT EXISTS idx_cargo_index_unique_version
ON cargo_index(repo_name, replace(lower(name), '-', '_'), split_part(version, '+', 1));