Merge branch 'TBSliver/Postgres-Fixes' into development
This commit is contained in:
commit
d02f8f3931
7 changed files with 88 additions and 17 deletions
|
@ -150,7 +150,7 @@ sub post_upload {
|
||||||
street_name => $validation->param('street_name'),
|
street_name => $validation->param('street_name'),
|
||||||
town => $validation->param('town'),
|
town => $validation->param('town'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
pending => \"1"
|
pending => 1,
|
||||||
});
|
});
|
||||||
$organisation = $entity->organisation;
|
$organisation = $entity->organisation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use warnings;
|
||||||
|
|
||||||
use base 'DBIx::Class::Core';
|
use base 'DBIx::Class::Core';
|
||||||
|
|
||||||
__PACKAGE__->load_components("InflateColumn::DateTime");
|
__PACKAGE__->load_components("InflateColumn::DateTime", "FilterColumn");
|
||||||
|
|
||||||
__PACKAGE__->table("organisations");
|
__PACKAGE__->table("organisations");
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
pending => {
|
pending => {
|
||||||
data_type => 'boolean',
|
data_type => 'boolean',
|
||||||
default_value => \"0",
|
default => \"false",
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
submitted_by_id => {
|
submitted_by_id => {
|
||||||
|
@ -68,4 +68,40 @@ __PACKAGE__->belongs_to(
|
||||||
"entity_id",
|
"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;
|
1;
|
||||||
|
|
|
@ -11,6 +11,7 @@ __PACKAGE__->load_components( qw/
|
||||||
InflateColumn::DateTime
|
InflateColumn::DateTime
|
||||||
PassphraseColumn
|
PassphraseColumn
|
||||||
TimeStamp
|
TimeStamp
|
||||||
|
FilterColumn
|
||||||
/);
|
/);
|
||||||
|
|
||||||
__PACKAGE__->table("users");
|
__PACKAGE__->table("users");
|
||||||
|
@ -48,7 +49,7 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
"is_admin" => {
|
"is_admin" => {
|
||||||
data_type => "boolean",
|
data_type => "boolean",
|
||||||
default_value => \"0",
|
default_value => \"false",
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -77,6 +78,41 @@ __PACKAGE__->has_many(
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ 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 {
|
sub generate_session {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
--
|
--
|
||||||
-- Created by SQL::Translator::Producer::PostgreSQL
|
-- 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),
|
"postcode" character varying(16),
|
||||||
"country" character varying(255),
|
"country" character varying(255),
|
||||||
"sector" character varying(1),
|
"sector" character varying(1),
|
||||||
"pending" boolean DEFAULT 0 NOT NULL,
|
"pending" boolean DEFAULT false NOT NULL,
|
||||||
"submitted_by_id" integer,
|
"submitted_by_id" integer,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
@ -109,7 +109,7 @@ CREATE TABLE "users" (
|
||||||
"email" text NOT NULL,
|
"email" text NOT NULL,
|
||||||
"join_date" timestamp NOT NULL,
|
"join_date" timestamp NOT NULL,
|
||||||
"password" character varying(100) 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"),
|
PRIMARY KEY ("id"),
|
||||||
CONSTRAINT "users_email" UNIQUE ("email")
|
CONSTRAINT "users_email" UNIQUE ("email")
|
||||||
);
|
);
|
||||||
|
|
|
@ -34,7 +34,7 @@ CREATE TABLE "organisations" (
|
||||||
"postcode" character varying(16),
|
"postcode" character varying(16),
|
||||||
"country" character varying(255),
|
"country" character varying(255),
|
||||||
"sector" character varying(1),
|
"sector" character varying(1),
|
||||||
"pending" boolean DEFAULT 0 NOT NULL,
|
"pending" boolean DEFAULT false NOT NULL,
|
||||||
"submitted_by_id" integer,
|
"submitted_by_id" integer,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
@ -59,7 +59,7 @@ CREATE TABLE "users" (
|
||||||
"email" text NOT NULL,
|
"email" text NOT NULL,
|
||||||
"join_date" timestamp NOT NULL,
|
"join_date" timestamp NOT NULL,
|
||||||
"password" character varying(100) 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"),
|
PRIMARY KEY ("id"),
|
||||||
CONSTRAINT "users_email" UNIQUE ("email")
|
CONSTRAINT "users_email" UNIQUE ("email")
|
||||||
);
|
);
|
||||||
|
|
|
@ -652,7 +652,7 @@ schema:
|
||||||
pending:
|
pending:
|
||||||
data_type: boolean
|
data_type: boolean
|
||||||
default_value: !!perl/ref
|
default_value: !!perl/ref
|
||||||
=: 0
|
=: false
|
||||||
is_nullable: 0
|
is_nullable: 0
|
||||||
is_primary_key: 0
|
is_primary_key: 0
|
||||||
is_unique: 0
|
is_unique: 0
|
||||||
|
@ -1000,7 +1000,7 @@ schema:
|
||||||
is_admin:
|
is_admin:
|
||||||
data_type: boolean
|
data_type: boolean
|
||||||
default_value: !!perl/ref
|
default_value: !!perl/ref
|
||||||
=: 0
|
=: false
|
||||||
is_nullable: 0
|
is_nullable: 0
|
||||||
is_primary_key: 0
|
is_primary_key: 0
|
||||||
is_unique: 0
|
is_unique: 0
|
||||||
|
|
|
@ -201,8 +201,7 @@ $json = {
|
||||||
organisation_id => 1,
|
organisation_id => 1,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json)};
|
$t->post_ok('/api/upload' => json => $json )
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->or($framework->dump_error)
|
->or($framework->dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
|
Reference in a new issue