This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement schema/models for participant identities
- Loading branch information
1 parent
de796f9
commit fd6d635
Showing
7 changed files
with
478 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from postgres.orm import Model | ||
|
||
|
||
class Country(Model): | ||
typname = 'countries' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
CREATE TABLE countries -- http://www.iso.org/iso/country_codes | ||
( id bigserial primary key | ||
, code2 text NOT NULL UNIQUE | ||
, code3 text NOT NULL UNIQUE | ||
, name text NOT NULL UNIQUE | ||
); | ||
|
||
\i sql/countries.sql | ||
|
||
CREATE TABLE participant_identities | ||
( id bigserial primary key | ||
, ctime timestamp with time zone NOT NULL | ||
, mtime timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
, participant bigint NOT NULL REFERENCES participants(id) | ||
, country bigint NOT NULL REFERENCES countries(id) | ||
, info json | ||
, is_verified boolean DEFAULT FALSE | ||
); | ||
|
||
|
||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} false | ||
-- | ||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-12 2388765 8767 {"address": "bar"} true | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} false | ||
-- | ||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-13 2388765 8767 {"address": "bar"} false | ||
-- 2014-08-10 2014-08-12 2388765 8767 {"address": "bar"} true | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} true | ||
-- | ||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-14 2388765 8767 {"address": "bar"} true | ||
-- 2014-08-10 2014-08-13 2388765 8767 {"address": "bar"} false | ||
-- 2014-08-10 2014-08-12 2388765 8767 {"address": "foo"} true | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} false | ||
-- | ||
-- # user removes their registration | ||
-- | ||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-15 2388765 8767 NULL NULL | ||
-- 2014-08-10 2014-08-14 2388765 8767 {"address": "bar"} true | ||
-- 2014-08-10 2014-08-13 2388765 8767 {"address": "bar"} false | ||
-- 2014-08-10 2014-08-12 2388765 8767 {"address": "foo"} true | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} false | ||
-- | ||
-- # user reregisters for the same country - same ctime! | ||
-- | ||
-- ctime mtime participant country info is_verified | ||
-- 2014-08-10 2014-08-16 2388765 8767 {"address": "baz"} false | ||
-- 2014-08-10 2014-08-15 2388765 8767 NULL NULL | ||
-- 2014-08-10 2014-08-14 2388765 8767 {"address": "bar"} true | ||
-- 2014-08-10 2014-08-13 2388765 8767 {"address": "bar"} false | ||
-- 2014-08-10 2014-08-12 2388765 8767 {"address": "foo"} true | ||
-- 2014-08-10 2014-08-10 2388765 8767 {"address": "foo"} false | ||
|
||
|
||
CREATE VIEW current_participant_identities AS | ||
SELECT * FROM ( | ||
SELECT DISTINCT ON (participant, country) * | ||
FROM participant_identities | ||
ORDER BY participant, country, mtime DESC | ||
) AS _ WHERE info IS NOT NULL; |
Oops, something went wrong.