From: Justin Hunter Date: Sat, 11 Jul 2009 19:28:31 +0000 (-0700) Subject: add PrimaryKey and ForeignKey classes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fbf61b974d223040b2415f861e09426093440995;p=dbsrgits%2FSQL-Translator-2.0-ish.git add PrimaryKey and ForeignKey classes --- diff --git a/lib/SQL/Translator/Object/ForeignKey.pm b/lib/SQL/Translator/Object/ForeignKey.pm new file mode 100644 index 0000000..6f0f19f --- /dev/null +++ b/lib/SQL/Translator/Object/ForeignKey.pm @@ -0,0 +1,16 @@ +package SQL::Translator::Object::ForeignKey; +use Moose; +use SQL::Translator::Types qw(Index PrimaryKey); +extends 'SQL::Translator::Object::Constraint'; + +has '+type' => ( + default => 'FOREIGN_KEY', +); + +has 'references' => ( + isa => PrimaryKey | Index, + is => 'rw', + required => 1, +); + +1; diff --git a/lib/SQL/Translator/Object/PrimaryKey.pm b/lib/SQL/Translator/Object/PrimaryKey.pm new file mode 100644 index 0000000..8a1b16c --- /dev/null +++ b/lib/SQL/Translator/Object/PrimaryKey.pm @@ -0,0 +1,9 @@ +package SQL::Translator::Object::PrimaryKey; +use Moose; +extends 'SQL::Translator::Object::Index'; + +has '+type' => ( + default => 'PRIMARY_KEY', +); + +1; diff --git a/lib/SQL/Translator/Types.pm b/lib/SQL/Translator/Types.pm index 1693303..ed89687 100644 --- a/lib/SQL/Translator/Types.pm +++ b/lib/SQL/Translator/Types.pm @@ -1,10 +1,12 @@ package SQL::Translator::Types; use MooseX::Types::Moose qw(ArrayRef CodeRef Str); -use MooseX::Types -declare, [qw(Column Constraint Index Procedure Schema Sequence Table Trigger View DBIHandle)]; +use MooseX::Types -declare, [qw(Column Constraint ForeignKey Index PrimaryKey Procedure Schema Sequence Table Trigger View DBIHandle)]; class_type Column, { class => 'SQL::Translator::Object::Column' }; class_type Constraint, { class => 'SQL::Translator::Object::Constraint' }; +class_type ForeignKey, { class => 'SQL::Translator::Object::ForeignKey' }; class_type Index, { class => 'SQL::Translator::Object::Index' }; +class_type PrimaryKey, { class => 'SQL::Translator::Object::PrimaryKey' }; class_type Procedure, { class => 'SQL::Translator::Object::Procedure' }; class_type Schema, { class => 'SQL::Translator::Object::Schema' }; class_type Sequence, { class=> 'SQL::Translator::Object::Sequence' };