diff --git a/.github/workflows/ci-mssql.yml b/.github/workflows/ci-mssql.yml index f6bfe63..093a41b 100644 --- a/.github/workflows/ci-mssql.yml +++ b/.github/workflows/ci-mssql.yml @@ -27,26 +27,34 @@ jobs: - php: '8.0' extensions: pdo, pdo_sqlsrv mssql: 'server:2019-latest' + odbc-version: 18 + flag: "-C" - php: '8.1' extensions: pdo, pdo_sqlsrv mssql: 'server:2019-latest' + odbc-version: 18 + flag: "-C" - php: '8.2' extensions: pdo, pdo_sqlsrv mssql: 'server:2019-latest' + odbc-version: 18 + flag: "-C" - php: '8.3' extensions: pdo, pdo_sqlsrv mssql: 'server:2019-latest' + odbc-version: 18 + flag: "-C" services: mssql: - image: mcr.microsoft.com/mssql/${{ matrix.mssql }} - env: - SA_PASSWORD: SSpaSS__1 - ACCEPT_EULA: Y - MSSQL_PID: Developer - ports: - - 11433:1433 - options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SSpaSS__1' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3 + image: mcr.microsoft.com/mssql/${{ matrix.mssql }} + env: + SA_PASSWORD: SSpaSS__1 + ACCEPT_EULA: Y + MSSQL_PID: Developer + ports: + - 11433:1433 + options: --name=mssql --health-cmd="/opt/mssql-tools${{ matrix.odbc-version }}/bin/sqlcmd ${{ matrix.flag }} -S localhost -U SA -P 'SSpaSS__1' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=5 steps: - name: Checkout diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4872c41..20f3af2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: Setup DB services run: | cd tests - docker-compose up -d + docker compose up -d cd .. - name: Setup PHP ${{ matrix.php-versions }} uses: shivammathur/setup-php@v2 diff --git a/src/Definition/Field.php b/src/Definition/Field.php index cf73391..8cfd9fb 100644 --- a/src/Definition/Field.php +++ b/src/Definition/Field.php @@ -91,7 +91,7 @@ public function setPrimary(bool $primary): self public function isPrimary(): bool { - return $this->primary || in_array($this->type, ['primary', 'bigPrimary']); + return $this->primary || in_array($this->type, ['primary', 'bigPrimary', 'smallPrimary']); } /** diff --git a/src/Relation/Traits/FieldTrait.php b/src/Relation/Traits/FieldTrait.php index 897e374..fc443a4 100644 --- a/src/Relation/Traits/FieldTrait.php +++ b/src/Relation/Traits/FieldTrait.php @@ -156,6 +156,9 @@ protected function ensureField(Entity $target, string $fieldName, Field $outerFi case 'bigPrimary': $field->setType('bigint'); break; + case 'smallPrimary': + $field->setType('smallint'); + break; default: $field->setType($outerField->getType()); } diff --git a/tests/Schema/ColumnTest.php b/tests/Schema/ColumnTest.php index 0414d39..add4280 100644 --- a/tests/Schema/ColumnTest.php +++ b/tests/Schema/ColumnTest.php @@ -353,6 +353,39 @@ public function testRenderWithCustomType(): void $this->assertSame('ltree', $table->column('name')->getDeclaredType()); } + /** + * @dataProvider dataIsPrimary + */ + public function testIsPrimary(string $type, bool $expected = true): void + { + $field = new Field(); + $field->setType($type); + $field->setColumn('id'); + + $column = Column::parse($field); + $this->assertSame($expected, $column->isPrimary()); + } + + public function dataIsPrimary(): iterable + { + yield 'primary' => [ + 'primary', + true, + ]; + yield 'smallPrimary' => [ + 'smallPrimary', + true, + ]; + yield 'bigPrimary' => [ + 'bigPrimary', + true, + ]; + yield 'foo' => [ + 'foo', + false, + ]; + } + /** * @return AbstractTable */ diff --git a/tests/Schema/FieldsTest.php b/tests/Schema/FieldsTest.php index a9030cf..bbace9f 100644 --- a/tests/Schema/FieldsTest.php +++ b/tests/Schema/FieldsTest.php @@ -147,4 +147,34 @@ public function testGetByColumnNameShouldThrowAnExceptionWhenFieldNotFound(): vo $m->getByColumnName('slug'); } + + /** + * @dataProvider dataIsPrimary + */ + public function testIsPrimary(string $type, bool $expected = true): void + { + $field = new Field(); + $field->setType($type); + $this->assertSame($expected, $field->isPrimary()); + } + + public function dataIsPrimary(): iterable + { + yield 'primary' => [ + 'primary', + true, + ]; + yield 'smallPrimary' => [ + 'smallPrimary', + true, + ]; + yield 'bigPrimary' => [ + 'bigPrimary', + true, + ]; + yield 'foo' => [ + 'foo', + false, + ]; + } } diff --git a/tests/Schema/Relation/Traits/FieldTraitTest.php b/tests/Schema/Relation/Traits/FieldTraitTest.php index f518519..1526184 100644 --- a/tests/Schema/Relation/Traits/FieldTraitTest.php +++ b/tests/Schema/Relation/Traits/FieldTraitTest.php @@ -142,12 +142,27 @@ public function testEnsureFieldIfFieldNotExistsItShouldBeCreated( } } - public function outerFieldTypes(): array + public function outerFieldTypes(): iterable { - return [ - ['primary', 'int', false], - ['bigPrimary', 'bigint', true], - ['test', 'test', true], + yield 'primary' => [ + 'primary', + 'int', + false, + ]; + yield 'bigPrimary' => [ + 'bigPrimary', + 'bigint', + true, + ]; + yield 'smallPrimary' => [ + 'smallPrimary', + 'smallint', + true, + ]; + yield 'test' => [ + 'test', + 'test', + true, ]; } diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index ec1e1ec..9f2eb69 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,8 +1,6 @@ -version: "3" - services: sqlserver: - image: mcr.microsoft.com/mssql/server:2019-latest + image: mcr.microsoft.com/mssql/server:2019-CU25-ubuntu-20.04 ports: - "11433:1433" environment: @@ -11,7 +9,6 @@ services: mysql: image: mysql:8.0.37 - restart: always command: --default-authentication-plugin=mysql_native_password ports: - "13306:3306" @@ -22,7 +19,6 @@ services: postgres: image: postgres:12 - restart: always ports: - "15432:5432" environment: