migrate_example_setup.install 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. /**
  3. * @file
  4. * Set up source data and destination configuration for the migration example
  5. * module. We do this in a separate module so migrate_example itself is a pure
  6. * migration module.
  7. */
  8. function migrate_example_setup_schema() {
  9. $schema['migrate_example_beer_account'] = migrate_example_beer_schema_account();
  10. $schema['migrate_example_beer_node'] = migrate_example_beer_schema_node();
  11. $schema['migrate_example_beer_comment'] = migrate_example_beer_schema_comment();
  12. $schema['migrate_example_beer_topic'] = migrate_example_beer_schema_topic();
  13. $schema['migrate_example_beer_topic_node'] = migrate_example_beer_schema_topic_node();
  14. return $schema;
  15. }
  16. function migrate_example_setup_install() {
  17. // Populate our tables.
  18. migrate_example_beer_data_account();
  19. migrate_example_beer_data_node();
  20. migrate_example_beer_data_comment();
  21. migrate_example_beer_data_topic();
  22. migrate_example_beer_data_topic_node();
  23. }
  24. function migrate_example_beer_schema_node() {
  25. return array(
  26. 'description' => 'Beers of the world.',
  27. 'fields' => array(
  28. 'bid' => array(
  29. 'type' => 'serial',
  30. 'not null' => TRUE,
  31. 'description' => 'Beer ID.',
  32. ),
  33. 'name' => array(
  34. 'type' => 'varchar',
  35. 'length' => 255,
  36. 'not null' => TRUE,
  37. ),
  38. 'body' => array(
  39. 'type' => 'varchar',
  40. 'length' => 255,
  41. 'not null' => FALSE,
  42. 'description' => 'Full description of the beer.',
  43. ),
  44. 'excerpt' => array(
  45. 'type' => 'varchar',
  46. 'length' => 255,
  47. 'not null' => FALSE,
  48. 'description' => 'Abstract for this beer.',
  49. ),
  50. 'countries' => array(
  51. 'type' => 'varchar',
  52. 'length' => 255,
  53. 'not null' => FALSE,
  54. 'description' => 'Countries of origin. Multiple values, delimited by pipe',
  55. ),
  56. 'aid' => array(
  57. 'type' => 'int',
  58. 'not null' => FALSE,
  59. 'description' => 'Account Id of the author.',
  60. ),
  61. 'image' => array(
  62. 'type' => 'varchar',
  63. 'length' => 255,
  64. 'not null' => FALSE,
  65. 'description' => 'Image path',
  66. ),
  67. 'image_alt' => array(
  68. 'type' => 'varchar',
  69. 'length' => 255,
  70. 'not null' => FALSE,
  71. 'description' => 'Image ALT',
  72. ),
  73. 'image_title' => array(
  74. 'type' => 'varchar',
  75. 'length' => 255,
  76. 'not null' => FALSE,
  77. 'description' => 'Image title',
  78. ),
  79. 'image_description' => array(
  80. 'type' => 'varchar',
  81. 'length' => 255,
  82. 'not null' => FALSE,
  83. 'description' => 'Image description',
  84. ),
  85. ),
  86. 'primary key' => array('bid'),
  87. );
  88. }
  89. function migrate_example_beer_schema_topic() {
  90. return array(
  91. 'description' => 'Categories',
  92. 'fields' => array(
  93. 'style' => array(
  94. 'type' => 'varchar_ascii',
  95. 'length' => 255,
  96. 'not null' => TRUE,
  97. ),
  98. 'details' => array(
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => FALSE,
  102. ),
  103. 'style_parent' => array(
  104. 'type' => 'varchar',
  105. 'length' => 255,
  106. 'not null' => FALSE,
  107. 'description' => 'Parent topic, if any',
  108. ),
  109. 'region' => array(
  110. 'type' => 'varchar',
  111. 'length' => 255,
  112. 'not null' => FALSE,
  113. 'description' => 'Region first associated with this style',
  114. ),
  115. 'hoppiness' => array(
  116. 'type' => 'varchar',
  117. 'length' => 255,
  118. 'not null' => FALSE,
  119. 'description' => 'Relative hoppiness of the beer',
  120. ),
  121. ),
  122. 'primary key' => array('style'),
  123. );
  124. }
  125. function migrate_example_beer_schema_topic_node() {
  126. return array(
  127. 'description' => 'Beers topic pairs.',
  128. 'fields' => array(
  129. 'bid' => array(
  130. 'type' => 'int',
  131. 'not null' => TRUE,
  132. 'description' => 'Beer ID.',
  133. ),
  134. 'style' => array(
  135. 'type' => 'varchar_ascii',
  136. 'length' => 255,
  137. 'not null' => TRUE,
  138. 'description' => 'Topic name',
  139. ),
  140. ),
  141. 'primary key' => array('style', 'bid'),
  142. );
  143. }
  144. function migrate_example_beer_schema_comment() {
  145. return array(
  146. 'description' => 'Beers comments.',
  147. 'fields' => array(
  148. 'cid' => array(
  149. 'type' => 'serial',
  150. 'not null' => TRUE,
  151. 'description' => 'Comment ID.',
  152. ),
  153. 'bid' => array(
  154. 'type' => 'int',
  155. 'not null' => TRUE,
  156. 'description' => 'Beer ID that is being commented upon',
  157. ),
  158. 'cid_parent' => array(
  159. 'type' => 'int',
  160. 'not null' => FALSE,
  161. 'description' => 'Parent comment ID in case of comment replies.',
  162. ),
  163. 'subject' => array(
  164. 'type' => 'varchar',
  165. 'length' => 255,
  166. 'not null' => FALSE,
  167. 'description' => 'Comment subject',
  168. ),
  169. 'body' => array(
  170. 'type' => 'varchar',
  171. 'length' => 255,
  172. 'not null' => FALSE,
  173. 'description' => 'Comment body',
  174. ),
  175. 'name' => array(
  176. 'type' => 'varchar',
  177. 'length' => 255,
  178. 'not null' => FALSE,
  179. 'description' => 'Comment name (if anon)',
  180. ),
  181. 'mail' => array(
  182. 'type' => 'varchar',
  183. 'length' => 255,
  184. 'not null' => FALSE,
  185. 'description' => 'Comment email (if anon)',
  186. ),
  187. 'aid' => array(
  188. 'type' => 'int',
  189. 'not null' => FALSE,
  190. 'description' => 'Account ID (if any).',
  191. ),
  192. ),
  193. 'primary key' => array('cid'),
  194. );
  195. }
  196. function migrate_example_beer_schema_account() {
  197. return array(
  198. 'description' => 'Beers accounts.',
  199. 'fields' => array(
  200. 'aid' => array(
  201. 'type' => 'serial',
  202. 'not null' => TRUE,
  203. 'description' => 'Account ID',
  204. ),
  205. 'status' => array(
  206. 'type' => 'int',
  207. 'not null' => TRUE,
  208. 'description' => 'Blocked_Allowed',
  209. ),
  210. 'registered' => array(
  211. 'type' => 'varchar',
  212. 'length' => 255,
  213. 'not null' => TRUE,
  214. 'description' => 'Registration date',
  215. ),
  216. 'username' => array(
  217. 'type' => 'varchar',
  218. 'length' => 255,
  219. 'not null' => FALSE,
  220. 'description' => 'Account name (for login)',
  221. ),
  222. 'nickname' => array(
  223. 'type' => 'varchar',
  224. 'length' => 255,
  225. 'not null' => FALSE,
  226. 'description' => 'Account name (for display)',
  227. ),
  228. 'password' => array(
  229. 'type' => 'varchar',
  230. 'length' => 255,
  231. 'not null' => FALSE,
  232. 'description' => 'Account password (raw)',
  233. ),
  234. 'email' => array(
  235. 'type' => 'varchar',
  236. 'length' => 255,
  237. 'not null' => FALSE,
  238. 'description' => 'Account email',
  239. ),
  240. 'sex' => array(
  241. 'type' => 'int',
  242. 'not null' => FALSE,
  243. 'description' => 'Gender (0 for male, 1 for female)',
  244. ),
  245. 'beers' => array(
  246. 'type' => 'varchar',
  247. 'length' => 255,
  248. 'not null' => FALSE,
  249. 'description' => 'Favorite Beers',
  250. ),
  251. ),
  252. 'primary key' => array('aid'),
  253. );
  254. }
  255. function migrate_example_beer_data_node() {
  256. $fields = array('bid', 'name', 'body', 'excerpt', 'countries', 'aid', 'image',
  257. 'image_alt', 'image_title', 'image_description');
  258. $query = db_insert('migrate_example_beer_node')
  259. ->fields($fields);
  260. // Use high bid numbers to avoid overwriting an existing node id.
  261. $data = array(
  262. array(99999999, 'Heineken', 'Blab Blah Blah Green', 'Green', 'Netherlands|Belgium', 0, 'heineken.jpg', 'Heinekin alt', 'Heinekin title', 'Heinekin description'), // comes with migrate_example project.
  263. array(99999998, 'Miller Lite', 'We love Miller Brewing', 'Tasteless', 'USA|Canada', 1, NULL, NULL, NULL, NULL),
  264. array(99999997, 'Boddington', 'English occasionally get something right', 'A treat', 'United Kingdom', 1, NULL, NULL, NULL, NULL),
  265. );
  266. foreach ($data as $row) {
  267. $query->values(array_combine($fields, $row));
  268. }
  269. $query->execute();
  270. }
  271. // Note that alice has duplicate username. Exercises dedupe_entity plugin.
  272. // @TODO duplicate email also.
  273. function migrate_example_beer_data_account() {
  274. $fields = array('status', 'registered', 'username', 'nickname', 'password', 'email', 'sex', 'beers');
  275. $query = db_insert('migrate_example_beer_account')
  276. ->fields($fields);
  277. $data = array(
  278. array(1, '2010-03-30 10:31:05', 'alice', 'alice in beerland', 'alicepass', 'alice@example.com', '1', '99999999|99999998|99999997'),
  279. array(1, '2010-04-04 10:31:05', 'alice', 'alice in aleland', 'alicepass', 'alice2@example.com', '1', '99999999|99999998|99999997'),
  280. array(0, '2007-03-15 10:31:05', 'bob', 'rebob', 'bobpass', 'bob@example.com', '0', '99999999|99999997'),
  281. array(1, '2004-02-29 10:31:05', 'charlie', 'charlie chocolate', 'mykids', 'charlie@example.com', '0', '99999999|99999998'),
  282. );
  283. foreach ($data as $row) {
  284. $query->values(array_combine($fields, $row));
  285. }
  286. $query->execute();
  287. }
  288. function migrate_example_beer_data_comment() {
  289. $fields = array('bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid');
  290. $query = db_insert('migrate_example_beer_comment')
  291. ->fields($fields);
  292. $data = array(
  293. array(99999998, NULL, 'im first', 'full body', 'alice', 'alice@example.com', 0),
  294. array(99999998, NULL, 'im second', 'aromatic', 'alice', 'alice@example.com', 0),
  295. array(99999999, NULL, 'im parent', 'malty', 'alice', 'alice@example.com', 0),
  296. array(99999999, 1, 'im child', 'cold body', 'bob', NULL, 1),
  297. array(99999999, 4, 'im grandchild', 'bitter body', 'charlie@example.com', NULL, 1),
  298. );
  299. foreach ($data as $row) {
  300. $query->values(array_combine($fields, $row));
  301. }
  302. $query->execute();
  303. }
  304. function migrate_example_beer_data_topic() {
  305. $fields = array('style', 'details', 'style_parent', 'region', 'hoppiness');
  306. $query = db_insert('migrate_example_beer_topic')
  307. ->fields($fields);
  308. $data = array(
  309. array('ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'),
  310. array('red ale', 'colorful', 'ale', NULL, NULL),
  311. array('pilsner', 'refreshing', NULL, 'Pilsen, Bohemia (now Czech Republic)', 'Low'),
  312. );
  313. foreach ($data as $row) {
  314. $query->values(array_combine($fields, $row));
  315. }
  316. $query->execute();
  317. }
  318. function migrate_example_beer_data_topic_node() {
  319. $fields = array('bid', 'style');
  320. $query = db_insert('migrate_example_beer_topic_node')
  321. ->fields($fields);
  322. $data = array(
  323. array(99999999, 'pilsner'),
  324. array(99999999, 'red ale'),
  325. array(99999998, 'red ale'),
  326. );
  327. foreach ($data as $row) {
  328. $query->values(array_combine($fields, $row));
  329. }
  330. $query->execute();
  331. }