Skip to content

Commit e5e99bc

Browse files
committed
Support for Laravel 9
1 parent 892baa2 commit e5e99bc

26 files changed

+1011
-137
lines changed

.github/workflows/run-tests.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ name: run-tests
22

33
on:
44
push:
5-
branches: [main]
65
pull_request:
7-
branches: [main]
6+
branches: [ main ]
87

98
jobs:
109
test:
1110
runs-on: ${{ matrix.os }}
1211

1312
strategy:
13+
fail-fast: false
1414
matrix:
15-
os: [ubuntu-latest]
16-
php: [8.0, 8.1]
17-
laravel: [8.*]
18-
stability: [prefer-stable, prefer-lowest]
15+
os: [ ubuntu-latest ]
16+
php: [ 8.0, 8.1 ]
17+
laravel: [ 9.*, 8.* ]
18+
stability: [ prefer-stable, prefer-lowest ]
1919
include:
20+
- laravel: 9.*
21+
testbench: ^7.0
2022
- laravel: 8.*
21-
testbench: ^6.23
23+
testbench: ^6.24
2224

2325
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2426

@@ -44,8 +46,8 @@ jobs:
4446
4547
- name: Install dependencies
4648
run: |
47-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
48-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
49+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
50+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
4951
5052
- name: Configure Database
5153
run: |

