From a95679e56baa98f3dce1ef9ef56e32afbda9429b Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 1 Aug 2014 13:22:47 +0200 Subject: [PATCH] MT#8299 Add pbx device model annotations --- .../autoprov_device_line_annotations.pm | 72 +++++++++++++++++++ .../Result/autoprov_device_line_ranges.pm | 7 ++ 2 files changed, 79 insertions(+) create mode 100644 lib/NGCP/Schema/Result/autoprov_device_line_annotations.pm diff --git a/lib/NGCP/Schema/Result/autoprov_device_line_annotations.pm b/lib/NGCP/Schema/Result/autoprov_device_line_annotations.pm new file mode 100644 index 00000000..f120fc51 --- /dev/null +++ b/lib/NGCP/Schema/Result/autoprov_device_line_annotations.pm @@ -0,0 +1,72 @@ +package NGCP::Schema::Result::autoprov_device_line_annotations; +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components("InflateColumn::DateTime", "Helper::Row::ToJSON"); + +__PACKAGE__->table("provisioning.autoprov_device_line_annotations"); + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_auto_increment => 1, + is_nullable => 0, + }, + "range_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 0, + }, + "line_index", + { + data_type => "integer", + default_value => 0, + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "x", + { + data_type => "integer", + default_value => 0, + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "y", + { + data_type => "integer", + default_value => 0, + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "position", + { + data_type => "enum", + default_value => "top", + extra => { list => ["top", "bottom", "left", "right"] }, + is_nullable => 0, + }, +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->belongs_to( + "range", + "NGCP::Schema::Result::autoprov_device_line_ranges", + { id => "range_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; diff --git a/lib/NGCP/Schema/Result/autoprov_device_line_ranges.pm b/lib/NGCP/Schema/Result/autoprov_device_line_ranges.pm index 6a3ab317..1d8477b8 100644 --- a/lib/NGCP/Schema/Result/autoprov_device_line_ranges.pm +++ b/lib/NGCP/Schema/Result/autoprov_device_line_ranges.pm @@ -71,6 +71,13 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "annotations", + "NGCP::Schema::Result::autoprov_device_line_annotations", + { "foreign.range_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return {