Pflichtenheft-Angebot/Auftrag: DB-Schema & Models
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 9 Jul 2013 08:41:57 +0000 (10:41 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:03:25 +0000 (13:03 +0200)
SL/DB/Helper/ALL.pm
SL/DB/Helper/Mappings.pm
SL/DB/Manager/RequirementSpecOrder.pm [new file with mode: 0644]
SL/DB/MetaSetup/Default.pm
SL/DB/MetaSetup/RequirementSpecItem.pm
SL/DB/MetaSetup/RequirementSpecOrder.pm [new file with mode: 0644]
SL/DB/MetaSetup/RequirementSpecVersion.pm
SL/DB/RequirementSpecOrder.pm [new file with mode: 0644]
sql/Pg-upgrade2/requirement_specs_orders.sql [new file with mode: 0644]

index 190a52e..5e78a73 100644 (file)
@@ -81,6 +81,7 @@ use SL::DB::RequirementSpecAcceptanceStatus;
 use SL::DB::RequirementSpecComplexity;
 use SL::DB::RequirementSpecDependency;
 use SL::DB::RequirementSpecItem;
+use SL::DB::RequirementSpecOrder;
 use SL::DB::RequirementSpecPredefinedText;
 use SL::DB::RequirementSpecRisk;
 use SL::DB::RequirementSpecStatus;
index 6d7d8d0..3ccfb57 100644 (file)
@@ -161,6 +161,7 @@ my %kivitendo_package_names = (
   requirement_spec_complexities        => 'RequirementSpecComplexity',
   requirement_spec_item_dependencies   => 'RequirementSpecDependency',
   requirement_spec_items               => 'RequirementSpecItem',
+  requirement_spec_orders              => 'RequirementSpecOrder',
   requirement_spec_predefined_texts    => 'RequirementSpecPredefinedText',
   requirement_spec_risks               => 'RequirementSpecRisk',
   requirement_spec_statuses            => 'RequirementSpecStatus',
diff --git a/SL/DB/Manager/RequirementSpecOrder.pm b/SL/DB/Manager/RequirementSpecOrder.pm
new file mode 100644 (file)
index 0000000..d2a1086
--- /dev/null
@@ -0,0 +1,15 @@
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::Manager::RequirementSpecOrder;
+
+use strict;
+
+use SL::DB::Helper::Manager;
+use base qw(SL::DB::Helper::Manager);
+
+sub object_class { 'SL::DB::RequirementSpecOrder' }
+
+__PACKAGE__->make_manager_methods;
+
+1;
index c8f4ed4..5b547ef 100644 (file)
@@ -69,6 +69,7 @@ __PACKAGE__->meta->columns(
   purchase_order_show_delete                    => { type => 'boolean', default => 'true' },
   requirement_spec_function_block_number_format => { type => 'text', default => 'FB000', not_null => 1 },
   requirement_spec_section_number_format        => { type => 'text', default => 'A00', not_null => 1 },
+  requirement_spec_section_order_part_id        => { type => 'integer' },
   revtrans                                      => { type => 'boolean', default => 'false' },
   rfqnumber                                     => { type => 'text' },
   rmanumber                                     => { type => 'text' },
@@ -117,6 +118,11 @@ __PACKAGE__->meta->foreign_keys(
     key_columns => { currency_id => 'id' },
   },
 
+  requirement_spec_section_order_part => {
+    class       => 'SL::DB::Part',
+    key_columns => { requirement_spec_section_order_part_id => 'id' },
+  },
+
   warehouse => {
     class       => 'SL::DB::Warehouse',
     key_columns => { warehouse_id => 'id' },
index dfce581..63e4eec 100644 (file)
@@ -19,6 +19,7 @@ __PACKAGE__->meta->columns(
   item_type            => { type => 'text', not_null => 1 },
   itime                => { type => 'timestamp', default => 'now()', not_null => 1 },
   mtime                => { type => 'timestamp' },
+  order_part_id        => { type => 'integer' },
   parent_id            => { type => 'integer' },
   position             => { type => 'integer', not_null => 1 },
   requirement_spec_id  => { type => 'integer', not_null => 1 },
@@ -42,6 +43,11 @@ __PACKAGE__->meta->foreign_keys(
     key_columns => { complexity_id => 'id' },
   },
 
+  order_part => {
+    class       => 'SL::DB::Part',
+    key_columns => { order_part_id => 'id' },
+  },
+
   parent => {
     class       => 'SL::DB::RequirementSpecItem',
     key_columns => { parent_id => 'id' },
diff --git a/SL/DB/MetaSetup/RequirementSpecOrder.pm b/SL/DB/MetaSetup/RequirementSpecOrder.pm
new file mode 100644 (file)
index 0000000..33499bf
--- /dev/null
@@ -0,0 +1,44 @@
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::RequirementSpecOrder;
+
+use strict;
+
+use base qw(SL::DB::Object);
+
+__PACKAGE__->meta->table('requirement_spec_orders');
+
+__PACKAGE__->meta->columns(
+  id                  => { type => 'serial', not_null => 1 },
+  itime               => { type => 'timestamp', default => 'now()', not_null => 1 },
+  mtime               => { type => 'timestamp', default => 'now()', not_null => 1 },
+  order_id            => { type => 'integer', not_null => 1 },
+  requirement_spec_id => { type => 'integer', not_null => 1 },
+  version_id          => { type => 'integer' },
+);
+
+__PACKAGE__->meta->primary_key_columns([ 'id' ]);
+
+__PACKAGE__->meta->unique_keys([ 'requirement_spec_id', 'order_id' ]);
+
+__PACKAGE__->meta->allow_inline_column_values(1);
+
+__PACKAGE__->meta->foreign_keys(
+  order => {
+    class       => 'SL::DB::Order',
+    key_columns => { order_id => 'id' },
+  },
+
+  requirement_spec => {
+    class       => 'SL::DB::RequirementSpec',
+    key_columns => { requirement_spec_id => 'id' },
+  },
+
+  version => {
+    class       => 'SL::DB::RequirementSpecVersion',
+    key_columns => { version_id => 'id' },
+  },
+);
+
+1;
+;
index fd0dddf..3c285e3 100644 (file)
@@ -14,9 +14,6 @@ __PACKAGE__->meta->columns(
   id             => { type => 'serial', not_null => 1 },
   itime          => { type => 'timestamp', default => 'now()' },
   mtime          => { type => 'timestamp' },
-  order_date     => { type => 'date' },
-  order_id       => { type => 'integer' },
-  order_number   => { type => 'text' },
   version_number => { type => 'integer' },
 );
 
@@ -24,12 +21,5 @@ __PACKAGE__->meta->primary_key_columns([ 'id' ]);
 
 __PACKAGE__->meta->allow_inline_column_values(1);
 
-__PACKAGE__->meta->foreign_keys(
-  order => {
-    class       => 'SL::DB::Order',
-    key_columns => { order_id => 'id' },
-  },
-);
-
 1;
 ;
diff --git a/SL/DB/RequirementSpecOrder.pm b/SL/DB/RequirementSpecOrder.pm
new file mode 100644 (file)
index 0000000..7a31eae
--- /dev/null
@@ -0,0 +1,13 @@
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::RequirementSpecOrder;
+
+use strict;
+
+use SL::DB::MetaSetup::RequirementSpecOrder;
+use SL::DB::Manager::RequirementSpecOrder;
+
+__PACKAGE__->meta->initialize;
+
+1;
diff --git a/sql/Pg-upgrade2/requirement_specs_orders.sql b/sql/Pg-upgrade2/requirement_specs_orders.sql
new file mode 100644 (file)
index 0000000..92deba2
--- /dev/null
@@ -0,0 +1,35 @@
+-- @tag: requirement_specs_orders
+-- @description: requirement_specs_orders
+-- @depends: requirement_specs requirement_specs_section_templates
+
+-- Remove unneeded columns
+ALTER TABLE requirement_spec_versions DROP CONSTRAINT requirement_spec_versions_order_id_fkey;
+
+ALTER TABLE requirement_spec_versions DROP COLUMN order_date;
+ALTER TABLE requirement_spec_versions DROP COLUMN order_number;
+ALTER TABLE requirement_spec_versions DROP COLUMN order_id;
+
+-- Add new columns to existing tables
+ALTER TABLE requirement_spec_items ADD COLUMN order_part_id INTEGER;
+ALTER TABLE requirement_spec_items ADD FOREIGN KEY (order_part_id) REFERENCES parts (id) ON DELETE SET NULL;
+
+ALTER TABLE defaults ADD COLUMN requirement_spec_section_order_part_id INTEGER;
+ALTER TABLE defaults ADD FOREIGN KEY (requirement_spec_section_order_part_id) REFERENCES parts (id) ON DELETE SET NULL;
+
+-- Create new tables
+CREATE TABLE requirement_spec_orders (
+  id                  SERIAL,
+  requirement_spec_id INTEGER NOT NULL,
+  order_id            INTEGER NOT NULL,
+  version_id          INTEGER,
+  itime               TIMESTAMP NOT NULL DEFAULT now(),
+  mtime               TIMESTAMP NOT NULL DEFAULT now(),
+
+  PRIMARY KEY (id),
+  FOREIGN KEY (requirement_spec_id) REFERENCES requirement_specs         (id) ON DELETE CASCADE,
+  FOREIGN KEY (order_id)            REFERENCES oe                        (id) ON DELETE CASCADE,
+  FOREIGN KEY (version_id)          REFERENCES requirement_spec_versions (id) ON DELETE SET NULL,
+  CONSTRAINT requirement_spec_id_order_id_unique UNIQUE (requirement_spec_id, order_id)
+);
+
+CREATE TRIGGER mtime_requirement_spec_orders BEFORE UPDATE ON requirement_spec_orders FOR EACH ROW EXECUTE PROCEDURE set_mtime();