coderbunker / timesheet-backend

Timesheet Datawarehouse backend
MIT License
1 stars 0 forks source link

Use (membership_id, start_datetime) constraint for model.entry #32

Open rngadam opened 6 years ago

rngadam commented 6 years ago

It's sometimes possible that the stop_datetime will be modified after a previous synchronization and constraining on start_datetime not being the same for the same person is reasonable.

Right now, this query returns rows (28 right now) when it shouldn't:

SELECT * FROM (
    SELECT 
        count(*) AS count, 
        array_agg(id) AS entry_ids,
        membership_id, 
        start_datetime,
        array_agg(stop_datetime) AS stop_datetimes
    FROM model.entry
    GROUP BY membership_id, start_datetime
) t
WHERE count > 1
;