mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
* v2 init * chore: update eslint suppressions and package dependencies - Removed several eslint suppressions related to array sorting and reversing from eslint-suppressions.json to clean up the configuration. - Updated @lobehub/lint package version from 2.0.0-beta.6 to 2.0.0-beta.7 in package.json for improvements and bug fixes. - Made minor formatting adjustments in vitest.config.mts and various SKILL.md files for better readability and consistency. Signed-off-by: Innei <tukon479@gmail.com> * fix: clean up import statements and formatting - Removed unnecessary whitespace in replaceComponentImports.ts for improved readability. - Standardized import statements in contextEngineering.ts and createAgentExecutors.ts by adding missing spaces for consistency. Signed-off-by: Innei <tukon479@gmail.com> * chore: update eslint suppressions and clean up code formatting * 🐛 fix: use vi.hoisted for mock variable initialization Fix TDZ error in persona service test by using vi.hoisted() to ensure mock variables are available when vi.mock factory runs. --------- Signed-off-by: Innei <tukon479@gmail.com>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { join } from 'node:path';
|
|
|
|
import * as dotenv from 'dotenv';
|
|
import dotenvExpand from 'dotenv-expand';
|
|
import { migrate as neonMigrate } from 'drizzle-orm/neon-serverless/migrator';
|
|
import { migrate as nodeMigrate } from 'drizzle-orm/node-postgres/migrator';
|
|
|
|
// @ts-ignore tsgo handle esm import cjs and compatibility issues
|
|
import { DB_FAIL_INIT_HINT, DUPLICATE_EMAIL_HINT, PGVECTOR_HINT } from './errorHint';
|
|
|
|
// Load environment variables in priority order:
|
|
// 1. .env (lowest priority)
|
|
// 2. .env.[env] (medium priority, overrides .env)
|
|
// 3. .env.[env].local (highest priority, overrides previous)
|
|
// Use dotenv-expand to support ${var} variable expansion
|
|
const env = process.env.NODE_ENV || 'development';
|
|
dotenvExpand.expand(dotenv.config()); // Load .env
|
|
dotenvExpand.expand(dotenv.config({ override: true, path: `.env.${env}` })); // Load .env.[env] and override
|
|
dotenvExpand.expand(dotenv.config({ override: true, path: `.env.${env}.local` })); // Load .env.[env].local and override
|
|
|
|
const migrationsFolder = join(__dirname, '../../packages/database/migrations');
|
|
|
|
const isDesktop = process.env.NEXT_PUBLIC_IS_DESKTOP_APP === '1';
|
|
|
|
const runMigrations = async () => {
|
|
const { serverDB } = await import('../../packages/database/src/server');
|
|
|
|
const time = Date.now();
|
|
if (process.env.DATABASE_DRIVER === 'node') {
|
|
await nodeMigrate(serverDB, { migrationsFolder });
|
|
} else {
|
|
await neonMigrate(serverDB, { migrationsFolder });
|
|
}
|
|
|
|
console.log('✅ database migration pass. use: %s ms', Date.now() - time);
|
|
|
|
process.exit(0);
|
|
};
|
|
|
|
const connectionString = process.env.DATABASE_URL;
|
|
|
|
// only migrate database if the connection string is available
|
|
if (!isDesktop && connectionString) {
|
|
runMigrations().catch((err) => {
|
|
console.error('❌ Database migrate failed:', err);
|
|
|
|
const errMsg = err.message as string;
|
|
|
|
const constraint = (err as { constraint?: string })?.constraint;
|
|
|
|
if (errMsg.includes('extension "vector" is not available')) {
|
|
console.info(PGVECTOR_HINT);
|
|
} else if (constraint === 'users_email_unique' || errMsg.includes('users_email_unique')) {
|
|
console.info(DUPLICATE_EMAIL_HINT);
|
|
} else if (errMsg.includes(`Cannot read properties of undefined (reading 'migrate')`)) {
|
|
console.info(DB_FAIL_INIT_HINT);
|
|
}
|
|
|
|
process.exit(1);
|
|
});
|
|
} else {
|
|
console.log('🟢 not find database env or in desktop mode, migration skipped');
|
|
}
|