Browse Source

Fix #18040, fix #15265, fix #18232 database issues (#18225)

- Bug #18040: Display width specification for integer data types was deprecated in MySQL 8.0.19
- Bug #15265: PostgreSQL > 10.0 is not pass tests with default value of timestamp CURRENT_TIMESTAMP
- Bug #18232: Fail tests pgsql v-10.14, v-11.9, v-12-latest
tags/2.0.38
Wilmer Arambula 4 years ago committed by GitHub
parent
commit
5558ee793b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 80
      .github/workflows/ci-mysql.yml
  2. 84
      .github/workflows/ci-pgsql.yml
  3. 3
      framework/CHANGELOG.md
  4. 13
      framework/db/pgsql/Schema.php
  5. 59
      tests/framework/db/mysql/SchemaTest.php
  6. 4
      tests/framework/db/pgsql/SchemaTest.php

80
.github/workflows/ci-mysql.yml

@ -0,0 +1,80 @@
on:
- pull_request
- push
name: ci-mysql
jobs:
tests:
name: PHP ${{ matrix.php-version }}-mysql-${{ matrix.mysql-version }}
env:
extensions: curl, intl, pdo, pdo_mysql
key: cache-v1
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
php-version:
- "7.4"
mysql-version:
- "latest"
services:
mysql:
image: mysql:${{ matrix.mysql-version }}
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: yiitest
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
- name: Determine composer cache directory
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Run mysql tests with phpunit
run: vendor/bin/phpunit --group mysql

84
.github/workflows/ci-pgsql.yml

@ -0,0 +1,84 @@
on:
- pull_request
- push
name: ci-pgsql
jobs:
tests:
name: PHP ${{ matrix.php-version }}-pgsql-${{ matrix.pgsql-version }}
env:
extensions: curl, intl, pdo, pdo_pgsql
key: cache-v1
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
php-version:
- "7.4"
pgsql-version:
- "10"
- "11"
- "12"
- "13"
services:
postgres:
image: postgres:${{ matrix.pgsql-version }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: yiitest
ports:
- 5432:5432
options: --name=postgres --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
- name: Determine composer cache directory
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Run pgsql tests with phpunit
run: vendor/bin/phpunit --group pgsql

3
framework/CHANGELOG.md

@ -14,6 +14,9 @@ Yii Framework 2 Change Log
- Bug #18239: Fix support of no-extension files for `FileValidator::validateExtension()` (darkdef)
- Bug #18229: Add flag for recognize SyBase databases on uses pdo_dblib (darkdef)
- Bug #13973: Correct alterColumn for MSSQL & drop constraints before drop column (darkdef)
- Bug #18040: Display width specification for integer data types was deprecated in MySQL 8.0.19 (terabytesoftw)
- Bug #15265: PostgreSQL > 10.0 is not pass tests with default value of timestamp CURRENT_TIMESTAMP (terabytesoftw)
- Bug #18232: Fail tests pgsql v-10.14, v-11.9, v-12-latest (terabytesoftw)
2.0.37 August 07, 2020

13
framework/db/pgsql/Schema.php

@ -548,14 +548,21 @@ SQL;
}
$column->defaultValue = null;
} elseif ($column->defaultValue) {
if ($column->type === 'timestamp' && $column->defaultValue === 'now()') {
if (
in_array($column->type, [self::TYPE_TIMESTAMP, self::TYPE_DATE, self::TYPE_TIME], true) &&
in_array(
strtoupper($column->defaultValue),
['NOW()', 'CURRENT_TIMESTAMP', 'CURRENT_DATE', 'CURRENT_TIME'],
true
)
) {
$column->defaultValue = new Expression($column->defaultValue);
} elseif ($column->type === 'boolean') {
$column->defaultValue = ($column->defaultValue === 'true');
} elseif (preg_match("/^B'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = bindec($matches[1]);
} elseif (strncasecmp($column->dbType, 'bit', 3) === 0 || strncasecmp($column->dbType, 'varbit', 6) === 0) {
$column->defaultValue = bindec(trim($column->defaultValue, 'B\''));
} elseif (preg_match("/^'(\d+)'::\"bit\"$/", $column->defaultValue, $matches)) {
$column->defaultValue = bindec($matches[1]);
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = $column->phpTypecast($matches[1]);
} elseif (preg_match('/^(\()?(.*?)(?(1)\))(?:::.+)?$/', $column->defaultValue, $matches)) {

59
tests/framework/db/mysql/SchemaTest.php

@ -118,4 +118,63 @@ SQL;
$this->assertInstanceOf(Expression::className(), $column->defaultValue);
$this->assertEquals('CURRENT_TIMESTAMP', $column->defaultValue);
}
public function getExpectedColumns()
{
$version = $this->getConnection()->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
return array_merge(
parent::getExpectedColumns(),
[
'int_col' => [
'type' => 'integer',
'dbType' => \version_compare($version, '8.0.17', '>') ? 'int' : 'int(11)',
'phpType' => 'integer',
'allowNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => \version_compare($version, '8.0.17', '>') ? null : 11,
'precision' => \version_compare($version, '8.0.17', '>') ? null : 11,
'scale' => null,
'defaultValue' => null,
],
'int_col2' => [
'type' => 'integer',
'dbType' => \version_compare($version, '8.0.17', '>') ? 'int' : 'int(11)',
'phpType' => 'integer',
'allowNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => \version_compare($version, '8.0.17', '>') ? null : 11,
'precision' => \version_compare($version, '8.0.17', '>') ? null : 11,
'scale' => null,
'defaultValue' => 1,
],
'tinyint_col' => [
'type' => 'tinyint',
'dbType' => \version_compare($version, '8.0.17', '>') ? 'tinyint' : 'tinyint(3)',
'phpType' => 'integer',
'allowNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => \version_compare($version, '8.0.17', '>') ? null : 3,
'precision' => \version_compare($version, '8.0.17', '>') ? null : 3,
'scale' => null,
'defaultValue' => 1,
],
'smallint_col' => [
'type' => 'smallint',
'dbType' => \version_compare($version, '8.0.17', '>') ? 'smallint' : 'smallint(1)',
'phpType' => 'integer',
'allowNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => \version_compare($version, '8.0.17', '>') ? null : 1,
'precision' => \version_compare($version, '8.0.17', '>') ? null : 1,
'scale' => null,
'defaultValue' => 1,
],
]
);
}
}

4
tests/framework/db/pgsql/SchemaTest.php

@ -75,7 +75,9 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
$columns['bool_col2']['precision'] = null;
$columns['bool_col2']['scale'] = null;
$columns['bool_col2']['defaultValue'] = true;
$columns['ts_default']['defaultValue'] = new Expression('now()');
if (version_compare($this->getConnection(false)->getServerVersion(), '10', '<')) {
$columns['ts_default']['defaultValue'] = new Expression('now()');
}
$columns['bit_col']['dbType'] = 'bit';
$columns['bit_col']['size'] = 8;
$columns['bit_col']['precision'] = null;

Loading…
Cancel
Save