-
Notifications
You must be signed in to change notification settings - Fork 75
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
1 parent
aa632e6
commit dabbadb
Showing
6 changed files
with
59 additions
and
25 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,7 @@ | ||
import { defineConfig } from "drizzle-kit"; | ||
|
||
export default defineConfig({ | ||
dialect: "postgresql", | ||
schema: "./src/db/schema/index.ts", | ||
out: "./drizzle", | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
/** | ||
* To run this script, run "pnpm run migrate". | ||
*/ | ||
|
||
import { drizzle } from 'drizzle-orm/postgres-js'; | ||
import { migrate } from 'drizzle-orm/postgres-js/migrator'; | ||
|
||
import { ddbClient } from '../src/db/ddb.ts'; | ||
import { db, client } from '../src/db/index.ts'; | ||
import { user } from '../src/db/schema/index.ts'; | ||
|
||
/** | ||
* Migrates the current drizzle schema to the PostgreSQL database associated | ||
* with the drizzle client. Before migrating, run "pnpm run generate" to generate | ||
* the migration files, and make sure the PostgreSQL database exists beforehand. | ||
*/ | ||
async function migrateToPostgres() { | ||
await migrate(drizzle(client), { | ||
migrationsFolder: './drizzle' | ||
}); | ||
} | ||
|
||
/** | ||
* Migrates user data from DynamoDB to the PostgreSQL database associated | ||
* with the drizzle client. | ||
*/ | ||
async function insertUsersToPostgres() { | ||
const userIds = await ddbClient.getUserIds(); | ||
const usersToInsert = userIds.map((userId) => ({ id: userId })); | ||
await db.insert(user).values(usersToInsert); | ||
console.log(await db.query.user.findMany()); | ||
} | ||
|
||
async function main() { | ||
try { | ||
await migrateToPostgres(); | ||
await insertUsersToPostgres(); | ||
} catch (error) { | ||
console.log(error); | ||
} finally { | ||
await client.end(); | ||
} | ||
} | ||
|
||
main(); |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { drizzle } from 'drizzle-orm/postgres-js'; | ||
import postgres from 'postgres'; | ||
import * as schema from './schema/index.js'; | ||
|
||
export const client = postgres('postgres://postgres:postgres@localhost:5432/antalmanac'); | ||
|
||
export const db = drizzle(client); | ||
export const db = drizzle(client, { schema }); |