Skip to content

Commit f23f8b6

Browse files
committed
Use built-in generation
1 parent d04d666 commit f23f8b6

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

src/Database/Models/DatabaseColumn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function __construct(string $table, array $column)
7979
$this->presetValues = [];
8080
$this->onUpdateCurrentTimestamp = false;
8181
$this->rawDefault = false;
82-
$this->virtualDefinition = null;
83-
$this->storedDefinition = null;
82+
$this->virtualDefinition = $column['generation'] !== null && $column['generation']['type'] === 'virtual' ? $column['generation']['expression'] : null;
83+
$this->storedDefinition = $column['generation'] !== null && $column['generation']['type'] === 'stored' ? $column['generation']['expression'] : null ;
8484
$this->spatialSubType = null;
8585
$this->spatialSrID = null;
8686

src/Database/Models/MySQL/MySQLColumn.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,27 @@ private function isJson(): bool
222222
*/
223223
private function setVirtualDefinition(): void
224224
{
225-
$virtualDefinition = $this->mysqlRepository->getVirtualDefinition($this->tableName, $this->name);
226-
227-
if ($virtualDefinition === null) {
225+
if ($this->virtualDefinition === null) {
228226
return;
229227
}
230228

231229
// The definition of MySQL8 returned `concat(string,_utf8mb4\' \',string_255)`.
232230
// Replace `\'` to `'` here to avoid double escape.
233-
$this->virtualDefinition = str_replace("\'", "'", $virtualDefinition);
231+
$this->virtualDefinition = str_replace("\'", "'", $this->virtualDefinition);
234232
}
235233

236234
/**
237235
* Set stored definition if the column is stored.
238236
*/
239237
private function setStoredDefinition(): void
240238
{
241-
$storedDefinition = $this->mysqlRepository->getStoredDefinition($this->tableName, $this->name);
242-
243-
if ($storedDefinition === null) {
239+
if ($this->storedDefinition === null) {
244240
return;
245241
}
246242

247243
// The definition of MySQL8 returned `concat(string,_utf8mb4\' \',string_255)`.
248244
// Replace `\'` to `'` here to avoid double escape.
249-
$this->storedDefinition = str_replace("\'", "'", $storedDefinition);
245+
$this->storedDefinition = str_replace("\'", "'", $this->storedDefinition);
250246
}
251247

252248
/**

src/Database/Models/PgSQL/PgSQLColumn.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function __construct(string $table, array $column)
5757

5858
default:
5959
}
60-
61-
$this->setStoredDefinition();
6260
}
6361

6462
/**
@@ -181,19 +179,4 @@ private function getEnumPresetValues(): array
181179

182180
return $presetValues;
183181
}
184-
185-
/**
186-
* Set stored definition if the column is stored.
187-
*/
188-
private function setStoredDefinition(): void
189-
{
190-
$this->storedDefinition = $this->repository->getStoredDefinition($this->tableName, $this->name);
191-
192-
// A generated column cannot have a column default or an identity definition.
193-
if ($this->storedDefinition === null) {
194-
return;
195-
}
196-
197-
$this->default = null;
198-
}
199182
}

0 commit comments

Comments
 (0)