my @target_tables = qw(
users
+ authors
);
my $admin_data = {
exit 7 unless drop_target_tables();
exit 8 unless create_target_tables();
+exit 99 unless optimize_target_tables();
+
exit 0;
###############################################################
#-------------------------------------------------------------
+=head2 optimize_target_tables( )
+
+=cut
+
+sub optimize_target_tables {
+
+ print green_star() . " Optimiere alle Zieltabellen ...\n";
+ for my $table ( @target_tables ) {
+ my $sql = "OPTIMIZE TABLE `" . $table . "`";
+ print " - " . $table . " ";
+ eval { die "Nicht optimiert.\n" unless $target_dbh->do($sql); };
+ if ($@) {
+ print not_ok() . "\n";
+ warn "$@\n";
+ return undef;
+ }
+ print ok() . "\n";
+ } ## end for my $table ( reverse(@target_tables) )
+ print "\n";
+
+ return 1;
+
+}
+
+#-------------------------------------------------------------
+
=head2 create_target_tables( )
Erstellt alle notwendigen Ziel-Tabellen ...
sub create_target_tables {
- my %create_method = ( 'users' => \&create_user_table, );
+ my %create_method = (
+ 'users' => \&create_user_table,
+ 'authors' => \&create_author_table,
+ );
print green_star() . " Erstelle Ziel-Tabellen ...\n";
#-------------------------------------------------------------
+=head2 create_author_table( )
+
+Erstellt die Tabelle 'authors' ...
+
+=cut
+
+sub create_author_table {
+
+ my $sql = <<END_SQL;
+CREATE TABLE `authors` (
+ `author_id` int(10) unsigned NOT NULL auto_increment,
+ `user_id` int(10) unsigned,
+ `old_author_id` int(11) COMMENT 'alte ID aus Kreceipes',
+ `author_name` varchar(100) NOT NULL COMMENT 'Name des Autors',
+ `date_created` datetime NOT NULL,
+ PRIMARY KEY (`author_id`),
+ UNIQUE KEY `author_name` (`author_name`),
+ KEY `user_id` (`user_id`),
+ KEY `old_author_id` (`old_author_id`),
+ FULLTEXT KEY `author_name_ft` (`author_name`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Kochrezept-Autoren'
+END_SQL
+
+ return undef unless $target_dbh->do($sql);
+
+ $sql = <<END_SQL;
+INSERT INTO `authors`
+ ( `author_id`, `user_id`, `old_author_id`, `author_name`, `date_created` )
+ VALUES
+ ( 1, 1, NULL, %s, now() )
+END_SQL
+
+ $sql = sprintf( $sql, $target_dbh->quote( $admin_data->{'vorname'} . " " . $admin_data->{'nachname'} ) );
+
+ return undef unless $target_dbh->do($sql);
+
+ return 1;
+}
+
+#-------------------------------------------------------------
+
=head2 create_user_table( )
Erstellt die Tabelle 'users' ...
$sql = <<END_SQL;
INSERT INTO `users`
( `user_id`, `login`, `vorname`, `nachname`, `password`, `date_created`, `date_changed`, `email`, `admin_status` )
- VALUES
+ VALUES
( 1, %s, %s, %s, %s, now(), now(), %s, 'y' )
END_SQL