Skip to content

Commit

Permalink
Merge branch 'master' into docker
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Dec 2, 2024
2 parents d03a8c2 + cc8ae67 commit b8f13ef
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 82 deletions.
173 changes: 173 additions & 0 deletions .github/workflows/db-migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
on:
pull_request:
paths:
- 'src/**'
- '.github/workflows/db-migration.yml'
- 'composer.json'

push:
branches: ['master']
paths:
- 'src/**'
- '.github/workflows/db-migration.yml'
- 'composer.json'

name: db-migration

jobs:
tests:
name: PHP ${{ matrix.php }}-db-migration-${{ matrix.os }}

env:
COMPOSER_ROOT_VERSION: dev-master
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.1
- 8.2
- 8.3

services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_PASSWORD: ''
MYSQL_DATABASE: yiitest
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
oci:
image: gvenzl/oracle-xe:latest
ports:
- 1521:1521
env:
ORACLE_DATABASE : yiitest
ORACLE_PASSWORD : root
options: >-
--name=oci
--health-cmd healthcheck.sh
--health-interval 10s
--health-timeout 5s
--health-retries 10
postgres:
image: postgres:16
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: yiitest
ports:
- 5432:5432
options: --name=postgres --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
SA_PASSWORD: YourStrong!Passw0rd
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 1433:1433
options: --name=mssql --health-cmd="/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Install ODBC driver.
run: |
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Checkout.
uses: actions/checkout@v4

- name: Create MS SQL Database.
run: docker exec -i mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
ini-values: date.timezone='UTC'
coverage: pcov

- name: Update composer.
run: composer self-update

- name: Set environment variables pull request linux.
uses: yiisoft/actions/db/environment-linux@master

- name: Install db-mssql.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-mssql
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install db-mysql.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-mysql
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install db-pgsql.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-pgsql
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install db-oracle.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-oracle
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install db-sqlite.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-sqlite
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install yiisoft/test-support
run: composer require yiisoft/test-support

- name: Install yiisoft/yii-console
run: composer require yiisoft/yii-console

- name: Install db-migration.
uses: yiisoft/actions/db/subpackage-install@master
with:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }}
CURRENT_PACKAGE: db-migration
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Run tests with phpunit with code coverage.
run: vendor/bin/phpunit --testsuite=DbMigration --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
- Chg #889: Update `AbstractDMLQueryBuilder::insertBatch()` method (@Tigrov)
- Enh #890: Add properties of `AbstractColumnSchema` class to constructor (@Tigrov)
- New #899: Add `ColumnSchemaInterface::hasDefaultValue()` and `ColumnSchemaInterface::null()` methods (@Tigrov)
- New #902: Add `QueryBuilderInterface::prepareParam()` and `QueryBuilderInterface::prepareValue()` methods (@Tigrov)
- Enh #902: Refactor `Quoter::quoteValue()` method (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
5 changes: 4 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace

- `QuoterInterface::getRawTableName()` - returns the raw table name without quotes;
- `SchemaInterface::getColumnFactory()` - returns the column factory object for concrete DBMS;
- `QueryBuilderInterface::buildColumnDefinition()` - builds column definition for `CREATE TABLE` statement.
- `QueryBuilderInterface::buildColumnDefinition()` - builds column definition for `CREATE TABLE` statement;
- `QueryBuilderInterface::prepareParam()` - converts a `ParamInterface` object to its SQL representation;
- `QueryBuilderInterface::prepareValue()` - converts a value to its SQL representation;

### Remove methods

