Merge branch 'TBSliver/Postgres-Fixes' into development

This commit is contained in:
Tom Bloor 2017-09-06 16:18:11 +01:00
commit d02f8f3931
7 changed files with 88 additions and 17 deletions

View file

@ -150,7 +150,7 @@ sub post_upload {
street_name => $validation->param('street_name'),
town => $validation->param('town'),
postcode => $validation->param('postcode'),
pending => \"1"
pending => 1,
});
$organisation = $entity->organisation;
}

View file

@ -5,7 +5,7 @@ use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime");
__PACKAGE__->load_components("InflateColumn::DateTime", "FilterColumn");
__PACKAGE__->table("organisations");
@ -51,7 +51,7 @@ __PACKAGE__->add_columns(
},
pending => {
data_type => 'boolean',
default_value => \"0",
default => \"false",
is_nullable => 0,
},
submitted_by_id => {
@ -68,4 +68,40 @@ __PACKAGE__->belongs_to(
"entity_id",
);
__PACKAGE__->filter_column( pending => {
filter_to_storage => 'to_bool',
filter_from_storage => 'from_bool',
});
# Only works when calling ->deploy, but atleast helps for tests
sub sqlt_deploy_hook {
my ( $source_instance, $sqlt_table ) = @_;
my $pending_field = $sqlt_table->get_field('pending');
if ( $sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
$pending_field->{default_value} = 0;
} else {
$pending_field->{default_value} = \"false";
}
}
sub to_bool {
my ( $self, $val ) = @_;
my $driver_name = $self->result_source->schema->storage->dbh->{Driver}->{Name};
if ( $driver_name eq 'SQLite' ) {
return $val ? 1 : 0;
} else {
return $val ? 'true' : 'false';
}
}
sub from_bool {
my ( $self, $val ) = @_;
my $driver_name = $self->result_source->schema->storage->dbh->{Driver}->{Name};
if ( $driver_name eq 'SQLite' ) {
return $val;
} else {
return lc $val eq 'true' ? 1 : 0;
}
}
1;

View file

@ -11,6 +11,7 @@ __PACKAGE__->load_components( qw/
InflateColumn::DateTime
PassphraseColumn
TimeStamp
FilterColumn
/);
__PACKAGE__->table("users");
@ -48,7 +49,7 @@ __PACKAGE__->add_columns(
},
"is_admin" => {
data_type => "boolean",
default_value => \"0",
default_value => \"false",
is_nullable => 0,
},
);
@ -77,6 +78,41 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
sub sqlt_deploy_hook {
my ( $source_instance, $sqlt_table ) = @_;
my $pending_field = $sqlt_table->get_field('is_admin');
if ( $sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
$pending_field->{default_value} = 0;
} else {
$pending_field->{default_value} = \"false";
}
}
__PACKAGE__->filter_column( is_admin => {
filter_to_storage => 'to_bool',
filter_from_storage => 'from_bool',
});
sub to_bool {
my ( $self, $val ) = @_;
my $driver_name = $self->result_source->schema->storage->dbh->{Driver}->{Name};
if ( $driver_name eq 'SQLite' ) {
return $val ? 1 : 0;
} else {
return $val ? 'true' : 'false';
}
}
sub from_bool {
my ( $self, $val ) = @_;
my $driver_name = $self->result_source->schema->storage->dbh->{Driver}->{Name};
if ( $driver_name eq 'SQLite' ) {
return $val;
} else {
return lc $val eq 'true' ? 1 : 0;
}
}
sub generate_session {
my $self = shift;

View file

@ -1,6 +1,6 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Fri Sep 1 15:14:28 2017
-- Created on Tue Sep 5 17:22:16 2017
--
;
--
@ -76,7 +76,7 @@ CREATE TABLE "organisations" (
"postcode" character varying(16),
"country" character varying(255),
"sector" character varying(1),
"pending" boolean DEFAULT 0 NOT NULL,
"pending" boolean DEFAULT false NOT NULL,
"submitted_by_id" integer,
PRIMARY KEY ("id")
);
@ -109,7 +109,7 @@ CREATE TABLE "users" (
"email" text NOT NULL,
"join_date" timestamp NOT NULL,
"password" character varying(100) NOT NULL,
"is_admin" boolean DEFAULT 0 NOT NULL,
"is_admin" boolean DEFAULT false NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "users_email" UNIQUE ("email")
);

View file

@ -34,7 +34,7 @@ CREATE TABLE "organisations" (
"postcode" character varying(16),
"country" character varying(255),
"sector" character varying(1),
"pending" boolean DEFAULT 0 NOT NULL,
"pending" boolean DEFAULT false NOT NULL,
"submitted_by_id" integer,
PRIMARY KEY ("id")
);
@ -59,7 +59,7 @@ CREATE TABLE "users" (
"email" text NOT NULL,
"join_date" timestamp NOT NULL,
"password" character varying(100) NOT NULL,
"is_admin" boolean DEFAULT 0 NOT NULL,
"is_admin" boolean DEFAULT false NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "users_email" UNIQUE ("email")
);

View file

@ -652,7 +652,7 @@ schema:
pending:
data_type: boolean
default_value: !!perl/ref
=: 0
=: false
is_nullable: 0
is_primary_key: 0
is_unique: 0
@ -1000,7 +1000,7 @@ schema:
is_admin:
data_type: boolean
default_value: !!perl/ref
=: 0
=: false
is_nullable: 0
is_primary_key: 0
is_unique: 0

View file

@ -201,8 +201,7 @@ $json = {
organisation_id => 1,
session_key => $session_key,
};
$upload = {json => Mojo::JSON::encode_json($json)};
$t->post_ok('/api/upload' => form => $upload )
$t->post_ok('/api/upload' => json => $json )
->status_is(200)
->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)