Skip to content

Commit

Permalink
chore: migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Mar 5, 2024
1 parent 8744147 commit 508d8ff
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dotenv/config';

import { logs } from './drizzle/schema';
import { connect } from './drizzle/prod/connect';

const data: any = await fetch(`https://resonance.breadio.wiki/api/product`).then((r) => r.json());

const database = connect();

for (const log of data.latest) {
try {
await database
.insert(logs)
.values({
name: log.name,
sourceCity: log.sourceCity,
targetCity: log.targetCity,
type: log.type,
trend: log.trend ? log.trend : 'same',
price: log.price,
percent: log.percent,
uploadedAt: new Date(log.uploadedAt),
uploaderId: 1
})
.onConflictDoNothing();
} catch (error) {
console.log(error);
console.log(log);
process.exit();
}
}

0 comments on commit 508d8ff

Please sign in to comment.