51 lines
2.7 KiB
PHP
51 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class CreateEventBookingsTable extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
$table = $this->table('event_bookings', [
|
|
'id' => false,
|
|
'primary_key' => ['id'],
|
|
'engine' => 'InnoDB',
|
|
'encoding' => 'utf8mb4',
|
|
'collation' => 'utf8mb4_unicode_ci',
|
|
]);
|
|
|
|
$table
|
|
->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])
|
|
->addColumn('event_id', 'biginteger', ['signed' => false, 'null' => false])
|
|
->addColumn('user_id', 'integer', ['signed' => false, 'null' => true, 'comment' => 'null = ospite non registrato'])
|
|
->addColumn('name', 'string', ['limit' => 191, 'null' => false])
|
|
->addColumn('email', 'string', ['limit' => 191, 'null' => false, 'comment' => 'raccolta contatti'])
|
|
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
|
->addColumn('seats', 'integer', ['signed' => false, 'null' => false, 'default' => 1])
|
|
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'pending', 'comment' => 'pending|confirmed|cancelled'])
|
|
->addColumn('amount', 'decimal', ['precision' => 8, 'scale' => 2, 'null' => true, 'comment' => 'pronto per pagamenti'])
|
|
->addColumn('token', 'string', ['limit' => 64, 'null' => false, 'comment' => 'gestione/annullo ospite via link email'])
|
|
->addColumn('consent_at', 'datetime', ['null' => true, 'comment' => 'accettazione privacy/termini'])
|
|
->addColumn('marketing_opt_in', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'comment' => 'consenso marketing Y/N'])
|
|
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => null])
|
|
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null])
|
|
->addIndex(['token'], ['unique' => true, 'name' => 'event_bookings_token_unique'])
|
|
->addIndex(['event_id'], ['name' => 'event_bookings_event_id_index'])
|
|
->addIndex(['email'], ['name' => 'event_bookings_email_index'])
|
|
->addIndex(['user_id'], ['name' => 'event_bookings_user_id_index'])
|
|
->addForeignKey('event_id', 'events', 'id', [
|
|
'delete' => 'CASCADE',
|
|
'update' => 'NO_ACTION',
|
|
'constraint' => 'event_bookings_event_id_foreign',
|
|
])
|
|
->addForeignKey('user_id', 'auth_users', 'id', [
|
|
'delete' => 'SET_NULL',
|
|
'update' => 'NO_ACTION',
|
|
'constraint' => 'event_bookings_user_id_foreign',
|
|
])
|
|
->create();
|
|
}
|
|
}
|