Skip to content

Commit 5a56ba7

Browse files
author
Bizley
authored
Merge pull request #125 from bizley/mysql-8
MySQL 8
2 parents b0ba289 + 68b72a2 commit 5a56ba7

20 files changed

+707
-173
lines changed
File renamed without changes.

.github/workflows/build-mysql8.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build with MySQL
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
9+
jobs:
10+
Tests:
11+
name: PHP ${{ matrix.php }} + MySQL ${{ matrix.mysql }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['7.4', '8.0']
17+
mysql: ['8.0']
18+
services:
19+
mysql:
20+
image: mysql:${{ matrix.mysql }}
21+
env:
22+
MYSQL_ALLOW_EMPTY_PASSWORD: false
23+
MYSQL_ROOT_PASSWORD: password
24+
MYSQL_DATABASE: migration
25+
MYSQL_USER: migration
26+
MYSQL_PASSWORD: password
27+
ports:
28+
- 3306/tcp
29+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v2
34+
35+
- name: Install PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
extensions: mbstring, intl, mysql
40+
coverage: none
41+
env:
42+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
update: true
44+
45+
- name: Start MySQL service
46+
run: sudo /etc/init.d/mysql start
47+
48+
- name: Get composer cache directory
49+
id: composer-cache
50+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
51+
52+
- name: Cache composer dependencies
53+
uses: actions/[email protected]
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
57+
restore-keys: ${{ runner.os }}-composer-
58+
59+
- name: Install dependencies
60+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
61+
62+
- name: Prepare DB connections for tests
63+
run: printf "<?php\n\n\$config['mysql']['dsn']='mysql:host=127.0.0.1;port=${{ job.services.mysql.ports['3306'] }};dbname=migration';\n" >> tests/config.local.php;
64+
65+
- name: PHPUnit tests
66+
run: vendor/bin/phpunit --exclude-group pgsql,sqlite

src/table/BigIntegerColumn.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
final class BigIntegerColumn extends Column implements PrimaryKeyVariantColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,7 @@ final class BigIntegerColumn extends Column implements PrimaryKeyVariantColumnIn
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
return $this->isSchemaLengthSupporting($schema, $engineVersion) ? $this->getSize() : null;
2842
}
2943

3044
/**
@@ -35,7 +49,7 @@ public function getLength(string $schema = null, string $engineVersion = null)
3549
*/
3650
public function setLength($value, string $schema = null, string $engineVersion = null): void
3751
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
52+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
3953
$this->setSize($value);
4054
$this->setPrecision($value);
4155
}

src/table/BigPrimaryKeyColumn.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
class BigPrimaryKeyColumn extends Column implements PrimaryKeyColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,7 @@ class BigPrimaryKeyColumn extends Column implements PrimaryKeyColumnInterface
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
return $this->isSchemaLengthSupporting($schema, $engineVersion) ? $this->getSize() : null;
2842
}
2943

3044
/**
@@ -35,7 +49,7 @@ public function getLength(string $schema = null, string $engineVersion = null)
3549
*/
3650
public function setLength($value, string $schema = null, string $engineVersion = null): void
3751
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
52+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
3953
$this->setSize($value);
4054
$this->setPrecision($value);
4155
}

src/table/IntegerColumn.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
final class IntegerColumn extends Column implements PrimaryKeyVariantColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,7 @@ final class IntegerColumn extends Column implements PrimaryKeyVariantColumnInter
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
return $this->isSchemaLengthSupporting($schema, $engineVersion) ? $this->getSize() : null;
2842
}
2943

3044
/**
@@ -35,7 +49,7 @@ public function getLength(string $schema = null, string $engineVersion = null)
3549
*/
3650
public function setLength($value, string $schema = null, string $engineVersion = null): void
3751
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
52+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
3953
$this->setSize($value);
4054
$this->setPrecision($value);
4155
}

src/table/PrimaryKeyColumn.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
class PrimaryKeyColumn extends Column implements PrimaryKeyColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,7 @@ class PrimaryKeyColumn extends Column implements PrimaryKeyColumnInterface
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
return $this->isSchemaLengthSupporting($schema, $engineVersion) ? $this->getSize() : null;
2842
}
2943

3044
/**
@@ -35,7 +49,7 @@ public function getLength(string $schema = null, string $engineVersion = null)
3549
*/
3650
public function setLength($value, string $schema = null, string $engineVersion = null): void
3751
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
52+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
3953
$this->setSize($value);
4054
$this->setPrecision($value);
4155
}

src/table/SmallIntegerColumn.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
final class SmallIntegerColumn extends Column implements ColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,7 @@ final class SmallIntegerColumn extends Column implements ColumnInterface
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
return $this->isSchemaLengthSupporting($schema, $engineVersion) ? $this->getSize() : null;
2842
}
2943

3044
/**
@@ -35,7 +49,7 @@ public function getLength(string $schema = null, string $engineVersion = null)
3549
*/
3650
public function setLength($value, string $schema = null, string $engineVersion = null): void
3751
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
52+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
3953
$this->setSize($value);
4054
$this->setPrecision($value);
4155
}

src/table/TinyIntegerColumn.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
use bizley\migration\Schema;
88

99
use function in_array;
10+
use function version_compare;
1011

1112
final class TinyIntegerColumn extends Column implements ColumnInterface
1213
{
1314
/** @var array<string> Schemas using length for this column */
14-
private $lengthSchemas = [
15-
Schema::MYSQL,
16-
Schema::OCI,
17-
];
15+
private $lengthSchemas = [Schema::OCI];
16+
17+
/**
18+
* Checks if schema supports length for this column.
19+
* In case of MySQL the engine version must be lower than 8.0.17.
20+
* @param string|null $schema
21+
* @param string|null $engineVersion
22+
* @return bool
23+
*/
24+
private function isSchemaLengthSupporting(?string $schema, ?string $engineVersion): bool
25+
{
26+
if ($engineVersion && $schema === Schema::MYSQL && version_compare($engineVersion, '8.0.17', '<')) {
27+
return true;
28+
}
29+
30+
return in_array($schema, $this->lengthSchemas, true);
31+
}
1832

1933
/**
2034
* Returns length of the column.
@@ -24,7 +38,16 @@ final class TinyIntegerColumn extends Column implements ColumnInterface
2438
*/
2539
public function getLength(string $schema = null, string $engineVersion = null)
2640
{
27-
return in_array($schema, $this->lengthSchemas, true) ? $this->getSize() : null;
41+
$size = $this->getSize();
42+
if ($this->isSchemaLengthSupporting($schema, $engineVersion)) {
43+
return $size;
44+
}
45+
if ($schema === Schema::MYSQL && (string)$size === '1') {
46+
// MySQL 8.0.17+ allows tiny integer to be set with size 1 for boolean columns
47+
return $size;
48+
}
49+
50+
return null;
2851
}
2952

3053
/**
@@ -35,7 +58,10 @@ public function getLength(string $schema = null, string $engineVersion = null)
3558
*/
3659
public function setLength($value, string $schema = null, string $engineVersion = null): void
3760
{
38-
if (in_array($schema, $this->lengthSchemas, true)) {
61+
if (
62+
$this->isSchemaLengthSupporting($schema, $engineVersion)
63+
|| ($schema === Schema::MYSQL && (string)$value === '1')
64+
) {
3965
$this->setSize($value);
4066
$this->setPrecision($value);
4167
}

0 commit comments

Comments
 (0)