Finish major rework of schema

This commit is contained in:
Tom Bloor 2017-04-21 22:12:53 +01:00
parent dd7862d93d
commit 3be6289fc3
15 changed files with 157 additions and 318 deletions

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::AccountToken;
use strict;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::AgeRange;
use strict;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::Customer;
use strict;

View file

@ -41,7 +41,7 @@ __PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(
"transactions",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.sellerorganisationid_fk" => 'self.id' },
{ "foreign.seller_id" => 'self.id' },
{ cascade_copy => 0, cascade_delete => 0 },
);

View file

@ -5,7 +5,10 @@ use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime");
__PACKAGE__->load_components( qw/
InflateColumn::DateTime
TimeStamp
/);
__PACKAGE__->table("pending_organisations");
@ -42,16 +45,17 @@ __PACKAGE__->add_columns(
submitted_at => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(
"pending_transactions",
"transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction",
{
"foreign.pendingsellerorganisationid_fk" => "self.id",
"foreign.seller_id" => "self.id",
},
{ cascade_copy => 0, cascade_delete => 1 },
);

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::PendingTransaction;
use strict;
@ -8,43 +7,56 @@ use base 'DBIx::Class::Core';
__PACKAGE__->load_components( qw/
InflateColumn::DateTime
InflateColumn::FS
TimeStamp
/);
__PACKAGE__->table("PendingTransactions");
__PACKAGE__->table("pending_transactions");
__PACKAGE__->add_columns(
"pendingtransactionid",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"buyeruserid_fk",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"pendingsellerorganisationid_fk",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"valuemicrocurrency",
{ data_type => "integer", is_nullable => 0 },
"proof_image",
{
"id" => {
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
},
"buyer_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"seller_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"value" => {
data_type => "decimal",
size => [ 16, 2 ],
is_nullable => 0,
},
"proof_image" => {
data_type => "text",
is_nullable => 0,
},
"timedatesubmitted",
{ data_type => "datetime", is_nullable => 0 },
"submitted_at" => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
);
__PACKAGE__->set_primary_key("pendingtransactionid");
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"buyeruserid_fk",
"buyer",
"Pear::LocalLoop::Schema::Result::User",
{ id => "buyeruserid_fk" },
{ id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
__PACKAGE__->belongs_to(
"pendingsellerorganisationid_fk",
"seller",
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
{ id => "pendingsellerorganisationid_fk" },
{ id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);

View file

@ -1,122 +1,39 @@
use utf8;
package Pear::LocalLoop::Schema::Result::SessionToken;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
=head1 NAME
Pear::LocalLoop::Schema::Result::SessionToken
=cut
use strict;
use warnings;
use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED
=over 4
=item * L<DBIx::Class::InflateColumn::DateTime>
=back
=cut
__PACKAGE__->load_components("InflateColumn::DateTime");
=head1 TABLE: C<SessionTokens>
=cut
__PACKAGE__->table("SessionTokens");
=head1 ACCESSORS
=head2 sessiontokenid
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
=head2 sessiontokenname
data_type: 'text'
is_nullable: 0
=head2 useridassignedto_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 expiredatetime
data_type: 'integer'
is_nullable: 0
=cut
__PACKAGE__->table("session_tokens");
__PACKAGE__->add_columns(
"sessiontokenid",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"sessiontokenname",
{ data_type => "text", is_nullable => 0 },
"useridassignedto_fk",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"expiredatetime",
{ data_type => "datetime", is_nullable => 0 },
"id" => {
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
},
"token" => {
data_type => "varchar",
size => 255,
is_nullable => 0,
},
"user_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
);
=head1 PRIMARY KEY
__PACKAGE__->set_primary_key("id");
=over 4
=item * L</sessiontokenid>
=back
=cut
__PACKAGE__->set_primary_key("sessiontokenid");
=head1 UNIQUE CONSTRAINTS
=head2 C<sessiontokenname_unique>
=over 4
=item * L</sessiontokenname>
=back
=cut
__PACKAGE__->add_unique_constraint("sessiontokenname_unique", ["sessiontokenname"]);
=head1 RELATIONS
=head2 useridassignedto_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::User>
=cut
__PACKAGE__->add_unique_constraint(["token"]);
__PACKAGE__->belongs_to(
"user",
"Pear::LocalLoop::Schema::Result::User",
{ id => "useridassignedto_fk" },
{ id => "user_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/mNAPeSmfsDSIpey+eUucg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;

View file

@ -1,144 +1,63 @@
use utf8;
package Pear::LocalLoop::Schema::Result::Transaction;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
=head1 NAME
Pear::LocalLoop::Schema::Result::Transaction
=cut
use strict;
use warnings;
use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED
=over 4
=item * L<DBIx::Class::InflateColumn::DateTime>
=back
=cut
__PACKAGE__->load_components(qw/
InflateColumn::DateTime
InflateColumn::FS
TimeStamp
/);
=head1 TABLE: C<Transactions>
=cut
__PACKAGE__->table("Transactions");
=head1 ACCESSORS
=head2 transactionid
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
=head2 buyeruserid_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 sellerorganisationid_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 valuemicrocurrency
data_type: 'integer'
is_nullable: 0
=head2 proofimage
data_type: 'text'
is_nullable: 0
=head2 timedatesubmitted
data_type: 'integer'
is_nullable: 0
=cut
__PACKAGE__->table("transactions");
__PACKAGE__->add_columns(
"transactionid",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"buyeruserid_fk",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"sellerorganisationid_fk",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"valuemicrocurrency",
{ data_type => "integer", is_nullable => 0 },
"proof_image",
{
"id" => {
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
},
"buyer_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"seller_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"value" => {
data_type => "decimal",
size => [ 16, 2 ],
is_nullable => 0,
},
"proof_image" => {
data_type => "text",
is_nullable => 0,
},
"timedatesubmitted",
{ data_type => "datetime", is_nullable => 0 },
"submitted_at" => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
);
=head1 PRIMARY KEY
=over 4
=item * L</transactionid>
=back
=cut
__PACKAGE__->set_primary_key("transactionid");
=head1 RELATIONS
=head2 buyeruserid_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::User>
=cut
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"buyeruserid_fk",
"buyer",
"Pear::LocalLoop::Schema::Result::User",
{ id => "buyeruserid_fk" },
{ id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
=head2 sellerorganisationid_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
=cut
__PACKAGE__->belongs_to(
"sellerorganisationid_fk",
"seller",
"Pear::LocalLoop::Schema::Result::Organisation",
{ id => "sellerorganisationid_fk" },
{ id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CfPoE2egoSD1tKo7fYjZdg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::User;
use strict;
@ -6,6 +5,8 @@ use warnings;
use base 'DBIx::Class::Core';
use Data::UUID;
__PACKAGE__->load_components( qw/
InflateColumn::DateTime
PassphraseColumn
@ -70,7 +71,7 @@ __PACKAGE__->might_have(
__PACKAGE__->belongs_to(
"customer",
"Pear::LocalLoop::Schema::Result::Customer",
{ id => "customer_id" },
{ "foreign.id" => "self.customer_id" },
{
is_deferrable => 0,
join_type => "LEFT",
@ -82,7 +83,7 @@ __PACKAGE__->belongs_to(
__PACKAGE__->belongs_to(
"organisation",
"Pear::LocalLoop::Schema::Result::Organisation",
{ id => "organisation_id" },
{ "foreign.id" => "self.organisation_id" },
{
is_deferrable => 0,
join_type => "LEFT",
@ -101,22 +102,36 @@ __PACKAGE__->has_many(
__PACKAGE__->has_many(
"pending_transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction",
{ "foreign.buyeruserid_fk" => "self.id" },
{ "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"session_tokens",
"Pear::LocalLoop::Schema::Result::SessionToken",
{ "foreign.useridassignedto_fk" => "self.id" },
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"transactions",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.buyeruserid_fk" => "self.id" },
{ "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub generate_session {
my $self = shift;
my $token = Data::UUID->new->create_str();
$self->create_related(
'session_tokens',
{
token => $token,
},
);
return $token;
}
1;