Skip to content

Commit

Permalink
add remove duplicate script to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza-sharifpour committed Oct 26, 2024
1 parent ce7d0dd commit 2218092
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"generate-transactions": "ts-node -r dotenv/config scripts/generateCitizenTransactions.ts",
"db:populate": "node --experimental-specifier-resolution=node --loader ts-node/esm src/server/db/migrations/populate_db.ts",
"update-farcaster": "cross-env NODE_ENV=development tsx src/scripts/updateFarcasterData.ts",
"update-farcaster-prod": "cross-env NODE_ENV=production tsx src/scripts/updateFarcasterData.ts"
"update-farcaster-prod": "cross-env NODE_ENV=production tsx src/scripts/updateFarcasterData.ts",
"remove-duplicates": "node --experimental-specifier-resolution=node --loader ts-node/esm src/scripts/removeDuplicates.ts",
"remove-duplicates-prod": "cross-env NODE_ENV=production node --experimental-specifier-resolution=node --loader ts-node/esm src/scripts/removeDuplicates.ts"
},
"dependencies": {
"@airstack/node": "^0.0.7",
Expand Down
35 changes: 35 additions & 0 deletions src/scripts/removeDuplicates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import "dotenv/config";

import postgres from "postgres";
import { removeDuplicateLinks } from "../server/db/scripts/removeDuplicateLinks.js";

// Initialize database connection
if (!process.env.DATABASE_URL) {
console.error("DATABASE_URL is required");
process.exit(1);
}

const sql = postgres(process.env.DATABASE_URL, { max: 1 });

async function main() {
try {
console.log("Starting duplicate links removal...");
await removeDuplicateLinks();
console.log("Completed removing duplicate links");
} catch (error) {
console.error("Failed to remove duplicate links:", error);
process.exit(1);
} finally {
await sql.end();
}
}

// If running as a module
if (import.meta.url === import.meta.resolve(process.argv[1])) {
main().catch((error) => {
console.error("Script failed:", error);
process.exit(1);
});
}

export { main as removeDuplicates };

0 comments on commit 2218092

Please sign in to comment.