From 07ed8a1e4829568907a4bdff139bc2ebd497fc8b Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 24 Nov 2016 19:27:00 +0100 Subject: [PATCH] TT#5004 add autoprov_firmwares_data schema * also remove data col from autoprof_firmwares Change-Id: Ic0ee9ca8afa31d15c7d5c395bb829ed7e596f714 --- lib/NGCP/Schema/Result/autoprov_firmwares.pm | 14 +-- .../Schema/Result/autoprov_firmwares_data.pm | 102 ++++++++++++++++++ 2 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 lib/NGCP/Schema/Result/autoprov_firmwares_data.pm diff --git a/lib/NGCP/Schema/Result/autoprov_firmwares.pm b/lib/NGCP/Schema/Result/autoprov_firmwares.pm index bba66b9b..85e31cd1 100644 --- a/lib/NGCP/Schema/Result/autoprov_firmwares.pm +++ b/lib/NGCP/Schema/Result/autoprov_firmwares.pm @@ -27,8 +27,6 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 1, size => 255 }, "filename", { data_type => "varchar", is_nullable => 1, size => 255 }, - "data", - { data_type => "longblob", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); @@ -40,6 +38,13 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +__PACKAGE__->has_many( + "firmware_data", + "NGCP::Schema::Result::autoprov_firmwares_data", + { "foreign.fw_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { @@ -84,11 +89,6 @@ NGCP::Schema::provisioning::Result::autoprov_firmwares is_foreign_key: 1 is_nullable: 0 -=head2 data - - data_type: 'longblob' - is_nullable: 0 - =head1 PRIMARY KEY =over 4 diff --git a/lib/NGCP/Schema/Result/autoprov_firmwares_data.pm b/lib/NGCP/Schema/Result/autoprov_firmwares_data.pm new file mode 100644 index 00000000..3caf1e0e --- /dev/null +++ b/lib/NGCP/Schema/Result/autoprov_firmwares_data.pm @@ -0,0 +1,102 @@ +package NGCP::Schema::Result::autoprov_firmwares_data; +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_firmwares_data"); + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_auto_increment => 1, + is_nullable => 0, + }, + "fw_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 0, + }, + "data", + { data_type => "longblob", is_nullable => 0 }, +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->belongs_to( + "firmware", + "NGCP::Schema::Result::autoprov_firmwares", + { id => "fw_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; +__END__ + +=encoding UTF-8 + +=head1 NAME + +NGCP::Schema::provisioning::Result::autoprov_firmwares + +=head1 COMPONENTS LOADED + +=over 4 + +=item * L + +=item * L + +=back + +=head1 TABLE: C + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + extra: {unsigned => 1} + is_auto_increment: 1 + is_nullable: 0 + +=head2 fw_id + + data_type: 'integer' + extra: {unsigned => 1} + is_foreign_key: 1 + is_nullable: 0 + +=head2 data + + data_type: 'longblob' + is_nullable: 0 + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=head1 RELATIONS + +=head2 firmware + +Type: belongs_to + +Related object: L