1 / 19

Ibiza, June 6 th 2011

Advanced Database Install Scripts. Ibiza, June 6 th 2011 . Presentation Summary. Advanced Database Install Scripts. What Are They and Why Are T hey Awesome ? Your First Magento Module I nstall S cript Upgrade Scripts Combining Upgrade and I nstall S cripts

roscoe
Download Presentation

Ibiza, June 6 th 2011

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Database Install Scripts Ibiza, June 6th 2011

  2. Presentation Summary Advanced Database Install Scripts What Are They and Why Are TheyAwesome? Your First Magento Module InstallScript UpgradeScripts Combining Upgrade and Install Scripts Utilizing The Installer Class What Magento Is Doing Behind The Scenes Tips & Tricks & Good Resources

  3. Advanced Database Install Scripts 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)

  4. Advanced Database Install Scripts 1. What Are They and Why Are TheyAwesome? • What are they? • runcode when the module first runs • runcode when the module updates • elegantlybuild the database architecture • Why are they awesome? • Couples database architecture with software architecture • Allows consistent migration when transporting Magento modules

  5. Advanced Database Install Scripts 2. Your First Magento Module Install Script • Make sure you module is ready to go, but has never run on this store. • Add config.xml entry: • Set your version number • … . . . <modules> <TBT_Producthistory> <version>1.0.0.0</version> </TBT_Producthistory> </modules> . . . • 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. Advanced Database Install Scripts 2. Your First Magento Module Install Script • Make sure you module is ready to go, but has never run on this store. • Add config.xml entry: • Set your version number • Set the resource setup class/connection • Define entities . . . <modules> <TBT_Producthistory> <version>1.0.0.0</version> </TBT_Producthistory> </modules> . . . . . . <global><models> <producthistory> <class>TBT_Producthistory_Model</class> <resourceModel>producthistory_mysql4</resourceModel> </producthistory> <producthistory_mysql4> <class>TBT_Producthistory_Model_Mysql4</class> <entities> <revision> <table>producthistory_revision</table> </revision> </entities> </producthistory_mysql4> </models>. . .

  7. Advanced Database Install Scripts 2. Your First Magento Module Install Script • Make sure you module is ready to go, but has never run on this store. • Add config.xml entry • 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

  8. Advanced Database Install Scripts 2. Your First Magento Module Install Script mysql4-install-1.0.0.0.php may look like this: $installer = $this; $installer->startSetup(); • $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->endSetup();

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

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

  11. Advanced Database Install Scripts 3. Upgrade scripts • 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 Time for (another) EPIC Demo…

  12. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts • Scripts are run in sequential order, starting with biggest install. • 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. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts • Scripts are run in sequential order, starting with biggest install. • Example A: 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 • mysql4-upgrade-1.1.0.0-1.3.0.0.php

  14. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts • Scripts are run in sequential order, starting with biggest install. • 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. Advanced Database Install Scripts 4. Combining Upgrade and Install Scripts • Scripts are run in sequential order, starting with biggest install. • 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 • mysql4-install-1.1.0.0.php • mysql4-upgrade-1.1.0.0-1.3.0.0.php

  16. Advanced Database Install Scripts 5. Utilizing the installer class • Instead of putting core setup functions in the sql files • Specify Install class in config.xml <resources> <!-- ... --> <producthistory_setup> <setup> <module>TBT_Producthistory</module> <class>TBT_Producthistory_Model_Resource_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </producthistory_setup> <!-- ... --> </resources> 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. Advanced Database Install Scripts 7. Tips & Tricks & Good Resources Subscribe to Alan Storm’s Blog @ http://alanstorm.com/magento_setup_resources Subscribe to our WDCA Blog @ www.wdca.ca/blog E-mail me at nelkaake@wdca.ca if you have any questions Download the 3-hour developed hack-a-thon extension here: http://www.wdca.ca/downloads/producthistory.zip

  19. Happy DB-installing with Magento!

More Related