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 nelkaake@wdca.ca 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... 1.0.0.0... For this example we will use producthistory_setup and the TBT_Producthistory module at v1.0.0.0 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... 1.0.0.0... 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-1.0.0.0.php Runs if v1.0 is installed Advanced Database Install Scripts 2. Your First Magento Module Install Script

8 mysql4-install-1.0.0.0.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-1.0.0.0.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-1.0.0.0.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-1.0.0.0-1.1.0.0.php This will run if module version is upgraded from v1 to v1.1.0.0 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-1.0.0.0.php mysql4-upgrade-1.0.0.0-1.1.0.0.php mysql4-upgrade-1.1.0.0-1.3.0.0.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-1.0.0.0.php 2.mysql4-upgrade-1.0.0.0-1.1.0.0.php 3.mysql4-upgrade-1.1.0.0-1.3.0.0.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-1.0.0.0.php mysql4-install-1.1.0.0.php mysql4-upgrade-1.0.0.0-1.1.0.0.php mysql4-upgrade-1.1.0.0-1.3.0.0.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-1.0.0.0.php mysql4-upgrade-1.0.0.0-1.1.0.0.php 1.mysql4-install-1.1.0.0.php 2.mysql4-upgrade-1.1.0.0-1.3.0.0.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 | 1.0.0 | | admin_setup | 0.7.1 | | amazonpayments_setup | 0.1.2 | | api_setup | 0.8.1 | | backup_setup | 0.7.0 | | bundle_setup | 0.1.7 | | catalogindex_setup | 0.7.10 | | cataloginventory_setup | 0.7.5 | | catalogrule_setup | 0.7.7 | …. | producthistory| 1.0.0.0 | You can remove an entry to force DB scripts to re-run

18 Subscribe to Alan Storm’s Blog @ http://alanstorm.com/magento_setup_resourceshttp://alanstorm.com/magento_setup_resources Subscribe to our WDCA Blog @ www.wdca.ca/blogwww.wdca.ca/blog E-mail me at nelkaake@wdca.ca if you have any questionsnelkaake@wdca.ca Download the 3-hour developed hack-a-thon extension here: http://www.wdca.ca/downloads/producthistory.zip 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