diff --git a/lib/NGCP/Schema/Result/events.pm b/lib/NGCP/Schema/Result/events.pm index ca1480cb..be5062fb 100644 --- a/lib/NGCP/Schema/Result/events.pm +++ b/lib/NGCP/Schema/Result/events.pm @@ -51,6 +51,20 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +__PACKAGE__->has_many( + "relation_data", + "NGCP::Schema::Result::events_relation_data", + { "foreign.event_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "tag_data", + "NGCP::Schema::Result::events_tag_data", + { "foreign.event_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/events_relation.pm b/lib/NGCP/Schema/Result/events_relation.pm new file mode 100644 index 00000000..68047b36 --- /dev/null +++ b/lib/NGCP/Schema/Result/events_relation.pm @@ -0,0 +1,49 @@ +package NGCP::Schema::Result::events_relation; + +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", +); + +__PACKAGE__->table("accounting.events_relation"); + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_auto_increment => 1, + is_nullable => 0, + }, + "type", + { + data_type => "enum", + extra => { list => [ + 'primary_number_id', + 'subscriber_profile_id', + 'subscriber_profile_set_id', + 'pilot_primary_number_id', + 'pilot_subscriber_profile_id', + 'pilot_subscriber_profile_set_id', + ] }, + is_nullable => 0, + }, +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->add_unique_constraint("erc_type_idx", ["type"]); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; diff --git a/lib/NGCP/Schema/Result/events_relation_data.pm b/lib/NGCP/Schema/Result/events_relation_data.pm new file mode 100644 index 00000000..2cbf20c9 --- /dev/null +++ b/lib/NGCP/Schema/Result/events_relation_data.pm @@ -0,0 +1,52 @@ +package NGCP::Schema::Result::events_relation_data; + +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMilli", +); + +__PACKAGE__->table("accounting.events_relation_data"); + +__PACKAGE__->add_columns( + "event_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "relation_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "val", + { data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0 }, + "event_timestamp", + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, + +); + +__PACKAGE__->set_primary_key("event_id","relation_id","event_timestamp"); + +__PACKAGE__->has_one( + "relation", + 'NGCP::Schema::Result::events_relation', + { 'foreign.id' => 'self.relation_id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; diff --git a/lib/NGCP/Schema/Result/events_tag.pm b/lib/NGCP/Schema/Result/events_tag.pm new file mode 100644 index 00000000..8687b187 --- /dev/null +++ b/lib/NGCP/Schema/Result/events_tag.pm @@ -0,0 +1,53 @@ +package NGCP::Schema::Result::events_tag; + +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", +); + +__PACKAGE__->table("accounting.events_tag"); + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_auto_increment => 1, + is_nullable => 0, + }, + "type", + { + data_type => "enum", + extra => { list => [ + 'primary_number_cc', + 'primary_number_ac', + 'primary_number_sn', + 'pilot_primary_number_cc', + 'pilot_primary_number_ac', + 'pilot_primary_number_sn', + 'subscriber_profile_name', + 'subscriber_profile_set_name', + 'pilot_subscriber_profile_name', + 'pilot_subscriber_profile_set_name', + ] }, + is_nullable => 0, + }, +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->add_unique_constraint("etc_type_idx", ["type"]); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; diff --git a/lib/NGCP/Schema/Result/events_tag_data.pm b/lib/NGCP/Schema/Result/events_tag_data.pm new file mode 100644 index 00000000..85c5c14e --- /dev/null +++ b/lib/NGCP/Schema/Result/events_tag_data.pm @@ -0,0 +1,52 @@ +package NGCP::Schema::Result::events_tag_data; + +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMilli", +); + +__PACKAGE__->table("accounting.events_tag_data"); + +__PACKAGE__->add_columns( + "event_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "tag_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "val", + { data_type => "text", is_nullable => 0 }, + "event_timestamp", + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, + +); + +__PACKAGE__->set_primary_key("event_id","tag_id","event_timestamp"); + +__PACKAGE__->has_one( + "relation", + 'NGCP::Schema::Result::events_tag', + { 'foreign.id' => 'self.tag_id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1;