Skip to content

Commit abcacab

Browse files
committed
fix bug with prefix on migration table.
1 parent 89e2a44 commit abcacab

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/Illuminate/Database/Connection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ public function setDatabaseName($database)
641641
$this->database = $database;
642642
}
643643

644+
/**
645+
* Get the table prefix for the connection.
646+
*
647+
* @return string
648+
*/
649+
public function getTablePrefix()
650+
{
651+
return $this->tablePrefix;
652+
}
653+
644654
/**
645655
* Set the table prefix and return the grammar.
646656
*

src/Illuminate/Database/Schema/Builder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function hasTable($table)
4242
{
4343
$sql = $this->grammar->compileTableExists();
4444

45+
$table = $this->connection->getTablePrefix().$table;
46+
4547
return count($this->connection->select($sql, array($table))) > 0;
4648
}
4749

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Mockery as m;
4+
use Illuminate\Database\Schema\Builder;
5+
6+
class DatabaseSchemaBuilderTest extends PHPUnit_Framework_TestCase {
7+
8+
public function tearDown()
9+
{
10+
m::close();
11+
}
12+
13+
14+
public function testHasTableCorrectlyCallsGrammar()
15+
{
16+
$connection = m::mock('Illuminate\Database\Connection');
17+
$grammar = m::mock('StdClass');
18+
$connection->shouldReceive('getSchemaGrammar')->andReturn($grammar);
19+
$builder = new Builder($connection);
20+
$grammar->shouldReceive('compileTableExists')->once()->andReturn('sql');
21+
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
22+
$connection->shouldReceive('select')->once()->with('sql', array('prefix_table'))->andReturn(array('prefix_table'));
23+
24+
$this->assertTrue($builder->hasTable('table'));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)