Skip to content

Commit fe97e34

Browse files
committed
Expand schema with more FK tables
1 parent 298c758 commit fe97e34

File tree

6 files changed

+233
-10
lines changed

6 files changed

+233
-10
lines changed

lib/PgDataApp/DB/Result/Complaint.pm

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ __PACKAGE__->add_columns(
2525
"case_region",
2626
{ data_type => "varchar", is_nullable => 1 },
2727
"case_country",
28-
{ data_type => "varchar", is_nullable => 1 },
28+
{ data_type => "varchar", is_foreign_key => 1, is_nullable => 1 },
2929
"sector",
3030
{ data_type => "varchar", is_nullable => 1 },
3131
"sub_sector",
@@ -41,7 +41,7 @@ __PACKAGE__->add_columns(
4141
"product_form_detail",
4242
{ data_type => "varchar", is_nullable => 1 },
4343
"flavor_scent_detail",
44-
{ data_type => "varchar", is_nullable => 1 },
44+
{ data_type => "varchar", is_foreign_key => 1, is_nullable => 1 },
4545
"collection",
4646
{ data_type => "varchar", is_nullable => 1 },
4747
"version",
@@ -83,7 +83,7 @@ __PACKAGE__->add_columns(
8383
"conclusion_code",
8484
{ data_type => "varchar", is_nullable => 1 },
8585
"store_of_purchase",
86-
{ data_type => "varchar", is_nullable => 1 },
86+
{ data_type => "varchar", is_foreign_key => 1, is_nullable => 1 },
8787
"complaint_metric",
8888
{ data_type => "varchar", is_nullable => 1 },
8989
"pc_invalid",
@@ -103,14 +103,47 @@ __PACKAGE__->belongs_to(
103103
{
104104
is_deferrable => 0,
105105
join_type => "LEFT",
106-
on_delete => "CASCADE",
106+
on_delete => "RESTRICT",
107+
on_update => "CASCADE",
108+
},
109+
);
110+
__PACKAGE__->belongs_to(
111+
"case_country",
112+
"PgDataApp::DB::Result::Country",
113+
{ name => "case_country" },
114+
{
115+
is_deferrable => 0,
116+
join_type => "LEFT",
117+
on_delete => "RESTRICT",
118+
on_update => "CASCADE",
119+
},
120+
);
121+
__PACKAGE__->belongs_to(
122+
"flavor_scent_detail",
123+
"PgDataApp::DB::Result::FlavorScent",
124+
{ name => "flavor_scent_detail" },
125+
{
126+
is_deferrable => 0,
127+
join_type => "LEFT",
128+
on_delete => "RESTRICT",
129+
on_update => "CASCADE",
130+
},
131+
);
132+
__PACKAGE__->belongs_to(
133+
"store_of_purchase",
134+
"PgDataApp::DB::Result::Store",
135+
{ name => "store_of_purchase" },
136+
{
137+
is_deferrable => 0,
138+
join_type => "LEFT",
139+
on_delete => "RESTRICT",
107140
on_update => "CASCADE",
108141
},
109142
);
110143

111144

112-
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-07-22 19:31:48
113-
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jKhZ8LQL931iVAuEaiiAdg
145+
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-07-22 20:08:58
146+
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SYJSSWQvFpcOpA/VwD4MYg
114147

115148
use PgDataApp::Util ':all';
116149

@@ -120,8 +153,20 @@ sub insert {
120153
my ($self, $columns) = @_;
121154
$self->set_inflated_columns($columns) if ($columns);
122155

123-
if(my $method = $self->get_column('case_contact_method')) {
124-
$self->schema->resultset('ContactMethod')->find_or_create({ method => $method });
156+
if(my $fk = $self->get_column('case_contact_method')) {
157+
$self->schema->resultset('ContactMethod')->find_or_create({ method => $fk });
158+
}
159+
160+
if(my $fk = $self->get_column('case_country')) {
161+
$self->schema->resultset('Country')->find_or_create({ name => $fk });
162+
}
163+
164+
if(my $fk = $self->get_column('flavor_scent_detail')) {
165+
$self->schema->resultset('FlavorScent')->find_or_create({ name => $fk });
166+
}
167+
168+
if(my $fk = $self->get_column('store_of_purchase')) {
169+
$self->schema->resultset('Store')->find_or_create({ name => $fk });
125170
}
126171

127172
my $invalid_pc = undef;

lib/PgDataApp/DB/Result/Country.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use utf8;
2+
package PgDataApp::DB::Result::Country;
3+
4+
# Created by DBIx::Class::Schema::Loader
5+
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6+
7+
use strict;
8+
use warnings;
9+
10+
use Moose;
11+
use MooseX::NonMoose;
12+
use MooseX::MarkAsMethods autoclean => 1;
13+
extends 'DBIx::Class::Core';
14+
__PACKAGE__->load_components("InflateColumn::DateTime");
15+
__PACKAGE__->table("country");
16+
__PACKAGE__->add_columns("name", { data_type => "varchar", is_nullable => 0 });
17+
__PACKAGE__->set_primary_key("name");
18+
__PACKAGE__->has_many(
19+
"complaints",
20+
"PgDataApp::DB::Result::Complaint",
21+
{ "foreign.case_country" => "self.name" },
22+
{ cascade_copy => 0, cascade_delete => 0 },
23+
);
24+
25+
26+
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-07-22 20:08:58
27+
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qDIkT6+YK0trwPj7pkGd4g
28+
29+
30+
# You can replace this text with custom code or comments, and it will be preserved on regeneration
31+
__PACKAGE__->meta->make_immutable;
32+
1;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use utf8;
2+
package PgDataApp::DB::Result::FlavorScent;
3+
4+
# Created by DBIx::Class::Schema::Loader
5+
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6+
7+
use strict;
8+
use warnings;
9+
10+
use Moose;
11+
use MooseX::NonMoose;
12+
use MooseX::MarkAsMethods autoclean => 1;
13+
extends 'DBIx::Class::Core';
14+
__PACKAGE__->load_components("InflateColumn::DateTime");
15+
__PACKAGE__->table("flavor_scent");
16+
__PACKAGE__->add_columns("name", { data_type => "varchar", is_nullable => 0 });
17+
__PACKAGE__->set_primary_key("name");
18+
__PACKAGE__->has_many(
19+
"complaints",
20+
"PgDataApp::DB::Result::Complaint",
21+
{ "foreign.flavor_scent_detail" => "self.name" },
22+
{ cascade_copy => 0, cascade_delete => 0 },
23+
);
24+
25+
26+
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-07-22 20:08:58
27+
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CWUn4Bn2Sy6LWZXIA6lKXQ
28+
29+
30+
# You can replace this text with custom code or comments, and it will be preserved on regeneration
31+
__PACKAGE__->meta->make_immutable;
32+
1;

lib/PgDataApp/DB/Result/Store.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use utf8;
2+
package PgDataApp::DB::Result::Store;
3+
4+
# Created by DBIx::Class::Schema::Loader
5+
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6+
7+
use strict;
8+
use warnings;
9+
10+
use Moose;
11+
use MooseX::NonMoose;
12+
use MooseX::MarkAsMethods autoclean => 1;
13+
extends 'DBIx::Class::Core';
14+
__PACKAGE__->load_components("InflateColumn::DateTime");
15+
__PACKAGE__->table("store");
16+
__PACKAGE__->add_columns("name", { data_type => "varchar", is_nullable => 0 });
17+
__PACKAGE__->set_primary_key("name");
18+
__PACKAGE__->has_many(
19+
"complaints",
20+
"PgDataApp::DB::Result::Complaint",
21+
{ "foreign.store_of_purchase" => "self.name" },
22+
{ cascade_copy => 0, cascade_delete => 0 },
23+
);
24+
25+
26+
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-07-22 20:08:58
27+
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3RDvUqM5XRGtVu0hmpQ6Jw
28+
29+
30+
# You can replace this text with custom code or comments, and it will be preserved on regeneration
31+
__PACKAGE__->meta->make_immutable;
32+
1;

lib/PgDataApp/Model/DB.pm

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,72 @@ __PACKAGE__->config(
325325
},
326326
},
327327
},
328+
Country => {
329+
display_column => 'name',
330+
title => 'Country',
331+
title_multi => 'Country Rows',
332+
iconCls => 'ra-icon-pg',
333+
multiIconCls => 'ra-icon-pg-multi',
334+
columns => {
335+
name => {
336+
header => 'name',
337+
#width => 100,
338+
#renderer => 'RA.ux.App.someJsFunc',
339+
#profiles => [],
340+
},
341+
complaints => {
342+
header => 'complaints',
343+
#width => 100,
344+
#sortable => 1,
345+
#renderer => 'RA.ux.App.someJsFunc',
346+
#profiles => [],
347+
},
348+
},
349+
},
350+
FlavorScent => {
351+
display_column => 'name',
352+
title => 'FlavorScent',
353+
title_multi => 'FlavorScent Rows',
354+
iconCls => 'ra-icon-pg',
355+
multiIconCls => 'ra-icon-pg-multi',
356+
columns => {
357+
name => {
358+
header => 'name',
359+
#width => 100,
360+
#renderer => 'RA.ux.App.someJsFunc',
361+
#profiles => [],
362+
},
363+
complaints => {
364+
header => 'complaints',
365+
#width => 100,
366+
#sortable => 1,
367+
#renderer => 'RA.ux.App.someJsFunc',
368+
#profiles => [],
369+
},
370+
},
371+
},
372+
Store => {
373+
display_column => 'name',
374+
title => 'Store',
375+
title_multi => 'Store Rows',
376+
iconCls => 'ra-icon-pg',
377+
multiIconCls => 'ra-icon-pg-multi',
378+
columns => {
379+
name => {
380+
header => 'name',
381+
#width => 100,
382+
#renderer => 'RA.ux.App.someJsFunc',
383+
#profiles => [],
384+
},
385+
complaints => {
386+
header => 'complaints',
387+
#width => 100,
388+
#sortable => 1,
389+
#renderer => 'RA.ux.App.someJsFunc',
390+
#profiles => [],
391+
},
392+
},
393+
},
328394
},
329395
},
330396

sql/pgdataapp.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-- your DBIC schema classes and update your base TableSpec configs, run this command
88
-- from your app home directory:
99
--
10-
-- perl devel/model_DB_updater.pl --from-ddl --cfg
10+
-- perl devel/model_DB_updater.pl --from-ddl --cfg --go
1111
--
1212
--------------------------------------------------------------------------------
1313

@@ -16,6 +16,18 @@ CREATE TABLE [contact_method] (
1616
[method] varchar PRIMARY KEY NOT NULL
1717
);
1818

19+
CREATE TABLE [country] (
20+
[name] varchar PRIMARY KEY NOT NULL
21+
);
22+
23+
CREATE TABLE [flavor_scent] (
24+
[name] varchar PRIMARY KEY NOT NULL
25+
);
26+
27+
CREATE TABLE [store] (
28+
[name] varchar PRIMARY KEY NOT NULL
29+
);
30+
1931
CREATE TABLE [complaint] (
2032
[id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
2133
[initial_receipt_date] date,
@@ -59,6 +71,10 @@ CREATE TABLE [complaint] (
5971
[pc_plant_code] varchar,
6072
[pc_line_number] varchar,
6173

62-
FOREIGN KEY ([case_contact_method]) REFERENCES [contact_method] ([method]) ON DELETE CASCADE ON UPDATE CASCADE
74+
FOREIGN KEY ([case_contact_method]) REFERENCES [contact_method] ([method]) ON DELETE RESTRICT ON UPDATE CASCADE,
75+
FOREIGN KEY ([case_country]) REFERENCES [country] ([name]) ON DELETE RESTRICT ON UPDATE CASCADE,
76+
FOREIGN KEY ([flavor_scent_detail]) REFERENCES [flavor_scent] ([name]) ON DELETE RESTRICT ON UPDATE CASCADE,
77+
FOREIGN KEY ([store_of_purchase]) REFERENCES [store] ([name]) ON DELETE RESTRICT ON UPDATE CASCADE
78+
6379
);
6480

0 commit comments

Comments
 (0)