37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Migration: Fügt invoice_id Spalte zu journal_entries hinzu
|
|
* Ausführen: php tools/migrate_journal_invoice_link.php
|
|
*/
|
|
|
|
require_once __DIR__ . '/../src/config.php';
|
|
require_once __DIR__ . '/../src/db.php';
|
|
|
|
$pdo = get_db();
|
|
|
|
echo "Migration: journal_entries.invoice_id\n";
|
|
|
|
try {
|
|
// Prüfen ob Spalte existiert
|
|
$stmt = $pdo->query("SELECT column_name FROM information_schema.columns
|
|
WHERE table_name = 'journal_entries' AND column_name = 'invoice_id'");
|
|
$exists = $stmt->fetch();
|
|
|
|
if ($exists) {
|
|
echo "Spalte invoice_id existiert bereits.\n";
|
|
} else {
|
|
// Spalte hinzufügen
|
|
$pdo->exec("ALTER TABLE journal_entries ADD COLUMN invoice_id INTEGER REFERENCES invoices(id) ON DELETE SET NULL");
|
|
echo "Spalte invoice_id hinzugefügt.\n";
|
|
|
|
// Index erstellen
|
|
$pdo->exec("CREATE INDEX IF NOT EXISTS idx_journal_entries_invoice ON journal_entries(invoice_id)");
|
|
echo "Index erstellt.\n";
|
|
}
|
|
|
|
echo "Migration erfolgreich!\n";
|
|
} catch (PDOException $e) {
|
|
echo "Fehler: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|