Skip to content

Commit

Permalink
Merge branch 'master' into support_composite_types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Sep 6, 2023
2 parents 0747938 + 53d7b0e commit c6ba36f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Enh #300: Refactor `ArrayExpressionBuilder` (@Tigrov)
- Enh #302: Refactor `ColumnSchema` (@Tigrov)
- Bug #302: Fix incorrect convert string value for BIT type (@Tigrov)
- Bug #309: Fix retrieving sequence name from default value (@Tigrov)

## 1.1.0 July 24, 2023

Expand Down
5 changes: 3 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Exception;
use Throwable;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\ConvertException;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;

Expand Down Expand Up @@ -49,7 +48,9 @@ protected function internalExecute(string|null $rawSql): void
&& $this->db->getTransaction() === null
) {
$this->db->transaction(
fn (PdoConnectionInterface $db) => $this->internalExecute($rawSql),
function () use ($rawSql): void {
$this->internalExecute($rawSql);
},
$this->isolationLevel
);
} else {
Expand Down
10 changes: 3 additions & 7 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* column_default: string|null,
* is_autoinc: bool,
* sequence_name: string|null,
* enum_values: array<array-key, float|int|string>|string|null,
* enum_values: string|null,
* numeric_precision: int|null,
* numeric_scale: int|null,
* size: string|null,
Expand Down Expand Up @@ -804,13 +804,9 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface

if (
$defaultValue !== null
&& preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $defaultValue) === 1
&& preg_match("/^nextval\('([^']+)/", $defaultValue, $matches) === 1
) {
$column->sequenceName(preg_replace(
['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'],
'',
$defaultValue
));
$column->sequenceName($matches[1]);
} elseif ($info['sequence_name'] !== null) {
$column->sequenceName($this->resolveTableName($info['sequence_name'])->getFullName());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ public function testSequenceName(): void
$sequenceName = $tableSchema->getSequenceName();
$command->setSql(
<<<SQL
ALTER TABLE "item" ALTER COLUMN "id" SET DEFAULT nextval('item_id_seq_2')
ALTER TABLE "item" ALTER COLUMN "id" SET DEFAULT nextval('nextval_item_id_seq_2')
SQL,
)->execute();
$schema->refreshTableSchema('item');
$tableSchema = $schema->getTableSchema('item');

$this->assertNotNull($tableSchema);
$this->assertEquals('item_id_seq_2', $tableSchema->getSequenceName());
$this->assertEquals('nextval_item_id_seq_2', $tableSchema->getSequenceName());

$command->setSql(
<<<SQL
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/Fixture/pgsql.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP TABLE IF EXISTS "composite_fk" CASCADE;
DROP TABLE IF EXISTS "order_item" CASCADE;
DROP TABLE IF EXISTS "item" CASCADE;
DROP SEQUENCE IF EXISTS "item_id_seq_2" CASCADE;
DROP SEQUENCE IF EXISTS "nextval_item_id_seq_2" CASCADE;
DROP TABLE IF EXISTS "order_item_with_null_fk" CASCADE;
DROP TABLE IF EXISTS "order" CASCADE;
DROP TABLE IF EXISTS "order_with_null_fk" CASCADE;
Expand Down Expand Up @@ -88,7 +88,7 @@ CREATE TABLE "item" (
name varchar(128) NOT NULL,
category_id integer NOT NULL references "category"(id) on UPDATE CASCADE on DELETE CASCADE
);
CREATE SEQUENCE "item_id_seq_2";
CREATE SEQUENCE "nextval_item_id_seq_2";

CREATE TABLE "order" (
id serial not null primary key,
Expand Down

0 comments on commit c6ba36f

Please sign in to comment.