TT#5826 add contact.timezone, add timezone views

* add voip_subscriber_timezone (view)
    * add voip_contract_timezone (view)
    * add voip_reseller_timezone (view)

Change-Id: Ib61df3627b7f8f06753beb0652a297c45cd043ad
changes/47/10947/14
Kirill Solomko 9 years ago
parent 84d5bcef26
commit 2433052dae

@ -110,6 +110,8 @@ __PACKAGE__->add_columns(
extra => { list => [ "active", "terminated"] }, extra => { list => [ "active", "terminated"] },
is_nullable => 0, is_nullable => 0,
}, },
"timezone",
{ data_type => "varchar", is_nullable => 1, size => 80 },
); );
__PACKAGE__->set_primary_key("id"); __PACKAGE__->set_primary_key("id");
@ -302,6 +304,12 @@ NGCP::Schema::Result::contacts
is_nullable: 1 is_nullable: 1
size: 31 size: 31
=head2 timezone
data_type: 'varchar'
is_nullable: 1
size: 80
=head1 PRIMARY KEY =head1 PRIMARY KEY
=over 4 =over 4

@ -0,0 +1,58 @@
package NGCP::Schema::Result::contract_timezone;
use Scalar::Util qw(blessed);
use base qw/DBIx::Class::Core/;
our $VERSION = '2.007';
__PACKAGE__->load_components(
"InflateColumn::DateTime",
"Helper::Row::ToJSON",
"+NGCP::Schema::InflateColumn::DateTime::EpochMicro",
);
__PACKAGE__->table("billing.v_contract_timezone");
__PACKAGE__->add_columns(
"contact_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 1,
},
"contract_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 0,
},
"name",
{
data_type => "varchar",
size => 80,
is_nullable => 1,
},
);
__PACKAGE__->belongs_to(
"contract",
"NGCP::Schema::Result::contracts",
{ id => "contract_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"contact",
"NGCP::Schema::Result::contacts",
{ id => "contact_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub TO_JSON {
my ($self) = @_;
return {
map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method }
};
}
1;

@ -0,0 +1,58 @@
package NGCP::Schema::Result::reseller_timezone;
use Scalar::Util qw(blessed);
use base qw/DBIx::Class::Core/;
our $VERSION = '2.007';
__PACKAGE__->load_components(
"InflateColumn::DateTime",
"Helper::Row::ToJSON",
"+NGCP::Schema::InflateColumn::DateTime::EpochMicro",
);
__PACKAGE__->table("billing.v_reseller_timezone");
__PACKAGE__->add_columns(
"contact_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 1,
},
"reseller_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 0,
},
"name",
{
data_type => "varchar",
size => 80,
is_nullable => 1,
},
);
__PACKAGE__->belongs_to(
"reseller",
"NGCP::Schema::Result::resellers",
{ id => "reseller_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"contact",
"NGCP::Schema::Result::contacts",
{ id => "contact_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub TO_JSON {
my ($self) = @_;
return {
map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method }
};
}
1;

@ -0,0 +1,51 @@
package NGCP::Schema::Result::timezones;
use Scalar::Util qw(blessed);
use base qw/DBIx::Class::Core/;
our $VERSION = '2.007';
__PACKAGE__->load_components(
"InflateColumn::DateTime",
"Helper::Row::ToJSON",
"+NGCP::Schema::InflateColumn::DateTime::EpochMicro",
);
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table("timezones");
__PACKAGE__->add_columns(
"id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 0,
},
"name",
{
data_type => "varchar",
size => 80,
is_nullable => 0,
},
);
sub TO_JSON {
my ($self) = @_;
return {
map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method }
};
}
my $timezones_sql = 'SELECT @rc:=@rc+1 as id, t.name FROM (' .
(join " UNION ALL ",
map { sprintf "SELECT '%s' as name", $_ }
DateTime::TimeZone->all_names) .
') t, (SELECT @rc:=0) as cnt';
__PACKAGE__->set_primary_key("name");
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition($timezones_sql);
1;

@ -0,0 +1,71 @@
package NGCP::Schema::Result::voip_subscriber_timezone;
use Scalar::Util qw(blessed);
use base qw/DBIx::Class::Core/;
our $VERSION = '2.007';
__PACKAGE__->load_components(
"InflateColumn::DateTime",
"Helper::Row::ToJSON",
"+NGCP::Schema::InflateColumn::DateTime::EpochMicro",
);
__PACKAGE__->table("billing.v_subscriber_timezone");
__PACKAGE__->add_columns(
"contact_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 1,
},
"subscriber_id",
{
data_type => "integer",
extra => { unsigned => 1 },
is_nullable => 0,
},
"uuid",
{
data_type => "char",
size => 36,
is_nullable => 0,
},
"name",
{
data_type => "varchar",
size => 80,
is_nullable => 1,
},
);
__PACKAGE__->belongs_to(
"voip_subscriber",
"NGCP::Schema::Result::voip_subscribers",
{ id => "subscriber_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"contract",
"NGCP::Schema::Result::contracts",
{ id => "contract_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"contact",
"NGCP::Schema::Result::contacts",
{ id => "contact_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub TO_JSON {
my ($self) = @_;
return {
map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method }
};
}
1;

@ -110,6 +110,13 @@ __PACKAGE__->might_have(
{ cascade_copy => 0, cascade_delete => 0 }, { cascade_copy => 0, cascade_delete => 0 },
); );
__PACKAGE__->might_have(
"timezone",
'NGCP::Schema::Result::voip_subscriber_timezone',
{ 'foreign.subscriber_id' => 'self.id' },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"contact", "contact",
"NGCP::Schema::Result::contacts", "NGCP::Schema::Result::contacts",

Loading…
Cancel
Save