]> Frank Brehm's Git Trees - cookbook.git/commitdiff
properties-Tabelle hinzugefügt
authorFrank Brehm <frank@brehm-online.com>
Fri, 10 Aug 2007 20:05:17 +0000 (20:05 +0000)
committerFrank Brehm <frank@brehm-online.com>
Fri, 10 Aug 2007 20:05:17 +0000 (20:05 +0000)
git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@22 191103c4-1d37-0410-b3e5-d8c2315c0aac

lib/CookBook/Db.pm
lib/CookBook/Db/Properties.pm [new file with mode: 0644]
sbin/initial_import.pl

index e5f5eebb21bca41c2f4302de9f4ccb206759bfdc..a8f47089ba395e22268d511dc914dd6d00ef07f2 100644 (file)
@@ -28,6 +28,7 @@ __PACKAGE__->load_classes(
         Categories
         Ingredients
         IngredientGroups
+        Properties
         RecipeAuthors
         RecipeCategories
         RecipeIngredients
diff --git a/lib/CookBook/Db/Properties.pm b/lib/CookBook/Db/Properties.pm
new file mode 100644 (file)
index 0000000..0a98a40
--- /dev/null
@@ -0,0 +1,58 @@
+package CookBook::Db::Properties;
+
+# $Id$
+# $URL$
+
+=head1 NAME
+
+CookBook::Db::Properties
+
+=head1 DESCRIPTION
+
+Module for abstract database access to the table 'properties'
+
+=cut
+
+#---------------------------------------------------------------------------
+
+use strict;
+use warnings;
+
+use CookBook::Common;
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(
+    qw/
+        PK::Auto
+        Core
+        /
+);
+
+__PACKAGE__->table('properties');
+
+__PACKAGE__->add_columns(
+    "property_id" => {
+        'data_type'         => "INT",
+        'default_value'     => undef,
+        'is_nullable'       => 0,
+        'size'              => 10,
+        'is_auto_increment' => 1,
+        'extras'            => { 'unsigned' => 1 },
+    },
+    "property_name" => { 'data_type' => "VARCHAR",  'default_value' => "",    'is_nullable' => 0, 'size' => 100 },
+    "units"         => { 'data_type' => "VARCHAR",  'default_value' => undef, 'is_nullable' => 1, 'size' => 30 },
+    "date_created"  => { 'data_type' => "DATETIME", 'default_value' => "",    'is_nullable' => 0, 'size' => 19 },
+    "date_changed"  => { 'data_type' => "DATETIME", 'default_value' => "",    'is_nullable' => 0, 'size' => 19 },
+);
+
+__PACKAGE__->set_primary_key("property_id");
+__PACKAGE__->add_unique_constraint( "property_name", ["property_name"] );
+
+#----------------------------------------------------------------------------------------
+
+1;
+
+#----------------------------------------------------------------------------------------
+
+__END__
+
index 06db69b0c70b7e735a8f7474df0f030c2cdef896..2988500a056b7559ba16fd21637da75a81f7cf24 100755 (executable)
@@ -36,6 +36,7 @@ my @target_tables = qw(
     yield_types
     unit_types
     units
+    properties
     categories
     ingredients
     ingredient_groups
@@ -60,6 +61,7 @@ my %create_method = (
     'units'              => \&create_units_table,
     'categories'         => \&create_categories_table,
     'recipe_categories'  => \&create_recipe_categories_table,
+    'properties'         => \&create_properties_table,
 );
 
 my @import_tables = qw(
@@ -67,6 +69,7 @@ my @import_tables = qw(
     yield_types
     units
     categories
+    properties
     ingredients
     ingredient_groups
     recipes
@@ -86,6 +89,7 @@ my %import_method = (
     'recipes'            => \&import_recipes_table,
     'recipe_authors'     => \&import_recipe_authors_table,
     'recipe_ingredients' => \&import_recipe_ingredients_table,
+    'properties'         => \&import_properties_table,
 );
 
 my $admin_data = {
@@ -785,6 +789,83 @@ END_SQL
 
 #-------------------------------------------------------------
 
+=head2 create_properties_table( )
+
+=cut
+
+sub create_properties_table {
+
+    my $sql = <<END_SQL;
+CREATE TABLE `properties` (
+  `property_id`   int(10) unsigned NOT NULL auto_increment,
+  `property_name` varchar(100)     NOT NULL COMMENT 'Name der Eigenschaft',
+  `units`         varchar(30)               COMMENT 'Maßeinheit für diese Eigenschaft',
+  `date_created`  datetime         NOT NULL,
+  `date_changed`  datetime         NOT NULL,
+  PRIMARY KEY                 (`property_id`),
+  UNIQUE KEY  `property_name` (`property_name`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Eigenschaften für Zutaten'
+END_SQL
+
+    return undef unless $target_dbh->do($sql);
+    return 1;
+
+} ## end sub create_recipe_authors_table
+
+#-------------------------------------------------------------
+
+=head2 import_categories_table( )
+
+=cut
+
+sub import_properties_table {
+
+    my $sql = <<END_SQL;
+SELECT `id`, `name`, `units`
+  FROM `ingredient_properties`
+ ORDER BY `name`
+END_SQL
+
+    my ( $source_sth, $target_sth, $prop, $qparams );
+
+    unless ( $source_sth = $source_dbh->prepare($sql) ) {
+        return undef;
+    }
+
+    return undef unless $source_sth->execute();
+
+    $sql = <<END_SQL;
+INSERT INTO `properties` ( `property_id`, `property_name`, `units`, `date_created`, `date_changed` )
+    VALUES ( ?, ?, ?, now(), now() )
+END_SQL
+    $target_sth = $target_dbh->prepare($sql);
+    unless ($target_sth) {
+        $source_sth->finish();
+        return undef;
+    }
+
+    while ( $prop = $source_sth->fetchrow_hashref() ) {
+
+        next unless $prop->{'name'};
+
+        $qparams = [];
+        push @$qparams, $prop->{'id'};
+        push @$qparams, $prop->{'name'};
+        push @$qparams, $prop->{'units'};
+
+        unless ( $target_dbh->do( $sql, {}, @$qparams ) ) {
+            $source_sth->finish();
+            return undef;
+        }
+
+    } ## end while ( $ingr = $source_sth->fetchrow_hashref...
+
+    return 1;
+
+} ## end sub import_ingredients_table
+
+#-------------------------------------------------------------
+
 =head2 create_session_table( )
 
 =cut