Skip to content

Commit feba5f1

Browse files
committed
Add support for PgSQL array data type
1 parent 37cfd68 commit feba5f1

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/lib/SchemaToDatabase.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public static function f7(array $schemasToDrop): array // TODO rename
272272
throw new \Exception('Malformed list of schemas to delete');
273273
}
274274

275-
$table = Yii::$app->db->schema->getTableSchema("{{%$tableName}}");
275+
$table = Yii::$app->db->schema->getTableSchema("{{%$tableName}}", true);
276276
if ($table) {
277277
$dbModelHere = new DbModel([
278278
'pkName' => $table->primaryKey[0],
@@ -312,8 +312,8 @@ public static function attributesFromColumnSchemas(array $columnSchemas)
312312
/** @var $columnSchema ColumnSchema */
313313
unset($attribute);
314314
$attribute = new Attribute($columnSchema->name, [
315-
'phpType' => $columnSchema->phpType, // pk
316-
'dbType' => $columnSchema->dbType, // pk
315+
'phpType' => $columnSchema->phpType,
316+
'dbType' => $columnSchema->dbType,
317317
'fkColName' => $columnSchema->name,
318318

319319
'required' => !$columnSchema->allowNull && ($columnSchema->defaultValue === null),
@@ -326,6 +326,13 @@ public static function attributesFromColumnSchemas(array $columnSchemas)
326326
'description' => $columnSchema->comment,
327327
]);
328328

329+
// PgSQL array
330+
if (property_exists($columnSchema, 'dimension') && $columnSchema->dimension !== 0) {
331+
for ($i = 0; $i < $columnSchema->dimension; $i++) {
332+
$attribute->dbType .= '[]';
333+
}
334+
}
335+
329336
// generate PK using `->primaryKeys()` or similar methods instead of separate SQL statement which sets only PK to a column of table
330337
// https://github.com/cebe/yii2-openapi/issues/132
331338
if (in_array($columnSchema->phpType, [

tests/specs/issue_fix/132_create_migration_for_drop_table/132_create_migration_for_drop_table.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ info:
44
title: 132_create_migration_for_drop_table \#132
55

66
x-deleted-schemas:
7-
- Pristine
8-
- Fruit # Example: table name evaluated to `itt_fruits`. `itt_` is prefix set in DB config
9-
- Mango: the_mango_table_name # custom table name; see `x-table` in README.md
10-
- Animal: the_animal_table_name
11-
- Upk
12-
- Bigpk
13-
- Ubigpk
7+
- Pristine
8+
- Fruit # Example: table name evaluated to `itt_fruits`. `itt_` is prefix set in DB config
9+
- Mango: the_mango_table_name # custom table name; see `x-table` in README.md
10+
- Animal: the_animal_table_name
11+
- Upk
12+
- Bigpk
13+
- Ubigpk
1414

1515
paths:
1616
/:

tests/unit/IssueFixTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ private function createTablesForCreateMigrationForDropTable132ForPgsql()
383383
// 'd SMALLINT UNSIGNED ZEROFILL',
384384
// 'e' => 'SMALLINT UNSIGNED ZEROFILL',
385385
// 'f' => 'decimal(12,4)',
386+
'g5' => 'text[]',
387+
'g6' => 'text[][]',
388+
'g7' => 'numeric(10,4)',
386389
])->execute();
387390

388391
// ---

0 commit comments

Comments
 (0)