From d8381bdd3ef4c781ac61dd259bd2b4677fecc5e6 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Fri, 3 Jun 2016 22:07:46 +0200 Subject: [PATCH] =?utf8?q?Erzeugnisfremdschl=C3=BCssel=20auf=20Artikel?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Tabelle assemblies mit parts verknüpfen --- SL/DB/MetaSetup/Assembly.pm | 9 ++++++++- sql/Pg-upgrade2/assembly_parts_foreign_key.sql | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 sql/Pg-upgrade2/assembly_parts_foreign_key.sql diff --git a/SL/DB/MetaSetup/Assembly.pm b/SL/DB/MetaSetup/Assembly.pm index 51073406b..373f54e6b 100644 --- a/SL/DB/MetaSetup/Assembly.pm +++ b/SL/DB/MetaSetup/Assembly.pm @@ -14,7 +14,7 @@ __PACKAGE__->meta->columns( id => { type => 'integer' }, itime => { type => 'timestamp', default => 'now()' }, mtime => { type => 'timestamp' }, - parts_id => { type => 'integer' }, + parts_id => { type => 'integer', not_null => 1 }, qty => { type => 'float', scale => 4 }, ); @@ -22,5 +22,12 @@ __PACKAGE__->meta->primary_key_columns([ 'assembly_id' ]); __PACKAGE__->meta->allow_inline_column_values(1); +__PACKAGE__->meta->foreign_keys( + parts => { + class => 'SL::DB::Part', + key_columns => { parts_id => 'id' }, + }, +); + 1; ; diff --git a/sql/Pg-upgrade2/assembly_parts_foreign_key.sql b/sql/Pg-upgrade2/assembly_parts_foreign_key.sql new file mode 100644 index 000000000..8b3d4b260 --- /dev/null +++ b/sql/Pg-upgrade2/assembly_parts_foreign_key.sql @@ -0,0 +1,7 @@ +-- @tag: assembly_parts_foreign_key +-- @description: Erzeugniselement (assembly) erhält Fremdschlüssel auf parts + NOT NULL +-- @depends: release_3_4_1 +-- @ignore: 0 + +ALTER TABLE assembly ADD FOREIGN KEY (parts_id) REFERENCES parts(id); +ALTER TABLE assembly ALTER COLUMN parts_id SET NOT NULL; -- 2.20.1