From 26c7273493319652fab4891d4e030f3eac4128b8 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Wed, 29 Feb 2012 15:09:13 -0600 Subject: [PATCH 1/2] Add unsigned() modifier, so you can create unsigned integer columns --- laravel/database/schema/grammars/mysql.php | 17 ++++++++++++++++- laravel/database/schema/grammars/postgres.php | 17 ++++++++++++++++- laravel/database/schema/grammars/sqlite.php | 17 ++++++++++++++++- laravel/database/schema/grammars/sqlserver.php | 17 ++++++++++++++++- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index 48542de3..caa76c7e 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -77,7 +77,7 @@ class MySQL extends Grammar { // types to the correct types. $sql = $this->wrap($column).' '.$this->type($column); - $elements = array('nullable', 'defaults', 'incrementer'); + $elements = array('unsigned', 'nullable', 'defaults', 'incrementer'); foreach ($elements as $element) { @@ -90,6 +90,21 @@ class MySQL extends Grammar { return $columns; } + /** + * Get the SQL syntax for indicating if a column is unsigned. + * + * @param Table $table + * @param Fluent $column + * @return string + */ + protected function unsigned(Table $table, Fluent $column) + { + if ($column->type == 'integer' && $column->unsigned) + { + return ' UNSIGNED'; + } + } + /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/postgres.php b/laravel/database/schema/grammars/postgres.php index fc4096ac..797de6bb 100644 --- a/laravel/database/schema/grammars/postgres.php +++ b/laravel/database/schema/grammars/postgres.php @@ -65,7 +65,7 @@ class Postgres extends Grammar { // types to the types used by the database. $sql = $this->wrap($column).' '.$this->type($column); - $elements = array('incrementer', 'nullable', 'defaults'); + $elements = array('unsigned', 'incrementer', 'nullable', 'defaults'); foreach ($elements as $element) { @@ -78,6 +78,21 @@ class Postgres extends Grammar { return $columns; } + /** + * Get the SQL syntax for indicating if a column is unsigned. + * + * @param Table $table + * @param Fluent $column + * @return string + */ + protected function unsigned(Table $table, Fluent $column) + { + if ($column->type == 'integer' && $column->unsigned) + { + return ' UNSIGNED'; + } + } + /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/sqlite.php b/laravel/database/schema/grammars/sqlite.php index 30bd5bb0..e6e3d95b 100644 --- a/laravel/database/schema/grammars/sqlite.php +++ b/laravel/database/schema/grammars/sqlite.php @@ -91,7 +91,7 @@ class SQLite extends Grammar { // types to the types used by the database. $sql = $this->wrap($column).' '.$this->type($column); - $elements = array('nullable', 'defaults', 'incrementer'); + $elements = array('unsigned', 'nullable', 'defaults', 'incrementer'); foreach ($elements as $element) { @@ -104,6 +104,21 @@ class SQLite extends Grammar { return $columns; } + /** + * Get the SQL syntax for indicating if a column is unsigned. + * + * @param Table $table + * @param Fluent $column + * @return string + */ + protected function unsigned(Table $table, Fluent $column) + { + if ($column->type == 'integer' && $column->unsigned) + { + return ' UNSIGNED'; + } + } + /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/sqlserver.php b/laravel/database/schema/grammars/sqlserver.php index eb6eb785..7b8d9619 100644 --- a/laravel/database/schema/grammars/sqlserver.php +++ b/laravel/database/schema/grammars/sqlserver.php @@ -72,7 +72,7 @@ class SQLServer extends Grammar { // types to the types used by the database. $sql = $this->wrap($column).' '.$this->type($column); - $elements = array('incrementer', 'nullable', 'defaults'); + $elements = array('unsigned', 'incrementer', 'nullable', 'defaults'); foreach ($elements as $element) { @@ -85,6 +85,21 @@ class SQLServer extends Grammar { return $columns; } + /** + * Get the SQL syntax for indicating if a column is unsigned. + * + * @param Table $table + * @param Fluent $column + * @return string + */ + protected function unsigned(Table $table, Fluent $column) + { + if ($column->type == 'integer' && $column->unsigned) + { + return ' UNSIGNED'; + } + } + /** * Get the SQL syntax for indicating if a column is nullable. * From b7d068f2f2f586271c158de2bb3e00fbd9ad0030 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Wed, 29 Feb 2012 15:21:20 -0600 Subject: [PATCH 2/2] Move method into grammar.php instead of duplicating in each grammar --- laravel/database/schema/grammars/grammar.php | 15 +++++++++++++++ laravel/database/schema/grammars/mysql.php | 15 --------------- laravel/database/schema/grammars/postgres.php | 15 --------------- laravel/database/schema/grammars/sqlite.php | 15 --------------- laravel/database/schema/grammars/sqlserver.php | 15 --------------- 5 files changed, 15 insertions(+), 60 deletions(-) diff --git a/laravel/database/schema/grammars/grammar.php b/laravel/database/schema/grammars/grammar.php index ac5b20ea..8212e219 100644 --- a/laravel/database/schema/grammars/grammar.php +++ b/laravel/database/schema/grammars/grammar.php @@ -39,4 +39,19 @@ abstract class Grammar extends \Laravel\Database\Grammar { return parent::wrap($value); } + /** + * Get the SQL syntax for indicating if a column is unsigned. + * + * @param Table $table + * @param Fluent $column + * @return string + */ + protected function unsigned(Table $table, Fluent $column) + { + if ($column->type == 'integer' && $column->unsigned) + { + return ' UNSIGNED'; + } + } + } \ No newline at end of file diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index caa76c7e..595c1dd8 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -90,21 +90,6 @@ class MySQL extends Grammar { return $columns; } - /** - * Get the SQL syntax for indicating if a column is unsigned. - * - * @param Table $table - * @param Fluent $column - * @return string - */ - protected function unsigned(Table $table, Fluent $column) - { - if ($column->type == 'integer' && $column->unsigned) - { - return ' UNSIGNED'; - } - } - /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/postgres.php b/laravel/database/schema/grammars/postgres.php index 797de6bb..b974efc9 100644 --- a/laravel/database/schema/grammars/postgres.php +++ b/laravel/database/schema/grammars/postgres.php @@ -78,21 +78,6 @@ class Postgres extends Grammar { return $columns; } - /** - * Get the SQL syntax for indicating if a column is unsigned. - * - * @param Table $table - * @param Fluent $column - * @return string - */ - protected function unsigned(Table $table, Fluent $column) - { - if ($column->type == 'integer' && $column->unsigned) - { - return ' UNSIGNED'; - } - } - /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/sqlite.php b/laravel/database/schema/grammars/sqlite.php index e6e3d95b..9fcbce2a 100644 --- a/laravel/database/schema/grammars/sqlite.php +++ b/laravel/database/schema/grammars/sqlite.php @@ -104,21 +104,6 @@ class SQLite extends Grammar { return $columns; } - /** - * Get the SQL syntax for indicating if a column is unsigned. - * - * @param Table $table - * @param Fluent $column - * @return string - */ - protected function unsigned(Table $table, Fluent $column) - { - if ($column->type == 'integer' && $column->unsigned) - { - return ' UNSIGNED'; - } - } - /** * Get the SQL syntax for indicating if a column is nullable. * diff --git a/laravel/database/schema/grammars/sqlserver.php b/laravel/database/schema/grammars/sqlserver.php index 7b8d9619..6cf1bffb 100644 --- a/laravel/database/schema/grammars/sqlserver.php +++ b/laravel/database/schema/grammars/sqlserver.php @@ -85,21 +85,6 @@ class SQLServer extends Grammar { return $columns; } - /** - * Get the SQL syntax for indicating if a column is unsigned. - * - * @param Table $table - * @param Fluent $column - * @return string - */ - protected function unsigned(Table $table, Fluent $column) - { - if ($column->type == 'integer' && $column->unsigned) - { - return ' UNSIGNED'; - } - } - /** * Get the SQL syntax for indicating if a column is nullable. *