Skip to content

Commit d3b887c

Browse files
authored
Merge pull request #62 from keboola/zajca-kbc-2791
KBC-2791 add default for SNFLK
2 parents 923a8b6 + e237041 commit d3b887c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Definition/Snowflake.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public function __construct(string $type, array $options = [])
101101
if ($diff !== []) {
102102
throw new InvalidOptionException("Option '{$diff[0]}' not supported");
103103
}
104+
if (array_key_exists('default', $options) && $options['default'] === '') {
105+
unset($options['default']);
106+
}
104107
parent::__construct($type, $options);
105108
}
106109

@@ -121,8 +124,10 @@ public function getSQLDefinition(): string
121124
if (!$this->isNullable()) {
122125
$definition .= ' NOT NULL';
123126
}
127+
if ($this->getDefault() !== null) {
128+
$definition .= ' DEFAULT ' . $this->getDefault();
129+
}
124130
return $definition;
125-
// TODO default value by basetype
126131
}
127132

128133
/**

tests/SnowflakeDatatypeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ public function testSqlDefinition(): void
121121
$definition = new Snowflake('NUMERIC', ['length' => '10,10', 'nullable' => true]);
122122
$this->assertSame($definition->getSQLDefinition(), 'NUMERIC (10,10)');
123123

124+
$definition = new Snowflake('NUMERIC', ['length' => '10,10', 'nullable' => true, 'default' => '10']);
125+
$this->assertSame($definition->getSQLDefinition(), 'NUMERIC (10,10) DEFAULT 10');
126+
127+
$definition = new Snowflake('NUMERIC', ['length' => '10,10', 'nullable' => true, 'default' => '']);
128+
$this->assertSame($definition->getSQLDefinition(), 'NUMERIC (10,10)');
129+
130+
$definition = new Snowflake('VARCHAR', ['length' => '10', 'nullable' => true, 'default' => '\'\'']);
131+
$this->assertSame($definition->getSQLDefinition(), 'VARCHAR (10) DEFAULT \'\'');
132+
124133
$definition = new Snowflake('TIMESTAMP_TZ', ['length' => '0']);
125134
$this->assertSame($definition->getSQLDefinition(), 'TIMESTAMP_TZ (0)');
126135

0 commit comments

Comments
 (0)