diff --git a/lib/NGCP/Schema/Result/billing_profiles.pm b/lib/NGCP/Schema/Result/billing_profiles.pm index f912b62e..a5775785 100644 --- a/lib/NGCP/Schema/Result/billing_profiles.pm +++ b/lib/NGCP/Schema/Result/billing_profiles.pm @@ -170,6 +170,20 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "before_topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.profile_before_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "after_topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.profile_after_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/cdr.pm b/lib/NGCP/Schema/Result/cdr.pm index fb9266fc..9693f726 100644 --- a/lib/NGCP/Schema/Result/cdr.pm +++ b/lib/NGCP/Schema/Result/cdr.pm @@ -140,9 +140,9 @@ __PACKAGE__->add_columns( "call_code", { data_type => "char", is_nullable => 0, size => 3 }, "init_time", - { data_type => "decimal", is_nullable => 0, size => [13, 3] }, + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, "start_time", - { data_type => "decimal", is_nullable => 0, size => [13, 3] }, + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, "duration", { data_type => "decimal", is_nullable => 0, size => [13, 3] }, "call_id", @@ -241,14 +241,6 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -for my $col (qw/init_time start_time/) { - if(__PACKAGE__->has_column($col)) { - __PACKAGE__->remove_column($col); - __PACKAGE__->add_column($col => - { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' } - ); - } -} __PACKAGE__->belongs_to( "source_customer_billing_zones_history", "NGCP::Schema::Result::billing_zones_history", diff --git a/lib/NGCP/Schema/Result/contract_balances.pm b/lib/NGCP/Schema/Result/contract_balances.pm index 9cbab43d..e61b7469 100644 --- a/lib/NGCP/Schema/Result/contract_balances.pm +++ b/lib/NGCP/Schema/Result/contract_balances.pm @@ -96,6 +96,20 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->has_many( + "before_topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.contract_balance_before_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "after_topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.contract_balance_after_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/contracts.pm b/lib/NGCP/Schema/Result/contracts.pm index bf2429dd..ec8dae17 100644 --- a/lib/NGCP/Schema/Result/contracts.pm +++ b/lib/NGCP/Schema/Result/contracts.pm @@ -265,6 +265,13 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->has_many( + "topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.contract_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/journals.pm b/lib/NGCP/Schema/Result/journals.pm index c149d896..da6c39c4 100644 --- a/lib/NGCP/Schema/Result/journals.pm +++ b/lib/NGCP/Schema/Result/journals.pm @@ -34,7 +34,7 @@ __PACKAGE__->add_columns( is_nullable => 0, }, "timestamp", - { data_type => "decimal", is_nullable => 0, size => [13, 3] }, + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, "username", { data_type => "varchar", is_nullable => 1, size => 127 }, "content_format", @@ -50,15 +50,6 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -for my $col (qw/timestamp/) { - if(__PACKAGE__->has_column($col)) { - __PACKAGE__->remove_column($col); - __PACKAGE__->add_column($col => - { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' } - ); - } -} - sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/malicious_calls.pm b/lib/NGCP/Schema/Result/malicious_calls.pm index 2d44a434..8dcdd46f 100644 --- a/lib/NGCP/Schema/Result/malicious_calls.pm +++ b/lib/NGCP/Schema/Result/malicious_calls.pm @@ -27,7 +27,7 @@ __PACKAGE__->add_columns( "callee", { data_type => "varchar", is_nullable => 0, size => 255 }, "start_time", - { data_type => "decimal", is_nullable => 0, size => [13,3] }, + { data_type => "decimal", is_nullable => 0, size => [13,3], inflate_datetime => 'epoch_milli' }, "duration", { data_type => "decimal", is_nullable => 0, size => [13,3] }, "source", @@ -43,15 +43,6 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -for my $col (qw/start_time/) { - if(__PACKAGE__->has_column($col)) { - __PACKAGE__->remove_column($col); - __PACKAGE__->add_column($col => - { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' } - ); - } -} - __PACKAGE__->add_unique_constraint("mcid_callid_idx", ["call_id"]); __PACKAGE__->belongs_to( diff --git a/lib/NGCP/Schema/Result/messages.pm b/lib/NGCP/Schema/Result/messages.pm index ca8efcf0..4ff92760 100644 --- a/lib/NGCP/Schema/Result/messages.pm +++ b/lib/NGCP/Schema/Result/messages.pm @@ -21,7 +21,7 @@ __PACKAGE__->add_columns( is_nullable => 0, }, "timestamp", - { data_type => "decimal", is_nullable => 0, size => [17, 6] }, + { data_type => "decimal", is_nullable => 0, size => [17, 6], inflate_datetime => 'epoch_micro' }, "protocol", { data_type => "enum", @@ -74,15 +74,6 @@ __PACKAGE__->has_many( __PACKAGE__->set_primary_key("id"); -for my $col (qw/timestamp/) { - if(__PACKAGE__->has_column($col)) { - __PACKAGE__->remove_column($col); - __PACKAGE__->add_column($col => - { data_type => "decimal", is_nullable => 0, size => [17, 6], inflate_datetime => 'epoch_micro' } - ); - } -} - sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/profile_packages.pm b/lib/NGCP/Schema/Result/profile_packages.pm index 1737a171..26218aee 100644 --- a/lib/NGCP/Schema/Result/profile_packages.pm +++ b/lib/NGCP/Schema/Result/profile_packages.pm @@ -175,6 +175,20 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "before_topup_log", + "NGCP::Schema::Result::topup_log", + { 'foreign.package_before_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "after_topup_log", + "NGCP::Schema::Result::topup_log", + { 'foreign.package_after_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub _join_condition { my ($args,$discriminator) = @_; return { #[{ diff --git a/lib/NGCP/Schema/Result/subscriber.pm b/lib/NGCP/Schema/Result/subscriber.pm index f29c6ad6..2821aefd 100644 --- a/lib/NGCP/Schema/Result/subscriber.pm +++ b/lib/NGCP/Schema/Result/subscriber.pm @@ -61,6 +61,13 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.subscriber_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/topup_logs.pm b/lib/NGCP/Schema/Result/topup_logs.pm new file mode 100644 index 00000000..41e55ed4 --- /dev/null +++ b/lib/NGCP/Schema/Result/topup_logs.pm @@ -0,0 +1,196 @@ +package NGCP::Schema::Result::topup_logs; +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("billing.topup_log"); + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + + "username", + { data_type => "varchar", is_nullable => 1, size => 127 }, + "timestamp", + { data_type => "decimal", is_nullable => 0, size => [13, 3], inflate_datetime => 'epoch_milli' }, + + "type", + { + data_type => "enum", + extra => { list => ["cash", "voucher"] }, + is_nullable => 0, + }, + "outcome", + { + data_type => "enum", + extra => { list => ["ok", "failed"] }, + is_nullable => 0, + }, + "message", + { data_type => "varchar", is_nullable => 1, size => 255 }, + + "subscriber_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + "contract_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + + "amount", + { data_type => "double precision", default_value => 0, is_nullable => 1 }, + "voucher_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + + "cash_balance_before", + { data_type => "double precision", default_value => 0, is_nullable => 1 }, + + "cash_balance_after", + { data_type => "double precision", default_value => 0, is_nullable => 1 }, + + "package_before_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + "package_after_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + + "profile_before_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + "profile_after_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + + "lock_level_before", + { data_type => "tinyint", extra => { unsigned => 1 }, is_nullable => 1 }, + "lock_level_after", + { data_type => "tinyint", extra => { unsigned => 1 }, is_nullable => 1 }, + + "contract_balance_before_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + "contract_balance_after_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 1, + }, + + "request_token", + { data_type => "varchar", is_nullable => 1, size => 255 }, + +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->belongs_to( + "subscriber", + "NGCP::Schema::Result::voip_subscribers", + { "foreign.id" => "self.subscriber_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "contract", + "NGCP::Schema::Result::contracts", + { "foreign.id" => "self.contract_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "voucher", + "NGCP::Schema::Result::vouchers", + { "foreign.id" => "self.voucher_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "old_package", + "NGCP::Schema::Result::profile_packages", + { "foreign.id" => "self.package_before_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "new_package", + "NGCP::Schema::Result::profile_packages", + { "foreign.id" => "self.package_after_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "old_profile", + "NGCP::Schema::Result::billing_profiles", + { "foreign.id" => "self.profile_before_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "new_profile", + "NGCP::Schema::Result::billing_profiles", + { "foreign.id" => "self.profile_after_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "old_contract_balance", + "NGCP::Schema::Result::contract_balances", + { "foreign.id" => "self.contract_balance_before_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "new_contract_balance", + "NGCP::Schema::Result::contract_balances", + { "foreign.id" => "self.contract_balance_after_id" }, + { is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", on_update => "CASCADE" }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; \ No newline at end of file diff --git a/lib/NGCP/Schema/Result/voicemail_spool.pm b/lib/NGCP/Schema/Result/voicemail_spool.pm index 83b475a1..55cdaa63 100644 --- a/lib/NGCP/Schema/Result/voicemail_spool.pm +++ b/lib/NGCP/Schema/Result/voicemail_spool.pm @@ -62,14 +62,15 @@ __PACKAGE__->belongs_to( }, ); -for my $col (qw/origtime/) { - if(__PACKAGE__->has_column($col)) { - __PACKAGE__->remove_column($col); - __PACKAGE__->add_column($col => - { data_type => "varchar", is_nullable => 0, inflate_datetime => 'epoch_string' } - ); - } -} +#is_nullable => 0 is changed here! why? +#for my $col (qw/origtime/) { +# if(__PACKAGE__->has_column($col)) { +# __PACKAGE__->remove_column($col); +# __PACKAGE__->add_column($col => +# { data_type => "varchar", is_nullable => 0, inflate_datetime => 'epoch_string' } +# ); +# } +#} sub TO_JSON { my ($self) = @_; diff --git a/lib/NGCP/Schema/Result/vouchers.pm b/lib/NGCP/Schema/Result/vouchers.pm index b3095d6f..e174353c 100644 --- a/lib/NGCP/Schema/Result/vouchers.pm +++ b/lib/NGCP/Schema/Result/vouchers.pm @@ -121,6 +121,13 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->has_many( + "topup_log", + "NGCP::Schema::Result::topup_logs", + { 'foreign.voucher_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return {