README.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/ylsideas/cockroachdb-laravel/Check%20&%20fix%20styling?label=code%20style)](https://github.com/ylsideas/cockroachdb-laravel/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/ylsideas/cockroachdb-laravel.svg?style=flat-square)](https://packagist.org/packages/ylsideas/cockroachdb-laravel)
77

8-
A driver/grammar for Laravel that works with CockroachDB. This is currently an alpha.
9-
All tests pass, but you may run into bugs potentially going forward.
8+
A driver/grammar for Laravel that works with CockroachDB. While CockroachDB is compatible with Postgresql, this support
9+
is not 1 to 1 meaning you may run into issues, this driver hopes to resolve those problems as much as possible.
10+
11+
Laravel 8 and 9 are both supported and tested against CockroachDB 2.5.
12+
13+
## Support
14+
15+
Peter Fox here, I just want to say this project has been my hardest yet. It's been a real labour of love to make and takes
16+
up a lot of time trying to organise the test suite so that compatibility is maintained between Eloquent and CockroachDB.
17+
18+
I see a lot of promise in using CockroachDB's serverless offering which is what compelled me to go down this route originally.
19+
You can read [an article](https://medium.com/@SlyFireFox/laravel-tip-cockroachdbs-serverless-database-322aa7f5f7ef)
20+
I made about using their service.
21+
22+
If you're using this project at all then do please consider [sponsoring me](https://github.com/sponsors/peterfox)
23+
as a way of encouraging more development.
1024

1125
## Installation
1226

@@ -40,9 +54,23 @@ To enable set `DB_CONNECTION=crdb` in your .env.
4054

4155
## Notes
4256

57+
CockroachDB should work inline with the feature set of Postgresql, with some exceptions. You can look at the
58+
features of each CockroachDB server in the CockroachDB [Docs](https://www.cockroachlabs.com/docs/stable/sql-feature-support.html#indexes).
59+
60+
### Deletes with Joins
4361
CockroachDB does not support performing deletes using joins. If you wish to
4462
do something like this you will need to use a sub-query instead.
4563

64+
At current if you try to call the `delete` method of the Query builder together with a `join` then
65+
a `YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException` exception will be thrown.
66+
67+
### Fulltext Search
68+
Eloquent and Postgresql support Fulltext search. CockroachDB does not support any full text
69+
search meaning the feature cannot be used when using this driver.
70+
71+
At current if you try to create a Fulltext index using the Schema builder or try to use the `whereFulltext`
72+
method of the Query builder a `YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException` exception will be thrown.
73+
4674
## Testing
4775

4876
The tests try to closely follow the same functionality of the grammar provided by Laravel

composer.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"require": {
1919
"php": "^8.0",
2020
"spatie/laravel-package-tools": "^1.9.2",
21-
"illuminate/contracts": "8.*"
21+
"illuminate/contracts": "9.*|8.*"
2222
},
2323
"require-dev": {
2424
"doctrine/dbal": "^3.2",
25-
"nunomaduro/collision": "^5.10",
25+
"nunomaduro/collision": "^6.0|^5.10",
2626
"nunomaduro/larastan": "^1.0",
27-
"orchestra/testbench": "^6.22",
27+
"orchestra/testbench": "^7.0|^6.24",
2828
"pestphp/pest": "^1.21",
2929
"pestphp/pest-plugin-laravel": "^1.1",
3030
"phpstan/extension-installer": "^1.1",
@@ -35,8 +35,7 @@
3535
},
3636
"autoload": {
3737
"psr-4": {
38-
"YlsIdeas\\CockroachDb\\": "src",
39-
"YlsIdeas\\CockroachDb\\Database\\Factories\\": "database/factories"
38+
"YlsIdeas\\CockroachDb\\": "src"
4039
}
4140
},
4241
"autoload-dev": {
@@ -50,7 +49,11 @@
5049
"test-coverage": "vendor/bin/pest coverage"
5150
},
5251
"config": {
53-
"sort-packages": true
52+
"sort-packages": true,
53+
"allow-plugins": {
54+
"phpstan/extension-installer": true,
55+
"pestphp/pest-plugin": true
56+
}
5457
},
5558
"extra": {
5659
"laravel": {

database.php

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
CREATE DATABASE IF NOT EXISTS forge;
2121
CREATE USER IF NOT EXISTS forge;
2222
GRANT ALL ON DATABASE forge TO forge;
23+
24+
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = true;
25+
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
26+
SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
27+
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
28+
SET CLUSTER SETTING jobs.retention_time = '15s';
29+
SET CLUSTER SETTING schemachanger.backfiller.buffer_increment = '128 KiB';
30+
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
31+
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
32+
ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 5;
33+
ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 5;
2334
heredoc);
2435
} catch (PDOException $exception) {
2536
exit('Failed to creating database: ' . $exception->getMessage() . PHP_EOL);

database/factories/ModelFactory.php

-19
This file was deleted.

database/migrations/create_cockroachdb-laravel_table.php.stub

-19
This file was deleted.

docker-compose.yml

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
version: '3'
22
services:
33
crdb:
4-
image: cockroachdb/cockroach:v21.2.2
4+
image: cockroachdb/cockroach:v21.2.5
55
ports:
66
- "26257:26257"
77
- "8080:8080"
8-
command: start-single-node --cluster-name=example-single-node --logtostderr=WARNING --log-file-verbosity=WARNING --insecure
9-
volumes:
10-
- crdb-volume:/cockroach/cockroach-data
8+
command: start-single-node --insecure --store=type=mem,size=0.9 --advertise-addr=localhost
9+
# volumes:
10+
# - crdb-volume:/cockroach/cockroach-data
11+
deploy:
12+
resources:
13+
limits:
14+
cpus: '2'
15+
memory: 2G
16+
reservations:
17+
cpus: '0.25'
18+
memory: 500M
1119

12-
volumes:
13-
crdb-volume:
20+
#volumes:
21+
# crdb-volume:

phpstan.neon.dist

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ parameters:
55
level: 4
66
paths:
77
- src
8-
- config
9-
- database
108
tmpDir: build/phpstan
119
checkOctaneCompatibility: true
1210
checkModelProperties: true

resources/views/.gitkeep

Whitespace-only changes.

src/Commands/CockroachDbCommand.php

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace YlsIdeas\CockroachDb\Exceptions;
4+
5+
class FeatureNotSupportedException extends \LogicException
6+
{
7+
}

src/Query/CockroachGrammar.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Query\Builder;
66
use Illuminate\Database\Query\Grammars\Grammar;
77
use Illuminate\Database\Query\Grammars\PostgresGrammar;
8+
use YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException;
89

910
class CockroachGrammar extends PostgresGrammar
1011
{
@@ -46,7 +47,7 @@ public function compileDelete(Builder $query)
4647
$where = $this->compileWheres($query);
4748

4849
if (! empty($query->joins)) {
49-
throw new \LogicException(
50+
throw new FeatureNotSupportedException(
5051
'Joins for deletions are not supported by CockroachDB, consider using a where in sub-query instead.'
5152
);
5253
}
@@ -61,4 +62,16 @@ public function compileDelete(Builder $query)
6162

6263
return trim($statement);
6364
}
65+
66+
/**
67+
* Compile a "where fulltext" clause.
68+
*
69+
* @param \Illuminate\Database\Query\Builder $query
70+
* @param array $where
71+
* @return string
72+
*/
73+
public function whereFullText(Builder $query, $where)
74+
{
75+
throw new FeatureNotSupportedException('Fulltext indexes are not supported by CockroachDB as of version 2.5');
76+
}
6477
}

src/Schema/CockroachGrammar.php

+28
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,36 @@
22

33
namespace YlsIdeas\CockroachDb\Schema;
44

5+
use Illuminate\Database\Schema\Blueprint;
56
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
7+
use Illuminate\Support\Fluent;
8+
use YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException;
69

710
class CockroachGrammar extends PostgresGrammar
811
{
12+
/**
13+
* Compile a fulltext index key command.
14+
*
15+
* @param \Illuminate\Database\Schema\Blueprint $blueprint
16+
* @param \Illuminate\Support\Fluent $command
17+
* @return string
18+
*
19+
* @throws \RuntimeException
20+
*/
21+
public function compileFulltext(Blueprint $blueprint, Fluent $command)
22+
{
23+
throw new FeatureNotSupportedException('Fulltext indexes are not supported by CockroachDB as of version 2.5');
24+
}
25+
26+
/**
27+
* Compile a drop fulltext index command.
28+
*
29+
* @param \Illuminate\Database\Schema\Blueprint $blueprint
30+
* @param \Illuminate\Support\Fluent $command
31+
* @return string
32+
*/
33+
public function compileDropFullText(Blueprint $blueprint, Fluent $command)
34+
{
35+
return $this->compileDropIndex($blueprint, $command);
36+
}
937
}

0 commit comments

Comments
 (0)