-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { MongoClient } from 'mongodb' | ||
export type Target = { | ||
key: string | ||
value: { | ||
pixKey: string | ||
city: string | ||
name: string | ||
query: string | ||
} | ||
} | ||
|
||
export type Origin = { | ||
telegramId: number | ||
pixKey: string | ||
city: string | ||
name: string | ||
} | ||
|
||
function convert(origin: Origin): Target { | ||
return { | ||
key: origin.telegramId.toString(), | ||
value: { | ||
pixKey: origin.pixKey, | ||
city: origin.city, | ||
name: origin.name, | ||
query: '' | ||
} | ||
} | ||
} | ||
|
||
const DB_URI = process.env.DB_URI ?? '' | ||
const PROD_DBNAME = 'amandapix' | ||
|
||
async function main() { | ||
const client = new MongoClient(DB_URI) | ||
await client.connect() | ||
const db = client.db(PROD_DBNAME) | ||
const users = db.collection<Origin>('users') | ||
const sessions = db.collection<Target>('sessions') | ||
|
||
const migrated = await users | ||
.find({}) | ||
.toArray() | ||
.then((users) => users.filter((user) => user.pixKey)) | ||
.then((users) => users.map(convert)) | ||
|
||
await sessions.insertMany(migrated) | ||
|
||
await client.close() | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log('Done') | ||
}) | ||
.catch(console.error) |
43d3ddf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
amandapix-telegram-bot – ./
amandapix-telegram-bot.vercel.app
amandapix-telegram-bot-roziscoding.vercel.app
amandapix-telegram-bot-git-main-roziscoding.vercel.app