diff --git a/DB/etc/schema.sql b/DB/etc/schema.sql index 1999b4d..b14c28d 100644 --- a/DB/etc/schema.sql +++ b/DB/etc/schema.sql @@ -11,6 +11,16 @@ CREATE TABLE person ( created_at timestamptz not null default current_timestamp ); +-- For stripe subscriptions +CREATE TABLE subscription ( + id serial PRIMARY KEY, + person_id int not null unique references person(id), + stripe_customer_id text , + is_valid boolean not null default false, + last_checked_at timestamptz not null default current_timestamp, + created_at timestamptz not null default current_timestamp +); + -- Allow notes to be made about a person (Admin Panel -> People -> Person) CREATE TABLE person_note ( id serial PRIMARY KEY, diff --git a/DB/lib/MJB/DB/Result/Person.pm b/DB/lib/MJB/DB/Result/Person.pm index 83861e9..ec2b1b1 100644 --- a/DB/lib/MJB/DB/Result/Person.pm +++ b/DB/lib/MJB/DB/Result/Person.pm @@ -276,9 +276,24 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 subscription -# Created by DBIx::Class::Schema::Loader v0.07051 @ 2022-11-30 08:15:37 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Qd7nLf0vOON2dDPyaISk8g +Type: might_have + +Related object: L + +=cut + +__PACKAGE__->might_have( + "subscription", + "MJB::DB::Result::Subscription", + { "foreign.person_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07051 @ 2022-12-05 17:03:53 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3HftwG4z/Uy9wCkoSBRk2Q sub as_hashref { my ( $self ) = @_; diff --git a/DB/lib/MJB/DB/Result/Subscription.pm b/DB/lib/MJB/DB/Result/Subscription.pm new file mode 100644 index 0000000..0566439 --- /dev/null +++ b/DB/lib/MJB/DB/Result/Subscription.pm @@ -0,0 +1,165 @@ +use utf8; +package MJB::DB::Result::Subscription; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +MJB::DB::Result::Subscription + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 COMPONENTS LOADED + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->load_components("InflateColumn::DateTime", "InflateColumn::Serializer"); + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("subscription"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + sequence: 'subscription_id_seq' + +=head2 person_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 stripe_customer_id + + data_type: 'text' + is_nullable: 1 + +=head2 is_valid + + data_type: 'boolean' + default_value: false + is_nullable: 0 + +=head2 last_checked_at + + data_type: 'timestamp with time zone' + default_value: current_timestamp + is_nullable: 0 + +=head2 created_at + + data_type: 'timestamp with time zone' + default_value: current_timestamp + is_nullable: 0 + +=cut + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "subscription_id_seq", + }, + "person_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "stripe_customer_id", + { data_type => "text", is_nullable => 1 }, + "is_valid", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "last_checked_at", + { + data_type => "timestamp with time zone", + default_value => \"current_timestamp", + is_nullable => 0, + }, + "created_at", + { + data_type => "timestamp with time zone", + default_value => \"current_timestamp", + is_nullable => 0, + }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("subscription_person_id_key", ["person_id"]); + +=head1 RELATIONS + +=head2 person + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "person", + "MJB::DB::Result::Person", + { id => "person_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07051 @ 2022-12-05 17:03:53 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JCgARbPdOi4GeCGbqhLNow + +sub as_hashref { + my ( $self ) = @_; + + return +{ + id => $self->id, + person_id => $self->person_id, + stripe_customer_id => $self->stripe_customer_id, + is_valid => $self->is_valid, + last_checked_at => $self->last_checked_at->strftime( '%F %T' ), + created_at => $self->created_at->strftime( '%F %T' ), + }; +} +1;