Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function processIndexes($results)

return [
'name' => $name = strtolower($result->name),
'columns' => explode(',', $result->columns),
'columns' => $result->columns ? explode(',', $result->columns) : [],
'type' => strtolower($result->type),
'unique' => (bool) $result->unique,
'primary' => $name === 'primary',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function processIndexes($results)

return [
'name' => strtolower($result->name),
'columns' => explode(',', $result->columns),
'columns' => $result->columns ? explode(',', $result->columns) : [],
'type' => strtolower($result->type),
'unique' => (bool) $result->unique,
'primary' => (bool) $result->primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function processIndexes($results)

return [
'name' => strtolower($result->name),
'columns' => explode(',', $result->columns),
'columns' => $result->columns ? explode(',', $result->columns) : [],
'type' => null,
'unique' => (bool) $result->unique,
'primary' => $isPrimary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function processIndexes($results)

return [
'name' => strtolower($result->name),
'columns' => explode(',', $result->columns),
'columns' => $result->columns ? explode(',', $result->columns) : [],
'type' => strtolower($result->type),
'unique' => (bool) $result->unique,
'primary' => (bool) $result->primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\Attributes\RequiresDatabase;
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;

Expand All @@ -29,4 +30,18 @@ public function testAddCommentToTable()

Schema::drop('users');
}

#[RequiresDatabase('mysql', '>=8.0.13')]
public function testGetRawIndex()
{
Schema::create('table', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->rawIndex('(year(created_at))', 'table_raw_index');
});

$indexes = Schema::getIndexes('table');

$this->assertSame([], collect($indexes)->firstWhere('name', 'table_raw_index')['columns']);
}
}
23 changes: 15 additions & 8 deletions tests/Integration/Database/Postgres/PostgresSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ public function testDropAllViewsOnAllSchemas()
DB::statement('create view public.foo (id) as select 1');
DB::statement('create view private.foo (id) as select 1');

$this->assertTrue(Schema::hasView('public.foo'));
$this->assertTrue(Schema::hasView('private.foo'));

Schema::dropAllViews();

$this->assertFalse($this->hasView('public', 'foo'));
$this->assertFalse($this->hasView('private', 'foo'));
$this->assertFalse(Schema::hasView('public.foo'));
$this->assertFalse(Schema::hasView('private.foo'));
}

public function testAddTableCommentOnNewTable()
Expand Down Expand Up @@ -190,12 +193,16 @@ public function testDropPartitionedTables()
$this->assertNotContains('groups_2', $tables);
}

protected function hasView($schema, $table)
public function testGetRawIndex()
{
return DB::table('information_schema.views')
->where('table_catalog', $this->app['config']->get('database.connections.pgsql.database'))
->where('table_schema', $schema)
->where('table_name', $table)
->exists();
Schema::create('public.table', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->rawIndex("DATE_TRUNC('year'::text,created_at)", 'table_raw_index');
});

$indexes = Schema::getIndexes('public.table');

$this->assertSame([], collect($indexes)->firstWhere('name', 'table_raw_index')['columns']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ public function testGetViews()

$this->assertEmpty(Schema::getViews());
}

public function testGetRawIndex()
{
Schema::create('table', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->rawIndex('(strftime("%Y", created_at))', 'table_raw_index');
});

$indexes = Schema::getIndexes('table');

$this->assertSame([], collect($indexes)->firstWhere('name', 'table_raw_index')['columns']);
}
}