diff --git a/laravel/database/connectors/sqlite.php b/laravel/database/connectors/sqlite.php index 4516da28..8e7d70d2 100644 --- a/laravel/database/connectors/sqlite.php +++ b/laravel/database/connectors/sqlite.php @@ -14,8 +14,7 @@ class SQLite extends Connector { // SQLite provides supported for "in-memory" databases, which exist only for the // lifetime of the request. Any given in-memory database may only have one PDO - // connection open to it at a time. Generally, these databases are used for - // testing and development purposes, not in production scenarios. + // connection open to it at a time. These are usually for testing. if ($config['database'] == ':memory:') { return new PDO('sqlite::memory:', null, null, $options); diff --git a/laravel/database/grammar.php b/laravel/database/grammar.php index 04ef2c57..079a4452 100644 --- a/laravel/database/grammar.php +++ b/laravel/database/grammar.php @@ -63,8 +63,7 @@ abstract class Grammar { // If the value being wrapped contains a column alias, we need to // wrap it a little differently as each segment must be wrapped - // and not the entire string. We'll split the value on the "as" - // joiner to extract the column and the alias. + // and not the entire string. if (strpos(strtolower($value), ' as ') !== false) { $segments = explode(' ', $value); diff --git a/laravel/database/query.php b/laravel/database/query.php index 8aa7bb1f..8c0ef25d 100644 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -401,11 +401,11 @@ class Query { // will allow the developer to have a fresh query. $query = new Query($this->connection, $this->grammar, $this->from); - // Once the callback has been run on the query, we will store the - // nested query instance on the where clause array so that it's - // passed to the query grammar. call_user_func($callback, $query); + // Once the callback has been run on the query, we will store the + // nested query instance on the where clause array so that it's + // passed to the query's query grammar instance. $this->wheres[] = compact('type', 'query', 'connector'); $this->bindings = array_merge($this->bindings, $query->bindings); diff --git a/laravel/database/schema.php b/laravel/database/schema.php index ffd20fe1..38e188a4 100644 --- a/laravel/database/schema.php +++ b/laravel/database/schema.php @@ -16,7 +16,44 @@ class Schema { { call_user_func($callback, $table = new Schema\Table($table)); - static::implications($table); + return static::execute($table); + } + + /** + * Create a new database table schema. + * + * @param string $table + * @param Closure $callback + * @return void + */ + public static function create($table, $callback) + { + $table = new Schema\Table($table); + + // To indicate that the table is new and needs to be created, we'll run + // the "create" command on the table instance. This tells schema it is + // not simply a column modification operation. + $table->create(); + + call_user_func($callback, $table); + + return static::execute($table); + } + + /** + * Drop a database table from the schema. + * + * @param string $table + * @return void + */ + public static function drop($table) + { + $table = new Schema\Table($table); + + // To indicate that the table needs to be dropped, we will run the + // "drop" command on the table instance and pass the instance to + // the execute method as calling a Closure isn't needed. + $table->drop(); return static::execute($table); } @@ -29,22 +66,27 @@ class Schema { */ public static function execute($table) { + // The implications method is responsible for finding any fluently + // defined indexes on the schema table and adding the explicit + // commands that are needed to tbe schema instance. + static::implications($table); + foreach ($table->commands as $command) { $connection = DB::connection($table->connection); $grammar = static::grammar($connection); - // Each grammar has a function that corresponds to the command type and is for - // building that command's SQL. This lets the SQL generation stay granular - // and flexible across various database systems. + // Each grammar has a function that corresponds to the command type and + // is for building that command's SQL. This lets the SQL syntax builds + // stay granular across various database systems. if (method_exists($grammar, $method = $command->type)) { $statements = $grammar->$method($table, $command); - // Once we have the statements, we will cast them to an array even though - // not all of the commands return an array just in case the command - // needs multiple queries to complete its database work. + // Once we have the statements, we will cast them to an array even + // though not all of the commands return an array just in case it + // needs multiple queries to complete. foreach ((array) $statements as $statement) { $connection->statement($statement); diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index ece51d62..48542de3 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -28,9 +28,6 @@ class MySQL extends Grammar { // of the table as they're added in separate commands. $sql = 'CREATE TABLE '.$this->wrap($table).' ('.$columns.')'; - // MySQL supports various "engines" for database tables. If an engine was - // specified by the developer, we will set it after adding the columns - // the table creation statement the schema. if ( ! is_null($table->engine)) { $sql .= ' ENGINE = '.$table->engine;