This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #604 from mozilla-services/keep-last-modified
Keep last modified
- Loading branch information
Showing
11 changed files
with
331 additions
and
35 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
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
41 changes: 41 additions & 0 deletions
41
cliquet/storage/postgresql/migrations/migration_008_009.sql
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,41 @@ | ||
CREATE OR REPLACE FUNCTION from_epoch(epoch BIGINT) RETURNS TIMESTAMP AS $$ | ||
BEGIN | ||
RETURN TIMESTAMP WITH TIME ZONE 'epoch' + epoch * INTERVAL '1 millisecond'; | ||
END; | ||
$$ LANGUAGE plpgsql | ||
IMMUTABLE; | ||
|
||
|
||
CREATE OR REPLACE FUNCTION bump_timestamp() | ||
RETURNS trigger AS $$ | ||
DECLARE | ||
previous TIMESTAMP; | ||
current TIMESTAMP; | ||
|
||
BEGIN | ||
-- | ||
-- This bumps the current timestamp to 1 msec in the future if the previous | ||
-- timestamp is equal to the current one (or higher if was bumped already). | ||
-- | ||
-- If a bunch of requests from the same user on the same collection | ||
-- arrive in the same millisecond, the unicity constraint can raise | ||
-- an error (operation is cancelled). | ||
-- See https://github.com/mozilla-services/cliquet/issues/25 | ||
-- | ||
previous := collection_timestamp(NEW.parent_id, NEW.collection_id); | ||
|
||
IF NEW.last_modified IS NULL THEN | ||
current := clock_timestamp(); | ||
IF previous >= current THEN | ||
current := previous + INTERVAL '1 milliseconds'; | ||
END IF; | ||
NEW.last_modified := current; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
|
||
-- Bump storage schema version. | ||
INSERT INTO metadata (name, value) VALUES ('storage_schema_version', '9'); |
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
Oops, something went wrong.