Skip to content

Commit f4e17d3

Browse files
committed
Merge branch '2.x' into fork/markinigor/2.x
2 parents a43105e + 6a87a69 commit f4e17d3

File tree

18 files changed

+341
-84
lines changed

18 files changed

+341
-84
lines changed

.github/workflows/apply-labels.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ name: 🏷️ Add labels
1414

1515
jobs:
1616
label:
17+
permissions:
18+
contents: read
19+
pull-requests: write
1720
uses: cycle/gh-actions/.github/workflows/[email protected]
1821
with:
1922
os: ubuntu-latest

.github/workflows/ci.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ jobs:
5454
strict: true
5555

5656
- name: 🛠️ Setup PHP
57-
uses: shivammathur/setup-php@2.30.2
57+
uses: shivammathur/setup-php@v2
5858
with:
5959
php-version: ${{ matrix.php-version }}
6060
extensions: mbstring, pdo, pdo_sqlite
6161
ini-values: error_reporting=E_ALL
62-
coverage: xdebug
6362

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

71-
- name: 🔍 Get composer cache directory
72-
uses: cycle/gh-actions/actions/composer/[email protected]
73-
74-
- name: ♻️ Restore cached dependencies installed with composer
75-
uses: actions/[email protected]
76-
with:
77-
path: ${{ env.COMPOSER_CACHE_DIR }}
78-
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
79-
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
80-
81-
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
82-
uses: cycle/gh-actions/actions/composer/[email protected]
70+
- name: 📥 Install dependencies with composer
71+
uses: ramsey/composer-install@v3
8372
with:
84-
dependencies: ${{ matrix.dependencies }}
73+
dependency-versions: ${{ matrix.dependencies }}
8574

8675
- name: 🔍 Run composer-normalize
8776
run: composer normalize --ansi --dry-run

.github/workflows/main.yml

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,48 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
php-versions: ['8.0', '8.1', '8.2', '8.3']
19+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
2020
steps:
2121
- name: Install ODBC driver.
2222
run: |
2323
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
2424
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
2525
26-
- name: Checkout
26+
- name: 📦 Checkout
2727
uses: actions/checkout@v2
28-
- name: Setup DB services
28+
- name: 🛠️ Setup DB services
2929
run: |
3030
cd tests
3131
docker compose up -d
3232
cd ..
33-
- name: Setup PHP ${{ matrix.php-versions }}
33+
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
3434
uses: shivammathur/setup-php@v2
3535
with:
3636
php-version: ${{ matrix.php-versions }}
3737
coverage: pcov
3838
tools: pecl
3939
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
40-
- name: Get Composer Cache Directory
41-
id: composer-cache
42-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
43-
- name: Restore Composer Cache
44-
uses: actions/cache@v2
45-
with:
46-
path: ${{ steps.composer-cache.outputs.dir }}
47-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
48-
restore-keys: ${{ runner.os }}-composer-
4940

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

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

58-
- name: Execute Tests
49+
- name: 🚀 Execute Tests
5950
run: |
6051
vendor/bin/phpunit --coverage-clover=coverage.clover
61-
- name: Upload coverage to Codecov
52+
53+
- name: 🦆 Upload coverage to Codecov
6254
continue-on-error: true # if is fork
6355
uses: codecov/codecov-action@v1
6456
with:
6557
token: ${{ secrets.CODECOV_TOKEN }}
6658
file: ./coverage.clover
67-
- name: Upload coverage to Scrutinizer
59+
60+
- name: 🦆 Upload coverage to Scrutinizer
6861
continue-on-error: true # if is fork
6962
uses: sudo-bot/action-scrutinizer@latest
7063
with:
@@ -75,36 +68,27 @@ jobs:
7568
runs-on: ubuntu-latest
7669
strategy:
7770
matrix:
78-
php-versions: ['8.0', '8.1', '8.2', '8.3']
71+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
7972
steps:
80-
- name: Checkout
73+
- name: 📦 Checkout
8174
uses: actions/checkout@v2
82-
- name: Setup PHP ${{ matrix.php-versions }}
75+
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
8376
uses: shivammathur/setup-php@v2
8477
with:
8578
php-version: ${{ matrix.php-versions }}
8679
coverage: pcov
8780
tools: pecl
8881
extensions: mbstring, pdo, pdo_sqlite
89-
- name: Get Composer Cache Directory
90-
id: composer-cache
91-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
92-
- name: Restore Composer Cache
93-
uses: actions/cache@v2
94-
with:
95-
path: ${{ steps.composer-cache.outputs.dir }}
96-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
97-
restore-keys: ${{ runner.os }}-composer-
9882

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

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

