import { stmt } from "./db";
/** Statements that point the old repo location at the repo and free the new location from stale redirects. */
export function repoMoveStatements(
repoId: string,
from: { owner: string; name: string },
to: { owner: string; name: string },
): D1PreparedStatement[] {
return [
stmt("DELETE FROM repo_redirects WHERE owner_name = ? AND repo_name = ?", to.owner, to.name),
stmt(
`INSERT INTO repo_redirects (owner_name, repo_name, repo_id, created_at) VALUES (?, ?, ?, ?)
ON CONFLICT (owner_name, repo_name) DO UPDATE SET repo_id = excluded.repo_id, created_at = excluded.created_at`,
from.owner,
from.name,
repoId,
Date.now(),
),
];
}