73 lines
4.2 KiB
PHP
73 lines
4.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Migrations\BaseMigration;
|
|
|
|
class CreateInitialSchema extends BaseMigration
|
|
{
|
|
/**
|
|
* Creates users, customers and cars tables.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function change(): void
|
|
{
|
|
$this->table('users')
|
|
->addColumn('email', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('password', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('first_name', 'string', ['limit' => 100, 'null' => false])
|
|
->addColumn('last_name', 'string', ['limit' => 100, 'null' => false])
|
|
->addColumn('role', 'string', ['limit' => 20, 'null' => false, 'default' => 'user'])
|
|
->addColumn('active', 'boolean', ['null' => false, 'default' => true])
|
|
->addColumn('last_login', 'datetime', ['null' => true, 'default' => null])
|
|
->addColumn('created', 'datetime', ['null' => false])
|
|
->addColumn('modified', 'datetime', ['null' => false])
|
|
->addIndex(['email'], ['unique' => true])
|
|
->create();
|
|
|
|
$this->table('customers')
|
|
->addColumn('type', 'string', ['limit' => 20, 'null' => false, 'default' => 'individual'])
|
|
->addColumn('first_name', 'string', ['limit' => 100, 'null' => false])
|
|
->addColumn('last_name', 'string', ['limit' => 100, 'null' => false])
|
|
->addColumn('email', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('phone', 'string', ['limit' => 30, 'null' => false])
|
|
->addColumn('company_name', 'string', ['limit' => 255, 'null' => true, 'default' => null])
|
|
->addColumn('tax_id', 'string', ['limit' => 20, 'null' => true, 'default' => null])
|
|
->addColumn('street', 'string', ['limit' => 255, 'null' => true, 'default' => null])
|
|
->addColumn('city', 'string', ['limit' => 100, 'null' => true, 'default' => null])
|
|
->addColumn('postal_code', 'string', ['limit' => 10, 'null' => true, 'default' => null])
|
|
->addColumn('country', 'string', ['limit' => 2, 'null' => false, 'default' => 'PL'])
|
|
->addColumn('birth_date', 'date', ['null' => true, 'default' => null])
|
|
->addColumn('notes', 'text', ['null' => true, 'default' => null])
|
|
->addColumn('created_by', 'integer', ['null' => true, 'default' => null])
|
|
->addColumn('created', 'datetime', ['null' => false])
|
|
->addColumn('modified', 'datetime', ['null' => false])
|
|
->addIndex(['email'], ['unique' => true])
|
|
->addIndex(['last_name'])
|
|
->addForeignKey('created_by', 'users', 'id', ['delete' => 'SET_NULL', 'update' => 'CASCADE'])
|
|
->create();
|
|
|
|
$this->table('cars')
|
|
->addColumn('customer_id', 'integer', ['null' => false])
|
|
->addColumn('make', 'string', ['limit' => 50, 'null' => false])
|
|
->addColumn('model', 'string', ['limit' => 50, 'null' => false])
|
|
->addColumn('production_year', 'integer', ['null' => false])
|
|
->addColumn('vin', 'string', ['limit' => 17, 'null' => false])
|
|
->addColumn('registration_number', 'string', ['limit' => 10, 'null' => false])
|
|
->addColumn('fuel_type', 'string', ['limit' => 20, 'null' => false])
|
|
->addColumn('color', 'string', ['limit' => 30, 'null' => true, 'default' => null])
|
|
->addColumn('engine_capacity', 'integer', ['null' => true, 'default' => null])
|
|
->addColumn('power_hp', 'integer', ['null' => true, 'default' => null])
|
|
->addColumn('transmission', 'string', ['limit' => 20, 'null' => true, 'default' => null])
|
|
->addColumn('mileage', 'integer', ['null' => true, 'default' => null])
|
|
->addColumn('notes', 'text', ['null' => true, 'default' => null])
|
|
->addColumn('created', 'datetime', ['null' => false])
|
|
->addColumn('modified', 'datetime', ['null' => false])
|
|
->addIndex(['vin'], ['unique' => true])
|
|
->addIndex(['registration_number'], ['unique' => true])
|
|
->addIndex(['customer_id'])
|
|
->addForeignKey('customer_id', 'customers', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
|
->create();
|
|
}
|
|
}
|