107-
- name: Execute Tests
91+
- name: 🚀 Execute Tests
10892
env:
10993
DB: sqlite
11094
run: |

.well-known/funding-manifest-urls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://cycle-orm.dev/funding.json

psalm-baseline.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@
895895
<code><![CDATA[\is_array($values) ? $values : \func_get_args()]]></code>
896896
</MixedArgument>
897897
<MixedAssignment>
898+
<code><![CDATA[$column->comment]]></code>
898899
<code><![CDATA[$column->type]]></code>
899900
<code><![CDATA[$defaultValue]]></code>
900901
</MixedAssignment>
@@ -905,6 +906,7 @@
905906
<code><![CDATA[$schema['Field']]]></code>
906907
<code><![CDATA[$schema['Null']]]></code>
907908
<code><![CDATA[$schema['Type']]]></code>
909+
<code><![CDATA[$schema['Comment']]]></code>
908910
</PossiblyUndefinedStringArrayOffset>
909911
<RiskyTruthyFalsyComparison>
910912
<code><![CDATA[empty($matches['attr'])]]></code>
@@ -1299,10 +1301,12 @@
12991301
<code><![CDATA[$constrain]]></code>
13001302
<code><![CDATA[$constraint]]></code>
13011303
<code><![CDATA[$identifier]]></code>
1304+
<code><![CDATA[$identifier]]></code>
13021305
<code><![CDATA[$range]]></code>
13031306
<code><![CDATA[$value]]></code>
13041307
<code><![CDATA[$value]]></code>
13051308
<code><![CDATA[$value]]></code>
1309+
<code><![CDATA[$tableName]]></code>
13061310
</MixedAssignment>
13071311
<MixedOperand>
13081312
<code><![CDATA[$schema['dtd_identifier']]]></code>
@@ -1326,6 +1330,7 @@
13261330
<code><![CDATA[$schema['tableOID']]]></code>
13271331
<code><![CDATA[$schema['typname']]]></code>
13281332
<code><![CDATA[$schema['typtype']]]></code>
1333+
<code><![CDATA[$schema['description']]]></code>
13291334
</PossiblyUndefinedStringArrayOffset>
13301335
<RedundantCast>
13311336
<code><![CDATA[(bool) (
@@ -1344,6 +1349,8 @@
13441349
<code><![CDATA[identifier]]></code>
13451350
<code><![CDATA[identifier]]></code>
13461351
<code><![CDATA[identifier]]></code>
1352+
<code><![CDATA[identifier]]></code>
1353+
<code><![CDATA[identifier]]></code>
13471354
</UndefinedInterfaceMethod>
13481355
</file>
13491356
<file src="src/Driver/Postgres/Schema/PostgresForeignKey.php">

src/ColumnInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
/**
1515
* Represents table schema column abstraction.
16+
*
17+
* @method string getComment() Get column comment.
18+
* An empty string will be returned if the feature is not supported by the driver.
1619
*/
1720
interface ColumnInterface
1821
{

src/Driver/MySQL/Schema/MySQLColumn.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
* @method $this|AbstractColumn bigInteger(int $size, bool $unsigned = false, $zerofill = false)
3333
* @method $this|AbstractColumn unsigned(bool $value)
3434
* @method $this|AbstractColumn zerofill(bool $value)
35+
* @method $this|AbstractColumn comment(string $value)
3536
*/
3637
class MySQLColumn extends AbstractColumn
3738
{
3839
/**
39-
* Default timestamp expression (driver specific).
40+
* Default timestamp expression ().
4041
*/
4142
public const DATETIME_NOW = 'CURRENT_TIMESTAMP';
4243

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

181+
/**
182+
* Column comment.
183+
*/
184+
#[ColumnAttribute]
185+
protected string $comment = '';
186+
180187
/**
181188
* @psalm-param non-empty-string $table
182189
*/
@@ -185,6 +192,7 @@ public static function createInstance(string $table, array $schema, ?\DateTimeZo
185192
$column = new self($table, $schema['Field'], $timezone);
186193

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

290298
$this->defaultValue = $defaultValue;
291-
if ($this->autoIncrement) {
292-
return "{$statement} AUTO_INCREMENT";
299+
300+
if ($this->comment !== '') {
301+
return "{$statement} COMMENT {$driver->quote($this->comment)}";
293302
}
294303

295304
return $statement;
@@ -355,6 +364,11 @@ public function binary(int $size = 0): self
355364
return $this;
356365
}
357366

367+
public function getComment(): string
368+
{
369+
return $this->comment;
370+
}
371+
358372
protected static function isEnum(AbstractColumn $column): bool
359373
{
360374
return $column->getAbstractType() === 'enum' || $column->getAbstractType() === 'set';
@@ -381,11 +395,12 @@ protected function formatDatetime(
381395
private function sqlStatementInteger(DriverInterface $driver): string
382396
{
383397
return \sprintf(
384-
'%s %s(%s)%s%s%s%s%s',
398+
'%s %s(%s)%s%s%s%s%s%s',
385399
$driver->identifier($this->name),
386400
$this->type,
387401
$this->size,
388402
$this->unsigned ? ' UNSIGNED' : '',
403+
$this->comment !== '' ? " COMMENT {$driver->quote($this->comment)}" : '',
389404
$this->zerofill ? ' ZEROFILL' : '',
390405
$this->nullable ? ' NULL' : ' NOT NULL',
391406
$this->defaultValue !== null ? " DEFAULT {$this->quoteDefault($driver)}" : '',

src/Driver/Postgres/PostgresHandler.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,21 @@ public function alterColumn(
117117

118118
//Postgres columns should be altered using set of operations
119119
$operations = $column->alterOperations($this->driver, $initial);
120-
if (empty($operations)) {
121-
return;
120+
if (\count($operations) > 0) {
121+
//Postgres columns should be altered using set of operations
122+
$query = \sprintf(
123+
'ALTER TABLE %s %s',
124+
$this->identify($table),
125+
\trim(\implode(', ', $operations), ', '),
126+
);
127+
128+
$this->run($query);
122129
}
123130

124-
//Postgres columns should be altered using set of operations
125-
$query = \sprintf(
126-
'ALTER TABLE %s %s',
127-
$this->identify($table),
128-
\trim(\implode(', ', $operations), ', '),
129-
);
130-
131-
$this->run($query);
131+
$operation = $column->commentOperation($this->driver, $initial);
132+
if ($operation !== null) {
133+
$this->run($operation);
134+
}
132135
}
133136

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

147+
public function createTable(AbstractTable $table): void
148+
{
149+
if (!$table instanceof PostgresTable) {
150+
throw new SchemaException('Postgres handler can work only with Postgres table');
151+
}
152+
153+
parent::createTable($table);
154+
155+
foreach ($table->getColumns() as $column) {
156+
$this->createComment($column);
157+
}
158+
}
159+
160+
public function createComment(PostgresColumn $column): void
161+
{
162+
if ($column->getComment() !== '') {
163+
$this->run($column->createComment($this->driver));
164+
}
165+
}
166+
144167
/**
145168
* @psalm-param non-empty-string $statement
146169
*/

0 commit comments

Comments
 (0)