Expand Down Expand Up @@ -146,3 +148,4 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace
- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method;
- Allow `QueryInterface::one()` to return an object;
- Allow `QueryInterface::all()` to return array of objects;
- Change `Quoter::quoteValue()` parameter type and return type from `mixed` to `string`;
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@
"Yiisoft\\Db\\Mysql\\Tests\\": "vendor/yiisoft/db-mysql/tests",
"Yiisoft\\Db\\Oracle\\Tests\\": "vendor/yiisoft/db-oracle/tests",
"Yiisoft\\Db\\Pgsql\\Tests\\": "vendor/yiisoft/db-pgsql/tests",
"Yiisoft\\Db\\Sqlite\\Tests\\": "vendor/yiisoft/db-sqlite/tests"
"Yiisoft\\Db\\Sqlite\\Tests\\": "vendor/yiisoft/db-sqlite/tests",
"Yiisoft\\Db\\Migration\\Tests\\": "vendor/yiisoft/db-migration/tests",
"Yiisoft\\Db\\Migration\\Tests\\NonExistsDirectory\\": "vendor/yiisoft/db-migration/tests/non-exists-directory",
"Yiisoft\\Db\\Migration\\Tests\\ForTest\\": "vendor/yiisoft/db-migration/tests/Support",
"Yiisoft\\Db\\Migration\\Tests\\Support\\": "vendor/yiisoft/db-migration/tests/Support",
"Yiisoft\\Db\\Migration\\Tests\\Support\\MigrationsExtra\\": [
"vendor/yiisoft/db-migration/tests/Support/MigrationsExtra",
"vendor/yiisoft/db-migration/tests/Support/MigrationsExtra2"
]
}
},
"extra": {
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<testsuite name="ActiveRecord">
<directory>./vendor/yiisoft/active-record/tests/Driver</directory>
</testsuite>
<testsuite name="DbMigration">
<directory>./vendor/yiisoft/db-migration/tests/Driver</directory>
</testsuite>
<testsuite name="Mssql">
<directory>./vendor/yiisoft/db-mssql/tests</directory>
</testsuite>
Expand Down
24 changes: 3 additions & 21 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Closure;
use Throwable;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Constant\GettypeResult;
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface;
Expand All @@ -17,14 +15,12 @@

use function explode;
use function get_resource_type;
use function gettype;
use function is_array;
use function is_int;
use function is_resource;
use function is_scalar;
use function is_string;
use function preg_replace_callback;
use function str_starts_with;
use function stream_get_contents;

/**
Expand Down Expand Up @@ -351,28 +347,14 @@ public function getRawSql(): string
}

$params = [];
$quoter = $this->getQueryBuilder()->quoter();
$queryBuilder = $this->getQueryBuilder();

foreach ($this->params as $name => $param) {
if (is_string($name) && !str_starts_with($name, ':')) {
if (is_string($name) && $name[0] !== ':') {
$name = ':' . $name;
}

$value = $param->getValue();

$params[$name] = match ($param->getType()) {
DataType::INTEGER => (string) (int) $value,
DataType::STRING, DataType::LOB => match (gettype($value)) {
GettypeResult::RESOURCE => $name,
GettypeResult::DOUBLE => (string) $value,
default => $value instanceof Expression
? (string) $value
: $quoter->quoteValue((string) $value),
},
DataType::BOOLEAN => $value ? 'TRUE' : 'FALSE',
DataType::NULL => 'NULL',
default => $name,
};
$params[$name] = $queryBuilder->prepareParam($param);
}

/** @var string[] $params */
Expand Down
4 changes: 4 additions & 0 deletions src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public function insertBatch(string $table, iterable $rows, array $columns = []):
* @param int|null $length The length of the data type.
* @param mixed|null $driverOptions The driver-specific options.
*
* @psalm-param DataType::*|null $dataType
*
* @throws Exception
*/
public function bindParam(
Expand Down Expand Up @@ -244,6 +246,8 @@ public function addUnique(string $table, string $name, array|string $columns): s
* @param mixed $value The value to bind to the parameter.
* @param int|null $dataType The {@see DataType SQL data type} of the parameter. If null, the type is determined
* by the PHP type of the value.
*
* @psalm-param DataType::*|null $dataType
*/
public function bindValue(int|string $name, mixed $value, int $dataType = null): static;

Expand Down
6 changes: 6 additions & 0 deletions src/Command/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
*/
final class Param implements ParamInterface, ExpressionInterface
{
/**
* @psalm-param DataType::* $type
*/
public function __construct(private mixed $value, private int $type)
{
}

/**
* @psalm-return DataType::*
*/
public function getType(): int
{
return $this->type;
Expand Down
4 changes: 4 additions & 0 deletions src/Command/ParamInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ interface ParamInterface
* @param mixed $value The value to bind to the parameter.
* @param int $type The SQL data type of the parameter.
* If `null`, the type is determined by the PHP type of the value.
*
* @psalm-param DataType::* $type
*/
public function __construct(mixed $value, int $type);

/**
* @return int The SQL data type of the parameter.
*
* @psalm-return DataType::*
*/
public function getType(): int;

Expand Down
4 changes: 4 additions & 0 deletions src/Constant/GettypeResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ final class GettypeResult
* Define the php type as `resource`.
*/
public const RESOURCE = 'resource';
/**
* Define the php type as `resource (closed)`.
*/
public const RESOURCE_CLOSED = 'resource (closed)';
/**
* Define the php type as `string`.
*/
Expand Down
Loading

0 comments on commit b8f13ef

Please sign in to comment.