Version 1
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example_advanced / migrate_example_advanced_setup / migrate_example_advanced_setup.install
1 <?php
2 use Drupal\user\RoleInterface;
3
4 /**
5  * @file
6  * Set up source data and destination configuration for the migration example
7  * module. We do this in a separate module so migrate_example_advanced itself is
8  * a pure migration module.
9  */
10
11 /**
12  * Implements hook_schema().
13  */
14 function migrate_example_advanced_setup_schema() {
15   $schema['migrate_example_advanced_account'] = migrate_example_advanced_schema_account();
16   $schema['migrate_example_advanced_account_updates'] = migrate_example_advanced_schema_account_updates();
17   $schema['migrate_example_advanced_categories'] = migrate_example_advanced_schema_categories();
18   $schema['migrate_example_advanced_vintages'] = migrate_example_advanced_schema_vintages();
19   $schema['migrate_example_advanced_variety_updates'] = migrate_example_advanced_schema_variety_updates();
20   $schema['migrate_example_wine'] = migrate_example_advanced_schema_wine();
21   $schema['migrate_example_advanced_updates'] = migrate_example_advanced_schema_updates();
22   $schema['migrate_example_advanced_producer'] = migrate_example_advanced_schema_producer();
23   $schema['migrate_example_advanced_category_wine'] = migrate_example_advanced_schema_category_wine();
24   $schema['migrate_example_advanced_category_producer'] = migrate_example_advanced_schema_category_producer();
25   $schema['migrate_example_advanced_comment'] = migrate_example_advanced_schema_comment();
26   $schema['migrate_example_advanced_comment_updates'] = migrate_example_advanced_schema_comment_updates();
27   $schema['migrate_example_advanced_files'] = migrate_example_advanced_schema_files();
28   $schema['migrate_example_advanced_blobs'] = migrate_example_advanced_schema_blobs();
29   $schema['migrate_example_advanced_table_source'] = migrate_example_advanced_schema_table_source();
30   $schema['migrate_example_advanced_table_dest'] = migrate_example_advanced_schema_table_dest();
31
32   return $schema;
33 }
34
35 /**
36  * Implements hook_install().
37  */
38 function migrate_example_advanced_setup_install() {
39   // Populate our tables.
40   migrate_example_advanced_data_account();
41   migrate_example_advanced_data_account_updates();
42   migrate_example_advanced_data_categories();
43   migrate_example_advanced_data_vintages();
44   migrate_example_advanced_data_variety_updates();
45   migrate_example_advanced_data_wine();
46   migrate_example_advanced_data_updates();
47   migrate_example_advanced_data_producer();
48   migrate_example_advanced_data_category_wine();
49   migrate_example_advanced_data_category_producer();
50   migrate_example_advanced_data_comment();
51   migrate_example_advanced_data_comment_updates();
52   migrate_example_advanced_data_files();
53   migrate_example_advanced_data_blobs();
54   migrate_example_advanced_data_table_source();
55 }
56
57 function migrate_example_advanced_schema_wine() {
58   return [
59     'description' => 'Wines of the world',
60     'fields' => [
61       'wineid'  => [
62         'type' => 'int',
63         'unsigned' => TRUE,
64         'not null' => TRUE,
65         'description' => 'Wine ID',
66       ],
67       'name'  => [
68         'type' => 'varchar',
69         'length' => 255,
70         'not null' => TRUE,
71       ],
72       'body' => [
73         'type' => 'varchar',
74         'length' => 255,
75         'not null' => FALSE,
76         'description' => 'Full description of the wine.',
77       ],
78       'excerpt' => [
79         'type' => 'varchar',
80         'length' => 255,
81         'not null' => FALSE,
82         'description' => 'Abstract for this wine.',
83       ],
84       'accountid' => [
85         'type' => 'int',
86         'unsigned' => TRUE,
87         'not null' => FALSE,
88         'description' => 'ID of the author.',
89       ],
90       'posted' => [
91         'type' => 'int',
92         'unsigned' => TRUE,
93         'not null' => TRUE,
94         'description' => 'Original creation date',
95       ],
96       'last_changed' => [
97         'type' => 'int',
98         'unsigned' => TRUE,
99         'not null' => TRUE,
100         'description' => 'Last change date',
101       ],
102       'variety' => [
103         'type' => 'int',
104         'unsigned' => TRUE,
105         'not null' => TRUE,
106         'description' => 'Wine variety',
107       ],
108       'region' => [
109         'type' => 'int',
110         'unsigned' => TRUE,
111         'not null' => TRUE,
112         'description' => 'Wine region',
113       ],
114       'rating' => [
115         'type' => 'int',
116         'unsigned' => TRUE,
117         'not null' => FALSE,
118         'description' => 'Rating (100-point scale)',
119       ],
120     ],
121     'primary key' => ['wineid'],
122   ];
123 }
124
125 function migrate_example_advanced_schema_updates() {
126   return array(
127     'description' => 'Updated wine ratings',
128     'fields' => [
129       'wineid'  => [
130         'type' => 'int',
131         'unsigned' => TRUE,
132         'not null' => TRUE,
133         'description' => 'Wine ID',
134       ],
135       'rating' => [
136         'type' => 'int',
137         'unsigned' => TRUE,
138         'not null' => FALSE,
139         'description' => 'Rating (100-point scale)',
140       ],
141     ],
142     'primary key' => ['wineid'],
143   );
144 }
145
146 function migrate_example_advanced_schema_producer() {
147   return array(
148     'description' => 'Wine producers of the world',
149     'fields' => array(
150       'producerid'  => array(
151         'type' => 'int',
152         'unsigned' => TRUE,
153         'not null' => TRUE,
154         'description' => 'Producer ID',
155       ),
156       'name'  => array(
157         'type' => 'varchar',
158         'length' => 255,
159         'not null' => TRUE,
160       ),
161       'body' => array(
162         'type' => 'varchar',
163         'length' => 255,
164         'not null' => FALSE,
165         'description' => 'Full description of the producer.',
166       ),
167       'excerpt' => array(
168         'type' => 'varchar',
169         'length' => 255,
170         'not null' => FALSE,
171         'description' => 'Abstract for this producer.',
172       ),
173       'accountid' => array(
174         'type' => 'int',
175         'unsigned' => TRUE,
176         'not null' => FALSE,
177         'description' => 'Account ID of the author.',
178       ),
179     ),
180     'primary key' => array('producerid'),
181   );
182 }
183
184 function migrate_example_advanced_schema_categories() {
185   return array(
186     'description' => 'Categories',
187     'fields' => array(
188       'categoryid' => array(
189         'type' => 'int',
190         'not null' => TRUE,
191         'unsigned' => TRUE,
192         'description' => 'Category ID',
193       ),
194       'type' => array(
195         'type' => 'varchar',
196         'length' => 255,
197         'not null' => TRUE,
198         'description' => 'Type of category: variety, region, best_with',
199       ),
200       'name'  => array(
201         'type' => 'varchar',
202         'length' => 255,
203         'not null' => TRUE,
204       ),
205       'details' => array(
206         'type' => 'varchar',
207         'length' => 255,
208         'not null' => FALSE,
209       ),
210       'category_parent' => array(
211         'type' => 'int',
212         'unsigned' => TRUE,
213         'not null' => FALSE,
214         'description' => 'Parent category, if any',
215       ),
216       'ordering' => array(
217         'type' => 'int',
218         'unsigned' => FALSE,
219         'not null' => FALSE,
220         'description' => 'Order in which to display categories',
221       ),
222     ),
223     'primary key' => array('categoryid'),
224   );
225 }
226
227 function migrate_example_advanced_schema_vintages() {
228   return array(
229     'description' => 'Wine vintages',
230     'fields' => array(
231       'wineid'  => array(
232         'type' => 'int',
233         'not null' => TRUE,
234         'description' => 'Wine ID',
235       ),
236       'vintage'  => array(
237         'type' => 'int',
238         'unsigned' => TRUE,
239         'not null' => TRUE,
240         'description' => 'Vintage (year)',
241       ),
242     ),
243     'primary key' => array('wineid', 'vintage'),
244   );
245 }
246
247 function migrate_example_advanced_schema_variety_updates() {
248   return array(
249     'description' => 'Variety updates',
250     'fields' => array(
251       'categoryid' => array(
252         'type' => 'int',
253         'not null' => TRUE,
254         'unsigned' => TRUE,
255         'description' => 'Category ID',
256       ),
257       'details' => array(
258         'type' => 'varchar',
259         'length' => 255,
260         'not null' => FALSE,
261       ),
262     ),
263     'primary key' => array('categoryid'),
264   );
265 }
266
267 function migrate_example_advanced_schema_category_wine() {
268   return array(
269     'description' => 'Wine category assignments',
270     'fields' => array(
271       'wineid'  => array(
272         'type' => 'int',
273         'not null' => TRUE,
274         'description' => 'Wine ID',
275       ),
276       'categoryid'  => array(
277         'type' => 'int',
278         'unsigned' => TRUE,
279         'not null' => TRUE,
280         'description' => 'Category ID',
281       ),
282     ),
283     'primary key' => array('categoryid', 'wineid'),
284   );
285 }
286
287 function migrate_example_advanced_schema_category_producer() {
288   return array(
289     'description' => 'Producer category assignments',
290     'fields' => array(
291       'producerid'  => array(
292         'type' => 'int',
293         'not null' => TRUE,
294         'description' => 'Producer ID',
295       ),
296       'categoryid'  => array(
297         'type' => 'int',
298         'unsigned' => TRUE,
299         'not null' => TRUE,
300         'description' => 'Category ID',
301       ),
302     ),
303     'primary key' => array('categoryid', 'producerid'),
304   );
305 }
306
307 function migrate_example_advanced_schema_comment() {
308   return array(
309     'description' => 'Wine comments',
310     'fields' => array(
311       'commentid'  => array(
312         'type' => 'int',
313         'unsigned' => TRUE,
314         'not null' => TRUE,
315         'description' => 'Comment ID',
316       ),
317       'wineid'  => array(
318         'type' => 'int',
319         'unsigned' => TRUE,
320         'not null' => TRUE,
321         'description' => 'Wine ID that is being commented upon',
322       ),
323       'comment_parent' => array(
324         'type' => 'int',
325         'unsigned' => TRUE,
326         'not null' => FALSE,
327         'description' => 'Parent comment ID in case of comment replies.',
328       ),
329       'subject' => array(
330         'type' => 'varchar',
331         'length' => 255,
332         'not null' => FALSE,
333         'description' => 'Comment subject',
334       ),
335       'body' => array(
336         'type' => 'varchar',
337         'length' => 255,
338         'not null' => FALSE,
339         'description' => 'Comment body',
340       ),
341       'name' => array(
342         'type' => 'varchar',
343         'length' => 255,
344         'not null' => FALSE,
345         'description' => 'Comment name (if anon)',
346       ),
347       'mail' => array(
348         'type' => 'varchar',
349         'length' => 255,
350         'not null' => FALSE,
351         'description' => 'Comment email (if anon)',
352       ),
353       'accountid' => array(
354         'type' => 'int',
355         'unsigned' => TRUE,
356         'not null' => FALSE,
357         'description' => 'Account ID (if any).',
358       ),
359       'commenthost' => array(
360         'type' => 'varchar',
361         'length' => 255,
362         'not null' => FALSE,
363         'description' => 'IP/domain of host posted from',
364       ),
365       'userpage' => array(
366         'type' => 'varchar',
367         'length' => 255,
368         'not null' => FALSE,
369         'description' => 'User homepage',
370       ),
371       'posted' => array(
372         'type' => 'int',
373         'unsigned' => TRUE,
374         'not null' => TRUE,
375         'description' => 'Date comment posted',
376       ),
377       'lastchanged' => array(
378         'type' => 'int',
379         'unsigned' => TRUE,
380         'not null' => TRUE,
381         'description' => 'Date comment last changed',
382       ),
383     ),
384     'primary key' => array('commentid'),
385   );
386 }
387
388 function migrate_example_advanced_schema_comment_updates() {
389   return array(
390     'description' => 'Wine comment updates',
391     'fields' => array(
392       'commentid'  => array(
393         'type' => 'int',
394         'unsigned' => TRUE,
395         'not null' => TRUE,
396         'description' => 'Comment ID',
397       ),
398       'subject' => array(
399         'type' => 'varchar',
400         'length' => 255,
401         'not null' => FALSE,
402         'description' => 'Comment subject',
403       ),
404     ),
405     'primary key' => array('commentid'),
406   );
407 }
408
409 function migrate_example_advanced_schema_account() {
410   return array(
411     'description' => 'Wine accounts.',
412     'fields' => array(
413       'accountid'  => array(
414         'type' => 'serial',
415         'not null' => TRUE,
416         'description' => 'Account ID',
417       ),
418       'status'  => array(
419         'type' => 'int',
420         'not null' => TRUE,
421         'description' => 'Blocked_Allowed',
422       ),
423       'posted' => array(
424         'type' => 'varchar',
425         'length' => 255,
426         'not null' => TRUE,
427         'description' => 'Registration date',
428       ),
429       'last_access' => array(
430         'type' => 'varchar',
431         'length' => 255,
432         'not null' => TRUE,
433         'description' => 'Last access date',
434       ),
435       'last_login' => array(
436         'type' => 'varchar',
437         'length' => 255,
438         'not null' => TRUE,
439         'description' => 'Last login date',
440       ),
441       'name' => array(
442         'type' => 'varchar',
443         'length' => 255,
444         'not null' => FALSE,
445         'description' => 'Account name (for login)',
446       ),
447       'sex' => array(
448         'type' => 'char',
449         'length' => 1,
450         'not null' => FALSE,
451         'description' => 'Gender',
452       ),
453       'password' => array(
454         'type' => 'varchar',
455         'length' => 255,
456         'not null' => FALSE,
457         'description' => 'Account password (raw)',
458       ),
459       'mail' => array(
460         'type' => 'varchar',
461         'length' => 255,
462         'not null' => FALSE,
463         'description' => 'Account email',
464       ),
465       'original_mail' => array(
466         'type' => 'varchar',
467         'length' => 255,
468         'not null' => FALSE,
469         'description' => 'Original account email',
470       ),
471       'sig' => array(
472         'type' => 'varchar',
473         'length' => 255,
474         'not null' => TRUE,
475         'description' => 'Signature for comments',
476       ),
477       'imageid'  => array(
478         'type' => 'int',
479         'unsigned' => TRUE,
480         'not null' => FALSE,
481         'description' => 'Image ID',
482       ),
483       'positions' => array(
484         'type' => 'varchar',
485         'length' => 255,
486         'not null' => FALSE,
487         'description' => 'Positions held',
488       ),
489     ),
490     'primary key' => array('accountid'),
491   );
492 }
493
494 function migrate_example_advanced_schema_account_updates() {
495   return array(
496     'description' => 'Wine account updates',
497     'fields' => array(
498       'accountid'  => array(
499         'type' => 'serial',
500         'not null' => TRUE,
501         'description' => 'Account ID',
502       ),
503       'sex' => array(
504         'type' => 'char',
505         'length' => 1,
506         'not null' => FALSE,
507         'description' => 'Gender',
508       ),
509     ),
510     'primary key' => array('accountid'),
511   );
512 }
513
514 function migrate_example_advanced_schema_blobs() {
515   return array(
516     'description' => 'Wine blobs to be migrated to file entities',
517     'fields' => array(
518       'imageid'  => array(
519         'type' => 'int',
520         'unsigned' => TRUE,
521         'not null' => TRUE,
522         'description' => 'Image ID',
523       ),
524       'imageblob' => array(
525         'type' => 'blob',
526         'size' => 'normal',
527         'description' => 'binary image data',
528       ),
529     ),
530     'primary key' => array('imageid'),
531   );
532 }
533
534 function migrate_example_advanced_schema_files() {
535   return array(
536     'description' => 'Wine and account files',
537     'fields' => array(
538       'imageid'  => array(
539         'type' => 'int',
540         'unsigned' => TRUE,
541         'not null' => TRUE,
542         'description' => 'Image ID',
543       ),
544       'url'  => array(
545         'type' => 'varchar',
546         'length' => 255,
547         'not null' => TRUE,
548         'description' => 'Image URL',
549       ),
550       'image_alt'  => array(
551         'type' => 'varchar',
552         'length' => 255,
553         'not null' => FALSE,
554         'description' => 'Image alt',
555       ),
556       'image_title'  => array(
557         'type' => 'varchar',
558         'length' => 255,
559         'not null' => FALSE,
560         'description' => 'Image title',
561       ),
562       'wineid'  => array(
563         'type' => 'int',
564         'unsigned' => TRUE,
565         'not null' => FALSE,
566         'description' => 'Wine node this is associated with',
567       ),
568     ),
569     'primary key' => array('imageid'),
570   );
571 }
572
573 function migrate_example_advanced_schema_table_source() {
574   return array(
575     'description' => 'Source data to go into a custom Drupal table',
576     'fields' => array(
577       'fooid'  => array(
578         'type' => 'int',
579         'unsigned' => TRUE,
580         'not null' => TRUE,
581         'description' => 'Primary key',
582       ),
583       'field1'  => array(
584         'type' => 'varchar',
585         'length' => 255,
586         'not null' => TRUE,
587         'description' => 'First field',
588       ),
589       'field2'  => array(
590         'type' => 'int',
591         'unsigned' => TRUE,
592         'not null' => TRUE,
593         'description' => 'Second field',
594       ),
595     ),
596     'primary key' => array('fooid'),
597   );
598 }
599
600 function migrate_example_advanced_schema_table_dest() {
601   return array(
602     'description' => 'Custom Drupal table to receive source data directly',
603     'fields' => array(
604       'recordid'  => array(
605         'type' => 'serial',
606         'unsigned' => TRUE,
607         'not null' => TRUE,
608         'description' => 'Primary key',
609       ),
610       'drupal_text'  => array(
611         'type' => 'varchar',
612         'length' => 255,
613         'not null' => TRUE,
614         'description' => 'First field',
615       ),
616       'drupal_int'  => array(
617         'type' => 'int',
618         'unsigned' => TRUE,
619         'not null' => TRUE,
620         'description' => 'Second field',
621       ),
622     ),
623     'primary key' => array('recordid'),
624   );
625 }
626
627 function migrate_example_advanced_data_wine() {
628   $fields = array('wineid', 'name', 'body', 'excerpt', 'accountid',
629     'posted', 'last_changed', 'variety', 'region', 'rating');
630   $query = db_insert('migrate_example_wine')
631            ->fields($fields);
632   $data = array(
633     array(1, 'Montes Classic Cabernet Sauvignon', 'Intense ruby-red color', 'Great!', 9,
634       strtotime('2010-01-02 03:04:05'), strtotime('2010-03-04 05:06:07'), 25, 17, 95),
635     array(2, 'Archeo Ruggero di Tasso Nero d\'Avola', 'Lots of berry character', 'Pair with red sauced dishes', 3,
636       strtotime('2010-09-03 18:23:58'), strtotime('2010-09-03 18:23:58'), 26, 2, 85),
637   );
638   foreach ($data as $row) {
639     $query->values(array_combine($fields, $row));
640   }
641   $query->execute();
642 }
643
644 function migrate_example_advanced_data_updates() {
645   $fields = array('wineid', 'rating');
646   $query = db_insert('migrate_example_advanced_updates')
647            ->fields($fields);
648   $data = array(
649     array(1, 93),
650     array(2, NULL),
651   );
652   foreach ($data as $row) {
653     $query->values(array_combine($fields, $row));
654   }
655   $query->execute();
656 }
657
658 function migrate_example_advanced_data_producer() {
659   $fields = array('producerid', 'name', 'body', 'excerpt', 'accountid');
660   $query = db_insert('migrate_example_advanced_producer')
661            ->fields($fields);
662   $data = array(
663     array(1, 'Montes', 'Fine Chilean winery', 'Great!', 9),
664     array(2, 'Archeo', 'Sicilia!', NULL, 3),
665   );
666   foreach ($data as $row) {
667     $query->values(array_combine($fields, $row));
668   }
669   $query->execute();
670 }
671
672 function migrate_example_advanced_data_account() {
673   $fields = array('accountid', 'status', 'posted', 'last_access', 'last_login',
674     'name', 'sex', 'password', 'mail', 'original_mail', 'sig', 'imageid', 'positions');
675   $query = db_insert('migrate_example_advanced_account')
676     ->fields($fields);
677   $data = array(
678     array(1, 1, '2010-03-30 10:31:05', '2010-04-30 18:25:24', '2010-04-30 14:01:02',
679       'darren', 'M', 'dpass', 'ddarren@example.com', 'darren@example.com',
680       'All about the Australians', NULL, '5'),
681     array(3, 0, '2007-03-15 10:31:05', '2007-06-10 04:11:38', '2007-06-10 04:11:38',
682       'emily', 'F', 'insecure', 'emily@example.com', 'emily@example.com',
683       'Sommelier to the stars', NULL, '18'),
684     array(9, 1, '2004-02-29 10:31:05', '2004-02-29 10:31:05', '2004-02-29 10:31:05',
685       'fonzie', NULL, 'bike', 'thefonz@example.com', 'arthur@example.com',
686       'Aaay!', 1, '5,18'),
687   );
688   foreach ($data as $row) {
689     $query->values(array_combine($fields, $row));
690   }
691   $query->execute();
692 }
693
694 function migrate_example_advanced_data_account_updates() {
695   $fields = array('accountid', 'sex');
696   $query = db_insert('migrate_example_advanced_account_updates')
697            ->fields($fields);
698   $data = array(
699     array(1, NULL),
700     array(3, 'M'),
701     array(9, 'F'),
702   );
703   foreach ($data as $row) {
704     $query->values(array_combine($fields, $row));
705   }
706   $query->execute();
707 }
708
709 function migrate_example_advanced_data_comment() {
710   $fields = array('commentid', 'wineid', 'comment_parent', 'subject', 'body',
711     'name', 'mail', 'accountid', 'commenthost', 'userpage', 'posted', 'lastchanged');
712   $query = db_insert('migrate_example_advanced_comment')
713     ->fields($fields);
714   $data = array(
715     array(1, 1, NULL, 'im first', 'Tasty', 'grace', 'grace@example.com', 0,
716       '123.456.78.9', 'http:://grace.example.com/',
717       strtotime('2010-01-02 03:04:05'), strtotime('2010-04-05 06:07:08')),
718     array(2, 1, NULL, 'im second', 'Delicious', 'horace', 'horace@example.com', 0,
719       'example.com', NULL,
720       strtotime('2010-02-02 03:04:05'), strtotime('2010-05-05 06:07:08')),
721     array(3, 1, NULL, 'im parent', 'Don\'t care for it', 'irene', 'irene@example.com', 0,
722       '254.0.2.5', 'http:://www.example.com/irene',
723       strtotime('2010-03-02 03:04:05'), strtotime('2010-03-02 03:04:05')),
724     array(4, 1, 3, 'im child', 'But it\'s so good!', 'emily', NULL, 3,
725       '58.29.126.1', 'http:://www.wine.com/',
726       strtotime('2010-01-02 03:04:05'), strtotime('2010-01-02 03:04:05')),
727     array(5, 1, 4, 'im grandchild', 'Right on, Emily!', 'thefonz@example.com', NULL, 9,
728       '123.456.78.9', NULL,
729       strtotime('2010-06-02 03:04:05'), strtotime('2010-06-02 03:04:05')),
730   );
731   foreach ($data as $row) {
732     $query->values(array_combine($fields, $row));
733   }
734   $query->execute();
735 }
736
737 function migrate_example_advanced_data_comment_updates() {
738   $fields = array('commentid', 'subject');
739   $query = db_insert('migrate_example_advanced_comment_updates')
740            ->fields($fields);
741   $data = array(
742     array(1, 'I am first'),
743     array(2, 'I am second'),
744     array(3, 'I am parent'),
745     array(4, ''),
746     array(5, 'I am Spartacus'),
747   );
748   foreach ($data as $row) {
749     $query->values(array_combine($fields, $row));
750   }
751   $query->execute();
752 }
753
754 function migrate_example_advanced_data_categories() {
755   $fields = array('categoryid', 'type', 'name', 'category_parent', 'details', 'ordering');
756   $query = db_insert('migrate_example_advanced_categories')
757            ->fields($fields);
758   $data = array(
759     array(1, 'variety', 'White wine', NULL, 'White wines are generally simpler and sweeter than red', 3),
760     array(3, 'variety', 'Red wine', NULL, 'Red wines are generally more complex and "dry" than white', 1),
761     array(8, 'variety', 'Riesling', 1, 'Associated with Germany', 2),
762     array(9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1),
763     array(13, 'variety', 'Merlot', 3, 'Very drinkable', 4),
764     array(14, 'variety', 'Syrah', 3, 'A.k.a. shiraz', -3),
765     array(25, 'variety', 'Cabernet Sauvignon', 3, 'A basic', -5),
766     array(26, 'variety', "Nero d'Avola", 3, 'Sicilian specialty', 2),
767     array(2, 'region', 'Italy', NULL, 'Largest producer of wine', 5),
768     array(11, 'region', 'Tuscany', 2, NULL, 2),
769     array(18, 'region', 'Chianti', 11, NULL, -1),
770     array(19, 'region', 'Elba', 11, NULL, 5),
771     array(4, 'region', 'France', NULL, 'C\'est bon', 6),
772     array(5, 'region', 'Bordeaux', 4, NULL, 1),
773     array(6, 'region', 'Barsac', 5, NULL, 3),
774     array(7, 'region', 'Pomerol', 5, NULL, 2),
775     array(16, 'region', 'Chile', NULL, NULL, 3),
776     array(17, 'region', 'Colchagua Valley', 16, NULL, 1),
777     array(20, 'region', 'California', NULL, NULL, 5),
778     array(21, 'region', 'Redwood Valley', 20, NULL, 1),
779     array(10, 'best_with', 'Beef', NULL, NULL, 5),
780     array(12, 'best_with', 'Pork', NULL, NULL, -3),
781     array(15, 'best_with', 'Chicken', NULL, NULL, -5),
782   );
783   foreach ($data as $row) {
784     $query->values(array_combine($fields, $row));
785   }
786   $query->execute();
787 }
788
789 function migrate_example_advanced_data_vintages() {
790   $fields = array('wineid', 'vintage');
791   $query = db_insert('migrate_example_advanced_vintages')
792            ->fields($fields);
793   $data = array(
794     array(1, 2006),
795     array(1, 2007),
796     array(2, 2001),
797   );
798   foreach ($data as $row) {
799     $query->values(array_combine($fields, $row));
800   }
801   $query->execute();
802 }
803
804 function migrate_example_advanced_data_variety_updates() {
805   $fields = array('categoryid', 'details');
806   $query = db_insert('migrate_example_advanced_variety_updates')
807            ->fields($fields);
808   $data = array(
809     array(1, 'White wines are simpler and sweeter than red'),
810     array(3, 'Red wines are generally more complex and dry than white'),
811     array(8, 'Usually associated with Germany'),
812     array(9, NULL),
813     array(13, 'Common, very drinakable'),
814     array(14, 'AKA Shiraz'),
815     array(25, 'Basic'),
816     array(26, 'A specialty of Sicily'),
817   );
818   foreach ($data as $row) {
819     $query->values(array_combine($fields, $row));
820   }
821   $query->execute();
822 }
823
824 function migrate_example_advanced_data_category_wine() {
825   $fields = array('wineid', 'categoryid');
826   $query = db_insert('migrate_example_advanced_category_wine')
827     ->fields($fields);
828   $data = array(
829     array(1, 12),
830     array(1, 15),
831     array(2, 10),
832   );
833   foreach ($data as $row) {
834     $query->values(array_combine($fields, $row));
835   }
836   $query->execute();
837 }
838
839 function migrate_example_advanced_data_category_producer() {
840   $fields = array('producerid', 'categoryid');
841   $query = db_insert('migrate_example_advanced_category_producer')
842     ->fields($fields);
843   $data = array(
844     array(1, 17),
845   );
846   foreach ($data as $row) {
847     $query->values(array_combine($fields, $row));
848   }
849   $query->execute();
850 }
851
852 function migrate_example_advanced_data_files() {
853   $fields = array('imageid', 'url', 'image_alt', 'image_title', 'wineid');
854   $query = db_insert('migrate_example_advanced_files')
855     ->fields($fields);
856   $data = array(
857     array(1, 'http://placekitten.com/200/200', NULL, NULL, NULL),
858     array(2, 'http://cyrve.com/files/penguin.jpeg', 'Penguin alt', 'Penguin title', 1),
859     array(3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2),
860     array(4, 'http://cyrve.com/files/boutisse_0.jpeg', 'Boutisse alt', 'Boutisse title', 2),
861   );
862   foreach ($data as $row) {
863     $query->values(array_combine($fields, $row));
864   }
865   $query->execute();
866 }
867
868 function migrate_example_advanced_data_blobs() {
869   $blob = file_get_contents('core/misc/druplicon.png');
870   $fields = array('imageid', 'imageblob');
871   $query = db_insert('migrate_example_advanced_blobs')
872     ->fields($fields);
873   $data = array(
874     array(1, $blob),
875   );
876   foreach ($data as $row) {
877     $query->values(array_combine($fields, $row));
878   }
879   $query->execute();
880 }
881
882 function migrate_example_advanced_data_table_source() {
883   $fields = array('fooid', 'field1', 'field2');
884   $query = db_insert('migrate_example_advanced_table_source')
885     ->fields($fields);
886   $data = array(
887     array(3, 'Some sample data', 58),
888     array(15, 'Whatever', 2),
889     array(646, 'More sample data', 34989),
890   );
891   foreach ($data as $row) {
892     $query->values(array_combine($fields, $row));
893   }
894   $query->execute();
895 }