-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
14 changed files
with
394 additions
and
53 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, './server/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PgliteDatabase } from 'drizzle-orm/pglite'; | ||
|
||
import * as schema from '../server/schemas/lobechat'; | ||
|
||
export type LobeChatDatabaseSchema = typeof schema; | ||
|
||
export type LobeChatDatabase = PgliteDatabase<LobeChatDatabaseSchema>; |
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
Oops, something went wrong.