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
3 changes: 3 additions & 0 deletions .github/workflows/apply-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ name: 🏷️ Add labels

jobs:
label:
permissions:
contents: read
pull-requests: write
uses: cycle/gh-actions/.github/workflows/apply-labels.yml@v4.0.0
with:
os: ubuntu-latest
Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ jobs:
strict: true

- name: 🛠️ Setup PHP
uses: shivammathur/setup-php@2.30.2
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, pdo, pdo_sqlite
ini-values: error_reporting=E_ALL
coverage: xdebug

- name: 🛠️ Setup problem matchers
run: |
Expand All @@ -68,20 +67,10 @@ jobs:
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: cycle/gh-actions/actions/composer/get-cache-directory@v4.0.0

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/cache@v4.0.2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies
uses: cycle/gh-actions/actions/composer/install@v4.0.0
- name: 📥 Install dependencies with composer
uses: ramsey/composer-install@v3
with:
dependencies: ${{ matrix.dependencies }}
dependency-versions: ${{ matrix.dependencies }}

- name: 🔍 Run composer-normalize
run: composer normalize --ansi --dry-run
Expand Down
66 changes: 25 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,48 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
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
- name: 📦 Checkout
uses: actions/checkout@v2
- name: Setup DB services
- name: 🛠️ Setup DB services
run: |
cd tests
docker compose up -d
cd ..
- name: Setup PHP ${{ matrix.php-versions }}
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
tools: pecl
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies with composer
if: matrix.php-versions != '8.3'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: Install dependencies with composer php 8.3
if: matrix.php-versions == '8.3'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
- name: 📥 Install dependencies with composer
uses: ramsey/composer-install@v3
with:
dependency-versions: "highest"

- name: Execute Tests
- name: 🚀 Execute Tests
run: |
vendor/bin/phpunit --coverage-clover=coverage.clover
- name: Upload coverage to Codecov

- name: 🦆 Upload coverage to Codecov
continue-on-error: true # if is fork
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.clover
- name: Upload coverage to Scrutinizer

- name: 🦆 Upload coverage to Scrutinizer
continue-on-error: true # if is fork
uses: sudo-bot/action-scrutinizer@latest
with:
Expand All @@ -75,36 +68,27 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout
- name: 📦 Checkout
uses: actions/checkout@v2
- name: Setup PHP ${{ matrix.php-versions }}
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
tools: pecl
extensions: mbstring, pdo, pdo_sqlite
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies with composer
if: matrix.php-versions != '8.3'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: Install dependencies with composer php 8.3
if: matrix.php-versions == '8.3'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
- name: 📥 Install dependencies with composer
uses: ramsey/composer-install@v3
with:
dependency-versions: "highest"

