Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
7babecd
Fix-xDbType
siggi-k Jul 6, 2022
a934859
Fix-Nullable (#99)
siggi-k Jul 7, 2022
5870b24
Update README.md
cebe Jul 7, 2022
7754878
Fix-Enum on MariaDb
siggi-k Jul 12, 2022
304cf15
Merge branch 'fix-db-schema' of github.com:siggi-k/yii2-openapi into …
siggi-k Jul 12, 2022
6ae03fb
Fix-numeric (mariaDb)
siggi-k Aug 25, 2022
b92a2ab
test
SOHELAHMED7 Sep 30, 2022
2a7e053
Undo test
SOHELAHMED7 Sep 30, 2022
f12b01c
test
SOHELAHMED7 Sep 30, 2022
d177ed9
Undo test
SOHELAHMED7 Sep 30, 2022
314743e
test2
SOHELAHMED7 Oct 3, 2022
3184ae0
Merge branch '100-timestamp-migrations-do-not-work-in-mariadb' of git…
SOHELAHMED7 Oct 3, 2022
2af51fb
Undo test2
SOHELAHMED7 Oct 3, 2022
96b91b1
Simplify condition
SOHELAHMED7 Oct 3, 2022
2697fe8
Update fixture
SOHELAHMED7 Oct 4, 2022
73fd187
Enhancements
SOHELAHMED7 Oct 4, 2022
0fda678
Fix failing tests
SOHELAHMED7 Oct 4, 2022
540e9ff
Fix style
SOHELAHMED7 Oct 4, 2022
c9aeee7
test
SOHELAHMED7 Nov 2, 2022
fdfe048
undo test
SOHELAHMED7 Nov 2, 2022
3740d5b
Add composer package sam-it/yii2-mariadb
SOHELAHMED7 Nov 2, 2022
4a313cc
Remove enum as there is not enum physical type in \yii\db\pgsql\Schema
SOHELAHMED7 Nov 2, 2022
e0b8e00
Fix error in tests: Remove enum as there is not enum physical type in…
SOHELAHMED7 Nov 2, 2022
1b9f568
Fix errors in tests, fix fixtures, fix mariadb docker image; fix mari…
SOHELAHMED7 Nov 2, 2022
8fb7084
test
SOHELAHMED7 Nov 21, 2022
329866e
undo test
SOHELAHMED7 Nov 21, 2022
58e5772
Merge branches 'master' and '100-timestamp-migrations-do-not-work-in-…
SOHELAHMED7 Nov 21, 2022
4654195
Remove 'without UUID' test case
SOHELAHMED7 Nov 21, 2022
da85359
Remove 'without UUID' test case part 2
SOHELAHMED7 Nov 21, 2022
0b94b2a
Add TODO note [skip ci]
SOHELAHMED7 Nov 21, 2022
99433e1
Remove UUID in tests [skip ci]
SOHELAHMED7 Nov 22, 2022
ee5136c
Convert erroneous tests to failed tests
SOHELAHMED7 Nov 22, 2022
b667ac0
Use real app and real DB everywhere
SOHELAHMED7 Nov 22, 2022
930e39e
Edit GA to Run tests in Docker container in Github action
SOHELAHMED7 Nov 22, 2022
5a3395c
Change vendor of install-docker-compose in GA
SOHELAHMED7 Nov 22, 2022
bf0c9a7
Config GA - WIP
SOHELAHMED7 Nov 22, 2022
1924510
Config GA -part 2 - WIP
SOHELAHMED7 Nov 22, 2022
b4ec082
Config GA -part 3 - WIP
SOHELAHMED7 Nov 22, 2022
95dee95
Config GA -part 4 - WIP
SOHELAHMED7 Nov 22, 2022
a705c84
Config GA -part 5 - WIP
SOHELAHMED7 Nov 22, 2022
e9dea60
Config GA -part 6 - WIP
SOHELAHMED7 Nov 22, 2022
bfa65e2
Config GA -part 7 - WIP
SOHELAHMED7 Nov 22, 2022
17781a8
Fix failing tests and add more tests for Pgsql and Mariadb
SOHELAHMED7 Nov 22, 2022
e4e2488
Fix failing tests and bugs
SOHELAHMED7 Nov 23, 2022
a753d91
Fix enum related bug in failing tests - WIP
SOHELAHMED7 Nov 23, 2022
64b6936
WIP
SOHELAHMED7 Nov 23, 2022
6adae6a
Remove all enum related changes
SOHELAHMED7 Nov 25, 2022
015a1fc
Add TODO in Makefile
SOHELAHMED7 Nov 25, 2022
0a79006
Fix failing tests
SOHELAHMED7 Nov 25, 2022
68718e0
Attempt to fix failing tests in GA
SOHELAHMED7 Nov 25, 2022
f2cacfe
Error message betterment
SOHELAHMED7 Nov 25, 2022
4868df0
last commit ('Error message betterment') didn't seen in Github, check…
SOHELAHMED7 Nov 25, 2022
b32ae65
BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a defaul…
SOHELAHMED7 Nov 26, 2022
a3929f0
Fix failing tests caused by x-db-type implementation and running test…
SOHELAHMED7 Nov 26, 2022
54da89a
Cleanup
SOHELAHMED7 Nov 26, 2022
1516dd6
Cleanup 2
SOHELAHMED7 Nov 27, 2022
e8ae746
Fix bug in x-db-type feature + Add tests WIP
SOHELAHMED7 Nov 28, 2022
dbe2ba5
Fix failing test
SOHELAHMED7 Nov 28, 2022
22e3ace
Restructure base DbTestCase and organize tests
SOHELAHMED7 Nov 28, 2022
2f010bf
Add tests for x-db-type for MySQL, MariaDb and PgSQL for cases: fresh…
SOHELAHMED7 Nov 29, 2022
df929e0
Fix failing tests + add change column data type by x-db-type - WIP
SOHELAHMED7 Nov 30, 2022
15b1b68
Trigger Github Action
SOHELAHMED7 Nov 30, 2022
8feea61
Trigger Github Action 2
SOHELAHMED7 Nov 30, 2022
3085986
Trigger Github Action 3
SOHELAHMED7 Nov 30, 2022
9953ede
Trigger Github Action 4
SOHELAHMED7 Nov 30, 2022
632dcb8
Enh Github Action
SOHELAHMED7 Dec 1, 2022
44af514
Fix issue and failing test in implementation of x-db-type
SOHELAHMED7 Dec 1, 2022
109e46d
Enhance tests + organize code
SOHELAHMED7 Dec 2, 2022
5cc77ea
Change PropertySchema
SOHELAHMED7 Dec 2, 2022
fec8a0b
Consider phpType in comparison
SOHELAHMED7 Dec 2, 2022
c3c5367
Strengthen the way tmp column is stored for compareColumn part + fix …
SOHELAHMED7 Dec 3, 2022
7928ef0
Fix style + Implement Pgsql compare column change by new way
SOHELAHMED7 Dec 3, 2022
ac42564
Fix bugs in Decimal related x-db-type changes
SOHELAHMED7 Dec 5, 2022
6e2275d
Refactor migration generation code and add more tests for x-db-type f…
SOHELAHMED7 Dec 6, 2022
fb869ba
Add more tests for x-db-type for MySQL
SOHELAHMED7 Dec 6, 2022
dd0ce9b
Add more tests
SOHELAHMED7 Dec 7, 2022
2180f7a
Add more tests for edit column scenario
SOHELAHMED7 Dec 8, 2022
6a3e1da
Pass the CI
SOHELAHMED7 Dec 8, 2022
30671aa
Add tests for Mariadb + add tooling support to run migrations for mul…
SOHELAHMED7 Dec 8, 2022
d5d0f6f
Fix bug related to DB type with more than one word for MySQL and PgSQ…
SOHELAHMED7 Dec 12, 2022
02d06fa
Tests refactoring and add more x-db-type tests for PgSQL
SOHELAHMED7 Dec 13, 2022
4fb7b28
WIP
SOHELAHMED7 Dec 13, 2022
8449d44
Implement string base add column code - WIP ('double precision precis…
SOHELAHMED7 Dec 13, 2022
2baf6c5
Fix 'double precision precision' issue for x-db-type - WIP + Fix few …
SOHELAHMED7 Dec 14, 2022
3ac7837
Fix failing tests
SOHELAHMED7 Dec 14, 2022
7df1b85
Delete un-necessary file
SOHELAHMED7 Dec 14, 2022
b1cf636
Change addColumn feature in migration for x-db-type
SOHELAHMED7 Dec 17, 2022
8d19fe9
Fix issue for alter column for x-db-type in Pgsql
SOHELAHMED7 Dec 19, 2022
7f64da0
Fix style
SOHELAHMED7 Dec 19, 2022
477c38b
Fix tests for fresh tables scenario
SOHELAHMED7 Dec 19, 2022
0070b63
Enhance PR
SOHELAHMED7 Dec 20, 2022
595f25f
Add more tests
SOHELAHMED7 Dec 20, 2022
cbd1dc1
Enhance PR
SOHELAHMED7 Dec 20, 2022
a49eee1
Fix bugs + add more tests
SOHELAHMED7 Dec 20, 2022
984382f
Add docs
SOHELAHMED7 Dec 20, 2022
a00a8da
Fix failing test
SOHELAHMED7 Dec 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
SOHELAHMED7 committed Dec 13, 2022
commit 4fb7b28f2fcd4e5b2ce10d5cb6af41f9c7c7d93b
28 changes: 28 additions & 0 deletions src/db/ColumnSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @copyright Copyright (c) 2018 Carsten Brandt <[email protected]> and contributors
* @license https://github.com/cebe/yii2-openapi/blob/master/LICENSE
*/

namespace cebe\yii2openapi\db;

class ColumnSchema extends \yii\db\ColumnSchema
{
/**
* @var string|null|false
* Custom DB type which contains real DB type
* Contains x-db-type string if present in OpenAPI YAML/json file
* @see \cebe\yii2openapi\lib\items\Attribute::$xDbType and `x-db-type` docs in README.md
* Used to detect what kind of migration code for column is to be generated
* e.g. `double_p double precision NULL DEFAULT NULL`
* instead of
* ```php
* $this->createTable('{{%alldbdatatypes}}', [
* ...
* 'double_p' => 'double precision NULL DEFAULT NULL',
* ...
* ```
*/
public $xDbType;
}
1 change: 1 addition & 0 deletions src/lib/ColumnToCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function __construct(

public function getCode(bool $quoted = false):string
{
// echo PHP_EOL;VarDumper::dump($this->column->xDbType);echo PHP_EOL;
if ($this->isPk) {
return '$this->' . $this->fluentParts['type'];
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/items/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use cebe\yii2openapi\generator\ApiGenerator;
use cebe\yii2openapi\lib\exceptions\InvalidDefinitionException;
use yii\base\BaseObject;
use yii\db\ColumnSchema;
use cebe\yii2openapi\db\ColumnSchema;
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
use yii\db\mysql\Schema as MySqlSchema;
Expand Down Expand Up @@ -284,6 +284,7 @@ public function toColumnSchema():ColumnSchema
'type' => $this->yiiAbstractTypeForDbSpecificType($this->dbType),
'allowNull' => $this->allowNull(),
'size' => $this->size > 0 ? $this->size : null,
'xDbType' => $this->xDbType,
]);
$column->isPrimaryKey = $this->primary;
$column->autoIncrement = $this->primary && $this->phpType === 'int';
Expand Down
8 changes: 6 additions & 2 deletions src/lib/migrations/BaseMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ protected function isNeedUsingExpression(string $fromType, string $toType):bool
return !(in_array($fromType, $dates) && in_array($toType, $dates));
}

public function tmpSaveNewCol(ColumnSchema $columnSchema)//: ColumnSchema TODO
public function tmpSaveNewCol(\cebe\yii2openapi\db\ColumnSchema $columnSchema)//: ColumnSchema TODO
{
$tableName = 'tmp_table_';

Expand All @@ -432,6 +432,10 @@ public function tmpSaveNewCol(ColumnSchema $columnSchema)//: ColumnSchema TODO
// die;
}

// echo PHP_EOL;
// VarDumper::dump($columnSchema->xDbType);echo PHP_EOL;


Yii::$app->db->createCommand()->createTable($tableName, [
$columnSchema->name => $this->newColStr($columnSchema), // TODO
// $columnSchema->name.' '.$this->newColStr($columnSchema), // TODO for xDbType
Expand All @@ -445,7 +449,7 @@ public function tmpSaveNewCol(ColumnSchema $columnSchema)//: ColumnSchema TODO
return $table->columns[$columnSchema->name];
}

public function newColStr(ColumnSchema $columnSchema): string
public function newColStr(\cebe\yii2openapi\db\ColumnSchema $columnSchema): string
{
$ctc = new ColumnToCode(\Yii::$app->db->schema, $columnSchema, false, false, true);
// VarDumper::dump($ctc->getCode()); die;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/migrations/MigrationRecordBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function createTable(string $tableAlias, array $columns):string
$codeColumns = array_map(function (ColumnSchema $column) {
return $this->columnToCode($column, false)->getCode();
}, $columns);

// VarDumper::dump('$codeColumns');
// VarDumper::dump($codeColumns);
// VarDumper::dump($columns);

$codeColumns = str_replace([PHP_EOL, "\\\'"], [PHP_EOL . self::INDENT, "'"], VarDumper::export($codeColumns));
return sprintf(self::ADD_TABLE, $tableAlias, $codeColumns);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/migrations/MysqlMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ public static function getColumnSchemaBuilderClass(): string

public function modifyCurrent(ColumnSchema $current): void
{
/** @var $current \yii\db\mysql\ColumnSchema */
if ($current->phpType === 'integer' && $current->defaultValue !== null) {
$current->defaultValue = (int)$current->defaultValue;
}
}

public function modifyDesired(ColumnSchema $desired): void
{
/** @var $desired cebe\yii2openapi\db\ColumnSchema|\yii\db\mysql\ColumnSchema */
if ($desired->phpType === 'int' && $desired->defaultValue !== null) {
$desired->defaultValue = (int)$desired->defaultValue;
}
Expand All @@ -134,6 +136,8 @@ public function modifyDesired(ColumnSchema $desired): void

public function modifyDesiredInContextOfCurrent(ColumnSchema $current, ColumnSchema $desired): void
{
/** @var $current \yii\db\mysql\ColumnSchema */
/** @var $desired cebe\yii2openapi\db\ColumnSchema|\yii\db\mysql\ColumnSchema */
if ($current->dbType === 'tinyint(1)' && $desired->type === 'boolean') {
if (is_bool($desired->defaultValue) || is_string($desired->defaultValue)) {
$desired->defaultValue = (int)$desired->defaultValue;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/migrations/PostgresMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

final class PostgresMigrationBuilder extends BaseMigrationBuilder
{

/**
* @param array|ColumnSchema[] $columns
* @throws \yii\base\InvalidConfigException
Expand Down Expand Up @@ -203,13 +202,15 @@ public static function getColumnSchemaBuilderClass(): string

public function modifyCurrent(ColumnSchema $current): void
{
/** @var $current \yii\db\pgsql\ColumnSchema */
if ($current->phpType === 'integer' && $current->defaultValue !== null) {
$current->defaultValue = (int)$current->defaultValue;
}
}

public function modifyDesired(ColumnSchema $desired): void
{
/** @var $desired cebe\yii2openapi\db\ColumnSchema|\yii\db\pgsql\ColumnSchema */
if (in_array($desired->phpType, ['int', 'integer']) && $desired->defaultValue !== null) {
$desired->defaultValue = (int)$desired->defaultValue;
}
Expand All @@ -221,6 +222,8 @@ public function modifyDesired(ColumnSchema $desired): void

public function modifyDesiredInContextOfCurrent(ColumnSchema $current, ColumnSchema $desired): void
{
/** @var $current \yii\db\pgsql\ColumnSchema */
/** @var $desired cebe\yii2openapi\db\ColumnSchema|\yii\db\pgsql\ColumnSchema */
if ($current->type === $desired->type && !$desired->size && $this->isDbDefaultSize($current)) {
$desired->size = $current->size;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/openapi/PropertySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public function guessDbType($forReference = false):string
}
if ($this->hasAttr(CustomSpecAttr::DB_TYPE) && $this->getAttr(CustomSpecAttr::DB_TYPE) !== false) {
$customDbType = strtolower($this->getAttr(CustomSpecAttr::DB_TYPE));
if ($customDbType === 'varchar') {
return YiiDbSchema::TYPE_STRING;
}
// if ($customDbType === 'varchar') {
// return YiiDbSchema::TYPE_STRING;
// }
if ($customDbType !== null) {
return $customDbType;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/specs/x_db_type/pgsql/x_db_type_pgsql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ components:
double_p_2:
type: string
x-db-type: DOUBLE PRECISION
double_p_3:
type: string
x-db-type: double precision

real:
type: string
Expand Down
34 changes: 12 additions & 22 deletions tests/unit/XDbTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class XDbTypeTest extends DbTestCase
public function testXDbTypeFresh()
{
// default db is Mysql
$this->deleteTables();
$testFile = Yii::getAlias("@specs/x_db_type/mysql/x_db_type_mysql.php");
$this->runGenerator($testFile, 'mysql');
// $this->compareFiles($testFile); # TODO

// same yaml file is used for MySQL and MariaDB
$this->changeDbToMariadb();
$this->deleteTables();
$testFile = Yii::getAlias("@specs/x_db_type/mysql/x_db_type_mysql.php");
$this->runGenerator($testFile, 'maria');
// $this->deleteTables();
// $testFile = Yii::getAlias("@specs/x_db_type/mysql/x_db_type_mysql.php");
// $this->runGenerator($testFile, 'mysql');
// // $this->compareFiles($testFile); # TODO

// // same yaml file is used for MySQL and MariaDB
// $this->changeDbToMariadb();
// $this->deleteTables();
// $testFile = Yii::getAlias("@specs/x_db_type/mysql/x_db_type_mysql.php");
// $this->runGenerator($testFile, 'maria');
// $this->compareFiles($testFile); # TODO

$this->changeDbToPgsql();
Expand All @@ -39,12 +39,7 @@ public function testXDbTypeFresh()

public function testXDbTypeSecondaryWithNewColumn() // v2
{
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%pristines}}')->execute();
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%newcolumns}}')->execute();
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%editcolumns}}')->execute();

Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%alldbdatatypes}}')->execute();

$this->deleteTables();
Yii::$app->db->createCommand()->createTable('{{%newcolumns}}', [
'id' => 'pk',
'name' => 'string not null',
Expand All @@ -58,12 +53,7 @@ public function testXDbTypeSecondaryWithNewColumn() // v2

public function testXDbTypeSecondaryWithEditColumn() // v3
{
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%pristines}}')->execute();
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%newcolumns}}')->execute();
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%editcolumns}}')->execute();

Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%alldbdatatypes}}')->execute();

$this->deleteTables();
Yii::$app->db->createCommand()->createTable('{{%editcolumns}}', [
'id' => 'pk',
'name' => 'varchar(255) not null default "Horse"',
Expand Down