Initial
Takes in a file, process it and output a new file with additional columns.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
try {
|
||||
$database = \App\Database::fromConfig($appConfig ?? []);
|
||||
$pdo = $database->pdo();
|
||||
|
||||
$statements = [
|
||||
<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS import_batches (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
source_filename TEXT NOT NULL,
|
||||
original_headers JSONB NOT NULL,
|
||||
calculated_headers JSONB NOT NULL,
|
||||
row_count INTEGER NOT NULL DEFAULT 0,
|
||||
warnings_count INTEGER NOT NULL DEFAULT 0,
|
||||
status TEXT NOT NULL DEFAULT 'complete',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)
|
||||
SQL,
|
||||
"ALTER TABLE import_batches ADD COLUMN IF NOT EXISTS status TEXT NOT NULL DEFAULT 'complete'",
|
||||
<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS import_rows (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
batch_id BIGINT NOT NULL REFERENCES import_batches(id) ON DELETE CASCADE,
|
||||
row_number INTEGER NOT NULL,
|
||||
source_row JSONB NOT NULL,
|
||||
normalized_row JSONB NOT NULL,
|
||||
calculated_row JSONB NOT NULL,
|
||||
merged_row JSONB NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)
|
||||
SQL,
|
||||
'CREATE INDEX IF NOT EXISTS idx_import_rows_batch_row_number ON import_rows (batch_id, row_number)',
|
||||
];
|
||||
|
||||
foreach ($statements as $statement) {
|
||||
$pdo->exec($statement);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, "Migration completed.\n");
|
||||
} catch (Throwable $throwable) {
|
||||
fwrite(STDERR, "Migration failed: " . $throwable->getMessage() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user