table('events', [ 'id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'encoding' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', ]); $table ->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false]) ->addColumn('user_id', 'integer', ['signed' => false, 'null' => true, 'comment' => 'insegnante/creatore -> auth_users.id']) ->addColumn('title', 'string', ['limit' => 191, 'null' => false]) ->addColumn('slug', 'string', ['limit' => 191, 'null' => false, 'comment' => 'URL pubblico / widget']) ->addColumn('description', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'comment' => 'HTML editor']) ->addColumn('organizer_name', 'string', ['limit' => 191, 'null' => true, 'comment' => 'nome libero; se null usa il creatore']) ->addColumn('starts_at', 'datetime', ['null' => false]) ->addColumn('ends_at', 'datetime', ['null' => true]) ->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'comment' => 'testo per Google Maps']) ->addColumn('lat', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true]) ->addColumn('lng', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true]) ->addColumn('cost', 'decimal', ['precision' => 8, 'scale' => 2, 'null' => false, 'default' => 0]) ->addColumn('currency', 'string', ['limit' => 3, 'null' => false, 'default' => 'EUR']) ->addColumn('max_seats', 'integer', ['signed' => false, 'null' => false, 'default' => 0]) ->addColumn('max_per_booking', 'integer', ['signed' => false, 'null' => false, 'default' => 1]) ->addColumn('color', 'string', ['limit' => 7, 'null' => false, 'default' => '#4CAF50', 'comment' => 'hex card']) ->addColumn('cover_image', 'string', ['limit' => 191, 'null' => true, 'comment' => 'gallery in futuro']) ->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'draft', 'comment' => 'draft|published|cancelled']) ->addColumn('created_at', 'timestamp', ['null' => true, 'default' => null]) ->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null]) ->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique']) ->addIndex(['status', 'starts_at'], ['name' => 'events_status_starts_at_index']) ->addIndex(['user_id'], ['name' => 'events_user_id_index']) ->addForeignKey('user_id', 'auth_users', 'id', [ 'delete' => 'SET_NULL', 'update' => 'NO_ACTION', 'constraint' => 'events_user_id_foreign', ]) ->create(); } }