Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ parameters:
count: 1
path: src/Db/Adapter/SqliteAdapter.php

-
message: '#^Call to an undefined method Migrations\\Db\\Table\\Index\:\:setUnique\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Db/Table/Index.php

-
message: '#^Call to an undefined method Migrations\\MigrationInterface\:\:down\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Migration/Environment.php

-
message: '#^Call to an undefined method Migrations\\MigrationInterface\:\:up\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Migration/Environment.php

-
message: '#^Call to function method_exists\(\) with Migrations\\MigrationInterface and ''useTransactions'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
Expand Down
40 changes: 0 additions & 40 deletions src/Db/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,24 @@ interface AdapterInterface
public const PHINX_TYPE_TINY_INTEGER = TableSchemaInterface::TYPE_TINYINTEGER;
public const PHINX_TYPE_SMALL_INTEGER = TableSchemaInterface::TYPE_SMALLINTEGER;
public const PHINX_TYPE_BIG_INTEGER = TableSchemaInterface::TYPE_BIGINTEGER;

/** @deprecated Use smallinteger or boolean instead */
public const PHINX_TYPE_BIT = 'bit';

public const PHINX_TYPE_FLOAT = TableSchemaInterface::TYPE_FLOAT;
public const PHINX_TYPE_DECIMAL = TableSchemaInterface::TYPE_DECIMAL;

/** @deprecated Use float instead */
public const PHINX_TYPE_DOUBLE = 'double';

public const PHINX_TYPE_DATETIME = TableSchemaInterface::TYPE_DATETIME;
public const PHINX_TYPE_TIMESTAMP = TableSchemaInterface::TYPE_TIMESTAMP;
public const PHINX_TYPE_TIME = TableSchemaInterface::TYPE_TIME;
public const PHINX_TYPE_DATE = TableSchemaInterface::TYPE_DATE;
public const PHINX_TYPE_BINARY = TableSchemaInterface::TYPE_BINARY;

/** @deprecated Use binary instead */
public const PHINX_TYPE_VARBINARY = 'varbinary';

public const PHINX_TYPE_BINARYUUID = TableSchemaInterface::TYPE_BINARY_UUID;

/** @deprecated Use binary instead */
public const PHINX_TYPE_BLOB = 'blob';

/** @deprecated Use binary with length instead */
public const PHINX_TYPE_TINYBLOB = 'tinyblob'; // Specific to Mysql.

/** @deprecated Use binary with length instead */
public const PHINX_TYPE_MEDIUMBLOB = 'mediumblob'; // Specific to Mysql

/** @deprecated Use binary with length instead */
public const PHINX_TYPE_LONGBLOB = 'longblob'; // Specific to Mysql
public const PHINX_TYPE_BOOLEAN = TableSchemaInterface::TYPE_BOOLEAN;
public const PHINX_TYPE_JSON = TableSchemaInterface::TYPE_JSON;
public const PHINX_TYPE_UUID = TableSchemaInterface::TYPE_UUID;
public const PHINX_TYPE_NATIVEUUID = TableSchemaInterface::TYPE_NATIVE_UUID;
/** @deprecated Use json instead */
public const PHINX_TYPE_JSONB = 'jsonb';
/** @deprecated Use blob instead */
public const PHINX_TYPE_FILESTREAM = 'filestream';

// Geospatial database types
public const PHINX_TYPE_GEOMETRY = TableSchemaInterface::TYPE_GEOMETRY;
public const PHINX_TYPE_POINT = TableSchemaInterface::TYPE_POINT;
public const PHINX_TYPE_LINESTRING = TableSchemaInterface::TYPE_LINESTRING;
public const PHINX_TYPE_POLYGON = TableSchemaInterface::TYPE_POLYGON;
/** @deprecated Will be removed in 5.x */
public const PHINX_TYPE_GEOGRAPHY = 'geography';

public const PHINX_TYPES_GEOSPATIAL = [
self::PHINX_TYPE_GEOMETRY,
Expand All @@ -88,16 +58,6 @@ interface AdapterInterface
self::PHINX_TYPE_POLYGON,
];

