-
-
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 with Postgres and drizzle ORM
- Loading branch information
Showing
55 changed files
with
7,502 additions
and
54 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,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); | ||
}); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/app/api/webhooks/clerk/__tests__/fixtures/createUser.json
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,73 @@ | ||
{ | ||
"backup_code_enabled": false, | ||
"banned": false, | ||
"create_organization_enabled": true, | ||
"created_at": 1713709987911, | ||
"delete_self_enabled": true, | ||
"email_addresses": [ | ||
{ | ||
"created_at": 1713709977919, | ||
"email_address": "arvinx@foxmail.com", | ||
"id": "idn_2fPkD9X1lfzSn5lJVDGyochYq8k", | ||
"linked_to": [], | ||
"object": "email_address", | ||
"reserved": false, | ||
"updated_at": 1713709987951, | ||
"verification": [] | ||
} | ||
], | ||
"external_accounts": [ | ||
{ | ||
"approved_scopes": "read:user user:email", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/28616219?v=4", | ||
"created_at": 1713709542104, | ||
"email_address": "arvinx@foxmail.com", | ||
"first_name": "Arvin", | ||
"id": "eac_2fPjKROeJ1bBs8Uxa6RFMxKogTB", | ||
"identification_id": "idn_2fPjyV3sqtQJZUbEzdK2y23a1bq", | ||
"image_url": "https://img.clerk.com/eyJ0eXBlIjoicHJveHkiLCJzcmMiOiJodHRwczovL2F2YXRhcnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3UvMjg2MTYyMTk/dj00IiwicyI6IkhCeHE5NmdlRk85ekRxMjJlR05EalUrbVFBbmVDZjRVQkpwNGYxcW5JajQifQ", | ||
"label": null, | ||
"last_name": "Xu", | ||
"object": "external_account", | ||
"provider": "oauth_github", | ||
"provider_user_id": "28616219", | ||
"public_metadata": {}, | ||
"updated_at": 1713709542104, | ||
"username": "arvinxx", | ||
"verification": { | ||
"attempts": null, | ||
"expire_at": 1713710140131, | ||
"status": "verified", | ||
"strategy": "oauth_github" | ||
} | ||
} | ||
], | ||
"external_id": null, | ||
"first_name": "Arvin", | ||
"has_image": true, | ||
"id": "user_2fPkELglwI48WpZVwwdAxBKBPK6", | ||
"image_url": "https://img.clerk.com/eyJ0eXBlIjoicHJveHkiLCJzcmMiOiJodHRwczovL2ltYWdlcy5jbGVyay5kZXYvb2F1dGhfZ2l0aHViL2ltZ18yZlBrRU1adVpwdlpvZFBHcVREdHJnTzJJM3cifQ", | ||
"last_active_at": 1713709987902, | ||
"last_name": "Xu", | ||
"last_sign_in_at": null, | ||
"locked": false, | ||
"lockout_expires_in_seconds": null, | ||
"object": "user", | ||
"passkeys": [], | ||
"password_enabled": false, | ||
"phone_numbers": [], | ||
"primary_email_address_id": "idn_2fPkD9X1lfzSn5lJVDGyochYq8k", | ||
"primary_phone_number_id": null, | ||
"primary_web3_wallet_id": null, | ||
"private_metadata": {}, | ||
"profile_image_url": "https://images.clerk.dev/oauth_github/img_2fPkEMZuZpvZodPGqTDtrgO2I3w", | ||
"public_metadata": {}, | ||
"saml_accounts": [], | ||
"totp_enabled": false, | ||
"two_factor_enabled": false, | ||
"unsafe_metadata": {}, | ||
"updated_at": 1713709987972, | ||
"username": "arvinxx", | ||
"verification_attempts_remaining": 100, | ||
"web3_wallets": [] | ||
} |
Oops, something went wrong.