remove old files
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateCompanyBrandDepartmentTables extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
/*
|
||||
* Companies table
|
||||
* Main customer/company registry for TRFgo.
|
||||
*/
|
||||
$this->table('companies', ['id' => 'idcompany', 'signed' => false])
|
||||
->addColumn('company_name', 'string', ['limit' => 255])
|
||||
->addColumn('legal_name', 'string', ['limit' => 255, 'null' => true])
|
||||
->addColumn('vat_number', 'string', ['limit' => 50, 'null' => true])
|
||||
->addColumn('external_code', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('address', 'string', ['limit' => 255, 'null' => true])
|
||||
->addColumn('city', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('zip', 'string', ['limit' => 50, 'null' => true])
|
||||
->addColumn('country_id', 'integer', ['signed' => false, 'null' => true])
|
||||
->addColumn('email', 'string', ['limit' => 191, 'null' => true])
|
||||
->addColumn('phone', 'string', ['limit' => 50, 'null' => true])
|
||||
->addColumn('status', 'enum', [
|
||||
'values' => ['active', 'inactive', 'suspended'],
|
||||
'default' => 'active',
|
||||
])
|
||||
->addTimestamps()
|
||||
->addIndex(['company_name'])
|
||||
->addIndex(['external_code'])
|
||||
->addIndex(['status'])
|
||||
->addForeignKey(
|
||||
'country_id',
|
||||
'auth_countries',
|
||||
'id',
|
||||
[
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->create();
|
||||
|
||||
/*
|
||||
* Brands table
|
||||
* Brand/division registry linked to a company.
|
||||
*/
|
||||
$this->table('brands', ['id' => 'idbrand', 'signed' => false])
|
||||
->addColumn('idcompany', 'integer', ['signed' => false])
|
||||
->addColumn('brand_name', 'string', ['limit' => 255])
|
||||
->addColumn('external_brand_code', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('status', 'enum', [
|
||||
'values' => ['active', 'inactive'],
|
||||
'default' => 'active',
|
||||
])
|
||||
->addTimestamps()
|
||||
->addIndex(['idcompany'])
|
||||
->addIndex(['brand_name'])
|
||||
->addIndex(['external_brand_code'])
|
||||
->addIndex(['status'])
|
||||
->addForeignKey(
|
||||
'idcompany',
|
||||
'companies',
|
||||
'idcompany',
|
||||
[
|
||||
'delete' => 'CASCADE',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->create();
|
||||
|
||||
/*
|
||||
* Departments table
|
||||
* Department registry linked to a company and optionally to a brand.
|
||||
*/
|
||||
$this->table('departments', ['id' => 'iddepartment', 'signed' => false])
|
||||
->addColumn('idcompany', 'integer', ['signed' => false])
|
||||
->addColumn('idbrand', 'integer', ['signed' => false, 'null' => true])
|
||||
->addColumn('department_name', 'string', ['limit' => 255])
|
||||
->addColumn('external_department_code', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('status', 'enum', [
|
||||
'values' => ['active', 'inactive'],
|
||||
'default' => 'active',
|
||||
])
|
||||
->addTimestamps()
|
||||
->addIndex(['idcompany'])
|
||||
->addIndex(['idbrand'])
|
||||
->addIndex(['department_name'])
|
||||
->addIndex(['external_department_code'])
|
||||
->addIndex(['status'])
|
||||
->addForeignKey(
|
||||
'idcompany',
|
||||
'companies',
|
||||
'idcompany',
|
||||
[
|
||||
'delete' => 'CASCADE',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->addForeignKey(
|
||||
'idbrand',
|
||||
'brands',
|
||||
'idbrand',
|
||||
[
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->create();
|
||||
|
||||
/*
|
||||
* Company users table
|
||||
* Bridge between Vanguard users and TRFgo companies/brands/departments.
|
||||
* It does not replace auth_users; it only defines data visibility and operational role.
|
||||
*/
|
||||
$this->table('company_users', ['id' => 'idcompanyuser', 'signed' => false])
|
||||
->addColumn('iduser', 'integer', ['signed' => false])
|
||||
->addColumn('idcompany', 'integer', ['signed' => false])
|
||||
->addColumn('idbrand', 'integer', ['signed' => false, 'null' => true])
|
||||
->addColumn('iddepartment', 'integer', ['signed' => false, 'null' => true])
|
||||
->addColumn('user_scope', 'enum', [
|
||||
'values' => ['company', 'brand', 'department'],
|
||||
'default' => 'company',
|
||||
])
|
||||
->addColumn('company_role', 'enum', [
|
||||
'values' => [
|
||||
'owner',
|
||||
'admin',
|
||||
'manager',
|
||||
'operator',
|
||||
'viewer',
|
||||
'api_user',
|
||||
'lab_user',
|
||||
],
|
||||
'default' => 'viewer',
|
||||
])
|
||||
->addColumn('status', 'enum', [
|
||||
'values' => ['active', 'inactive'],
|
||||
'default' => 'active',
|
||||
])
|
||||
->addTimestamps()
|
||||
->addIndex(['iduser'])
|
||||
->addIndex(['idcompany'])
|
||||
->addIndex(['idbrand'])
|
||||
->addIndex(['iddepartment'])
|
||||
->addIndex(['user_scope'])
|
||||
->addIndex(['company_role'])
|
||||
->addIndex(['status'])
|
||||
->addIndex(
|
||||
['iduser', 'idcompany', 'idbrand', 'iddepartment'],
|
||||
['unique' => true, 'name' => 'uq_company_user_scope']
|
||||
)
|
||||
->addForeignKey(
|
||||
'iduser',
|
||||
'auth_users',
|
||||
'id',
|
||||
[
|
||||
'delete' => 'CASCADE',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->addForeignKey(
|
||||
'idcompany',
|
||||
'companies',
|
||||
'idcompany',
|
||||
[
|
||||
'delete' => 'CASCADE',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->addForeignKey(
|
||||
'idbrand',
|
||||
'brands',
|
||||
'idbrand',
|
||||
[
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->addForeignKey(
|
||||
'iddepartment',
|
||||
'departments',
|
||||
'iddepartment',
|
||||
[
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'CASCADE',
|
||||
]
|
||||
)
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user