diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-11 15:40:26 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-23 18:55:08 +0100 |
commit | a3c182e75b022b3002eb4801fd446c891391b675 (patch) | |
tree | 326d72e08fe65454d20117092a0f308e1b4f0c2b | |
parent | a82cbf8c4709c4c04c8a1625946132bac8f4e74e (diff) |
Add created and last_active columns to user.
-rwxr-xr-x | bin/update-schema | 1 | ||||
-rw-r--r-- | db/downgrade_0062---0061.sql | 6 | ||||
-rw-r--r-- | db/schema.sql | 2 | ||||
-rw-r--r-- | db/schema_0062-add-user-created-last-active.sql | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 26 |
5 files changed, 36 insertions, 6 deletions
diff --git a/bin/update-schema b/bin/update-schema index fb88c84a1..2ae374e61 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -212,6 +212,7 @@ else { # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { return 'EMPTY' if ! table_exists('problem'); + return '0062' if column_exists('users', 'created'); return '0061' if column_exists('body', 'extra'); return '0060' if column_exists('body', 'convert_latlong'); return '0059' if column_exists('response_templates', 'external_status_code'); diff --git a/db/downgrade_0062---0061.sql b/db/downgrade_0062---0061.sql new file mode 100644 index 000000000..fa958169a --- /dev/null +++ b/db/downgrade_0062---0061.sql @@ -0,0 +1,6 @@ +BEGIN; + +ALTER TABLE users DROP created; +ALTER TABLE users DROP last_active; + +COMMIT; diff --git a/db/schema.sql b/db/schema.sql index fa0bd07bd..30f5d3a30 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -30,6 +30,8 @@ create table users ( from_body integer, flagged boolean not null default 'f', is_superuser boolean not null default 'f', + created timestamp not null default current_timestamp, + last_active timestamp not null default current_timestamp, title text, twitter_id bigint unique, facebook_id bigint unique, diff --git a/db/schema_0062-add-user-created-last-active.sql b/db/schema_0062-add-user-created-last-active.sql new file mode 100644 index 000000000..0e8875870 --- /dev/null +++ b/db/schema_0062-add-user-created-last-active.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE users ADD created timestamp default current_timestamp not null; +ALTER TABLE users ADD last_active timestamp default current_timestamp not null; + +COMMIT; + diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index db68236bf..c624a2efe 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -20,10 +20,14 @@ __PACKAGE__->add_columns( }, "email", { data_type => "text", is_nullable => 1 }, + "email_verified", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "name", { data_type => "text", is_nullable => 1 }, "phone", { data_type => "text", is_nullable => 1 }, + "phone_verified", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "password", { data_type => "text", default_value => "", is_nullable => 0 }, "from_body", @@ -42,10 +46,20 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "extra", { data_type => "text", is_nullable => 1 }, - "email_verified", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, - "phone_verified", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "created", + { + data_type => "timestamp", + default_value => \"current_timestamp", + is_nullable => 0, + original => { default_value => \"now()" }, + }, + "last_active", + { + data_type => "timestamp", + default_value => \"current_timestamp", + is_nullable => 0, + original => { default_value => \"now()" }, + }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("users_facebook_id_key", ["facebook_id"]); @@ -105,8 +119,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-09-19 18:02:17 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OKHKCSahWD3Ov6ulj+2f/w +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-05-23 18:54:36 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/V7+Ygv/t6VX8dDhNGN16w # These are not fully unique constraints (they only are when the *_verified # is true), but this is managed in ResultSet::User's find() wrapper. |