-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: support server db mode with Postgres / Drizzle ORM / tRPC (#2556
- Loading branch information
Showing
81 changed files
with
14,663 additions
and
227 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
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 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: off | ||
server: | ||
flags: | ||
- server | ||
app: | ||
flags: | ||
- app | ||
patch: off |
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,29 @@ | ||
import * as dotenv from 'dotenv'; | ||
import type { Config } from 'drizzle-kit'; | ||
|
||
// Read the .env file if it exists, or a file specified by the | ||
|
||
// dotenv_config_path parameter that's passed to Node.js | ||
|
||
dotenv.config(); | ||
|
||
let connectionString = process.env.DATABASE_URL; | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
console.log('current ENV:', process.env.NODE_ENV); | ||
connectionString = process.env.DATABASE_TEST_URL; | ||
} | ||
|
||
if (!connectionString) | ||
throw new Error('`DATABASE_URL` or `DATABASE_TEST_URL` not found in environment'); | ||
|
||
export default { | ||
dbCredentials: { | ||
url: connectionString, | ||
}, | ||
dialect: 'postgresql', | ||
out: './src/database/server/migrations', | ||
|
||
schema: './src/database/server/schemas/lobechat.ts', | ||
strict: true, | ||
} satisfies Config; |
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,30 @@ | ||
import * as dotenv from 'dotenv'; | ||
import * as migrator from 'drizzle-orm/neon-serverless/migrator'; | ||
import { join } from 'node:path'; | ||
|
||
import { serverDB } from '../../src/database/server/core/db'; | ||
|
||
// Read the `.env` file if it exists, or a file specified by the | ||
// dotenv_config_path parameter that's passed to Node.js | ||
dotenv.config(); | ||
|
||
const runMigrations = async () => { | ||
await migrator.migrate(serverDB, { | ||
migrationsFolder: join(__dirname, '../../src/database/server/migrations'), | ||
}); | ||
console.log('✅ database migration pass.'); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(0); | ||
}; | ||
|
||
let connectionString = process.env.DATABASE_URL; | ||
|
||
// only migrate database if the connection string is available | ||
if (connectionString) { | ||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
runMigrations().catch((err) => { | ||
console.error('❌ Database migrate failed:', err); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(1); | ||
}); | ||
} |
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.