Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace EureciaCatalogSetup;
- use MagentoFrameworkSetupInstallSchemaInterface;
- use MagentoFrameworkSetupModuleContextInterface;
- use MagentoFrameworkSetupSchemaSetupInterface;
- use MagentoFrameworkDBDdlTable;
- use MagentoFrameworkDBAdapterAdapterInterface;
- class InstallSchema implements InstallSchemaInterface
- {
- /**
- * {@inheritdoc}
- */
- public function install(
- SchemaSetupInterface $setup,
- ModuleContextInterface $context
- ) {
- $installer = $setup;
- $installer->startSetup();
- // Get eurecia_catalog table
- $tableName = $installer->getTable('eurecia_providers');
- // Check if the table already exists
- if ($installer->getConnection()->isTableExists($tableName) != true) {
- // Create eurecia_catalog table
- $table = $installer->getConnection()
- ->newTable($tableName)
- ->addColumn(
- 'id_provider',
- Table::TYPE_INTEGER,
- null,
- [
- 'identity' => true,
- 'unsigned' => true,
- 'nullable' => false,
- 'primary' => true
- ],
- 'ID Provider'
- )
- ->addColumn(
- 'name',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Name'
- )
- ->addColumn(
- 'subdomain',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Subdomain'
- )
- ->addColumn(
- 'summary',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Summary'
- )
- ->addColumn(
- 'address',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Address'
- )
- ->addColumn(
- 'maxdist',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Maxdist'
- )
- ->addColumn(
- 'status',
- Table::TYPE_SMALLINT,
- null,
- ['nullable' => false, 'default' => '0'],
- 'Status'
- )
- ->setComment('Catalog Table')
- ->setOption('type', 'InnoDB')
- ->setOption('charset', 'utf8');
- $installer->getConnection()->createTable($table);
- }
- // Get eurecia_company table
- $tableName = $installer->getTable('eurecia_company');
- // Check if the table already exists
- if ($installer->getConnection()->isTableExists($tableName) != true) {
- // Create eurecia_company table
- $table = $installer->getConnection()
- ->newTable($tableName)
- ->addColumn(
- 'id_company',
- Table::TYPE_INTEGER,
- null,
- [
- 'identity' => true,
- 'unsigned' => true,
- 'nullable' => false,
- 'primary' => true
- ],
- 'ID Company'
- )
- ->addColumn(
- 'name',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Name'
- )
- ->addColumn(
- 'subdomain',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Subdomain'
- )
- ->addColumn(
- 'address',
- Table::TYPE_TEXT,
- null,
- ['nullable' => false, 'default' => ''],
- 'Address'
- )
- ->addColumn(
- 'status',
- Table::TYPE_SMALLINT,
- null,
- ['nullable' => false, 'default' => '0'],
- 'Status'
- )
- ->setComment('Catalog Table')
- ->setOption('type', 'InnoDB')
- ->setOption('charset', 'utf8');
- $installer->getConnection()->createTable($table);
- }
- if (!$installer->tableExists('eurecia_catalog_assoc')) {
- $table = $installer->getConnection()
- ->newTable($installer->getTable('eurecia_catalog_assoc'));
- $table->addColumn(
- 'id_company',
- Table::TYPE_INTEGER,
- null,
- [
- 'unsigned' => true,
- 'nullable' => false,
- 'primary' => true,
- ],
- 'company ID'
- )
- ->addColumn(
- 'id_provider',
- Table::TYPE_INTEGER,
- null,
- [
- 'unsigned' => true,
- 'nullable' => false,
- 'primary' => true,
- ],
- 'provider ID'
- )
- ->addColumn(
- 'position',
- Table::TYPE_INTEGER,
- null,
- [
- 'nullable' => false,
- 'default' => '0'
- ],
- 'Position'
- )
- ->addIndex(
- $installer->getIdxName('eurecia_catalog_assoc', ['id_company']),
- ['id_company']
- )
- ->addIndex(
- $installer->getIdxName('eurecia_catalog_assoc', ['id_provider']),
- ['id_provider']
- )
- ->addForeignKey(
- $installer->getFkName(
- 'eurecia_catalog_assoc',
- 'id_company',
- 'eurecia_company',
- 'id_company'
- ),
- 'id_company',
- $installer->getTable('eurecia_company'),
- 'id_company',
- Table::ACTION_CASCADE,
- Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $installer->getFkName(
- 'eurecia_catalog_assoc',
- 'id_provider',
- 'eurecia_providers',
- 'id_provider'
- ),
- 'id_provider',
- $installer->getTable('eurecia_providers'),
- 'id_provider',
- Table::ACTION_CASCADE,
- Table::ACTION_CASCADE
- )
- ->addIndex(
- $installer->getIdxName(
- 'eurecia_catalog_assoc',
- [
- 'id_company',
- 'id_provider'
- ],
- AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- [
- 'id_company',
- 'id_provider'
- ],
- [
- 'type' => AdapterInterface::INDEX_TYPE_UNIQUE
- ]
- )
- ->setComment('Company to provider Link Table');
- $installer->getConnection()->createTable($table);
- }
- $setup->endSetup();
- }
- }
- ->addColumn(
- 'id_company',
- Table::TYPE_INTEGER,
- 10,
- [
- 'identity' => true,
- 'unsigned' => true,
- 'nullable' => false,
- 'primary' => true
- ],
- 'ID Company'
- )
Add Comment
Please, Sign In to add comment