Skip to content

Instantly share code, notes, and snippets.

@glasserc
Created December 5, 2017 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glasserc/8297592bebdccc44956af31f9fd4facf to your computer and use it in GitHub Desktop.
Save glasserc/8297592bebdccc44956af31f9fd4facf to your computer and use it in GitHub Desktop.
diff between existing and plausable hotfix
diff --git a/kinto/core/storage/postgresql/migrations/migration_019_hotfix.sql b/kinto/core/storage/postgresql/migrations/migration_019_hotfix.sql
index 1795b55a..bab9234d 100644
--- a/kinto/core/storage/postgresql/migrations/migration_019_hotfix.sql
+++ b/kinto/core/storage/postgresql/migrations/migration_019_hotfix.sql
@@ -5,29 +5,36 @@ RETURNS trigger AS $$
DECLARE
previous TIMESTAMP;
current TIMESTAMP;
+ is_bucket BOOLEAN;
BEGIN
+ current := clock_timestamp();
+
previous := NULL;
- WITH existing_timestamps AS (
- -- Timestamp of latest record.
- (
- SELECT last_modified
- FROM records
- WHERE parent_id = NEW.parent_id
- AND collection_id = NEW.collection_id
- ORDER BY last_modified DESC
- LIMIT 1
- )
- -- Timestamp when collection was empty.
- UNION
- (
- SELECT last_modified
- FROM timestamps
- WHERE parent_id = NEW.parent_id
- AND collection_id = NEW.collection_id
- )
- )
- SELECT MAX(last_modified) INTO previous
- FROM existing_timestamps;
+
+ is_bucket := NEW.parent_id = '' AND NEW.collection_id = 'bucket';
+ IF NOT is_bucket THEN
+ WITH existing_timestamps AS (
+ -- Timestamp of latest record.
+ (
+ SELECT last_modified
+ FROM records
+ WHERE parent_id = NEW.parent_id
+ AND collection_id = NEW.collection_id
+ ORDER BY last_modified DESC
+ LIMIT 1
+ )
+ -- Timestamp when collection was empty.
+ UNION
+ (
+ SELECT last_modified
+ FROM timestamps
+ WHERE parent_id = NEW.parent_id
+ AND collection_id = NEW.collection_id
+ )
+ )
+ SELECT MAX(last_modified) INTO previous
+ FROM existing_timestamps;
+ END IF;
--
-- This bumps the current timestamp to 1 msec in the future if the previous
@@ -38,7 +45,6 @@ BEGIN
-- an error (operation is cancelled).
-- See https://github.com/mozilla-services/cliquet/issues/25
--
- current := clock_timestamp();
IF previous IS NOT NULL AND previous >= current THEN
current := previous + INTERVAL '1 milliseconds';
END IF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment