Skip to content

Commit 2eb9891

Browse files
committed
feat: detect filler columns
1 parent 115222b commit 2eb9891

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/SQLLoader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ protected function buildDefaultColumns(string $table, array $columns): array
122122
continue;
123123
}
124124

125+
if (! $schemaColumns->contains('name', $column)) {
126+
$columns[$key] = "{$escapedColumn} FILLER";
127+
125128
continue;
126129
}
127130

tests/Feature/SQLLoaderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,20 @@
122122
return str_contains((string) $process->command, "sqlldr userid={$username}/{$password}@{$host}:{$port}/{$database} control={$controlFile}");
123123
});
124124
});
125+
126+
test('it can detect FILLER and DATE columns', function () {
127+
Process::fake();
128+
129+
$loader = new SQLLoader();
130+
$loader->inFile(__DIR__.'/../data/filler.dat')
131+
->as('users.ctl')
132+
->withHeaders()
133+
->into('users')
134+
->execute();
135+
136+
$controlFile = $loader->buildControlFile();
137+
assertStringContainsString("\"NAME\",\n", $controlFile);
138+
assertStringContainsString("\"EMAIL\",\n", $controlFile);
139+
assertStringContainsString('"PHONE" FILLER', $controlFile);
140+
assertStringContainsString('"CREATED_AT" DATE', $controlFile);
141+
});

tests/data/filler.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NAME,EMAIL,PHONE,CREATED_AT
2+
John Doe,john@doe.com,123-456-7890,2016-01-01T00:00:00.000000Z
3+
Jane Doe,jane@doe.com,123-456-7890,2016-01-01T00:00:00.000000Z
4+
"Mr. ""John"" Doe",j@doe.com,123-456-7890,2016-01-01T00:00:00.000000Z
5+
"Ms. Doe, Jane", jj@doe.com,123-456-7890,2016-01-01T00:00:00.000000Z

0 commit comments

Comments
 (0)