Skip to content

Commit

Permalink
Merge pull request #855 from yajra/schema-patch
Browse files Browse the repository at this point in the history
fix: schema due to removal of dbal
  • Loading branch information
yajra authored May 22, 2024
2 parents 21e81d1 + 3cfeb57 commit d83082c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 34 deletions.
13 changes: 0 additions & 13 deletions src/Oci8/Oci8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Yajra\Oci8;

use Doctrine\DBAL\Driver\OCI8\Driver as DoctrineDriver;
use Doctrine\DBAL\Version;
use Illuminate\Database\Connection;
use Illuminate\Database\Grammar;
use Illuminate\Support\Str;
use PDO;
use PDOStatement;
use Throwable;
use Yajra\Oci8\PDO\Oci8Driver;
use Yajra\Oci8\Query\Grammars\OracleGrammar as QueryGrammar;
use Yajra\Oci8\Query\OracleBuilder as QueryBuilder;
use Yajra\Oci8\Query\Processors\OracleProcessor as Processor;
Expand Down Expand Up @@ -187,16 +184,6 @@ public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS')
return $this->setSessionVars($sessionVars);
}

/**
* Get doctrine driver.
*
* @return \Doctrine\DBAL\Driver\OCI8\Driver|\Yajra\Oci8\PDO\Oci8Driver
*/
protected function getDoctrineDriver()
{
return class_exists(Version::class) ? new DoctrineDriver : new Oci8Driver();
}

/**
* Execute a PL/SQL Function and return its value.
* Usage: DB::executeFunction('function_name', ['binding_1' => 'hi', 'binding_n' =>
Expand Down
19 changes: 0 additions & 19 deletions src/Oci8/PDO/Oci8Driver.php

This file was deleted.

55 changes: 53 additions & 2 deletions src/Oci8/Schema/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne
$table = $this->wrapTable($blueprint);

$rs = [];
$rs[0] = 'alter table '.$table.' rename column '.$command->from.' to '.$command->to;
$rs[0] = 'alter table '.$table.' rename column '.$this->wrap($command->from).' to '.$this->wrap($command->to);

return (array) $rs;
return $rs;
}

/**
Expand Down Expand Up @@ -905,4 +905,55 @@ protected function wrapValue($value)

return parent::wrapValue($value);
}

/**
* Compile a change column command into a series of SQL statements.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @return array|string
*
* @throws \RuntimeException
*/
public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection)
{
$columns = [];

foreach ($blueprint->getChangedColumns() as $column) {
$changes = [$this->getType($column).$this->modifyCollate($blueprint, $column)];

foreach ($this->modifiers as $modifier) {
if ($modifier === 'Collate') {
continue;
}

if (method_exists($this, $method = "modify{$modifier}")) {
$constraints = (array) $this->{$method}($blueprint, $column);

foreach ($constraints as $constraint) {
$changes[] = $constraint;
}
}
}

$columns[] = 'modify '.$this->wrap($column).' '.implode(' ', array_filter(array_map('trim', $changes)));
}

return 'alter table '.$this->wrapTable($blueprint).' '.implode(' ', $columns);
}

/**
* Get the SQL for a collation column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->collation)) {
return ' collate '.$this->wrapValue($column->collation);
}
}
}
68 changes: 68 additions & 0 deletions tests/Database/Oci8SchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,74 @@ public function testBasicAlterTable()
$statements[0]);
}

public function testAlterTableRenameColumn()
{
$blueprint = new Blueprint('users');
$blueprint->renameColumn('email', 'email_address');

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" rename column "EMAIL" to "EMAIL_ADDRESS"', $statements[0]);
}

public function testAlterTableRenameMultipleColumns()
{
$blueprint = new Blueprint('users');
$blueprint->renameColumn('email', 'email_address');
$blueprint->renameColumn('address', 'address_1');

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(2, $statements);
$this->assertEquals('alter table "USERS" rename column "EMAIL" to "EMAIL_ADDRESS"', $statements[0]);
$this->assertEquals('alter table "USERS" rename column "ADDRESS" to "ADDRESS_1"', $statements[1]);
}

public function testAlterTableModifyColumn()
{
$blueprint = new Blueprint('users');
$blueprint->string('email')->change();

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" modify "EMAIL" varchar2(255) not null', $statements[0]);
}

public function testAlterTableModifyColumnWithCollate()
{
$blueprint = new Blueprint('users');
$blueprint->string('email')->change()->collation('latin1_swedish_ci');

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" modify "EMAIL" varchar2(255) collate "LATIN1_SWEDISH_CI" not null', $statements[0]);
}

public function testAlterTableModifyMultipleColumns()
{
$blueprint = new Blueprint('users');
$blueprint->string('email')->change();
$blueprint->string('name')->change();

$conn = $this->getConnection();

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" modify "EMAIL" varchar2(255) not null modify "NAME" varchar2(255) not null', $statements[0]);
}

public function testBasicAlterTableWithPrimary()
{
$blueprint = new Blueprint('users');
Expand Down

0 comments on commit d83082c

Please sign in to comment.