diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea65cf7..f50896d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: php: [ 8.3, 8.2, 8.1 ] - database: [ mysql, mariadb, pgsql, sqlite, sqlsrv, singlestore ] + database: [ mysql, mariadb, pgsql, sqlite, sqlsrv, singlestore, firebird ] release: [ stable, lowest ] include: - php: 8.3 diff --git a/README.md b/README.md index b2a7377..08d6e9b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ This Laravel Eloquent extension provides recursive relationships for [trees](#tr - SQLite 3.8.3+ - SQL Server 2008+ - SingleStore 8.1+ (only [trees](#trees-one-parent-per-node-one-to-many)) +- Firebird ## Installation diff --git a/composer.json b/composer.json index 382ea96..0b3b47c 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,12 @@ "php": "^8.1", "illuminate/database": "^10.0", "staudenmeir/eloquent-has-many-deep-contracts": "^1.1", - "staudenmeir/laravel-cte": "^1.8" + "staudenmeir/laravel-cte": "^1.10" }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.13", "doctrine/dbal": "^3.5.2", + "harrygulliford/laravel-firebird": "^3.2", "larastan/larastan": "^2.0", "mockery/mockery": "^1.5.1", "orchestra/testbench": "^8.15", diff --git a/docker-compose.yml b/docker-compose.yml index 4152167..b498c2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,6 +75,14 @@ services: - test volumes: - .docker/singlestore/init.sql:/init.sql + firebird: + image: jacobalberty/firebird:latest + environment: + FIREBIRD_DATABASE: 'test.fdb' + ISC_PASSWORD: 'password' + EnableLegacyClientAuth: 'true' + networks: + - test networks: test: diff --git a/src/Eloquent/Relations/Traits/IsOfDescendantsRelation.php b/src/Eloquent/Relations/Traits/IsOfDescendantsRelation.php index cf7c681..e0b999c 100644 --- a/src/Eloquent/Relations/Traits/IsOfDescendantsRelation.php +++ b/src/Eloquent/Relations/Traits/IsOfDescendantsRelation.php @@ -276,8 +276,11 @@ protected function getInitialQuery(ExpressionGrammar $grammar, callable $constra $depth = $grammar->wrap($model->getDepthName()); - $query = $model->newModelQuery() - ->select('*') + $query = $model->newModelQuery(); + + $table = $alias ?: $query->getQuery()->from; + + $query->select("$table.*") ->selectRaw("$initialDepth as $depth"); if ($alias) { diff --git a/src/Eloquent/Traits/BuildsAdjacencyListQueries.php b/src/Eloquent/Traits/BuildsAdjacencyListQueries.php index 209ba04..db7fcc4 100644 --- a/src/Eloquent/Traits/BuildsAdjacencyListQueries.php +++ b/src/Eloquent/Traits/BuildsAdjacencyListQueries.php @@ -5,6 +5,7 @@ use Illuminate\Database\PostgresConnection; use PDO; use RuntimeException; +use Staudenmeir\LaravelAdjacencyList\Query\Grammars\FirebirdGrammar; use Staudenmeir\LaravelAdjacencyList\Query\Grammars\MariaDbGrammar; use Staudenmeir\LaravelAdjacencyList\Query\Grammars\MySqlGrammar; use Staudenmeir\LaravelAdjacencyList\Query\Grammars\PostgresGrammar; @@ -104,6 +105,10 @@ public function getExpressionGrammar() return $this->query->getConnection()->withTablePrefix( new SingleStoreGrammar($this->model) ); + case 'firebird': + return $this->query->getConnection()->withTablePrefix( + new FirebirdGrammar($this->model) + ); } throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore diff --git a/src/Eloquent/Traits/HasRecursiveRelationshipScopes.php b/src/Eloquent/Traits/HasRecursiveRelationshipScopes.php index ba492de..4571548 100644 --- a/src/Eloquent/Traits/HasRecursiveRelationshipScopes.php +++ b/src/Eloquent/Traits/HasRecursiveRelationshipScopes.php @@ -184,6 +184,8 @@ public function scopeWithRelationshipExpression(Builder $query, $direction, call */ protected function getInitialQuery(ExpressionGrammar $grammar, callable $constraint, $initialDepth, $from) { + $table = explode(' as ', $from)[1] ?? $from; + $depth = $grammar->wrap($this->getDepthName()); $initialPath = $grammar->compileInitialPath( @@ -192,7 +194,7 @@ protected function getInitialQuery(ExpressionGrammar $grammar, callable $constra ); $query = $this->newModelQuery() - ->select('*') + ->select("$table.*") ->selectRaw($initialDepth.' as '.$depth) ->selectRaw($initialPath) ->from($from); @@ -241,7 +243,10 @@ protected function getRecursiveQuery(ExpressionGrammar $grammar, $direction, $fr ]; if ($direction === 'both') { - $recursiveDepth = "$depth + (case when {$joinColumns['desc'][1]}={$joinColumns['desc'][0]} then 1 else -1 end)"; + $left = $grammar->wrap($joinColumns['desc'][1]); + $right = $grammar->wrap($joinColumns['desc'][0]); + + $recursiveDepth = "$depth + (case when $left=$right then 1 else -1 end)"; } else { $recursiveDepth = $depth.' '.($direction === 'asc' ? '-' : '+').' 1'; } diff --git a/src/Query/Grammars/FirebirdGrammar.php b/src/Query/Grammars/FirebirdGrammar.php new file mode 100644 index 0000000..6a358dc --- /dev/null +++ b/src/Query/Grammars/FirebirdGrammar.php @@ -0,0 +1,75 @@ +wrap($column) . ' as varchar(8191)) as ' . $this->wrap($alias); + } + + public function compileRecursivePath($column, $alias, bool $reverse = false) + { + $wrappedColumn = $this->wrap($column); + $wrappedAlias = $this->wrap($alias); + $placeholder = 'cast(? as varchar(8191))'; + + return $reverse ? "($wrappedColumn || $placeholder || $wrappedAlias)" : "($wrappedAlias || $placeholder || $wrappedColumn)"; + } + + public function getRecursivePathBindings($separator) + { + return [$separator]; + } + + public function selectPathList(Builder $query, $expression, $column, $pathSeparator, $listSeparator) + { + return $query->selectRaw( + 'list(' . $this->wrap($column) . ", '$listSeparator')" + )->from($expression); + } + + public function compilePivotColumnNullValue(string $type, int $precision, int $scale): string + { + return 'null'; + } + + public function compileCycleDetection(string $localKey, string $path): string + { + $localKey = $this->wrap($localKey); + $path = $this->wrap($path); + + return "position($localKey || ?, $path) > 0 or position(? || $localKey || ?, $path) > 0"; + } + + public function getCycleDetectionBindings(string $pathSeparator): array + { + return [$pathSeparator, $pathSeparator, $pathSeparator]; + } + + public function compileCycleDetectionInitialSelect(string $column): string + { + return 'false as ' . $this->wrap($column); + } + + public function compileCycleDetectionRecursiveSelect(string $sql, string $column): string + { + return $sql; + } + + public function compileCycleDetectionStopConstraint(string $column): string + { + return 'not ' . $this->wrap($column); + } + + public function supportsUnionInRecursiveExpression(): bool + { + return false; + } +} diff --git a/tests/Graph/AncestorsTest.php b/tests/Graph/AncestorsTest.php index 5bf918a..cc49eb9 100644 --- a/tests/Graph/AncestorsTest.php +++ b/tests/Graph/AncestorsTest.php @@ -12,7 +12,7 @@ class AncestorsTest extends TestCase { public function testLazyLoading() { - $ancestors = Node::find(5)->ancestors; + $ancestors = Node::find(5)->ancestors()->orderByDesc('depth')->orderBy('id')->get(); $this->assertEquals([1, 2, 10, 1, 9], $ancestors->pluck('id')->all()); $this->assertEquals([-1, -1, -1, -2, -2], $ancestors->pluck('depth')->all()); @@ -71,7 +71,7 @@ public function testLazyLoadingWithCycleDetectionAndStart(string $class, array $ public function testLazyLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -113,7 +113,7 @@ public function testLazyLoadingAndSelf() public function testLazyLoadingAndSelfWithCycleDetection() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -127,7 +127,7 @@ public function testLazyLoadingAndSelfWithCycleDetection() public function testLazyLoadingAndSelfWithCycleDetectionAndStart() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -171,6 +171,11 @@ public function testEagerLoadingWithCycleDetection(string $class, array $exclusi $this->markTestSkipped(); } + // TODO[L11] + if ($this->connection === 'firebird' && version_compare(phpversion(), '8.2', '<')) { + $this->markTestSkipped(); + } + $this->seedCycle(); $nodes = $class::with([ @@ -188,6 +193,11 @@ public function testEagerLoadingWithCycleDetectionAndStart(string $class, array $this->markTestSkipped(); } + // TODO[L11] + if ($this->connection === 'firebird' && version_compare(phpversion(), '8.2', '<')) { + $this->markTestSkipped(); + } + $this->seedCycle(); $nodes = $class::with([ @@ -201,7 +211,7 @@ public function testEagerLoadingWithCycleDetectionAndStart(string $class, array public function testEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -240,7 +250,7 @@ public function testEagerLoadingAndSelf() public function testEagerLoadingAndSelfWithCycleDetection() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -254,7 +264,7 @@ public function testEagerLoadingAndSelfWithCycleDetection() public function testEagerLoadingAndSelfWithCycleDetectionAndStart() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -293,7 +303,7 @@ public function testLazyEagerLoading() public function testLazyEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -332,7 +342,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -343,7 +353,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -365,7 +375,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -387,7 +397,7 @@ public function testWithSumForSelfRelation() public function testWithSumForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -398,7 +408,7 @@ public function testWithSumForSelfRelationAndSelf() public function testDelete() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Graph/CollectionTest.php b/tests/Graph/CollectionTest.php index 5087007..da67ae0 100644 --- a/tests/Graph/CollectionTest.php +++ b/tests/Graph/CollectionTest.php @@ -11,7 +11,7 @@ class CollectionTest extends TestCase { public function testToTree() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -41,7 +41,7 @@ public function testToTreeWithRelationship() public function testToTreeWithCycle() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -61,7 +61,7 @@ public function testToTreeWithCycle() public function testToTreeWithCycleAndStart() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -81,7 +81,7 @@ public function testToTreeWithCycleAndStart() public function testToTreeWithEmptyCollection() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Graph/Concatenation/AncestorsTest.php b/tests/Graph/Concatenation/AncestorsTest.php index d32ee3f..131a6e4 100644 --- a/tests/Graph/Concatenation/AncestorsTest.php +++ b/tests/Graph/Concatenation/AncestorsTest.php @@ -18,7 +18,7 @@ public function testLazyLoading() public function testLazyLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -40,7 +40,7 @@ public function testEagerLoading() public function testEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -76,7 +76,7 @@ public function testLazyEagerLoading() public function testLazyEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -91,7 +91,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -102,7 +102,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -113,7 +113,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -124,7 +124,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Graph/Concatenation/DescendantsTest.php b/tests/Graph/Concatenation/DescendantsTest.php index 04a83ad..470453b 100644 --- a/tests/Graph/Concatenation/DescendantsTest.php +++ b/tests/Graph/Concatenation/DescendantsTest.php @@ -18,7 +18,7 @@ public function testLazyLoading() public function testLazyLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -39,7 +39,7 @@ public function testEagerLoading() public function testEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -73,7 +73,7 @@ public function testLazyEagerLoading() public function testLazyEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -87,7 +87,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -98,7 +98,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -109,7 +109,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -120,7 +120,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Graph/DescendantsTest.php b/tests/Graph/DescendantsTest.php index 5548fe0..57657cc 100644 --- a/tests/Graph/DescendantsTest.php +++ b/tests/Graph/DescendantsTest.php @@ -12,7 +12,7 @@ class DescendantsTest extends TestCase { public function testLazyLoading() { - $descendants = Node::find(2)->descendants; + $descendants = Node::find(2)->descendants()->orderBy('depth')->get(); $this->assertEquals([5, 7, 8, 8], $descendants->pluck('id')->all()); $this->assertEquals([1, 2, 2, 3], $descendants->pluck('depth')->all()); @@ -71,7 +71,7 @@ public function testLazyLoadingWithCycleDetectionAndStart(string $class, array $ public function testLazyLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -113,7 +113,7 @@ public function testLazyLoadingAndSelf() public function testLazyLoadingAndSelfWithCycleDetection() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -127,7 +127,7 @@ public function testLazyLoadingAndSelfWithCycleDetection() public function testLazyLoadingAndSelfWithCycleDetectionAndStart() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -179,6 +179,11 @@ public function testEagerLoadingWithCycleDetection(string $class, array $exclusi $this->markTestSkipped(); } + // TODO[L11] + if ($this->connection === 'firebird' && version_compare(phpversion(), '8.2', '<')) { + $this->markTestSkipped(); + } + $this->seedCycle(); $nodes = $class::with([ @@ -196,6 +201,11 @@ public function testEagerLoadingWithCycleDetectionAndStart(string $class, array $this->markTestSkipped(); } + // TODO[L11] + if ($this->connection === 'firebird' && version_compare(phpversion(), '8.2', '<')) { + $this->markTestSkipped(); + } + $this->seedCycle(); $nodes = $class::with([ @@ -209,7 +219,7 @@ public function testEagerLoadingWithCycleDetectionAndStart(string $class, array public function testEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -256,7 +266,7 @@ public function testEagerLoadingAndSelf() public function testEagerLoadingAndSelfWithCycleDetection() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -270,7 +280,7 @@ public function testEagerLoadingAndSelfWithCycleDetection() public function testEagerLoadingAndSelfWithCycleDetectionAndStart() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -317,7 +327,7 @@ public function testLazyEagerLoading() public function testLazyEagerLoadingAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -364,7 +374,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -375,7 +385,7 @@ public function testExistenceQuery() public function testExistenceQueryWithCycleDetection() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -388,7 +398,7 @@ public function testExistenceQueryWithCycleDetection() public function testExistenceQueryWithCycleDetectionAndStart() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -401,7 +411,7 @@ public function testExistenceQueryWithCycleDetectionAndStart() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -412,7 +422,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryAndSelfWithCycleDetection() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -425,7 +435,7 @@ public function testExistenceQueryAndSelfWithCycleDetection() public function testExistenceQueryAndSelfWithCycleDetectionAndStart() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -449,7 +459,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -471,7 +481,7 @@ public function testWithSumForSelfRelation() public function testWithSumForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -482,7 +492,7 @@ public function testWithSumForSelfRelationAndSelf() public function testDelete() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Graph/EloquentTest.php b/tests/Graph/EloquentTest.php index 3765dc2..2fc1bb8 100644 --- a/tests/Graph/EloquentTest.php +++ b/tests/Graph/EloquentTest.php @@ -9,7 +9,7 @@ class EloquentTest extends TestCase { public function testScopeSubgraph() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -22,7 +22,7 @@ public function testScopeSubgraph() public function testScopeSubgraphWithMaxDepth() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -53,7 +53,7 @@ public function testChildren() public function testChildrenAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -82,7 +82,7 @@ public function testParents() public function testParentsAndSelf() { - if ($this->connection === 'sqlsrv') { + if (in_array($this->connection, ['sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -114,6 +114,10 @@ public function testScopeBreadthFirst() public function testScopeDepthFirst() { + if ($this->connection === 'firebird') { + $this->markTestSkipped(); + } + $nodes = Node::find(1)->descendants()->depthFirst()->get(); $this->assertEquals([2, 5, 7, 8, 8, 3, 6, 4, 5, 7, 8, 8], $nodes->pluck('id')->all()); diff --git a/tests/Graph/Models/Node.php b/tests/Graph/Models/Node.php index 273d678..cc54f3c 100644 --- a/tests/Graph/Models/Node.php +++ b/tests/Graph/Models/Node.php @@ -22,6 +22,8 @@ class Node extends Model use HasTableAlias; use SoftDeletes; + public $incrementing = false; + protected $table = 'nodes'; public function getPivotTableName(): string @@ -41,7 +43,9 @@ public function getCustomPaths(): array ], [ 'name' => 'reverse_slug_path', - 'column' => new Expression('nodes.slug'), + 'column' => new Expression( + $this->newQuery()->getGrammar()->wrap('nodes.slug') + ), 'separator' => '/', 'reverse' => true, ], diff --git a/tests/Graph/Models/Post.php b/tests/Graph/Models/Post.php index aa5eac6..b9594b3 100644 --- a/tests/Graph/Models/Post.php +++ b/tests/Graph/Models/Post.php @@ -15,6 +15,8 @@ class Post extends Model use QueriesExpressions; use SoftDeletes; + public $incrementing = false; + public function node(): BelongsTo { return $this->belongsTo(Node::class); diff --git a/tests/Graph/TestCase.php b/tests/Graph/TestCase.php index 3d442e8..238336b 100644 --- a/tests/Graph/TestCase.php +++ b/tests/Graph/TestCase.php @@ -3,6 +3,7 @@ namespace Staudenmeir\LaravelAdjacencyList\Tests\Graph; use Carbon\Carbon; +use HarryGulliford\Firebird\FirebirdServiceProvider; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; @@ -43,12 +44,14 @@ protected function tearDown(): void protected function migrateDatabase(): void { - Schema::dropAllTables(); + Schema::dropIfExists('nodes'); + Schema::dropIfExists('edges'); + Schema::dropIfExists('posts'); Schema::create( 'nodes', function (Blueprint $table) { - $table->id(); + $table->unsignedBigInteger('id')->unique(); $table->string('slug')->unique(); $table->uuid()->unique(); $table->timestamps(); @@ -73,7 +76,7 @@ function (Blueprint $table) { Schema::create( 'posts', function (Blueprint $table) { - $table->unsignedInteger('id'); + $table->unsignedInteger('id')->unique(); $table->unsignedInteger('node_id'); $table->timestamps(); $table->softDeletes(); @@ -89,142 +92,138 @@ protected function seedDatabase(): void Model::unguard(); - Node::create(['slug' => 'node-1', 'uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-2', 'uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-3', 'uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-4', 'uuid' => 'd0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-5', 'uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-6', 'uuid' => 'f0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-7', 'uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-8', 'uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-9', 'uuid' => 'c1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-10', 'uuid' => 'd1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-11', 'uuid' => 'e1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', 'deleted_at' => Carbon::now()]); - - DB::table('edges')->insert( - [ - [ - 'parent_id' => 1, - 'child_id' => 2, - 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'a', - 'weight' => 1, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 1, - 'child_id' => 3, - 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'b', - 'weight' => 2, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 1, - 'child_id' => 4, - 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'd0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'c', - 'weight' => 3, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 1, - 'child_id' => 5, - 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'd', - 'weight' => 4, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 2, - 'child_id' => 5, - 'parent_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'e', - 'weight' => 5, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 3, - 'child_id' => 6, - 'parent_uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'f0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'f', - 'weight' => 6, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 5, - 'child_id' => 7, - 'parent_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'g', - 'weight' => 7, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 5, - 'child_id' => 8, - 'parent_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'h', - 'weight' => 8, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 7, - 'child_id' => 8, - 'parent_uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'i', - 'weight' => 9, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 9, - 'child_id' => 2, - 'parent_uuid' => 'c1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'j', - 'weight' => 10, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 10, - 'child_id' => 5, - 'parent_uuid' => 'd1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'k', - 'weight' => 11, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 11, - 'child_id' => 5, - 'parent_uuid' => 'e1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'l', - 'weight' => 12, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - ] - ); + Node::create(['id' => 1, 'slug' => 'node-1', 'uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 2, 'slug' => 'node-2', 'uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 3, 'slug' => 'node-3', 'uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 4, 'slug' => 'node-4', 'uuid' => 'd0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 5, 'slug' => 'node-5', 'uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 6, 'slug' => 'node-6', 'uuid' => 'f0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 7, 'slug' => 'node-7', 'uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 8, 'slug' => 'node-8', 'uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 9, 'slug' => 'node-9', 'uuid' => 'c1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 10, 'slug' => 'node-10', 'uuid' => 'd1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 11, 'slug' => 'node-11', 'uuid' => 'e1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', 'deleted_at' => Carbon::now()]); + + DB::table('edges')->insert([ + 'parent_id' => 1, + 'child_id' => 2, + 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'a', + 'weight' => 1, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 1, + 'child_id' => 3, + 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'b', + 'weight' => 2, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 1, + 'child_id' => 4, + 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'd0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'c', + 'weight' => 3, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 1, + 'child_id' => 5, + 'parent_uuid' => 'a0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'd', + 'weight' => 4, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 2, + 'child_id' => 5, + 'parent_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'e', + 'weight' => 5, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 3, + 'child_id' => 6, + 'parent_uuid' => 'c0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'f0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'f', + 'weight' => 6, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 5, + 'child_id' => 7, + 'parent_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'g', + 'weight' => 7, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 5, + 'child_id' => 8, + 'parent_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'h', + 'weight' => 8, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 7, + 'child_id' => 8, + 'parent_uuid' => 'a1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'b1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'i', + 'weight' => 9, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 9, + 'child_id' => 2, + 'parent_uuid' => 'c1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'b0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'j', + 'weight' => 10, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 10, + 'child_id' => 5, + 'parent_uuid' => 'd1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'k', + 'weight' => 11, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 11, + 'child_id' => 5, + 'parent_uuid' => 'e1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'e0f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'l', + 'weight' => 12, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); Post::create(['id' => 101, 'node_id' => 1, 'deleted_at' => null]); Post::create(['id' => 102, 'node_id' => 2, 'deleted_at' => null]); @@ -244,45 +243,40 @@ protected function seedCycle(): void { Model::unguard(); - Node::create(['slug' => 'node-12', 'uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-13', 'uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - Node::create(['slug' => 'node-14', 'uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); - - DB::table('edges')->insert( - [ - - [ - 'parent_id' => 12, - 'child_id' => 13, - 'parent_uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'm', - 'weight' => 13, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 13, - 'child_id' => 14, - 'parent_uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'n', - 'weight' => 14, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - [ - 'parent_id' => 14, - 'child_id' => 12, - 'parent_uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'child_uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', - 'label' => 'o', - 'weight' => 15, - 'value' => '123.456', - 'created_at' => Carbon::now(), - ], - ] - ); + Node::create(['id' => 12, 'slug' => 'node-12', 'uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 13, 'slug' => 'node-13', 'uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + Node::create(['id' => 14, 'slug' => 'node-14', 'uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b']); + + DB::table('edges')->insert([ + 'parent_id' => 12, + 'child_id' => 13, + 'parent_uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'm', + 'weight' => 13, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 13, + 'child_id' => 14, + 'parent_uuid' => 'a2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'n', + 'weight' => 14, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); + DB::table('edges')->insert([ + 'parent_id' => 14, + 'child_id' => 12, + 'parent_uuid' => 'b2f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'child_uuid' => 'f1f1b2c3-d4e5-4f6a-8b9b-0c1d2e3f4a5b', + 'label' => 'o', + 'weight' => 15, + 'value' => '123.456', + 'created_at' => Carbon::now(), + ]); Model::reguard(); } @@ -318,4 +312,9 @@ protected function getEnvironmentSetUp($app) $app['config']->set('database.connections.testing', $config[$this->connection]); } + + protected function getPackageProviders($app) + { + return [FirebirdServiceProvider::class]; + } } diff --git a/tests/Tree/AncestorsTest.php b/tests/Tree/AncestorsTest.php index 2b7d145..7374a7c 100644 --- a/tests/Tree/AncestorsTest.php +++ b/tests/Tree/AncestorsTest.php @@ -2,6 +2,7 @@ namespace Staudenmeir\LaravelAdjacencyList\Tests\Tree; +use Illuminate\Support\Facades\DB; use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors; use Staudenmeir\LaravelAdjacencyList\Tests\Tree\Models\User; @@ -102,7 +103,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -113,7 +114,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -124,7 +125,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -135,7 +136,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -146,7 +147,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testWithSumForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -157,7 +158,7 @@ public function testWithSumForSelfRelation() public function testWithSumForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -168,7 +169,7 @@ public function testWithSumForSelfRelationAndSelf() public function testUpdate() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/BelongsToManyOfDescendantsTest.php b/tests/Tree/BelongsToManyOfDescendantsTest.php index 16c45b8..1d1903c 100644 --- a/tests/Tree/BelongsToManyOfDescendantsTest.php +++ b/tests/Tree/BelongsToManyOfDescendantsTest.php @@ -87,7 +87,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -98,7 +98,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -109,7 +109,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -120,7 +120,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -131,7 +131,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testDelete() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } @@ -144,7 +144,7 @@ public function testDelete() public function testDeleteAndSelf() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/BloodlineTest.php b/tests/Tree/BloodlineTest.php index ce2ec90..a96ec63 100644 --- a/tests/Tree/BloodlineTest.php +++ b/tests/Tree/BloodlineTest.php @@ -45,7 +45,7 @@ public function testLazyEagerLoading() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -56,7 +56,7 @@ public function testExistenceQuery() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -67,7 +67,7 @@ public function testExistenceQueryForSelfRelation() public function testIncrement() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -81,7 +81,7 @@ public function testIncrement() public function testDecrement() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/Concatenation/AncestorsTest.php b/tests/Tree/Concatenation/AncestorsTest.php index b89aa6d..6c08558 100644 --- a/tests/Tree/Concatenation/AncestorsTest.php +++ b/tests/Tree/Concatenation/AncestorsTest.php @@ -92,7 +92,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -103,7 +103,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/Concatenation/BloodlineTest.php b/tests/Tree/Concatenation/BloodlineTest.php index 839bf83..755b469 100644 --- a/tests/Tree/Concatenation/BloodlineTest.php +++ b/tests/Tree/Concatenation/BloodlineTest.php @@ -47,7 +47,7 @@ public function testLazyEagerLoading() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/Concatenation/DescendantsTest.php b/tests/Tree/Concatenation/DescendantsTest.php index ce83063..78eb8f5 100644 --- a/tests/Tree/Concatenation/DescendantsTest.php +++ b/tests/Tree/Concatenation/DescendantsTest.php @@ -93,7 +93,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -104,7 +104,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/DescendantsTest.php b/tests/Tree/DescendantsTest.php index fa47785..292ee54 100644 --- a/tests/Tree/DescendantsTest.php +++ b/tests/Tree/DescendantsTest.php @@ -2,6 +2,7 @@ namespace Staudenmeir\LaravelAdjacencyList\Tests\Tree; +use Illuminate\Support\Facades\DB; use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants; use Staudenmeir\LaravelAdjacencyList\Tests\Tree\Models\User; @@ -9,8 +10,12 @@ class DescendantsTest extends TestCase { public function testLazyLoading() { + DB::connection()->enableQueryLog(); + $descendants = User::find(2)->descendants; + //dd(DB::getQueryLog()); + $this->assertEquals([5, 8], $descendants->pluck('id')->all()); $this->assertEquals([1, 2], $descendants->pluck('depth')->all()); $this->assertEquals(['5', '5.8'], $descendants->pluck('path')->all()); @@ -92,7 +97,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -103,7 +108,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -114,7 +119,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -125,7 +130,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -136,7 +141,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testWithSumForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -147,7 +152,7 @@ public function testWithSumForSelfRelation() public function testWithSumForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -158,7 +163,7 @@ public function testWithSumForSelfRelationAndSelf() public function testDelete() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -171,7 +176,7 @@ public function testDelete() public function testForceDelete() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/EloquentTest.php b/tests/Tree/EloquentTest.php index 1e3d728..25c74bc 100644 --- a/tests/Tree/EloquentTest.php +++ b/tests/Tree/EloquentTest.php @@ -158,6 +158,10 @@ public function testScopeBreadthFirst() public function testScopeDepthFirst() { + if ($this->connection === 'firebird') { + $this->markTestSkipped(); + } + $users = User::tree()->depthFirst()->get(); $this->assertEquals([1, 2, 5, 8, 3, 6, 9, 4, 7, 11, 12], $users->pluck('id')->all()); @@ -165,11 +169,11 @@ public function testScopeDepthFirst() public function testScopeDepthFirstWithNaturalSorting() { - if (in_array($this->connection, ['sqlite', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['sqlite', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } - User::forceCreate(['id' => 70, 'slug' => 'user-70', 'parent_id' => 5, 'deleted_at' => null]); + User::forceCreate(['id' => 70, 'slug' => 'user-70', 'parent_id' => 5, 'followers' => 1, 'deleted_at' => null]); $users = User::tree()->depthFirst()->get(); @@ -178,6 +182,10 @@ public function testScopeDepthFirstWithNaturalSorting() public function testScopeDepthFirstWithStringKey() { + if ($this->connection === 'firebird') { + $this->markTestSkipped(); + } + $categories = Category::tree()->depthFirst()->get(); $this->assertEquals(['a', 'b', 'c', 'd'], $categories->pluck('id')->all()); diff --git a/tests/Tree/HasManyOfDescendantsTest.php b/tests/Tree/HasManyOfDescendantsTest.php index 04e2133..a8aebcb 100644 --- a/tests/Tree/HasManyOfDescendantsTest.php +++ b/tests/Tree/HasManyOfDescendantsTest.php @@ -3,6 +3,7 @@ namespace Staudenmeir\LaravelAdjacencyList\Tests\Tree; use Illuminate\Database\Eloquent\SoftDeletingScope; +use Illuminate\Support\Facades\DB; use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants; use Staudenmeir\LaravelAdjacencyList\Tests\Scopes\DepthScope; use Staudenmeir\LaravelAdjacencyList\Tests\Tree\Models\Post; @@ -104,7 +105,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -115,7 +116,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -126,7 +127,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -137,7 +138,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -148,7 +149,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testUpdate() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } @@ -161,7 +162,7 @@ public function testUpdate() public function testUpdateAndSelf() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/Models/Post.php b/tests/Tree/Models/Post.php index 47b62bf..27d6c83 100644 --- a/tests/Tree/Models/Post.php +++ b/tests/Tree/Models/Post.php @@ -10,4 +10,6 @@ class Post extends Model { use QueriesExpressions; use SoftDeletes; + + public $incrementing = false; } diff --git a/tests/Tree/Models/Role.php b/tests/Tree/Models/Role.php index 0b2ac3b..03a8e5c 100644 --- a/tests/Tree/Models/Role.php +++ b/tests/Tree/Models/Role.php @@ -15,6 +15,8 @@ class Role extends Model use QueriesExpressions; use SoftDeletes; + public $incrementing = false; + public function userAncestors(): HasManyDeep { return $this->hasManyDeepFromRelations( diff --git a/tests/Tree/Models/Tag.php b/tests/Tree/Models/Tag.php index f9b188c..3ded267 100644 --- a/tests/Tree/Models/Tag.php +++ b/tests/Tree/Models/Tag.php @@ -10,4 +10,6 @@ class Tag extends Model { use QueriesExpressions; use SoftDeletes; + + public $incrementing = false; } diff --git a/tests/Tree/Models/User.php b/tests/Tree/Models/User.php index 2fa5e7f..cff17e3 100644 --- a/tests/Tree/Models/User.php +++ b/tests/Tree/Models/User.php @@ -23,6 +23,12 @@ class User extends Model use HasTableAlias; use SoftDeletes; + public $incrementing = false; + + protected $casts = [ + 'id' => 'int', + ]; + public function getCustomPaths(): array { return array_merge( @@ -35,7 +41,9 @@ public function getCustomPaths(): array ], [ 'name' => 'reverse_slug_path', - 'column' => new Expression('users.slug'), + 'column' => new Expression( + $this->newQuery()->getGrammar()->wrap('users.slug') + ), 'separator' => '/', 'reverse' => true, ], diff --git a/tests/Tree/Models/Video.php b/tests/Tree/Models/Video.php index 393b3be..fc48d50 100644 --- a/tests/Tree/Models/Video.php +++ b/tests/Tree/Models/Video.php @@ -10,4 +10,6 @@ class Video extends Model { use QueriesExpressions; use SoftDeletes; + + public $incrementing = false; } diff --git a/tests/Tree/MorphToManyOfDescendantsTest.php b/tests/Tree/MorphToManyOfDescendantsTest.php index 8131ecc..67d771a 100644 --- a/tests/Tree/MorphToManyOfDescendantsTest.php +++ b/tests/Tree/MorphToManyOfDescendantsTest.php @@ -87,7 +87,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -98,7 +98,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -109,7 +109,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -120,7 +120,7 @@ public function testExistenceQueryForSelfRelation() public function testExistenceQueryForSelfRelationAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -131,7 +131,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testDelete() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } @@ -144,7 +144,7 @@ public function testDelete() public function testDeleteAndSelf() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/MorphedByManyOfDescendantsTest.php b/tests/Tree/MorphedByManyOfDescendantsTest.php index 08bd5a6..e031f23 100644 --- a/tests/Tree/MorphedByManyOfDescendantsTest.php +++ b/tests/Tree/MorphedByManyOfDescendantsTest.php @@ -87,7 +87,7 @@ public function testLazyEagerLoadingAndSelf() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -98,7 +98,7 @@ public function testExistenceQuery() public function testExistenceQueryAndSelf() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -109,7 +109,7 @@ public function testExistenceQueryAndSelf() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'firebird'])) { $this->markTestSkipped(); } @@ -131,7 +131,7 @@ public function testExistenceQueryForSelfRelationAndSelf() public function testDelete() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } @@ -144,7 +144,7 @@ public function testDelete() public function testDeleteAndSelf() { - if ($this->connection === 'mariadb') { + if (in_array($this->connection, ['mariadb', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/RootAncestorOrSelfTest.php b/tests/Tree/RootAncestorOrSelfTest.php index 4688250..e2de851 100644 --- a/tests/Tree/RootAncestorOrSelfTest.php +++ b/tests/Tree/RootAncestorOrSelfTest.php @@ -42,7 +42,7 @@ public function testLazyEagerLoading() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -53,7 +53,7 @@ public function testExistenceQuery() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -64,7 +64,7 @@ public function testExistenceQueryForSelfRelation() public function testUpdate() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/RootAncestorTest.php b/tests/Tree/RootAncestorTest.php index 5480d49..9119bb9 100644 --- a/tests/Tree/RootAncestorTest.php +++ b/tests/Tree/RootAncestorTest.php @@ -39,7 +39,7 @@ public function testLazyEagerLoading() public function testExistenceQuery() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -50,7 +50,7 @@ public function testExistenceQuery() public function testExistenceQueryForSelfRelation() { - if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } @@ -61,7 +61,7 @@ public function testExistenceQueryForSelfRelation() public function testUpdate() { - if (in_array($this->connection, ['mariadb', 'singlestore'])) { + if (in_array($this->connection, ['mariadb', 'singlestore', 'firebird'])) { $this->markTestSkipped(); } diff --git a/tests/Tree/TestCase.php b/tests/Tree/TestCase.php index 6fa24f2..32261ad 100644 --- a/tests/Tree/TestCase.php +++ b/tests/Tree/TestCase.php @@ -3,6 +3,7 @@ namespace Staudenmeir\LaravelAdjacencyList\Tests\Tree; use Carbon\Carbon; +use HarryGulliford\Firebird\FirebirdServiceProvider; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; @@ -40,36 +41,56 @@ protected function tearDown(): void protected function migrateDatabase(): void { - Schema::dropAllTables(); + Schema::dropIfExists('users'); + Schema::dropIfExists('posts'); + Schema::dropIfExists('roles'); + Schema::dropIfExists('role_user'); + Schema::dropIfExists('tags'); + Schema::dropIfExists('taggables'); + Schema::dropIfExists('videos'); + Schema::dropIfExists('authorables'); + Schema::dropIfExists('categories'); Schema::create( 'users', function (Blueprint $table) { - $table->id(); + $table->unsignedBigInteger('id')->unique(); $table->string('slug'); - $table->unsignedInteger('parent_id')->nullable(); - $table->unsignedBigInteger('followers')->default(1); + $table->unsignedBigInteger('parent_id')->nullable(); + $table->unsignedBigInteger('followers'); $table->timestamps(); $table->softDeletes(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); Schema::create( 'posts', function (Blueprint $table) { - $table->unsignedInteger('id'); - $table->unsignedInteger('user_id'); + $table->unsignedBigInteger('id')->unique(); + $table->unsignedBigInteger('user_id'); $table->timestamps(); $table->softDeletes(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); Schema::create( 'roles', function (Blueprint $table) { - $table->unsignedInteger('id'); + $table->unsignedBigInteger('id')->unique(); $table->timestamps(); $table->softDeletes(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); @@ -84,16 +105,20 @@ function (Blueprint $table) { Schema::create( 'tags', function (Blueprint $table) { - $table->unsignedInteger('id'); + $table->unsignedBigInteger('id')->unique(); $table->timestamps(); $table->softDeletes(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); Schema::create( 'taggables', function (Blueprint $table) { - $table->unsignedInteger('tag_id'); + $table->unsignedBigInteger('tag_id'); $table->morphs('taggable'); } ); @@ -101,16 +126,20 @@ function (Blueprint $table) { Schema::create( 'videos', function (Blueprint $table) { - $table->unsignedInteger('id'); + $table->unsignedBigInteger('id')->unique(); $table->timestamps(); $table->softDeletes(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); Schema::create( 'authorables', function (Blueprint $table) { - $table->unsignedInteger('user_id'); + $table->unsignedBigInteger('user_id'); $table->morphs('authorable'); } ); @@ -118,9 +147,13 @@ function (Blueprint $table) { Schema::create( 'categories', function (Blueprint $table) { - $table->string('id'); + $table->string('id')->unique(); $table->string('parent_id')->nullable(); $table->timestamps(); + + if ($this->connection === 'singlestore') { + $table->shardKey('id'); + } } ); } @@ -129,18 +162,18 @@ protected function seedDatabase(): void { Model::unguard(); - User::create(['slug' => 'user-1', 'parent_id' => null, 'deleted_at' => null]); - User::create(['slug' => 'user-2', 'parent_id' => 1, 'deleted_at' => null]); - User::create(['slug' => 'user-3', 'parent_id' => 1, 'deleted_at' => null]); - User::create(['slug' => 'user-4', 'parent_id' => 1, 'deleted_at' => null]); - User::create(['slug' => 'user-5', 'parent_id' => 2, 'deleted_at' => null]); - User::create(['slug' => 'user-6', 'parent_id' => 3, 'deleted_at' => null]); - User::create(['slug' => 'user-7', 'parent_id' => 4, 'deleted_at' => null]); - User::create(['slug' => 'user-8', 'parent_id' => 5, 'deleted_at' => null]); - User::create(['slug' => 'user-9', 'parent_id' => 6, 'deleted_at' => null]); - User::create(['slug' => 'user-10', 'parent_id' => 7, 'deleted_at' => Carbon::now()]); - User::create(['slug' => 'user-11', 'parent_id' => null, 'deleted_at' => null]); - User::create(['slug' => 'user-12', 'parent_id' => 11, 'deleted_at' => null]); + User::create(['id' => 1, 'slug' => 'user-1', 'parent_id' => null, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 2, 'slug' => 'user-2', 'parent_id' => 1, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 3, 'slug' => 'user-3', 'parent_id' => 1, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 4, 'slug' => 'user-4', 'parent_id' => 1, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 5, 'slug' => 'user-5', 'parent_id' => 2, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 6, 'slug' => 'user-6', 'parent_id' => 3, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 7, 'slug' => 'user-7', 'parent_id' => 4, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 8, 'slug' => 'user-8', 'parent_id' => 5, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 9, 'slug' => 'user-9', 'parent_id' => 6, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 10, 'slug' => 'user-10', 'parent_id' => 7, 'followers' => 1, 'deleted_at' => Carbon::now()]); + User::create(['id' => 11, 'slug' => 'user-11', 'parent_id' => null, 'followers' => 1, 'deleted_at' => null]); + User::create(['id' => 12, 'slug' => 'user-12', 'parent_id' => 11, 'followers' => 1, 'deleted_at' => null]); Post::create(['id' => 10, 'user_id' => 1, 'deleted_at' => null]); Post::create(['id' => 20, 'user_id' => 2, 'deleted_at' => null]); @@ -168,22 +201,18 @@ protected function seedDatabase(): void Role::create(['id' => 111, 'deleted_at' => null]); Role::create(['id' => 121, 'deleted_at' => Carbon::now()]); - DB::table('role_user')->insert( - [ - ['role_id' => 11, 'user_id' => 1], - ['role_id' => 21, 'user_id' => 2], - ['role_id' => 31, 'user_id' => 3], - ['role_id' => 41, 'user_id' => 4], - ['role_id' => 51, 'user_id' => 5], - ['role_id' => 61, 'user_id' => 6], - ['role_id' => 71, 'user_id' => 7], - ['role_id' => 81, 'user_id' => 8], - ['role_id' => 91, 'user_id' => 10], - ['role_id' => 101, 'user_id' => 12], - ['role_id' => 111, 'user_id' => 12], - ['role_id' => 121, 'user_id' => 12], - ] - ); + DB::table('role_user')->insert(['role_id' => 11, 'user_id' => 1]); + DB::table('role_user')->insert(['role_id' => 21, 'user_id' => 2]); + DB::table('role_user')->insert(['role_id' => 31, 'user_id' => 3]); + DB::table('role_user')->insert(['role_id' => 41, 'user_id' => 4]); + DB::table('role_user')->insert(['role_id' => 51, 'user_id' => 5]); + DB::table('role_user')->insert(['role_id' => 61, 'user_id' => 6]); + DB::table('role_user')->insert(['role_id' => 71, 'user_id' => 7]); + DB::table('role_user')->insert(['role_id' => 81, 'user_id' => 8]); + DB::table('role_user')->insert(['role_id' => 91, 'user_id' => 10]); + DB::table('role_user')->insert(['role_id' => 101, 'user_id' => 12]); + DB::table('role_user')->insert(['role_id' => 111, 'user_id' => 12]); + DB::table('role_user')->insert(['role_id' => 121, 'user_id' => 12]); Tag::create(['id' => 12, 'deleted_at' => null]); Tag::create(['id' => 22, 'deleted_at' => null]); @@ -198,23 +227,19 @@ protected function seedDatabase(): void Tag::create(['id' => 112, 'deleted_at' => null]); Tag::create(['id' => 122, 'deleted_at' => Carbon::now()]); - DB::table('taggables')->insert( - [ - ['tag_id' => 12, 'taggable_type' => User::class, 'taggable_id' => 1], - ['tag_id' => 22, 'taggable_type' => User::class, 'taggable_id' => 2], - ['tag_id' => 32, 'taggable_type' => User::class, 'taggable_id' => 3], - ['tag_id' => 42, 'taggable_type' => User::class, 'taggable_id' => 4], - ['tag_id' => 52, 'taggable_type' => User::class, 'taggable_id' => 5], - ['tag_id' => 62, 'taggable_type' => User::class, 'taggable_id' => 6], - ['tag_id' => 72, 'taggable_type' => User::class, 'taggable_id' => 7], - ['tag_id' => 82, 'taggable_type' => User::class, 'taggable_id' => 8], - ['tag_id' => 92, 'taggable_type' => User::class, 'taggable_id' => 10], - ['tag_id' => 102, 'taggable_type' => User::class, 'taggable_id' => 12], - ['tag_id' => 112, 'taggable_type' => User::class, 'taggable_id' => 12], - ['tag_id' => 122, 'taggable_type' => User::class, 'taggable_id' => 12], - ['tag_id' => 12, 'taggable_type' => Post::class, 'taggable_id' => 5], - ] - ); + DB::table('taggables')->insert(['tag_id' => 12, 'taggable_type' => User::class, 'taggable_id' => 1]); + DB::table('taggables')->insert(['tag_id' => 22, 'taggable_type' => User::class, 'taggable_id' => 2]); + DB::table('taggables')->insert(['tag_id' => 32, 'taggable_type' => User::class, 'taggable_id' => 3]); + DB::table('taggables')->insert(['tag_id' => 42, 'taggable_type' => User::class, 'taggable_id' => 4]); + DB::table('taggables')->insert(['tag_id' => 52, 'taggable_type' => User::class, 'taggable_id' => 5]); + DB::table('taggables')->insert(['tag_id' => 62, 'taggable_type' => User::class, 'taggable_id' => 6]); + DB::table('taggables')->insert(['tag_id' => 72, 'taggable_type' => User::class, 'taggable_id' => 7]); + DB::table('taggables')->insert(['tag_id' => 82, 'taggable_type' => User::class, 'taggable_id' => 8]); + DB::table('taggables')->insert(['tag_id' => 92, 'taggable_type' => User::class, 'taggable_id' => 10]); + DB::table('taggables')->insert(['tag_id' => 102, 'taggable_type' => User::class, 'taggable_id' => 12]); + DB::table('taggables')->insert(['tag_id' => 112, 'taggable_type' => User::class, 'taggable_id' => 12]); + DB::table('taggables')->insert(['tag_id' => 122, 'taggable_type' => User::class, 'taggable_id' => 12]); + DB::table('taggables')->insert(['tag_id' => 12, 'taggable_type' => Post::class, 'taggable_id' => 5]); Video::create(['id' => 13, 'deleted_at' => null]); Video::create(['id' => 23, 'deleted_at' => null]); @@ -229,23 +254,19 @@ protected function seedDatabase(): void Video::create(['id' => 113, 'deleted_at' => null]); Video::create(['id' => 123, 'deleted_at' => Carbon::now()]); - DB::table('authorables')->insert( - [ - ['user_id' => 1, 'authorable_type' => Video::class, 'authorable_id' => 13], - ['user_id' => 2, 'authorable_type' => Video::class, 'authorable_id' => 23], - ['user_id' => 3, 'authorable_type' => Video::class, 'authorable_id' => 33], - ['user_id' => 4, 'authorable_type' => Video::class, 'authorable_id' => 43], - ['user_id' => 5, 'authorable_type' => Video::class, 'authorable_id' => 53], - ['user_id' => 6, 'authorable_type' => Video::class, 'authorable_id' => 63], - ['user_id' => 7, 'authorable_type' => Video::class, 'authorable_id' => 73], - ['user_id' => 8, 'authorable_type' => Video::class, 'authorable_id' => 83], - ['user_id' => 10, 'authorable_type' => Video::class, 'authorable_id' => 93], - ['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 103], - ['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 113], - ['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 123], - ['user_id' => 5, 'authorable_type' => Post::class, 'authorable_id' => 13], - ] - ); + DB::table('authorables')->insert(['user_id' => 1, 'authorable_type' => Video::class, 'authorable_id' => 13]); + DB::table('authorables')->insert(['user_id' => 2, 'authorable_type' => Video::class, 'authorable_id' => 23]); + DB::table('authorables')->insert(['user_id' => 3, 'authorable_type' => Video::class, 'authorable_id' => 33]); + DB::table('authorables')->insert(['user_id' => 4, 'authorable_type' => Video::class, 'authorable_id' => 43]); + DB::table('authorables')->insert(['user_id' => 5, 'authorable_type' => Video::class, 'authorable_id' => 53]); + DB::table('authorables')->insert(['user_id' => 6, 'authorable_type' => Video::class, 'authorable_id' => 63]); + DB::table('authorables')->insert(['user_id' => 7, 'authorable_type' => Video::class, 'authorable_id' => 73]); + DB::table('authorables')->insert(['user_id' => 8, 'authorable_type' => Video::class, 'authorable_id' => 83]); + DB::table('authorables')->insert(['user_id' => 10, 'authorable_type' => Video::class, 'authorable_id' => 93]); + DB::table('authorables')->insert(['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 103]); + DB::table('authorables')->insert(['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 113]); + DB::table('authorables')->insert(['user_id' => 12, 'authorable_type' => Video::class, 'authorable_id' => 123]); + DB::table('authorables')->insert(['user_id' => 5, 'authorable_type' => Post::class, 'authorable_id' => 13]); Category::create(['id' => 'a', 'parent_id' => null]); Category::create(['id' => 'd', 'parent_id' => 'a']); @@ -266,6 +287,6 @@ protected function getEnvironmentSetUp($app) protected function getPackageProviders($app) { - return [SingleStoreProvider::class]; + return [SingleStoreProvider::class, FirebirdServiceProvider::class]; } } diff --git a/tests/config/database.php b/tests/config/database.php index 015ff34..d826709 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -76,4 +76,14 @@ PDO::ATTR_EMULATE_PREPARES => true, ]) : [], ], + 'firebird' => [ + 'driver' => 'firebird', + 'host' => 'firebird', + 'port' => '3050', + 'database' => '/firebird/data/test.fdb', + 'username' => 'sysdba', + 'password' => 'password', + 'charset' => 'UTF8', + 'role' => null, + ], ];