refactor(scripts): delete 20 one-off/legacy scripts
The scripts/ directory had accumulated 29 entries, half of which were one-off fixes that had already done their job and several of which were Supabase-era artifacts that don't apply now that the project uses direct Postgres via `pg`. Deleted (none referenced from package.json, CLAUDE.md, MEMORY.md, .gitea/workflows/deploy.yml, db/seeds/, or src/): Supabase-era one-offs (the project moved off Supabase JS/REST): - apply-admin-create-stop.js (RPC installer against supabase.co) - fix-archived-rls.js (RLS repair against supabase.co) - seed.sh (pure supabase REST seeding) - seed_tuxedo_tour.py (Python equivalent of the JS seed) Codemods / lint fixers that ran once: - fix-server-auth.js, fix-server-auth-ast.js - fix-button-has-type.js, fix-control-has-associated-label.js Versioned iteration history of one-off checks: - check-stop-fns.js, check-stop-fns2.js, check-stop-fns3.js - verify-stop-fns.js (only referenced by apply-admin-create-stop.js) Other one-offs: - cleanup-duplicate-stops.ts - create-admin-user.ts, seed-admin.ts (superseded by provision-admin.ts) - seed-tuxedo.ts (superseded by seed-tuxedo-2026.js) - import-woo-to-route.ts (WooCommerce import, no longer used) - upload-tuxedo-video.mjs, verify-email.ts, e2e-test.sh Also updated one stale comment in src/actions/admin/users.ts that referenced scripts/seed-admin.ts. Kept (9 scripts, all live-referenced): - migrate.js (package.json + deploy.yml + MEMORY.md) - db-reset.js (package.json: db:reset) - seed-tuxedo-2026.js (package.json: db:seed:tour) - import-tuxedo-stops.ts (db/seeds preferred path) - provision-admin.ts (CLAUDE.md production bootstrap) - preflight-check.js, postflight-check.js (.gitea/workflows/deploy.yml) - generate-pwa-icons.js, generate-pwa-screenshots.js (reproducible PWA build assets, referenced in design docs) Verified: tsc clean, 174/175 tests pass (same baseline), package.json scripts and deploy.yml all still resolve to kept scripts.
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Cleanup script: remove duplicate stops from the Tuxedo Corn 2026 tour.
|
||||
* Keeps the row with the latest created_at per (brand_id, date, city, state, location, time).
|
||||
* Run: DATABASE_URL="postgresql://..." npx tsx scripts/cleanup-duplicate-stops.ts
|
||||
*/
|
||||
import { Pool } from "pg";
|
||||
|
||||
const pool = new Pool({
|
||||
connectionString:
|
||||
process.env.DATABASE_ADMIN_URL ??
|
||||
process.env.DATABASE_URL ??
|
||||
"postgres://postgres:postgres@localhost:5432/route_commerce",
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
await client.query("BEGIN");
|
||||
|
||||
// Find duplicate groups (same brand_id, date, city, state, location, time)
|
||||
const dupes = await client.query(`
|
||||
SELECT brand_id::text, date, city, state, location, time, count(*) as cnt, min(created_at::text) as oldest, max(created_at::text) as newest
|
||||
FROM stops
|
||||
WHERE deleted_at IS NULL
|
||||
GROUP BY brand_id, date, city, state, location, time
|
||||
HAVING count(*) > 1
|
||||
ORDER BY date, city
|
||||
`);
|
||||
|
||||
console.log(`Found ${dupes.rowCount} duplicate groups`);
|
||||
if (dupes.rowCount === 0) {
|
||||
await client.query("COMMIT");
|
||||
console.log("No duplicates found.");
|
||||
return;
|
||||
}
|
||||
|
||||
let totalDeleted = 0;
|
||||
for (const row of dupes.rows) {
|
||||
// Keep the row with the latest created_at, delete the rest
|
||||
const del = await client.query(`
|
||||
DELETE FROM stops
|
||||
WHERE brand_id = $1
|
||||
AND date = $2
|
||||
AND city = $3
|
||||
AND state = $4
|
||||
AND location = $5
|
||||
AND time IS NOT DISTINCT FROM $6
|
||||
AND deleted_at IS NULL
|
||||
AND created_at < (
|
||||
SELECT max(created_at) FROM stops s2
|
||||
WHERE s2.brand_id = stops.brand_id
|
||||
AND s2.date = stops.date
|
||||
AND s2.city = stops.city
|
||||
AND s2.state = stops.state
|
||||
AND s2.location = stops.location
|
||||
AND (s2.time IS NOT DISTINCT FROM stops.time)
|
||||
AND s2.deleted_at IS NULL
|
||||
)
|
||||
`, [row.brand_id, row.date, row.city, row.state, row.location, row.time]);
|
||||
totalDeleted += del.rowCount ?? 0;
|
||||
console.log(` Deleted ${del.rowCount} duplicate(s) for ${row.city}, ${row.state} on ${row.date}`);
|
||||
}
|
||||
|
||||
await client.query("COMMIT");
|
||||
console.log(`\nDone. Total duplicates removed: ${totalDeleted}`);
|
||||
} catch (e) {
|
||||
await client.query("ROLLBACK");
|
||||
throw e;
|
||||
} finally {
|
||||
client.release();
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user