Skip to content

Commit

Permalink
Merge pull request #76: Small primary
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Oct 22, 2024
2 parents 413af8f + 24ceab5 commit 32cff8f
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 20 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Relation/Traits/FieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Schema/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
30 changes: 30 additions & 0 deletions tests/Schema/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
25 changes: 20 additions & 5 deletions tests/Schema/Relation/Traits/FieldTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
6 changes: 1 addition & 5 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -11,7 +9,6 @@ services:

mysql:
image: mysql:8.0.37
restart: always
command: --default-authentication-plugin=mysql_native_password
ports:
- "13306:3306"
Expand All @@ -22,7 +19,6 @@ services:

postgres:
image: postgres:12
restart: always
ports:
- "15432:5432"
environment:
Expand Down

0 comments on commit 32cff8f

Please sign in to comment.