From 7500f95d88d7b6118e53ffe97f5945badfa53a90 Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sun, 8 Nov 2020 15:15:28 +0000 Subject: [PATCH] Add device token registration --- .../LocalLoop/Schema/Result/DeviceToken.pm | 47 +++++++++++++++++++ lib/Pear/LocalLoop/Schema/Result/User.pm | 7 +++ 2 files changed, 54 insertions(+) create mode 100644 lib/Pear/LocalLoop/Schema/Result/DeviceToken.pm diff --git a/lib/Pear/LocalLoop/Schema/Result/DeviceToken.pm b/lib/Pear/LocalLoop/Schema/Result/DeviceToken.pm new file mode 100644 index 0000000..3fd4686 --- /dev/null +++ b/lib/Pear/LocalLoop/Schema/Result/DeviceToken.pm @@ -0,0 +1,47 @@ +package Pear::LocalLoop::Schema::Result::DeviceToken; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->load_components( qw/ + InflateColumn::DateTime + TimeStamp + FilterColumn +/); + +__PACKAGE__->table("device_tokens"); + +__PACKAGE__->add_columns( + "id" => { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + }, + "user_id" => { + data_type => "integer", + is_foreign_key => 1, + is_nullable => 0, + }, + "token" => { + data_type => "varchar", + size => 200, + is_nullable => 0, + }, + "register_date" => { + data_type => "datetime", + set_on_create => 1, + }, +); + +__PACKAGE__->set_primary_key("id"); + +__PACKAGE__->belongs_to( + "user", + "Pear::LocalLoop::Schema::Result::User", + { id => "user_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + +1; diff --git a/lib/Pear/LocalLoop/Schema/Result/User.pm b/lib/Pear/LocalLoop/Schema/Result/User.pm index 9eee628..300d820 100644 --- a/lib/Pear/LocalLoop/Schema/Result/User.pm +++ b/lib/Pear/LocalLoop/Schema/Result/User.pm @@ -71,6 +71,13 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "device_tokens", + "Pear::LocalLoop::Schema::Result::DeviceToken", + { "foreign.user_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + __PACKAGE__->has_many( "feedback", "Pear::LocalLoop::Schema::Result::Feedback",