| 1 | |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use File::Basename; |
|---|
| 6 | use File::Spec; |
|---|
| 7 | use YAML; |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | my %TABLES = ( |
|---|
| 13 | base => [qw/ edits error_log forums group_permissions groups messages posts sessions shoutbox threads thread_views user_groups users /], |
|---|
| 14 | gallery => [qw/ creators gallery gallery_keywords item_keywords /], |
|---|
| 15 | pokedex => [qw/ abilities berries contest_effects evo_chains flavor_text items locations location_sections location_encounters machines moves move_effects pokemon pokemon_abilities pokemon_breeds pokemon_items pokemon_moves types /], |
|---|
| 16 | ); |
|---|
| 17 | |
|---|
| 18 | my (undef, $path) = fileparse( File::Spec->rel2abs($0) ); |
|---|
| 19 | chdir $path; |
|---|
| 20 | |
|---|
| 21 | my $config = YAML::LoadFile('../vee.yml'); |
|---|
| 22 | my ($db_db, $db_user, $db_pass) = @{ $config->{'Model::DBIC'}{connect_info} }; |
|---|
| 23 | $db_db =~ s/.+://g; # dbi:mysql:database -> database |
|---|
| 24 | |
|---|
| 25 | my @table_groups = @ARGV ? @ARGV : keys %TABLES; |
|---|
| 26 | |
|---|
| 27 | for my $table_group (@table_groups) { |
|---|
| 28 | next unless exists $TABLES{$table_group}; |
|---|
| 29 | |
|---|
| 30 | system mysqldump => qw/--skip-quote-names/, |
|---|
| 31 | ( $table_group eq 'pokedex' ? '--skip-extended-insert' : '-d' ), |
|---|
| 32 | '-r' => "$table_group.sql", |
|---|
| 33 | '-u' => $db_user, |
|---|
| 34 | ( $db_pass ? "-p$db_pass" : () ), |
|---|
| 35 | $db_db => @{ $TABLES{$table_group} }; |
|---|
| 36 | |
|---|
| 37 | system sed => '-ri', |
|---|
| 38 | |
|---|
| 39 | '-e' => '1, /^$/ d', |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | '-e' => 's/ AUTO_INCREMENT=[0-9]+//', |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | '-e' => '/^INSERT INTO/ { H ; d }', |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | '-e' => '/ENABLE KEYS/ { H ; s/.*// ; x ; s/^\n// ; s/;\nINSERT INTO \w+ VALUES /,\n/g }', |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | '-e' => '/^-- Dump completed/, $ d', |
|---|
| 58 | |
|---|
| 59 | "$table_group.sql"; |
|---|
| 60 | } |
|---|