I know that with migration
I can create the tables, but have some way to automate even the creation of the bank with migration
to follow as base I use Laravel 5.2
I know that with migration
I can create the tables, but have some way to automate even the creation of the bank with migration
to follow as base I use Laravel 5.2
According to documentation the migrations
does not create the database:
Migrations
is like version control for your database, allowing a team to easily modify and share the schema
of the application.
Laravel
Schema
facade
provides agnostic support for creating and manipulating tables. It shares the same template, API
fluente
in all database systems supported by Laravel
. doc
Something that can be done is to create a PHP
file to do this.
Example:
$pdo = $db->connect();
// ---------------------------------------------------------------------------------------
$query = "DROP DATABASE IF EXISTS '{$dbName}'";
$pdo->exec($query);
$query = "CREATE DATABASE '{$dbName}'";
$pdo->exec($query);
$query = "USE '{$dbName}'";
$pdo->exec($query);
// ---------------------------------------------------------------------------------------
$query = "
CREATE TABLE 'clientes' (
'id' INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
'nome' VARCHAR(255) NOT NULL,
'endereco' VARCHAR(255) NOT NULL,
'enderecoCobranca' VARCHAR(255) NULL,
'importancia' INT(1) UNSIGNED NOT NULL,
'tipoCliente' VARCHAR(10) NOT NULL,
'numId' VARCHAR(18) NOT NULL
)";
$pdo->exec($query);