// only for mysql so far
/** @deprecated Will be removed in 5.x */
public const PHINX_TYPE_MEDIUM_INTEGER = 'mediuminteger';

/** @deprecated Will be removed in 5.x */
public const PHINX_TYPE_ENUM = 'enum';

/** @deprecated Will be removed in 5.x */
public const PHINX_TYPE_SET = 'set';

// only for mysql so far
// TODO This can be aliased to TableSchema constants with cakephp 5.3
public const PHINX_TYPE_YEAR = 'year';
Expand Down
27 changes: 1 addition & 26 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ class MysqlAdapter extends AbstractAdapter
* @var string[]
*/
protected static array $specificColumnTypes = [
self::PHINX_TYPE_ENUM,
self::PHINX_TYPE_SET,
self::PHINX_TYPE_YEAR,
self::PHINX_TYPE_JSON,
self::PHINX_TYPE_BINARYUUID,
self::PHINX_TYPE_TINYBLOB,
self::PHINX_TYPE_MEDIUMBLOB,
self::PHINX_TYPE_LONGBLOB,
self::PHINX_TYPE_MEDIUM_INTEGER,
];

// These constants roughly correspond to the maximum allowed value for each field,
Expand Down Expand Up @@ -267,23 +261,7 @@ protected function mapColumnData(array $data): array
default => null,
};
}
$binaryTypes = [
self::PHINX_TYPE_BLOB,
self::PHINX_TYPE_TINYBLOB,
self::PHINX_TYPE_MEDIUMBLOB,
self::PHINX_TYPE_LONGBLOB,
self::PHINX_TYPE_VARBINARY,
self::PHINX_TYPE_BINARY,
];
if (in_array($data['type'], $binaryTypes, true)) {
if (!isset($data['length'])) {
$data['length'] = match ($data['type']) {
self::PHINX_TYPE_TINYBLOB => TableSchema::LENGTH_TINY,
self::PHINX_TYPE_MEDIUMBLOB => TableSchema::LENGTH_MEDIUM,
self::PHINX_TYPE_LONGBLOB => TableSchema::LENGTH_LONG,
default => $data['length'],
};
}
if ($data['type'] === self::PHINX_TYPE_BINARY) {
if ($data['length'] === self::BLOB_REGULAR) {
$data['type'] = TableSchema::TYPE_BINARY;
$data['length'] = null;
Expand All @@ -305,9 +283,6 @@ protected function mapColumnData(array $data): array
unset($data['length']);
}
unset($data['length']);
} elseif ($data['type'] == self::PHINX_TYPE_DOUBLE) {
$data['type'] = TableSchema::TYPE_FLOAT;
$data['length'] = 52;
}

return $data;
Expand Down
1 change: 0 additions & 1 deletion src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class PostgresAdapter extends AbstractAdapter
*/
protected static array $specificColumnTypes = [
self::PHINX_TYPE_JSON,
self::PHINX_TYPE_JSONB,
self::PHINX_TYPE_CIDR,
self::PHINX_TYPE_INET,
self::PHINX_TYPE_MACADDR,
Expand Down
4 changes: 0 additions & 4 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ class SqliteAdapter extends AbstractAdapter
self::PHINX_TYPE_BIG_INTEGER => 'biginteger',
self::PHINX_TYPE_BINARY => 'binary_blob',
self::PHINX_TYPE_BINARYUUID => 'uuid_blob',
self::PHINX_TYPE_BLOB => 'blob',
self::PHINX_TYPE_BOOLEAN => 'boolean_integer',
self::PHINX_TYPE_CHAR => 'char',
self::PHINX_TYPE_DATE => 'date_text',
self::PHINX_TYPE_DATETIME => 'datetime_text',
self::PHINX_TYPE_DECIMAL => 'decimal',
self::PHINX_TYPE_DOUBLE => 'double',
self::PHINX_TYPE_FLOAT => 'float',
self::PHINX_TYPE_INTEGER => 'integer',
self::PHINX_TYPE_JSON => 'json_text',
self::PHINX_TYPE_JSONB => 'jsonb_text',
self::PHINX_TYPE_SMALL_INTEGER => 'smallinteger',
self::PHINX_TYPE_STRING => 'varchar',
self::PHINX_TYPE_TEXT => 'text',
self::PHINX_TYPE_TIME => 'time_text',
self::PHINX_TYPE_TIMESTAMP => 'timestamp_text',
self::PHINX_TYPE_TINY_INTEGER => 'tinyinteger',
self::PHINX_TYPE_UUID => 'uuid_text',
self::PHINX_TYPE_VARBINARY => 'varbinary_blob',
];

/**
Expand Down
1 change: 0 additions & 1 deletion src/Db/Adapter/SqlserverAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SqlserverAdapter extends AbstractAdapter
* @var string[]
*/
protected static array $specificColumnTypes = [
self::PHINX_TYPE_FILESTREAM,
self::PHINX_TYPE_BINARYUUID,
self::PHINX_TYPE_NATIVEUUID,
];
Expand Down
10 changes: 0 additions & 10 deletions src/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,10 @@ class Column
public const BINARYUUID = TableSchemaInterface::TYPE_BINARY_UUID;
public const NATIVEUUID = TableSchemaInterface::TYPE_NATIVE_UUID;
/** MySQL-only column type */
public const MEDIUMINTEGER = AdapterInterface::PHINX_TYPE_MEDIUM_INTEGER;
/** MySQL-only column type */
public const ENUM = AdapterInterface::PHINX_TYPE_ENUM;
/** MySQL-only column type */
public const SET = AdapterInterface::PHINX_TYPE_STRING;
/** MySQL-only column type */
public const BLOB = AdapterInterface::PHINX_TYPE_BLOB;
/** MySQL-only column type */
public const YEAR = AdapterInterface::PHINX_TYPE_YEAR;
/** MySQL/Postgres-only column type */
public const JSON = TableSchemaInterface::TYPE_JSON;
/** Postgres-only column type */
public const JSONB = AdapterInterface::PHINX_TYPE_JSONB;
/** Postgres-only column type */
public const CIDR = AdapterInterface::PHINX_TYPE_CIDR;
/** Postgres-only column type */
public const INET = AdapterInterface::PHINX_TYPE_INET;
Expand Down
54 changes: 0 additions & 54 deletions tests/TestCase/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Cake\Database\Connection;
use Cake\Datasource\ConnectionManager;
use InvalidArgumentException;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Db\Adapter\MysqlAdapter;
use Migrations\Db\Literal;
use Migrations\Db\Table;
Expand All @@ -21,7 +20,6 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

class MysqlAdapterTest extends TestCase
{
Expand Down Expand Up @@ -783,38 +781,6 @@ public function testIntegerColumnTypes($phinx_type, $options, $sql_type, $width,
$this->assertEquals($type, $rows[1]['Type']);
}

/**
* Test that migrations still supports the `double` type but
* as an alias for a float/double column which cake/database provides.
*/
public function testAddDoubleDefaultSignedCompat(): void
{
$table = new Table('table1', [], $this->adapter);
$table->save();
$this->assertFalse($table->hasColumn('user_id'));
$table->addColumn('foo', 'double')
->save();
$rows = $this->adapter->fetchAll('SHOW FULL COLUMNS FROM table1');
$this->assertEquals('double', $rows[1]['Type']);
$this->assertEquals('YES', $rows[1]['Null']);
}

/**
* Test that migrations still supports the `double` type but
* as an alias for a float column which cake/database provides.
*/
public function testAddDoubleDefaultSignedCompatWithUnsigned(): void
{
$table = new Table('table1', [], $this->adapter);
$table->save();
$this->assertFalse($table->hasColumn('user_id'));
$table->addColumn('foo', 'double', ['signed' => false])
->save();
$rows = $this->adapter->fetchAll('SHOW COLUMNS FROM table1');
$this->assertEquals('double unsigned', $rows[1]['Type']);
$this->assertEquals('YES', $rows[1]['Null']);
}

public function testAddStringColumnWithSignedEqualsFalse(): void
{
$table = new Table('table1', [], $this->adapter);
Expand Down Expand Up @@ -2088,29 +2054,9 @@ public function testGeometrySridThrowsInsertDifferentSrid($type, $geom)
$this->adapter->execute("INSERT INTO table1 (`geom`) VALUES (ST_GeomFromText('{$geom}', 4322))");
}

/**
* Small check to verify if specific Mysql constants are handled in AdapterInterface
*
* @see https://github.com/cakephp/migrations/issues/359
*/
public function testMysqlBlobsConstants()
{
$reflector = new ReflectionClass(AdapterInterface::class);

$validTypes = array_filter($reflector->getConstants(), function ($constant) {
return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_';
}, ARRAY_FILTER_USE_KEY);

$this->assertTrue(in_array('tinyblob', $validTypes, true));
$this->assertTrue(in_array('blob', $validTypes, true));
$this->assertTrue(in_array('mediumblob', $validTypes, true));
$this->assertTrue(in_array('longblob', $validTypes, true));
}

public static function defaultsCastAsExpressions()
{
return [
[MysqlAdapter::PHINX_TYPE_BLOB, 'abc'],
[MysqlAdapter::PHINX_TYPE_JSON, '{"a": true}'],
[MysqlAdapter::PHINX_TYPE_TEXT, 'abc'],
[MysqlAdapter::PHINX_TYPE_GEOMETRY, 'POINT(0 0)'],
Expand Down
8 changes: 0 additions & 8 deletions tests/TestCase/Db/Adapter/SqliteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2660,36 +2660,28 @@ public static function provideColumnTypesForValidation()
return [
[SqliteAdapter::PHINX_TYPE_BIG_INTEGER, true],
[SqliteAdapter::PHINX_TYPE_BINARY, true],
[SqliteAdapter::PHINX_TYPE_BLOB, true],
[SqliteAdapter::PHINX_TYPE_BOOLEAN, true],
[SqliteAdapter::PHINX_TYPE_CHAR, true],
[SqliteAdapter::PHINX_TYPE_DATE, true],
[SqliteAdapter::PHINX_TYPE_DATETIME, true],
[SqliteAdapter::PHINX_TYPE_DOUBLE, true],
[SqliteAdapter::PHINX_TYPE_FLOAT, true],
[SqliteAdapter::PHINX_TYPE_INTEGER, true],
[SqliteAdapter::PHINX_TYPE_JSON, true],
[SqliteAdapter::PHINX_TYPE_JSONB, true],
[SqliteAdapter::PHINX_TYPE_SMALL_INTEGER, true],
[SqliteAdapter::PHINX_TYPE_STRING, true],
[SqliteAdapter::PHINX_TYPE_TEXT, true],
[SqliteAdapter::PHINX_TYPE_TIME, true],
[SqliteAdapter::PHINX_TYPE_UUID, true],
[SqliteAdapter::PHINX_TYPE_TIMESTAMP, true],
[SqliteAdapter::PHINX_TYPE_VARBINARY, true],
[SqliteAdapter::PHINX_TYPE_BIT, false],
[SqliteAdapter::PHINX_TYPE_CIDR, false],
[SqliteAdapter::PHINX_TYPE_DECIMAL, true],
[SqliteAdapter::PHINX_TYPE_ENUM, false],
[SqliteAdapter::PHINX_TYPE_FILESTREAM, false],
[SqliteAdapter::PHINX_TYPE_GEOMETRY, false],
[SqliteAdapter::PHINX_TYPE_INET, false],
[SqliteAdapter::PHINX_TYPE_INTERVAL, false],
[SqliteAdapter::PHINX_TYPE_LINESTRING, false],
[SqliteAdapter::PHINX_TYPE_MACADDR, false],
[SqliteAdapter::PHINX_TYPE_POINT, false],
[SqliteAdapter::PHINX_TYPE_POLYGON, false],
[SqliteAdapter::PHINX_TYPE_SET, false],
[Literal::from('someType'), true],
['someType', false],
];
Expand Down
Loading