-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
9 changed files
with
358 additions
and
34 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
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,11 @@ | ||
import { readMigrationFiles } from 'drizzle-orm/migrator'; | ||
import { join } from 'node:path'; | ||
|
||
const dbBase = join(__dirname, '../../src/database'); | ||
const migrationsFolder = join(dbBase, './migrations'); | ||
|
||
const migrations = readMigrationFiles({ migrationsFolder: migrationsFolder }); | ||
|
||
await Bun.write(join(dbBase, './client/migrations.json'), JSON.stringify(migrations)); | ||
|
||
console.log('🏁Migrations compiled!'); |
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,13 @@ | ||
import { IdbFs, PGlite } from '@electric-sql/pglite'; | ||
import { vector } from '@electric-sql/pglite/vector'; | ||
import { drizzle } from 'drizzle-orm/pglite'; | ||
|
||
import * as schema from '../server/schemas/lobechat'; | ||
|
||
const client = new PGlite({ | ||
extensions: { vector }, | ||
fs: new IdbFs('lobechat'), | ||
relaxedDurability: true, | ||
}); | ||
|
||
export const clientDB = drizzle({ client, schema }); |
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,14 @@ | ||
import type { MigrationConfig } from 'drizzle-orm/migrator'; | ||
|
||
import { clientDB } from './db'; | ||
import migrations from './migrations.json'; | ||
|
||
export const migrate = async () => { | ||
// refs: https://github.com/drizzle-team/drizzle-orm/discussions/2532 | ||
// @ts-ignore | ||
clientDB.dialect.migrate(migrations, clientDB.session, { | ||
migrationsTable: 'drizzle_migrations', | ||
} satisfies Omit<MigrationConfig, 'migrationsFolder'>); | ||
|
||
return clientDB; | ||
}; |
Large diffs are not rendered by default.
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
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
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ import * as dotenv from 'dotenv'; | |
|
||
dotenv.config(); | ||
|
||
global.crypto = new Crypto(); | ||
// global.crypto = new Crypto(); |