Skip to content

Commit

Permalink
Merge branch 'master' into typecast_refactoring
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Schema.php
  • Loading branch information
Tigrov committed Jul 14, 2023
2 parents 14726aa + b38e1df commit ccb0165
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.1 under development

- Enh #225: Typecast refactoring (@Tigrov)
- Enh #226: Add support for auto increment in primary key column. (@terabytesoftw)

## 1.0.0 April 12, 2023

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ your Oracle database and perform various database operations as needed.

| PHP | Oracle Version | CI-Actions
|:----:|:------------------------:|:---:|
|**8.0 - 8.2**| **11 - 21**|[![build](https://github.com/yiisoft/db-oracle/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-oracle/actions/workflows/build.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-oracle%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-oracle/master) [![static analysis](https://github.com/yiisoft/db-oracle/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-oracle/actions/workflows/static.yml) [![type-coverage](https://shepherd.dev/github/yiisoft/db-oracle/coverage.svg)](https://shepherd.dev/github/yiisoft/db-oracle)
|**8.0 - 8.2**| **12c - 21c**|[![build](https://github.com/yiisoft/db-oracle/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-oracle/actions/workflows/build.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-oracle%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-oracle/master) [![static analysis](https://github.com/yiisoft/db-oracle/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-oracle/actions/workflows/static.yml) [![type-coverage](https://shepherd.dev/github/yiisoft/db-oracle/coverage.svg)](https://shepherd.dev/github/yiisoft/db-oracle)

## Installation

Expand Down
8 changes: 4 additions & 4 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ final class QueryBuilder extends AbstractQueryBuilder
* @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values).
*/
protected array $typeMap = [
SchemaInterface::TYPE_PK => 'NUMBER(10) NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_UPK => 'NUMBER(10) UNSIGNED NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_BIGPK => 'NUMBER(20) NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_UBIGPK => 'NUMBER(20) UNSIGNED NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_PK => 'NUMBER(10) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_UPK => 'NUMBER(10) GENERATED BY DEFAULT AS IDENTITY UNSIGNED NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_BIGPK => 'NUMBER(20) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_UBIGPK => 'NUMBER(20) GENERATED BY DEFAULT AS IDENTITY UNSIGNED NOT NULL PRIMARY KEY',
SchemaInterface::TYPE_CHAR => 'CHAR(1)',
SchemaInterface::TYPE_STRING => 'VARCHAR2(255)',
SchemaInterface::TYPE_TEXT => 'CLOB',
Expand Down
4 changes: 3 additions & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* nullable: string,
* data_default: string|null,
* is_pk: string|null,
* identity_column: string,
* column_comment: string|null
* }
*
Expand Down Expand Up @@ -331,6 +332,7 @@ protected function findColumns(TableSchemaInterface $table): bool
A.DATA_TYPE,
A.DATA_PRECISION,
A.DATA_SCALE,
A.IDENTITY_COLUMN,
(
CASE A.CHAR_USED WHEN 'C' THEN A.CHAR_LENGTH
ELSE A.DATA_LENGTH
Expand Down Expand Up @@ -370,7 +372,6 @@ protected function findColumns(TableSchemaInterface $table): bool

/** @psalm-var string[][] $columns */
foreach ($columns as $column) {
/** @psalm-var ColumnInfoArray $column */
$column = $this->normalizeRowKeyCase($column, false);

$c = $this->createColumnSchema($column);
Expand Down Expand Up @@ -420,6 +421,7 @@ protected function createColumnSchema(array $info): ColumnSchemaInterface
$column->allowNull($info['nullable'] === 'Y');
$column->comment($info['column_comment']);
$column->primaryKey((bool) $info['is_pk']);
$column->autoIncrement($info['identity_column'] === 'YES');
$column->size((int) $info['data_length']);
$column->precision($info['data_precision'] !== null ? (int) $info['data_precision'] : null);
$column->scale($info['data_scale'] !== null ? (int) $info['data_scale'] : null);
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static function columns(): array
'phpType' => 'integer',
'primaryKey' => true,
'allowNull' => false,
'autoIncrement' => false,
'autoIncrement' => true,
'enumValues' => null,
'size' => 22,
'precision' => null,
Expand Down
2 changes: 1 addition & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function testCreateTable(): void
$this->assertSame(
<<<SQL
CREATE TABLE "test" (
\t"id" NUMBER(10) NOT NULL PRIMARY KEY,
\t"id" NUMBER(10) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
\t"name" VARCHAR2(255) NOT NULL,
\t"email" VARCHAR2(255) NOT NULL,
\t"status" NUMBER(10) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/Fixture/oci.sql
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ CREATE SEQUENCE "bool_values_SEQ";


CREATE TABLE "animal" (
"id" integer,
"id" integer generated by default as identity,
"type" varchar2(255) not null,
CONSTRAINT "animal_PK" PRIMARY KEY ("id") ENABLE
);
Expand Down

0 comments on commit ccb0165

Please sign in to comment.