Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ibiza, June 6 th 2011 Advanced Database Install Scripts.

Similar presentations


Presentation on theme: "Ibiza, June 6 th 2011 Advanced Database Install Scripts."— Presentation transcript:

1 Ibiza, June 6 th 2011 Advanced Database Install Scripts

2 Presentation Summary 1.What Are They and Why Are They Awesome? 2.Your First Magento Module Install Script 3.Upgrade Scripts 4.Combining Upgrade and Install Scripts 5.Utilizing The Installer Class 6.What Magento Is Doing Behind The Scenes 7.Tips & Tricks & Good Resources Advanced Database Install Scripts

3 My Background Jay El-Kaake, CANADA Worked with Magento in BETA stages Previous history at TELUS Inc, etc Developed Free Enhanced Admin Grid ext CEO of WDCA (WDCA.ca) Better Store Search (BetterStoreSearch.com) Sweet Tooth (SweetToothRewards.com) Advanced Database Install Scripts

4 1. What Are They and Why Are They Awesome? What are they? run code when the module first runs run code when the module updates elegantly build the database architecture Advanced Database Install Scripts Why are they awesome? Couples database architecture with software architecture Allows consistent migration when transporting Magento modules

5 1.Make sure you module is ready to go, but has never run on this store. 2.Add config.xml entry: 1.Set your version number 2.… Advanced Database Install Scripts 2. Your First Magento Module Install Script For this example we will use producthistory_setup and the TBT_Producthistory module at v Watch out: Magento only recognized version numbers >= 3 decimals!

6 1.Make sure you module is ready to go, but has never run on this store. 2.Add config.xml entry: 1.Set your version number 2.Set the resource setup class/connection 3.Define entities Advanced Database Install Scripts 2. Your First Magento Module Install Script TBT_Producthistory_Model producthistory_mysql4 TBT_Producthistory_Model_Mysql4 producthistory_revision...

7 1.Make sure you module is ready to go, but has never run on this store. 2.Add config.xml entry 3.In your module folder, add app/code/community/TBT/Producthistory/sql/producthistory_setup/mysql4- install php Runs if v1.0 is installed Advanced Database Install Scripts 2. Your First Magento Module Install Script

8 mysql4-install php may look like this: Advanced Database Install Scripts 2. Your First Magento Module Install Script $installer->run(" CREATE TABLE IF NOT EXISTS `{$this->getTable('producthistory_revision')}` ( `producthistory_revision_id` int(11) NOT NULL AUTO_INCREMENT, `store_id` int(11) DEFAULT NULL, `product_id` int(11) DEFAULT NULL, `revision_date` datetime DEFAULT NULL, `data_hash` text, PRIMARY KEY (`producthistory_revision_id`), UNIQUE KEY `producthistory_revision_id` (`producthistory_revision_id`) ) ENGINE=MyISAM DEFAULT CHARSET=UTF8; "); $installer = $this; $installer->startSetup(); $installer->endSetup();

9 1.Make sure you module is ready to go, but has never run on this store. 2.Add config.xml entry 3.In your module folder, add app/code/community/TBT/Producthistory/sql/producthistory_setup/mysql4- install php 4.Run the extension and see it go! Advanced Database Install Scripts 2. Your First Magento Module Install Script Time for an EPIC demo…

10 1.Make sure you module is ready to go, but has never run on this store. 2.Add config.xml entry 3.In your module folder, add app/code/community/TBT/Producthistory/sql/producthistory_setup/mysql4- install php 4.Run the extension and see it go! Advanced Database Install Scripts 2. Your First Magento Module Install Script Time for an EPIC demo…

11 Very similar, just use “upgrade” instead of install and set both versions Naming: mysql4-upgrade php This will run if module version is upgraded from v1 to v Advanced Database Install Scripts 3. Upgrade scripts Time for (another) EPIC Demo…

12 Scripts are run in sequential order, starting with biggest install. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts Example A: What order would these go in when installing v1.3? mysql4-install php mysql4-upgrade php mysql4-upgrade php

13 Scripts are run in sequential order, starting with biggest install. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts Example A: What order would these go in for installing v1.3? 1.mysql4-install php 2.mysql4-upgrade php 3.mysql4-upgrade php

14 Scripts are run in sequential order, starting with biggest install. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts Example B: What order would these go in for installing v1.3? mysql4-install php mysql4-install php mysql4-upgrade php mysql4-upgrade php

15 Scripts are run in sequential order, starting with biggest install. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts Example B: What order would these go in for installing v1.3? mysql4-install php mysql4-upgrade php 1.mysql4-install php 2.mysql4-upgrade php

16 Instead of putting core setup functions in the sql files 1.Specify Install class in config.xml Advanced Database Install Scripts 5. Utilizing the installer class TBT_Producthistory TBT_Producthistory_Model_Resource_Mysql4_Setup core_setup 2. Create class Example: app/…/Producthistory/Model/Resource/Mysql4/Setup.php

17 Advanced Database Install Scripts 6. What Magento Is Doing Behind The Scenes Magento core_resources table tracks versions installed mysql> select * from core_resource; | code | version | | adminnotification_setup | | | admin_setup | | | amazonpayments_setup | | | api_setup | | | backup_setup | | | bundle_setup | | | catalogindex_setup | | | cataloginventory_setup | | | catalogrule_setup | | …. | producthistory| | You can remove an entry to force DB scripts to re-run

18 Subscribe to Alan Storm’s Subscribe to our WDCA me at if you have any Download the 3-hour developed hack-a-thon extension here: Advanced Database Install Scripts 7. Tips & Tricks & Good Resources

19 Happy DB-installing with Magento!


Download ppt "Ibiza, June 6 th 2011 Advanced Database Install Scripts."

Similar presentations


Ads by Google