Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Part 3: Setup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash Smith committed Aug 16, 2015
1 parent f8369dd commit 33061c1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions Setup/InstallSchema.php
@@ -0,0 +1,46 @@
<?php namespace Ashsmith\Blog\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;

class InstallSchema implements InstallSchemaInterface
{
/**
* Installs DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;

$installer->startSetup();

$table = $installer->getConnection()
->newTable($installer->getTable('ashsmith_blog_post'))
->addColumn(
'post_id',
Table::TYPE_SMALLINT,
null,
['identity' => true, 'nullable' => false, 'primary' => true],
'Post ID'
)
->addColumn('url_key', Table::TYPE_TEXT, 100, ['nullable' => true, 'default' => null])
->addColumn('title', Table::TYPE_TEXT, 255, ['nullable' => false], 'Blog Title')
->addColumn('content', Table::TYPE_TEXT, '2M', [], 'Blog Content')
->addColumn('is_active', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '1'], 'Is Post Active?')
->addColumn('creation_time', Table::TYPE_DATETIME, null, ['nullable' => false], 'Creation Time')
->addColumn('update_time', Table::TYPE_DATETIME, null, ['nullable' => false], 'Update Time')
->addIndex($installer->getIdxName('blog_post', ['url_key']), ['url_key'])
->setComment('Ash Smith Blog Posts');

$installer->getConnection()->createTable($table);

$installer->endSetup();
}

}
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "ashsmith/magento2-blog-module-example",
"description": "A simple blog module.",
"type": "magento2-module",
"version": "0.2.0-stable",
"version": "0.3.0-stable",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down

0 comments on commit 33061c1

Please sign in to comment.