- name: Execute Tests
- name: 🚀 Execute Tests
env:
DB: sqlite
run: |
Expand Down
7 changes: 7 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@
<code><![CDATA[\is_array($values) ? $values : \func_get_args()]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$column->comment]]></code>
<code><![CDATA[$column->type]]></code>
<code><![CDATA[$defaultValue]]></code>
</MixedAssignment>
Expand All @@ -905,6 +906,7 @@
<code><![CDATA[$schema['Field']]]></code>
<code><![CDATA[$schema['Null']]]></code>
<code><![CDATA[$schema['Type']]]></code>
<code><![CDATA[$schema['Comment']]]></code>
</PossiblyUndefinedStringArrayOffset>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($matches['attr'])]]></code>
Expand Down Expand Up @@ -1299,10 +1301,12 @@
<code><![CDATA[$constrain]]></code>
<code><![CDATA[$constraint]]></code>
<code><![CDATA[$identifier]]></code>
<code><![CDATA[$identifier]]></code>
<code><![CDATA[$range]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$tableName]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$schema['dtd_identifier']]]></code>
Expand All @@ -1326,6 +1330,7 @@
<code><![CDATA[$schema['tableOID']]]></code>
<code><![CDATA[$schema['typname']]]></code>
<code><![CDATA[$schema['typtype']]]></code>
<code><![CDATA[$schema['description']]]></code>
</PossiblyUndefinedStringArrayOffset>
<RedundantCast>
<code><![CDATA[(bool) (
Expand All @@ -1344,6 +1349,8 @@
<code><![CDATA[identifier]]></code>
<code><![CDATA[identifier]]></code>
<code><![CDATA[identifier]]></code>
<code><![CDATA[identifier]]></code>
<code><![CDATA[identifier]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Driver/Postgres/Schema/PostgresForeignKey.php">
Expand Down
3 changes: 3 additions & 0 deletions src/ColumnInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

/**
* Represents table schema column abstraction.
*
* @method string getComment() Get column comment.
* An empty string will be returned if the feature is not supported by the driver.
*/
interface ColumnInterface
{
Expand Down
23 changes: 19 additions & 4 deletions src/Driver/MySQL/Schema/MySQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
* @method $this|AbstractColumn bigInteger(int $size, bool $unsigned = false, $zerofill = false)
* @method $this|AbstractColumn unsigned(bool $value)
* @method $this|AbstractColumn zerofill(bool $value)
* @method $this|AbstractColumn comment(string $value)
*/
class MySQLColumn extends AbstractColumn
{
/**
* Default timestamp expression (driver specific).
* Default timestamp expression ().
*/
public const DATETIME_NOW = 'CURRENT_TIMESTAMP';

Expand Down Expand Up @@ -177,6 +178,12 @@ class MySQLColumn extends AbstractColumn
#[ColumnAttribute(self::INTEGER_TYPES)]
protected bool $zerofill = false;

/**
* Column comment.
*/
#[ColumnAttribute]
protected string $comment = '';

/**
* @psalm-param non-empty-string $table
*/
Expand All @@ -185,6 +192,7 @@ public static function createInstance(string $table, array $schema, ?\DateTimeZo
$column = new self($table, $schema['Field'], $timezone);

$column->type = $schema['Type'];
$column->comment = $schema['Comment'];
$column->nullable = \strtolower($schema['Null']) === 'yes';
$column->defaultValue = $schema['Default'];
$column->autoIncrement = \stripos($schema['Extra'], 'auto_increment') !== false;
Expand Down Expand Up @@ -288,8 +296,9 @@ public function sqlStatement(DriverInterface $driver): string
$statement = parent::sqlStatement($driver);

$this->defaultValue = $defaultValue;
if ($this->autoIncrement) {
return "{$statement} AUTO_INCREMENT";

if ($this->comment !== '') {
return "{$statement} COMMENT {$driver->quote($this->comment)}";
}

return $statement;
Expand Down Expand Up @@ -355,6 +364,11 @@ public function binary(int $size = 0): self
return $this;
}

public function getComment(): string
{
return $this->comment;
}

protected static function isEnum(AbstractColumn $column): bool
{
return $column->getAbstractType() === 'enum' || $column->getAbstractType() === 'set';
Expand All @@ -381,11 +395,12 @@ protected function formatDatetime(
private function sqlStatementInteger(DriverInterface $driver): string
{
return \sprintf(
'%s %s(%s)%s%s%s%s%s',
'%s %s(%s)%s%s%s%s%s%s',
$driver->identifier($this->name),
$this->type,
$this->size,
$this->unsigned ? ' UNSIGNED' : '',
$this->comment !== '' ? " COMMENT {$driver->quote($this->comment)}" : '',
$this->zerofill ? ' ZEROFILL' : '',
$this->nullable ? ' NULL' : ' NOT NULL',
$this->defaultValue !== null ? " DEFAULT {$this->quoteDefault($driver)}" : '',
Expand Down
43 changes: 33 additions & 10 deletions src/Driver/Postgres/PostgresHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ public function alterColumn(

//Postgres columns should be altered using set of operations
$operations = $column->alterOperations($this->driver, $initial);
if (empty($operations)) {
return;
if (\count($operations) > 0) {
//Postgres columns should be altered using set of operations
$query = \sprintf(
'ALTER TABLE %s %s',
$this->identify($table),
\trim(\implode(', ', $operations), ', '),
);

$this->run($query);
}

//Postgres columns should be altered using set of operations
$query = \sprintf(
'ALTER TABLE %s %s',
$this->identify($table),
\trim(\implode(', ', $operations), ', '),
);

$this->run($query);
$operation = $column->commentOperation($this->driver, $initial);
if ($operation !== null) {
$this->run($operation);
}
}

public function enableForeignKeyConstraints(): void
Expand All @@ -141,6 +144,26 @@ public function disableForeignKeyConstraints(): void
$this->run('SET CONSTRAINTS ALL DEFERRED;');
}

public function createTable(AbstractTable $table): void
{
if (!$table instanceof PostgresTable) {
throw new SchemaException('Postgres handler can work only with Postgres table');
}

parent::createTable($table);

foreach ($table->getColumns() as $column) {
$this->createComment($column);
}
}

public function createComment(PostgresColumn $column): void
{
if ($column->getComment() !== '') {
$this->run($column->createComment($this->driver));
}
}

/**
* @psalm-param non-empty-string $statement
*/
Expand Down
Loading
Loading