Skip to content

Commit b4133cb

Browse files
committed
Fix truncating tables
1 parent 908ff64 commit b4133cb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Query/CockroachGrammar.php

+11
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,15 @@ public function whereFullText(Builder $query, $where)
7474
{
7575
throw new FeatureNotSupportedException('Fulltext indexes are not supported by CockroachDB as of version 2.5');
7676
}
77+
78+
/**
79+
* Compile a truncate table statement into SQL.
80+
*
81+
* @param \Illuminate\Database\Query\Builder $query
82+
* @return array
83+
*/
84+
public function compileTruncate(Builder $query)
85+
{
86+
return ['truncate ' . $this->wrapTable($query->from) . ' cascade' => []];
87+
}
7788
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace YlsIdeas\CockroachDb\Tests\Integration\Database;
4+
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
class TruncateTableTest extends DatabaseTestCase
10+
{
11+
protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
12+
{
13+
Schema::create('test_truncating_table', function (Blueprint $table) {
14+
$table->increments('id');
15+
$table->string('name');
16+
});
17+
}
18+
19+
public function testTruncatingTables()
20+
{
21+
DB::table('test_truncating_table')->insert([['name' => 'test']]);
22+
23+
DB::table('test_truncating_table')->truncate();
24+
25+
$this->assertDatabaseMissing('test_truncating_table', ['name' => 'test']);
26+
}
27+
}

0 commit comments

Comments
 (0)