From 7d4a346f84536f0a7cbb70a38660fbc439a74070 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Mon, 2 Apr 2012 11:30:53 -0500 Subject: [PATCH] Adding Schema::rename('oldtable','newtable') support Signed-off-by: Colin Viebrock --- laravel/database/schema/grammars/mysql.php | 12 ++++++++++++ laravel/database/schema/grammars/postgres.php | 14 +++++++++++++- laravel/database/schema/grammars/sqlite.php | 12 ++++++++++++ laravel/database/schema/grammars/sqlserver.php | 14 +++++++++++++- laravel/database/schema/table.php | 11 +++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index c2ae7455..bcc8e94a 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -212,6 +212,18 @@ class MySQL extends Grammar { 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. * diff --git a/laravel/database/schema/grammars/postgres.php b/laravel/database/schema/grammars/postgres.php index 760af1a8..3c1b62e2 100644 --- a/laravel/database/schema/grammars/postgres.php +++ b/laravel/database/schema/grammars/postgres.php @@ -198,6 +198,18 @@ class Postgres extends Grammar { 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. * @@ -302,7 +314,7 @@ class Postgres extends Grammar { */ public function drop_foreign(Table $table, Fluent $command) { - return $this->drop_constraint($table, $command); + return $this->drop_constraint($table, $command); } /** diff --git a/laravel/database/schema/grammars/sqlite.php b/laravel/database/schema/grammars/sqlite.php index 09102f52..00c69604 100644 --- a/laravel/database/schema/grammars/sqlite.php +++ b/laravel/database/schema/grammars/sqlite.php @@ -201,6 +201,18 @@ class SQLite extends Grammar { 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. * diff --git a/laravel/database/schema/grammars/sqlserver.php b/laravel/database/schema/grammars/sqlserver.php index 0fb80f6a..513ed0f4 100644 --- a/laravel/database/schema/grammars/sqlserver.php +++ b/laravel/database/schema/grammars/sqlserver.php @@ -212,6 +212,18 @@ class SQLServer extends Grammar { 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. * @@ -320,7 +332,7 @@ class SQLServer extends Grammar { */ public function drop_foreign(Table $table, Fluent $command) { - return $this->drop_constraint($table, $command); + return $this->drop_constraint($table, $command); } /** diff --git a/laravel/database/schema/table.php b/laravel/database/schema/table.php index 9518d6e7..f9561f07 100644 --- a/laravel/database/schema/table.php +++ b/laravel/database/schema/table.php @@ -142,6 +142,17 @@ class Table { 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. *