Creating an installation script (InstallSchema.php)

InstallSchema, or install script, is a way for us to set up tables in the database that will be used to persist our models later on.

If we look back at the module requirements, the following fields need to be created in the foggyline_helpdesk_ticket table:

  • ticket_id
  • customer_id
  • title
  • severity
  • created_at
  • status

Our InstallSchema is defined under the app/code/Foggyline/Helpdesk/Setup/InstallSchema.php file with (partial) content as follows:

<?php namespace Foggyline\Helpdesk\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; /** * @codeCoverageIgnore */ class InstallSchema implements InstallSchemaInterface ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.