From a87695b0df59a32654d6f102a591a0ebec5dabf8 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Tue, 1 Oct 2024 16:15:41 +0700 Subject: [PATCH] Update according changes in `ColumnSchemaInterface` (#320) --- CHANGELOG.md | 1 + src/Schema.php | 5 +- tests/Provider/SchemaProvider.php | 87 +++++++++++-------------------- 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc3a3236..0f78cc78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Enh #314: Implement `ColumnFactory` class (@Tigrov) - Enh #317: Separate column type constants (@Tigrov) - Enh #318: Realize `ColumnBuilder` class (@Tigrov) +- Enh #320: Update according changes in `ColumnSchemaInterface` (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Schema.php b/src/Schema.php index 67752a2a..c443b0d8 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -68,7 +68,6 @@ * dflt_value:string|null, * pk:string, * size?: int, - * precision?: int, * scale?: int, * } */ @@ -346,7 +345,7 @@ protected function findColumns(TableSchemaInterface $table): bool if ($column !== null && !strncasecmp($column->getDbType() ?? '', 'int', 3)) { $table->sequenceName(''); - $column->autoIncrement(true); + $column->autoIncrement(); } return !empty($columns); @@ -443,7 +442,7 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface $dbType = strtolower($info['type']); $column = $columnFactory->fromDefinition($dbType, ['name' => $info['name']]); $column->dbType($dbType); - $column->allowNull(!$info['notnull']); + $column->notNull((bool) $info['notnull']); $column->primaryKey((bool) $info['pk']); $column->defaultValue($this->normalizeDefaultValue($info['dflt_value'], $column)); diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index ac47dd20..f04bc4c9 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -19,11 +19,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -32,11 +31,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1, ], @@ -45,11 +43,10 @@ public static function columns(): array 'dbType' => 'tinyint(3)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 3, - 'precision' => 3, 'scale' => null, 'defaultValue' => 1, ], @@ -58,11 +55,10 @@ public static function columns(): array 'dbType' => 'smallint(1)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => 1, ], @@ -71,11 +67,10 @@ public static function columns(): array 'dbType' => 'char(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => null, ], @@ -84,11 +79,10 @@ public static function columns(): array 'dbType' => 'varchar(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => 'something"', ], @@ -97,11 +91,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -110,11 +103,10 @@ public static function columns(): array 'dbType' => 'double(4,3)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 4, - 'precision' => 4, 'scale' => 3, 'defaultValue' => null, ], @@ -123,11 +115,10 @@ public static function columns(): array 'dbType' => 'double', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1.23, ], @@ -136,11 +127,10 @@ public static function columns(): array 'dbType' => 'blob', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -149,11 +139,10 @@ public static function columns(): array 'dbType' => 'decimal(5,2)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 5, - 'precision' => 5, 'scale' => 2, 'defaultValue' => 33.22, ], @@ -162,11 +151,10 @@ public static function columns(): array 'dbType' => 'timestamp', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => '2002-01-01 00:00:00', ], @@ -175,11 +163,10 @@ public static function columns(): array 'dbType' => 'tinyint(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => null, ], @@ -188,11 +175,10 @@ public static function columns(): array 'dbType' => 'tinyint(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => true, ], @@ -201,11 +187,10 @@ public static function columns(): array 'dbType' => 'timestamp', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => new Expression('CURRENT_TIMESTAMP'), ], @@ -214,11 +199,10 @@ public static function columns(): array 'dbType' => 'bit(8)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 8, - 'precision' => 8, 'scale' => null, 'defaultValue' => 0b1000_0010, // 130 ], @@ -227,11 +211,10 @@ public static function columns(): array 'dbType' => 'json', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => ['number' => 10], ], @@ -240,11 +223,10 @@ public static function columns(): array 'dbType' => 'json', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -258,11 +240,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => true, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => true, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -271,11 +252,10 @@ public static function columns(): array 'dbType' => 'varchar(255)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 255, - 'precision' => 255, 'scale' => null, 'defaultValue' => null, ], @@ -289,11 +269,10 @@ public static function columns(): array 'dbType' => 'integer', 'phpType' => 'int', 'primaryKey' => true, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => true, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -302,11 +281,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 'CURRENT_TIMESTAMP', ], @@ -315,11 +293,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => new Expression('CURRENT_TIMESTAMP'), ], @@ -339,11 +316,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => null, ], @@ -352,11 +328,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(1)', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 1, - 'precision' => 1, 'scale' => null, 'defaultValue' => true, ], @@ -365,11 +340,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(32)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 32, - 'precision' => 32, 'scale' => null, 'defaultValue' => null, ], @@ -378,11 +352,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(32)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 32, - 'precision' => 32, 'scale' => null, 'defaultValue' => 1, ], @@ -391,11 +364,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(64)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, 'enumValues' => null, 'size' => 64, - 'precision' => 64, 'scale' => null, 'defaultValue' => null, ], @@ -404,11 +376,10 @@ public static function columnsTypeBit(): array 'dbType' => 'bit(64)', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, 'enumValues' => null, 'size' => 64, - 'precision' => 64, 'scale' => null, 'defaultValue' => 1, ],