/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php

https://github.com/rgranadino/magento-mirror · PHP · 322 lines · 254 code · 28 blank · 40 comment · 0 complexity · 4d21953fc38c606835715a5b68beedb8 MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_GoogleBase
  23. * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /* @var $installer Mage_Core_Model_Resource_Setup */
  27. $installer = $this;
  28. $installer->startSetup();
  29. /**
  30. * Drop foreign keys
  31. */
  32. $installer->getConnection()->dropForeignKey(
  33. $installer->getTable('googlebase/attributes'),
  34. 'FK_GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID'
  35. );
  36. $installer->getConnection()->dropForeignKey(
  37. $installer->getTable('googlebase/attributes'),
  38. 'GOOGLEBASE_ATTRIBUTES_TYPE_ID'
  39. );
  40. $installer->getConnection()->dropForeignKey(
  41. $installer->getTable('googlebase/items'),
  42. 'FK_GOOGLEBASE_ITEMS_PRODUCT_ID'
  43. );
  44. $installer->getConnection()->dropForeignKey(
  45. $installer->getTable('googlebase/items'),
  46. 'FK_GOOGLEBASE_ITEMS_STORE_ID'
  47. );
  48. $installer->getConnection()->dropForeignKey(
  49. $installer->getTable('googlebase/types'),
  50. 'FK_GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID'
  51. );
  52. /**
  53. * Drop indexes
  54. */
  55. $installer->getConnection()->dropIndex(
  56. $installer->getTable('googlebase/attributes'),
  57. 'GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID'
  58. );
  59. $installer->getConnection()->dropIndex(
  60. $installer->getTable('googlebase/attributes'),
  61. 'GOOGLEBASE_ATTRIBUTES_TYPE_ID'
  62. );
  63. $installer->getConnection()->dropIndex(
  64. $installer->getTable('googlebase/items'),
  65. 'GOOGLEBASE_ITEMS_PRODUCT_ID'
  66. );
  67. $installer->getConnection()->dropIndex(
  68. $installer->getTable('googlebase/items'),
  69. 'GOOGLEBASE_ITEMS_STORE_ID'
  70. );
  71. $installer->getConnection()->dropIndex(
  72. $installer->getTable('googlebase/types'),
  73. 'GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID'
  74. );
  75. /**
  76. * Change columns
  77. */
  78. $tables = array(
  79. $installer->getTable('googlebase/types') => array(
  80. 'columns' => array(
  81. 'type_id' => array(
  82. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  83. 'identity' => true,
  84. 'unsigned' => true,
  85. 'nullable' => false,
  86. 'primary' => true,
  87. 'comment' => 'Type id'
  88. ),
  89. 'attribute_set_id' => array(
  90. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  91. 'unsigned' => true,
  92. 'nullable' => false,
  93. 'comment' => 'Attribute set id'
  94. ),
  95. 'gbase_itemtype' => array(
  96. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  97. 'length' => 255,
  98. 'nullable' => false,
  99. 'comment' => 'Google base item type'
  100. ),
  101. 'target_country' => array(
  102. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  103. 'length' => 2,
  104. 'nullable' => false,
  105. 'default' => 'US',
  106. 'comment' => 'Target country'
  107. )
  108. ),
  109. 'comment' => 'Google Base Item Types link Attribute Sets'
  110. ),
  111. $installer->getTable('googlebase/items') => array(
  112. 'columns' => array(
  113. 'item_id' => array(
  114. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  115. 'identity' => true,
  116. 'unsigned' => true,
  117. 'nullable' => false,
  118. 'primary' => true,
  119. 'comment' => 'Item id'
  120. ),
  121. 'type_id' => array(
  122. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  123. 'unsigned' => true,
  124. 'nullable' => false,
  125. 'default' => '0',
  126. 'comment' => 'Type id'
  127. ),
  128. 'product_id' => array(
  129. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  130. 'unsigned' => true,
  131. 'nullable' => false,
  132. 'comment' => 'Product id'
  133. ),
  134. 'gbase_item_id' => array(
  135. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  136. 'length' => 255,
  137. 'nullable' => false,
  138. 'comment' => 'Google base item id'
  139. ),
  140. 'store_id' => array(
  141. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  142. 'unsigned' => true,
  143. 'nullable' => false,
  144. 'comment' => 'Store Id'
  145. ),
  146. 'published' => array(
  147. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  148. 'nullable' => false,
  149. 'comment' => 'Published'
  150. ),
  151. 'expires' => array(
  152. 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  153. 'nullable' => false,
  154. 'comment' => 'Expires'
  155. ),
  156. 'impr' => array(
  157. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  158. 'unsigned' => true,
  159. 'nullable' => false,
  160. 'default' => '0',
  161. 'comment' => 'Google impressions'
  162. ),
  163. 'clicks' => array(
  164. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  165. 'unsigned' => true,
  166. 'nullable' => false,
  167. 'default' => '0',
  168. 'comment' => 'Google clicks'
  169. ),
  170. 'views' => array(
  171. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  172. 'unsigned' => true,
  173. 'nullable' => false,
  174. 'default' => '0',
  175. 'comment' => 'Google views'
  176. ),
  177. 'is_hidden' => array(
  178. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  179. 'nullable' => false,
  180. 'default' => '0',
  181. 'comment' => 'Hidden flag'
  182. )
  183. ),
  184. 'comment' => 'Google Base Items Products'
  185. ),
  186. $installer->getTable('googlebase/attributes') => array(
  187. 'columns' => array(
  188. 'id' => array(
  189. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  190. 'identity' => true,
  191. 'unsigned' => true,
  192. 'nullable' => false,
  193. 'primary' => true,
  194. 'comment' => 'Id'
  195. ),
  196. 'attribute_id' => array(
  197. 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
  198. 'unsigned' => true,
  199. 'nullable' => false,
  200. 'comment' => 'Attribute id'
  201. ),
  202. 'gbase_attribute' => array(
  203. 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
  204. 'length' => 255,
  205. 'comment' => 'Google base attribute'
  206. ),
  207. 'type_id' => array(
  208. 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  209. 'unsigned' => true,
  210. 'nullable' => false,
  211. 'comment' => 'Type id'
  212. )
  213. ),
  214. 'comment' => 'Google Base Attributes link Product Attributes'
  215. )
  216. );
  217. $installer->getConnection()->modifyTables($tables);
  218. /**
  219. * Add indexes
  220. */
  221. $installer->getConnection()->addIndex(
  222. $installer->getTable('googlebase/attributes'),
  223. $installer->getIdxName('googlebase/attributes', array('attribute_id')),
  224. array('attribute_id')
  225. );
  226. $installer->getConnection()->addIndex(
  227. $installer->getTable('googlebase/attributes'),
  228. $installer->getIdxName('googlebase/attributes', array('type_id')),
  229. array('type_id')
  230. );
  231. $installer->getConnection()->addIndex(
  232. $installer->getTable('googlebase/items'),
  233. $installer->getIdxName('googlebase/items', array('product_id')),
  234. array('product_id')
  235. );
  236. $installer->getConnection()->addIndex(
  237. $installer->getTable('googlebase/items'),
  238. $installer->getIdxName('googlebase/items', array('store_id')),
  239. array('store_id')
  240. );
  241. $installer->getConnection()->addIndex(
  242. $installer->getTable('googlebase/types'),
  243. $installer->getIdxName('googlebase/types', array('attribute_set_id')),
  244. array('attribute_set_id')
  245. );
  246. /**
  247. * Add foreign keys
  248. */
  249. $installer->getConnection()->addForeignKey(
  250. $installer->getFkName('googlebase/attributes', 'attribute_id', 'eav/attribute', 'attribute_id'),
  251. $installer->getTable('googlebase/attributes'),
  252. 'attribute_id',
  253. $installer->getTable('eav/attribute'),
  254. 'attribute_id',
  255. Varien_Db_Ddl_Table::ACTION_CASCADE,
  256. Varien_Db_Ddl_Table::ACTION_NO_ACTION
  257. );
  258. $installer->getConnection()->addForeignKey(
  259. $installer->getFkName('googlebase/attributes', 'type_id', 'googlebase/types', 'type_id'),
  260. $installer->getTable('googlebase/attributes'),
  261. 'type_id',
  262. $installer->getTable('googlebase/types'),
  263. 'type_id',
  264. Varien_Db_Ddl_Table::ACTION_CASCADE,
  265. Varien_Db_Ddl_Table::ACTION_NO_ACTION
  266. );
  267. $installer->getConnection()->addForeignKey(
  268. $installer->getFkName('googlebase/items', 'product_id', 'catalog/product', 'entity_id'),
  269. $installer->getTable('googlebase/items'),
  270. 'product_id',
  271. $installer->getTable('catalog/product'),
  272. 'entity_id',
  273. Varien_Db_Ddl_Table::ACTION_CASCADE,
  274. Varien_Db_Ddl_Table::ACTION_NO_ACTION
  275. );
  276. $installer->getConnection()->addForeignKey(
  277. $installer->getFkName('googlebase/items', 'store_id', 'core/store', 'store_id'),
  278. $installer->getTable('googlebase/items'),
  279. 'store_id',
  280. $installer->getTable('core/store'),
  281. 'store_id',
  282. Varien_Db_Ddl_Table::ACTION_CASCADE,
  283. Varien_Db_Ddl_Table::ACTION_NO_ACTION
  284. );
  285. $installer->getConnection()->addForeignKey(
  286. $installer->getFkName('googlebase/types', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'),
  287. $installer->getTable('googlebase/types'),
  288. 'attribute_set_id',
  289. $installer->getTable('eav/attribute_set'),
  290. 'attribute_set_id',
  291. Varien_Db_Ddl_Table::ACTION_CASCADE,
  292. Varien_Db_Ddl_Table::ACTION_NO_ACTION
  293. );
  294. $installer->endSetup();