mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
* 💄 style: update logo style * ♻️ refactor: hide webrtc sync by default * 🔧 chore: improve db migration script * 💄 style: rename to assistant * 💄 style: update brand * 💄 style: update brand * ⚡️ perf: dynamic pwa install * ✅ test: fix tests * 📝 docs: update docs * 📝 docs: update env * 📝 docs: update docs
32 lines
1 KiB
TypeScript
32 lines
1 KiB
TypeScript
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);
|
|
});
|
|
} else {
|
|
console.log('🟢 not find database env, migration skipped');
|
|
}
|