fix: Produktions-Crash durch TypeORM-synchronize beheben
Build and Push Multi-Platform Images / build-and-push (push) Successful in 44s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 44s
NODE_ENV=production deaktiviert synchronize (zerstörerischer ADD/DROP-COLUMN- Churn auf MariaDB, der die 8126-Byte-Zeilengröße sprengte) und aktiviert migrationsRun. Neue data-source.ts als einzige Konfigquelle (Laufzeit + CLI), Migrations-Workflow (generate/run/revert) inkl. dotenv ergänzt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import 'reflect-metadata';
|
||||
import { join } from 'path';
|
||||
import { config as loadEnv } from 'dotenv';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
import {
|
||||
Client,
|
||||
DocumentType,
|
||||
DocumentField,
|
||||
Task,
|
||||
Postprocessing,
|
||||
PostprocessingAction,
|
||||
PostprocessingLog,
|
||||
ExportTarget,
|
||||
Setting,
|
||||
Kontonummer,
|
||||
Document,
|
||||
UserClient,
|
||||
Email,
|
||||
Attachment,
|
||||
Content,
|
||||
ApiKey,
|
||||
CorrespondentSetting,
|
||||
BarcodeTemplate,
|
||||
InboxDocument,
|
||||
InboxPostprocessingAction,
|
||||
CorrespondentEmailMapping,
|
||||
UserSettings,
|
||||
LabelPrintJob,
|
||||
} from './entities';
|
||||
|
||||
// CLI-Kontext: .env laden (Laufzeit im Container liefert die Variablen via Docker,
|
||||
// dotenv ist dort ein No-Op). dotenv überschreibt bereits gesetzte Variablen nicht.
|
||||
loadEnv();
|
||||
loadEnv({ path: join(process.cwd(), '..', '.env') });
|
||||
|
||||
export const entities = [
|
||||
Client,
|
||||
DocumentType,
|
||||
DocumentField,
|
||||
Task,
|
||||
Postprocessing,
|
||||
PostprocessingAction,
|
||||
PostprocessingLog,
|
||||
ExportTarget,
|
||||
Setting,
|
||||
Kontonummer,
|
||||
Document,
|
||||
UserClient,
|
||||
Email,
|
||||
Attachment,
|
||||
Content,
|
||||
ApiKey,
|
||||
CorrespondentSetting,
|
||||
BarcodeTemplate,
|
||||
InboxDocument,
|
||||
InboxPostprocessingAction,
|
||||
CorrespondentEmailMapping,
|
||||
UserSettings,
|
||||
LabelPrintJob,
|
||||
];
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
export const dataSourceOptions: DataSourceOptions = {
|
||||
type: 'mysql',
|
||||
host: process.env.DB_HOST ?? 'localhost',
|
||||
port: Number(process.env.DB_PORT ?? 3306),
|
||||
username: process.env.DB_USERNAME ?? 'root',
|
||||
password: process.env.DB_PASSWORD ?? '',
|
||||
database: process.env.DB_DATABASE ?? 'paperlessadd',
|
||||
charset: 'utf8mb4',
|
||||
entities,
|
||||
migrations: [join(__dirname, 'migrations', '*.{ts,js}')],
|
||||
// In Produktion: kein synchronize (zerstörerischer ALTER-Churn), Migrationen
|
||||
// werden beim Start automatisch ausgeführt. In Dev: synchronize wie bisher.
|
||||
synchronize: !isProduction,
|
||||
migrationsRun: isProduction,
|
||||
};
|
||||
|
||||
// Wird von der TypeORM-CLI verwendet (migration:generate / :run / :revert).
|
||||
export default new DataSource(dataSourceOptions);
|
||||
Reference in New Issue
Block a user