Merge pull request #56 from Pear-Trading/TBSliver/Transaction-Value-Fix

Changes to transaction value to allow for better maths
This commit is contained in:
Tom Bloor 2017-09-13 16:59:21 +01:00 committed by GitHub
commit e8a4718a75
21 changed files with 1785 additions and 41 deletions

View file

@ -18,23 +18,23 @@ sub post_index {
my $user = $c->stash->{api_user}->entity; my $user = $c->stash->{api_user}->entity;
my $today_rs = $user->purchases->today_rs; my $today_rs = $user->purchases->today_rs;
my $today_sum = $today_rs->get_column('value')->sum; my $today_sum = $today_rs->get_column('value')->sum || 0;
my $today_count = $today_rs->count; my $today_count = $today_rs->count;
my $week_rs = $user->purchases->week_rs; my $week_rs = $user->purchases->week_rs;
my $week_sum = $week_rs->get_column('value')->sum; my $week_sum = $week_rs->get_column('value')->sum || 0;
my $week_count = $week_rs->count; my $week_count = $week_rs->count;
my $month_rs = $user->purchases->month_rs; my $month_rs = $user->purchases->month_rs;
my $month_sum = $month_rs->get_column('value')->sum; my $month_sum = $month_rs->get_column('value')->sum || 0;
my $month_count = $month_rs->count; my $month_count = $month_rs->count;
my $user_rs = $user->purchases; my $user_rs = $user->purchases;
my $user_sum = $user_rs->get_column('value')->sum; my $user_sum = $user_rs->get_column('value')->sum || 0;
my $user_count = $user_rs->count; my $user_count = $user_rs->count;
my $global_rs = $c->schema->resultset('Transaction'); my $global_rs = $c->schema->resultset('Transaction');
my $global_sum = $global_rs->get_column('value')->sum; my $global_sum = $global_rs->get_column('value')->sum || 0;
my $global_count = $global_rs->count; my $global_count = $global_rs->count;
my $leaderboard_rs = $c->schema->resultset('Leaderboard'); my $leaderboard_rs = $c->schema->resultset('Leaderboard');
@ -44,15 +44,15 @@ sub post_index {
return $c->render( json => { return $c->render( json => {
success => Mojo::JSON->true, success => Mojo::JSON->true,
today_sum => $today_sum || 0, today_sum => $today_sum / 100000,
today_count => $today_count, today_count => $today_count,
week_sum => $week_sum || 0, week_sum => $week_sum / 100000,
week_count => $week_count, week_count => $week_count,
month_sum => $month_sum || 0, month_sum => $month_sum / 100000,
month_count => $month_count, month_count => $month_count,
user_sum => $user_sum || 0, user_sum => $user_sum / 100000,
user_count => $user_count, user_count => $user_count,
global_sum => $global_sum || 0, global_sum => $global_sum / 100000,
global_count => $global_count, global_count => $global_count,
user_position => defined $current_user_position ? $current_user_position->position : 0, user_position => defined $current_user_position ? $current_user_position->position : 0,
}); });
@ -91,6 +91,10 @@ sub post_leaderboards {
my @leaderboard_array = $today_values->all; my @leaderboard_array = $today_values->all;
if ( $validation->param('type') =~ /total$/ ) {
map { $_->{value} / 100000 } @leaderboard_array;
}
my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id }); my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id });
return $c->render( json => { return $c->render( json => {

View file

@ -34,7 +34,7 @@ sub post_transaction_list_purchases {
my @transaction_list = ( my @transaction_list = (
map {{ map {{
seller => $_->seller->name, seller => $_->seller->name,
value => $_->value, value => $_->value / 100000,
purchase_time => $_->purchase_time, purchase_time => $_->purchase_time,
}} $transactions->all }} $transactions->all
); );

View file

@ -176,7 +176,7 @@ sub post_upload {
'sales', 'sales',
{ {
buyer => $user->entity, buyer => $user->entity,
value => $transaction_value, value => $transaction_value * 100000,
( defined $file ? ( proof_image => $file ) : () ), ( defined $file ? ( proof_image => $file ) : () ),
purchase_time => $c->format_db_datetime($purchase_time), purchase_time => $c->format_db_datetime($purchase_time),
} }

View file

@ -139,7 +139,7 @@ sub _sales_last_duration {
->get_column('value') ->get_column('value')
->sum || 0 + 0; ->sum || 0 + 0;
push @{ $data->{ labels } }, $start->day_name; push @{ $data->{ labels } }, $start->day_name;
push @{ $data->{ data } }, $transactions; push @{ $data->{ data } }, $transactions / 100000;
$start->add( days => 1 ); $start->add( days => 1 );
} }
@ -171,7 +171,7 @@ sub _purchases_last_duration {
->get_column('value') ->get_column('value')
->sum || 0 + 0; ->sum || 0 + 0;
push @{ $data->{ labels } }, $start->day_name; push @{ $data->{ labels } }, $start->day_name;
push @{ $data->{ data } }, $transactions; push @{ $data->{ data } }, $transactions / 100000;
$start->add( days => 1 ); $start->add( days => 1 );
} }

View file

@ -28,26 +28,32 @@ sub index {
my $today_sales = $entity->sales->search_between( $today, $now ); my $today_sales = $entity->sales->search_between( $today, $now );
$data->{ today_sales_count } = $today_sales->count; $data->{ today_sales_count } = $today_sales->count;
$data->{ today_sales_total } = $today_sales->get_column('value')->sum || 0; $data->{ today_sales_total } = $today_sales->get_column('value')->sum || 0;
$data->{ today_sales_total } /= 100000;
my $week_sales = $entity->sales->search_between( $week_ago, $today ); my $week_sales = $entity->sales->search_between( $week_ago, $today );
$data->{ this_week_sales_count } = $week_sales->count; $data->{ this_week_sales_count } = $week_sales->count;
$data->{ this_week_sales_total } = $week_sales->get_column('value')->sum || 0; $data->{ this_week_sales_total } = $week_sales->get_column('value')->sum || 0;
$data->{ this_week_sales_total } /= 100000;
my $month_sales = $entity->sales->search_between( $month_ago, $today ); my $month_sales = $entity->sales->search_between( $month_ago, $today );
$data->{ this_month_sales_count } = $month_sales->count; $data->{ this_month_sales_count } = $month_sales->count;
$data->{ this_month_sales_total } = $month_sales->get_column('value')->sum || 0; $data->{ this_month_sales_total } = $month_sales->get_column('value')->sum || 0;
$data->{ this_month_sales_total } /= 100000;
my $today_purchases = $entity->purchases->search_between( $today, $now ); my $today_purchases = $entity->purchases->search_between( $today, $now );
$data->{ today_purchases_count } = $today_purchases->count; $data->{ today_purchases_count } = $today_purchases->count;
$data->{ today_purchases_total } = $today_purchases->get_column('value')->sum || 0; $data->{ today_purchases_total } = $today_purchases->get_column('value')->sum || 0;
$data->{ today_purchases_total } /= 100000;
my $week_purchases = $entity->purchases->search_between( $week_ago, $today ); my $week_purchases = $entity->purchases->search_between( $week_ago, $today );
$data->{ this_week_purchases_count } = $week_purchases->count; $data->{ this_week_purchases_count } = $week_purchases->count;
$data->{ this_week_purchases_total } = $week_purchases->get_column('value')->sum || 0; $data->{ this_week_purchases_total } = $week_purchases->get_column('value')->sum || 0;
$data->{ this_week_purchases_total } /= 100000;
my $month_purchases = $entity->purchases->search_between( $month_ago, $today ); my $month_purchases = $entity->purchases->search_between( $month_ago, $today );
$data->{ this_month_purchases_count } = $month_purchases->count; $data->{ this_month_purchases_count } = $month_purchases->count;
$data->{ this_month_purchases_total } = $month_purchases->get_column('value')->sum || 0; $data->{ this_month_purchases_total } = $month_purchases->get_column('value')->sum || 0;
$data->{ this_month_purchases_total } /= 100000;
return $c->render( return $c->render(
json => { json => {

View file

@ -6,7 +6,7 @@ use warnings;
use base 'DBIx::Class::Schema'; use base 'DBIx::Class::Schema';
our $VERSION = 6; our $VERSION = 7;
__PACKAGE__->load_namespaces; __PACKAGE__->load_namespaces;

View file

@ -28,8 +28,8 @@ __PACKAGE__->add_columns(
is_nullable => 0, is_nullable => 0,
}, },
"value" => { "value" => {
data_type => "decimal", data_type => "numeric",
size => [ 16, 2 ], size => [ 100, 0 ],
is_nullable => 0, is_nullable => 0,
}, },
"trend" => { "trend" => {

View file

@ -29,8 +29,8 @@ __PACKAGE__->add_columns(
is_nullable => 0, is_nullable => 0,
}, },
"value" => { "value" => {
data_type => "decimal", data_type => "numeric",
size => [ 16, 2 ], size => [ 100, 0 ],
is_nullable => 0, is_nullable => 0,
}, },
"proof_image" => { "proof_image" => {

View file

@ -1,5 +1,5 @@
package Test::Pear::LocalLoop; package Test::Pear::LocalLoop;
use Mojo::Base -base; use Moo;
use Test::More; use Test::More;
use File::Temp; use File::Temp;
@ -7,12 +7,48 @@ use Test::Mojo;
use DateTime::Format::Strptime; use DateTime::Format::Strptime;
use DBIx::Class::Fixtures; use DBIx::Class::Fixtures;
has config => sub { # Conditionally require Test::PostgreSQL
sub BUILD {
if ( $ENV{PEAR_TEST_PG} ) {
require Test::PostgreSQL
or die "you need Test::PostgreSQL to run PG testing";
Test::PostgreSQL->import;
}
}
sub DEMOLISH {
my ( $self, $in_global_destruction ) = @_;
if ( $ENV{PEAR_TEST_PG} && !$in_global_destruction ) {
$self->mojo->app->schema->storage->dbh->disconnect;
$self->pg->stop;
}
}
has pg => (
is => 'lazy',
builder => sub {
return Test::PostgreSQL->new();
},
);
has config => (
is => 'lazy',
builder => sub {
my $self = shift;
my $file = File::Temp->new; my $file = File::Temp->new;
print $file <<'END'; my $dsn;
if ( $ENV{PEAR_TEST_PG} ) {
$dsn = $self->pg->dsn;
} else {
$dsn = "dbi:SQLite::memory:";
}
print $file <<"END";
{ {
dsn => "dbi:SQLite::memory:", dsn => "$dsn",
user => undef, user => undef,
pass => undef, pass => undef,
} }
@ -20,9 +56,12 @@ END
$file->seek( 0, SEEK_END ); $file->seek( 0, SEEK_END );
return $file; return $file;
}; },
);
has mojo => sub { has mojo => (
is => 'lazy',
builder => sub {
my $self = shift; my $self = shift;
$ENV{MOJO_CONFIG} = $self->config->filename; $ENV{MOJO_CONFIG} = $self->config->filename;
@ -31,9 +70,18 @@ has mojo => sub {
$t->app->schema->deploy; $t->app->schema->deploy;
return $t; return $t;
}; },
);
has _deployed => sub { 0 }; has etc_dir => (
is => 'lazy',
builder => sub { die "etc dir not set" },
);
has _deployed => (
is => 'rwp',
default => 0,
);
sub framework { sub framework {
my $self = shift; my $self = shift;
@ -56,13 +104,11 @@ sub framework {
]); ]);
} }
$self->_deployed(1); $self->_set__deployed(1);
return $t; return $t;
}; };
has etc_dir => sub { die "etc dir not set" };
sub dump_error { sub dump_error {
return sub { return sub {
my $self = shift; my $self = shift;
@ -142,11 +188,40 @@ sub install_fixtures {
}); });
my $t = $self->framework(1); my $t = $self->framework(1);
my $schema = $t->app->schema;
$fixtures->populate({ $fixtures->populate({
directory => File::Spec->catdir( $self->etc_dir, 'fixtures', 'data', $fixture_name ), directory => File::Spec->catdir( $self->etc_dir, 'fixtures', 'data', $fixture_name ),
no_deploy => 1, no_deploy => 1,
schema => $t->app->schema, schema => $schema,
}); });
# Reset table id sequences
if ( $ENV{PEAR_TEST_PG} ) {
$schema->storage->dbh_do(
sub {
my ( $storage, $dbh, $sets ) = @_;
for my $table ( keys %$sets ) {
my $seq = $sets->{$table};
$dbh->do(
qq/
SELECT setval(
'$seq',
COALESCE(
(SELECT MAX(id)+1 FROM $table),
1
),
false
);
/);
}
},
{
entities => 'entities_id_seq',
organisations => 'organisations_id_seq',
}
);
}
} }
1; 1;

View file

@ -0,0 +1,18 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Wed Sep 13 15:24:20 2017
--
;
--
-- Table: dbix_class_deploymenthandler_versions
--
CREATE TABLE "dbix_class_deploymenthandler_versions" (
"id" serial NOT NULL,
"version" character varying(50) NOT NULL,
"ddl" text,
"upgrade_sql" text,
PRIMARY KEY ("id"),
CONSTRAINT "dbix_class_deploymenthandler_versions_version" UNIQUE ("version")
);
;

View file

@ -0,0 +1,210 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Wed Sep 13 15:24:20 2017
--
;
--
-- Table: account_tokens
--
CREATE TABLE "account_tokens" (
"id" serial NOT NULL,
"name" text NOT NULL,
"used" integer DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "account_tokens_name" UNIQUE ("name")
);
;
--
-- Table: entities
--
CREATE TABLE "entities" (
"id" serial NOT NULL,
"type" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
;
--
-- Table: leaderboards
--
CREATE TABLE "leaderboards" (
"id" serial NOT NULL,
"name" character varying(255) NOT NULL,
"type" character varying(255) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "leaderboards_type" UNIQUE ("type")
);
;
--
-- Table: customers
--
CREATE TABLE "customers" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"display_name" character varying(255) NOT NULL,
"full_name" character varying(255) NOT NULL,
"year_of_birth" integer NOT NULL,
"postcode" character varying(16) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "customers_idx_entity_id" on "customers" ("entity_id");
;
--
-- Table: leaderboard_sets
--
CREATE TABLE "leaderboard_sets" (
"id" serial NOT NULL,
"leaderboard_id" integer NOT NULL,
"date" timestamp NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "leaderboard_sets_idx_leaderboard_id" on "leaderboard_sets" ("leaderboard_id");
;
--
-- Table: organisations
--
CREATE TABLE "organisations" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"name" character varying(255) NOT NULL,
"street_name" text,
"town" character varying(255) NOT NULL,
"postcode" character varying(16),
"country" character varying(255),
"sector" character varying(1),
"pending" boolean DEFAULT false NOT NULL,
"submitted_by_id" integer,
PRIMARY KEY ("id")
);
CREATE INDEX "organisations_idx_entity_id" on "organisations" ("entity_id");
;
--
-- Table: transactions
--
CREATE TABLE "transactions" (
"id" serial NOT NULL,
"buyer_id" integer NOT NULL,
"seller_id" integer NOT NULL,
"value" numeric(100,0) NOT NULL,
"proof_image" text,
"submitted_at" timestamp NOT NULL,
"purchase_time" timestamp NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "transactions_idx_buyer_id" on "transactions" ("buyer_id");
CREATE INDEX "transactions_idx_seller_id" on "transactions" ("seller_id");
;
--
-- Table: users
--
CREATE TABLE "users" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"email" text NOT NULL,
"join_date" timestamp NOT NULL,
"password" character varying(100) NOT NULL,
"is_admin" boolean DEFAULT false NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "users_email" UNIQUE ("email")
);
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
;
--
-- Table: feedback
--
CREATE TABLE "feedback" (
"id" serial NOT NULL,
"user_id" integer NOT NULL,
"submitted_at" timestamp NOT NULL,
"feedbacktext" text NOT NULL,
"app_name" character varying(255) NOT NULL,
"package_name" character varying(255) NOT NULL,
"version_code" character varying(255) NOT NULL,
"version_number" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "feedback_idx_user_id" on "feedback" ("user_id");
;
--
-- Table: session_tokens
--
CREATE TABLE "session_tokens" (
"id" serial NOT NULL,
"token" character varying(255) NOT NULL,
"user_id" integer NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "session_tokens_token" UNIQUE ("token")
);
CREATE INDEX "session_tokens_idx_user_id" on "session_tokens" ("user_id");
;
--
-- Table: leaderboard_values
--
CREATE TABLE "leaderboard_values" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"set_id" integer NOT NULL,
"position" integer NOT NULL,
"value" numeric(100,0) NOT NULL,
"trend" integer DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "leaderboard_values_entity_id_set_id" UNIQUE ("entity_id", "set_id")
);
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
;
--
-- Foreign Key Definitions
--
;
ALTER TABLE "customers" ADD CONSTRAINT "customers_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "leaderboard_sets" ADD CONSTRAINT "leaderboard_sets_fk_leaderboard_id" FOREIGN KEY ("leaderboard_id")
REFERENCES "leaderboards" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "organisations" ADD CONSTRAINT "organisations_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_buyer_id" FOREIGN KEY ("buyer_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_seller_id" FOREIGN KEY ("seller_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "users" ADD CONSTRAINT "users_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "feedback" ADD CONSTRAINT "feedback_fk_user_id" FOREIGN KEY ("user_id")
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "session_tokens" ADD CONSTRAINT "session_tokens_fk_user_id" FOREIGN KEY ("user_id")
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_set_id" FOREIGN KEY ("set_id")
REFERENCES "leaderboard_sets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;

View file

@ -0,0 +1,15 @@
-- Convert schema 'share/ddl/_source/deploy/6/001-auto.yml' to 'share/ddl/_source/deploy/7/001-auto.yml':;
;
BEGIN;
;
ALTER TABLE leaderboard_values ALTER COLUMN value TYPE numeric(100,0) USING value * 100000;
;
ALTER TABLE transactions ALTER COLUMN value TYPE numeric(100,0) USING value * 100000;
;
COMMIT;

View file

@ -0,0 +1,18 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Wed Sep 13 15:24:20 2017
--
;
BEGIN TRANSACTION;
--
-- Table: dbix_class_deploymenthandler_versions
--
CREATE TABLE dbix_class_deploymenthandler_versions (
id INTEGER PRIMARY KEY NOT NULL,
version varchar(50) NOT NULL,
ddl text,
upgrade_sql text
);
CREATE UNIQUE INDEX dbix_class_deploymenthandler_versions_version ON dbix_class_deploymenthandler_versions (version);
COMMIT;

View file

@ -0,0 +1,145 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Wed Sep 13 15:24:20 2017
--
;
BEGIN TRANSACTION;
--
-- Table: account_tokens
--
CREATE TABLE account_tokens (
id INTEGER PRIMARY KEY NOT NULL,
name text NOT NULL,
used integer NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX account_tokens_name ON account_tokens (name);
--
-- Table: entities
--
CREATE TABLE entities (
id INTEGER PRIMARY KEY NOT NULL,
type varchar(255) NOT NULL
);
--
-- Table: leaderboards
--
CREATE TABLE leaderboards (
id INTEGER PRIMARY KEY NOT NULL,
name varchar(255) NOT NULL,
type varchar(255) NOT NULL
);
CREATE UNIQUE INDEX leaderboards_type ON leaderboards (type);
--
-- Table: customers
--
CREATE TABLE customers (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
display_name varchar(255) NOT NULL,
full_name varchar(255) NOT NULL,
year_of_birth integer NOT NULL,
postcode varchar(16) NOT NULL,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX customers_idx_entity_id ON customers (entity_id);
--
-- Table: leaderboard_sets
--
CREATE TABLE leaderboard_sets (
id INTEGER PRIMARY KEY NOT NULL,
leaderboard_id integer NOT NULL,
date datetime NOT NULL,
FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX leaderboard_sets_idx_leaderboard_id ON leaderboard_sets (leaderboard_id);
--
-- Table: organisations
--
CREATE TABLE organisations (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
name varchar(255) NOT NULL,
street_name text,
town varchar(255) NOT NULL,
postcode varchar(16),
country varchar(255),
sector varchar(1),
pending boolean NOT NULL DEFAULT false,
submitted_by_id integer,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX organisations_idx_entity_id ON organisations (entity_id);
--
-- Table: transactions
--
CREATE TABLE transactions (
id INTEGER PRIMARY KEY NOT NULL,
buyer_id integer NOT NULL,
seller_id integer NOT NULL,
value numeric(100,0) NOT NULL,
proof_image text,
submitted_at datetime NOT NULL,
purchase_time datetime NOT NULL,
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX transactions_idx_buyer_id ON transactions (buyer_id);
CREATE INDEX transactions_idx_seller_id ON transactions (seller_id);
--
-- Table: users
--
CREATE TABLE users (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
email text NOT NULL,
join_date datetime NOT NULL,
password varchar(100) NOT NULL,
is_admin boolean NOT NULL DEFAULT false,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX users_idx_entity_id ON users (entity_id);
CREATE UNIQUE INDEX users_email ON users (email);
--
-- Table: feedback
--
CREATE TABLE feedback (
id INTEGER PRIMARY KEY NOT NULL,
user_id integer NOT NULL,
submitted_at datetime NOT NULL,
feedbacktext text NOT NULL,
app_name varchar(255) NOT NULL,
package_name varchar(255) NOT NULL,
version_code varchar(255) NOT NULL,
version_number varchar(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX feedback_idx_user_id ON feedback (user_id);
--
-- Table: session_tokens
--
CREATE TABLE session_tokens (
id INTEGER PRIMARY KEY NOT NULL,
token varchar(255) NOT NULL,
user_id integer NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX session_tokens_idx_user_id ON session_tokens (user_id);
CREATE UNIQUE INDEX session_tokens_token ON session_tokens (token);
--
-- Table: leaderboard_values
--
CREATE TABLE leaderboard_values (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
set_id integer NOT NULL,
position integer NOT NULL,
value numeric(100,0) NOT NULL,
trend integer NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX leaderboard_values_idx_entity_id ON leaderboard_values (entity_id);
CREATE INDEX leaderboard_values_idx_set_id ON leaderboard_values (set_id);
CREATE UNIQUE INDEX leaderboard_values_entity_id_set_id ON leaderboard_values (entity_id, set_id);
COMMIT;

View file

@ -0,0 +1,98 @@
-- Convert schema 'share/ddl/_source/deploy/6/001-auto.yml' to 'share/ddl/_source/deploy/7/001-auto.yml':;
;
BEGIN;
;
CREATE TEMPORARY TABLE leaderboard_values_temp_alter (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
set_id integer NOT NULL,
position integer NOT NULL,
value decimal(16,2) NOT NULL,
trend integer NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
INSERT INTO leaderboard_values_temp_alter( id, entity_id, set_id, position, value, trend) SELECT id, entity_id, set_id, position, value, trend FROM leaderboard_values;
;
DROP TABLE leaderboard_values;
;
CREATE TABLE leaderboard_values (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
set_id integer NOT NULL,
position integer NOT NULL,
value numeric(100,0) NOT NULL,
trend integer NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
CREATE INDEX leaderboard_values_idx_enti00 ON leaderboard_values (entity_id);
;
CREATE INDEX leaderboard_values_idx_set_00 ON leaderboard_values (set_id);
;
CREATE UNIQUE INDEX leaderboard_values_entity_i00 ON leaderboard_values (entity_id, set_id);
;
INSERT INTO leaderboard_values SELECT id, entity_id, set_id, position, value, trend FROM leaderboard_values_temp_alter;
;
DROP TABLE leaderboard_values_temp_alter;
;
CREATE TEMPORARY TABLE transactions_temp_alter (
id INTEGER PRIMARY KEY NOT NULL,
buyer_id integer NOT NULL,
seller_id integer NOT NULL,
value decimal(16,2) NOT NULL,
proof_image text,
submitted_at datetime NOT NULL,
purchase_time datetime NOT NULL,
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
INSERT INTO transactions_temp_alter( id, buyer_id, seller_id, value, proof_image, submitted_at, purchase_time) SELECT id, buyer_id, seller_id, value, proof_image, submitted_at, purchase_time FROM transactions;
;
DROP TABLE transactions;
;
CREATE TABLE transactions (
id INTEGER PRIMARY KEY NOT NULL,
buyer_id integer NOT NULL,
seller_id integer NOT NULL,
value numeric(100,0) NOT NULL,
proof_image text,
submitted_at datetime NOT NULL,
purchase_time datetime NOT NULL,
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
CREATE INDEX transactions_idx_buyer_id02 ON transactions (buyer_id);
;
CREATE INDEX transactions_idx_seller_id02 ON transactions (seller_id);
;
INSERT INTO transactions SELECT id, buyer_id, seller_id, value * 100000, proof_image, submitted_at, purchase_time FROM transactions_temp_alter;
;
DROP TABLE transactions_temp_alter;
;
COMMIT;

View file

@ -0,0 +1,91 @@
---
schema:
procedures: {}
tables:
dbix_class_deploymenthandler_versions:
constraints:
- deferrable: 1
expression: ''
fields:
- id
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
expression: ''
fields:
- version
match_type: ''
name: dbix_class_deploymenthandler_versions_version
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: UNIQUE
fields:
ddl:
data_type: text
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: ddl
order: 3
size:
- 0
id:
data_type: int
default_value: ~
is_auto_increment: 1
is_nullable: 0
is_primary_key: 1
is_unique: 0
name: id
order: 1
size:
- 0
upgrade_sql:
data_type: text
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: upgrade_sql
order: 4
size:
- 0
version:
data_type: varchar
default_value: ~
is_nullable: 0
is_primary_key: 0
is_unique: 1
name: version
order: 2
size:
- 50
indices: []
name: dbix_class_deploymenthandler_versions
options: []
order: 1
triggers: {}
views: {}
translator:
add_drop_table: 0
filename: ~
no_comments: 0
parser_args:
sources:
- __VERSION
parser_type: SQL::Translator::Parser::DBIx::Class
producer_args: {}
producer_type: SQL::Translator::Producer::YAML
show_warnings: 0
trace: 0
version: 0.11021

File diff suppressed because it is too large Load diff

View file

@ -30,7 +30,7 @@ my $pending_entity = $schema->resultset('Entity')->create({
town => 'Midgar', town => 'Midgar',
sector => 'A', sector => 'A',
postcode => 'WC1E 6AD', postcode => 'WC1E 6AD',
pending => \"1", pending => 1,
}, },
type => "organisation", type => "organisation",
}); });

View file

@ -43,7 +43,7 @@ $t->post_ok('/api/stats' => json => { session_key => $session_key } )
for ( 1 .. 10 ) { for ( 1 .. 10 ) {
$user_result->create_related( 'purchases', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_, value => $_ * 100000,
proof_image => 'a', proof_image => 'a',
}); });
} }
@ -51,7 +51,7 @@ for ( 1 .. 10 ) {
for ( 11 .. 20 ) { for ( 11 .. 20 ) {
$user_result->create_related( 'purchases', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_, value => $_ * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 5 )), purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 5 )),
}); });
@ -60,7 +60,7 @@ for ( 11 .. 20 ) {
for ( 21 .. 30 ) { for ( 21 .. 30 ) {
$user_result->create_related( 'purchases', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_, value => $_ * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 25 )), purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 25 )),
}); });
@ -69,7 +69,7 @@ for ( 21 .. 30 ) {
for ( 31 .. 40 ) { for ( 31 .. 40 ) {
$user_result->create_related( 'purchases', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_, value => $_ * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )),
}); });
@ -78,7 +78,7 @@ for ( 31 .. 40 ) {
for ( 41 .. 50 ) { for ( 41 .. 50 ) {
$org_result->create_related( 'purchases', { $org_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_, value => $_ * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )),
}); });
@ -91,8 +91,8 @@ is $user_result->purchases->search({
$dtf->format_datetime(DateTime->today()->add( days => 1 )), $dtf->format_datetime(DateTime->today()->add( days => 1 )),
], ],
}, },
})->get_column('value')->sum, 55, 'Got correct sum'; })->get_column('value')->sum, 5500000, 'Got correct sum';
is $user_result->purchases->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs'; is $user_result->purchases->today_rs->get_column('value')->sum, 5500000, 'Got correct sum through rs';
$t->post_ok('/api/stats' => json => { session_key => $session_key } ) $t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200) ->status_is(200)

View file

@ -115,7 +115,7 @@ sub create_random_transaction {
$schema->resultset('Transaction')->create({ $schema->resultset('Transaction')->create({
buyer => $buyer_result, buyer => $buyer_result,
seller => $seller_result, seller => $seller_result,
value => 10, value => 10 * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $time, purchase_time => $time,
}); });

View file

@ -73,7 +73,7 @@ sub create_random_transaction {
$schema->resultset('Transaction')->create({ $schema->resultset('Transaction')->create({
buyer => $buyer_result, buyer => $buyer_result,
seller => $seller_result, seller => $seller_result,
value => 10, value => 10 * 100000,
proof_image => 'a', proof_image => 'a',
purchase_time => $time, purchase_time => $time,
}); });