3QVT6MA6I2CILQH3LUZABS4YQ7MN6CNRYTDRVS376OOHTPLYTFJAC
NEDDHXUK3GNFMOFO3KLU7NRIHCTYNWBT3D6HTKZAOXFDE6HMDZ6AC
2WOOGXDHVQ6L2MQYUTLJ6H6FVSQNJN6SMJL5DG7HAHFYPJLRT2SAC
QMRKFEPGFBCEWAIXPEIG5ILKAJ2JH5L3TOITHR4HNJXK5FN3KXBQC
IZEVQF627FA7VV25KJAWYWGGC35LZUUBBQRPN5ZAINTQLPEDRTEAC
GCVQD44VRPQVKPZEPIC4AOIXLJIG2ZMV3QI2Y7KALUT6NVUBSGSAC
A6HKMINBNGQLLX4QJMYWKQ4JAEHVJ4HIRVDKPPDI3FJUO2AAB7OQC
dbEval (CreateEvent (ProjectId pid) (UserId uid) (LogEntry a e m)) =
pinsert EventId
"INSERT INTO work_events (project_id, user_id, btc_addr, event_type, event_time, event_metadata) \
\VALUES (?, ?, ?, ?, ?, ?) \
\RETURNING id"
( pid, uid
, a ^. _BtcAddr
, eventName e
, fromThyme $ e ^. eventTime
, m
)
dbEval (CreateEvent (ProjectId pid) (UserId uid) (LogEntry c e m)) =
case c of
CreditToAddress addr ->
pinsert EventId
"INSERT INTO work_events \
\(project_id, user_id, credit_to_btc_addr, event_type, event_time, event_metadata) \
\VALUES (?, ?, ?, ?, ?, ?) \
\RETURNING id"
( pid, uid, addr ^. _BtcAddr, eventName e, fromThyme $ e ^. eventTime, m)
CreditToProject pid ->
pinsert EventId
"INSERT INTO work_events \
\(project_id, user_id, credit_to_project_id, event_type, event_time, event_metadata) \
\VALUES (?, ?, ?, ?, ?, ?) \
\RETURNING id"
( pid, uid, pid ^. _ProjectId, eventName e, fromThyme $ e ^. eventTime, m)
CreditToUser uid ->
pinsert EventId
"INSERT INTO work_events \
\(project_id, user_id, credit_to_user_id, event_type, event_time, event_metadata) \
\VALUES (?, ?, ?, ?, ?, ?) \
\RETURNING id"
( pid, uid, pid ^. _UserId, eventName e, fromThyme $ e ^. eventTime, m)
dbEval (AmendEvent (EventId eid) (AddressChange mt addr)) =
pinsert AmendmentId
"INSERT INTO event_addr_amendments (event_id, mod_time, btc_addr) VALUES (?, ?, ?) RETURNING id"
( eid, fromThyme $ mt ^. _ModTime, addr ^. _BtcAddr )
dbEval (AmendEvent (EventId eid) (CreditToChange mt creditTo)) =
case creditTo of
CreditToAddress addr ->
pinsert AmendmentId
"INSERT INTO event_credit_to_amendments \
\(event_id, amended_at, credit_to_type, credit_to_btc_addr) \
\VALUES (?, ?, ?, ?) RETURNING id"
( eid, fromThyme $ mt ^. _ModTime, "credit_to_address", addr ^. _BtcAddr )
CreditToProject pid ->
pinsert AmendmentId
"INSERT INTO event_credit_to_amendments \
\(event_id, amended_at, credit_to_type, credit_to_project_id) \
\VALUES (?, ?, ?, ?) RETURNING id"
( eid, fromThyme $ mt ^. _ModTime, "credit_to_project", pid ^. _ProjectId )
CreditToUser uid ->
"INSERT INTO event_credit_to_amendments \
\(event_id, amended_at, credit_to_type, credit_to_user_id) \
\VALUES (?, ?, ?, ?) RETURNING id"
( eid, fromThyme $ mt ^. _ModTime, "credit_to_user", uid ^. _UserId )
Description: (Describe migration here.)
Created: 2016-10-14 02:49:48.862103 UTC
Depends: 2016-10-13_05-36-55_user-event-log
Apply: |
create type credit_to_t as enum ('credit_to_address', 'credit_to_user', 'credit_to_project');
alter table work_events add column credit_to_type credit_to_t not null default 'credit_to_user';
alter table work_events alter column btc_addr drop not null;
alter table work_events rename column btc_addr to credit_to_btc_addr;
alter table work_events add column credit_to_user_id uuid references users(id);
alter table work_events add column credit_to_project_id uuid references projects(id);
create table event_time_amendments(
event_id uuid references work_events,
amended_at timestamp with time zone not null,
event_time timestamp with time zone not null
);
create table event_credit_to_amendments(
event_id uuid references work_events,
amended_at timestamp with time zone not null,
credit_to_type credit_to_t not null,
credit_to_btc_addr text,
credit_to_user_id uuid references users(id),
credit_to_project_id uuid references projects(id)
);
create table event_metadata_amendments(
event_id uuid references work_events,
amended_at timestamp with time zone not null,
event_metadata json not null
);
Revert: |
drop table event_metadata_amendments;
drop table event_credit_to_amendments;
drop table event_time_amendments;
alter table work_events drop column credit_to_project_id;
alter table work_events drop column credit_to_user_id;
alter table work_events rename column credit_to_btc_addr to btc_addr;
alter table work_events alter column btc_addr set not null;
alter table work_events drop column credit_to_type;
drop type credit_to_t;