Files
comelifacciamo/db/migrations/20260902145605_create_billing_profiles.php
T
2026-09-09 08:26:26 +02:00

44 lines
2.1 KiB
PHP

<?php
use Phinx\Migration\AbstractMigration;
/**
* Tabella billing_profiles: dati fiscali per la fatturazione degli abbonamenti.
* Legata sia all'utente (chi paga) sia al salone (per cosa), così regge
* anche il caso futuro di un owner con più saloni e P.IVA diverse.
*/
class CreateBillingProfiles extends AbstractMigration
{
public function change(): void
{
$t = $this->table('billing_profiles', [
'id' => false,
'primary_key' => ['id'],
'engine' => 'InnoDB',
'encoding' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
]);
$t
->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])
->addColumn('user_id', 'integer', ['signed' => false])
->addColumn('shop_id', 'biginteger', ['signed' => false, 'null' => true])
->addColumn('business_name', 'string', ['limit' => 191])
->addColumn('vat_number', 'string', ['limit' => 20])
->addColumn('tax_code', 'string', ['limit' => 20, 'null' => true])
->addColumn('address', 'string', ['limit' => 255])
->addColumn('zip_code', 'string', ['limit' => 10])
->addColumn('city', 'string', ['limit' => 100])
->addColumn('province', 'string', ['limit' => 50, 'null' => true])
->addColumn('pec', 'string', ['limit' => 191, 'null' => true])
->addColumn('sdi_code', 'string', ['limit' => 7, 'null' => true])
->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'null' => true])
->addColumn('updated_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'null' => true])
->addIndex(['user_id'], ['name' => 'idx_bp_user'])
->addIndex(['shop_id'], ['name' => 'idx_bp_shop'])
->addForeignKey('user_id', 'auth_users', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION', 'constraint' => 'fk_bp_user'])
->addForeignKey('shop_id', 'shops', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION', 'constraint' => 'fk_bp_shop'])
->create();
}
}