Adding Schema::rename('oldtable','newtable') support

Signed-off-by: Colin Viebrock <colin@viebrock.ca>
This commit is contained in:
Colin Viebrock 2012-04-02 11:30:53 -05:00
parent 2a49787e46
commit 7d4a346f84
5 changed files with 61 additions and 2 deletions

View File

@ -212,6 +212,18 @@ protected function key(Table $table, Fluent $command, $type)
return 'ALTER TABLE '.$this->wrap($table)." ADD {$type} {$name}({$keys})"; return 'ALTER TABLE '.$this->wrap($table)." ADD {$type} {$name}({$keys})";
} }
/**
* Generate the SQL statement for a rename table command.
*
* @param Table $table
* @param Fluent $command
* @return string
*/
public function rename(Table $table, Fluent $command)
{
return 'RENAME TABLE '.$this->wrap($table).' TO '.$this->wrap($command->name);
}
/** /**
* Generate the SQL statement for a drop table command. * Generate the SQL statement for a drop table command.
* *

View File

@ -198,6 +198,18 @@ protected function key(Table $table, Fluent $command, $unique = false)
return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})"; return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})";
} }
/**
* Generate the SQL statement for a rename table command.
*
* @param Table $table
* @param Fluent $command
* @return string
*/
public function rename(Table $table, Fluent $command)
{
return 'ALTER TABLE '.$this->wrap($table).' RENAME TO '.$this->wrap($command->name);
}
/** /**
* Generate the SQL statement for a drop table command. * Generate the SQL statement for a drop table command.
* *

View File

@ -201,6 +201,18 @@ protected function key(Table $table, Fluent $command, $unique = false)
return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})"; return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})";
} }
/**
* Generate the SQL statement for a rename table command.
*
* @param Table $table
* @param Fluent $command
* @return string
*/
public function rename(Table $table, Fluent $command)
{
return 'ALTER TABLE '.$this->wrap($table).' RENAME TO '.$this->wrap($command->name);
}
/** /**
* Generate the SQL statement for a drop table command. * Generate the SQL statement for a drop table command.
* *

View File

@ -212,6 +212,18 @@ protected function key(Table $table, Fluent $command, $unique = false)
return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})"; return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})";
} }
/**
* Generate the SQL statement for a rename table command.
*
* @param Table $table
* @param Fluent $command
* @return string
*/
public function rename(Table $table, Fluent $command)
{
return 'ALTER TABLE '.$this->wrap($table).' RENAME TO '.$this->wrap($command->name);
}
/** /**
* Generate the SQL statement for a drop table command. * Generate the SQL statement for a drop table command.
* *

View File

@ -142,6 +142,17 @@ public function key($type, $columns, $name)
return $this->command($type, compact('name', 'columns')); return $this->command($type, compact('name', 'columns'));
} }
/**
* Rename the database table.
*
* @param string $name
* @return Fluent
*/
public function rename($name)
{
return $this->command(__FUNCTION__, compact('name'));
}
/** /**
* Drop the database table. * Drop the database table.
* *