verifications will not be processed until their topic is active
authorJustin Wind <justin.wind+git@gmail.com>
Mon, 23 Aug 2021 21:56:09 +0000 (14:56 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Mon, 23 Aug 2021 22:00:14 +0000 (15:00 -0700)
Updates db schema to 1.0.1, replaces the view of needed verification
work.

src/db/postgres/index.js
src/db/postgres/sql/schema/1.0.0/apply.sql
src/db/postgres/sql/schema/1.0.1/apply.sql [new file with mode: 0644]
src/db/postgres/sql/schema/1.0.1/revert.sql [new file with mode: 0644]
src/db/sqlite/index.js
src/db/sqlite/sql/schema/1.0.1/apply.sql [new file with mode: 0644]
src/db/sqlite/sql/schema/1.0.1/revert.sql [new file with mode: 0644]

index 1c5d1d1c4f2253a79c3053232781f2bbb7e45f56..255909780fe71c41133fc4b29c30eb5ec563f27a 100644 (file)
@@ -30,7 +30,7 @@ const schemaVersionsSupported = {
   max: {
     major: 1,
     minor: 0,
-    patch: 0,
+    patch: 1,
   },
 };
 
index 2665882108cef64db73e9293442edac259020cff..24e955dbfc0c26423e998eff3870067164cecf89 100644 (file)
@@ -174,7 +174,7 @@ BEGIN;
                SELECT *
                FROM verification
                WHERE
-                       (topic_id, callback, created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY (topic_id, callback))
+                       (topic_id, callback, created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY topic_id, callback)
                AND
                        (topic_id, callback) NOT IN (SELECT topic_id, callback FROM verification_in_progress_active)
                AND
diff --git a/src/db/postgres/sql/schema/1.0.1/apply.sql b/src/db/postgres/sql/schema/1.0.1/apply.sql
new file mode 100644 (file)
index 0000000..32eef6a
--- /dev/null
@@ -0,0 +1,18 @@
+BEGIN;
+       -- Ignore verifications with topics which are not yet active.
+       CREATE OR REPLACE VIEW verification_needed AS
+               SELECT v.*
+               FROM verification v JOIN topic t ON v.topic_id = t.id
+               WHERE
+                       t.is_active
+               AND
+                       (v.topic_id, v.callback, v.created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY topic_id, callback)
+               AND
+                       (v.topic_id, v.callback) NOT IN (SELECT topic_id, callback FROM verification_in_progress_active)
+               AND
+                       v.next_attempt <= now()
+       ;
+
+       INSERT INTO _meta_schema_version (major, minor, patch) VALUES (1, 0, 1);
+COMMIT;
+
diff --git a/src/db/postgres/sql/schema/1.0.1/revert.sql b/src/db/postgres/sql/schema/1.0.1/revert.sql
new file mode 100644 (file)
index 0000000..37813c6
--- /dev/null
@@ -0,0 +1,15 @@
+BEGIN;
+       CREATE OR REPLACE VIEW verification_needed AS
+               SELECT *
+               FROM verification
+               WHERE
+                       (topic_id, callback, created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY topic_id, callback)
+               AND
+                       (topic_id, callback) NOT IN (SELECT topic_id, callback FROM verification_in_progress_active)
+               AND
+                       next_attempt <= now()
+       ;
+
+       DELETE FROM _meta_schema_version WHERE major = 1 AND minor = 0 AND patch = 1;
+COMMIT;
+
index 9ef1fe54d2302e9523860a6196ebac9cd4f3a323..fba4e7ca326f828a6f9698258d2ec4628fb7665e 100644 (file)
@@ -20,7 +20,7 @@ const schemaVersionsSupported = {
   max: {
     major: 1,
     minor: 0,
-    patch: 0,
+    patch: 1,
   },
 };
 
diff --git a/src/db/sqlite/sql/schema/1.0.1/apply.sql b/src/db/sqlite/sql/schema/1.0.1/apply.sql
new file mode 100644 (file)
index 0000000..6a6552c
--- /dev/null
@@ -0,0 +1,18 @@
+BEGIN;
+       DROP VIEW verification_needed;
+       CREATE VIEW verification_needed AS
+               SELECT v.*
+               FROM verification v JOIN topic t ON v.topic_id = t.id
+               WHERE
+                       t.is_active
+               AND
+                       (v.topic_id, v.callback, v.created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY topic_id, callback)
+               AND
+                       (v.topic_id, v.callback) NOT IN (SELECT topic_id, callback FROM verification_in_progress_active)
+               AND
+                       v.next_attempt <= (strftime('%s', 'now'))
+       ;
+
+       INSERT INTO _meta_schema_version (major, minor, patch) VALUES (1, 0, 1);
+COMMIT;
+
diff --git a/src/db/sqlite/sql/schema/1.0.1/revert.sql b/src/db/sqlite/sql/schema/1.0.1/revert.sql
new file mode 100644 (file)
index 0000000..bff18bf
--- /dev/null
@@ -0,0 +1,16 @@
+BEGIN;
+       DROP VIEW verification_needed;
+       CREATE VIEW verification_needed AS
+               SELECT *
+               FROM verification
+               WHERE
+                       (topic_id, callback, created) IN (SELECT topic_id, callback, max(created) AS created FROM verification GROUP BY topic_id, callback)
+               AND
+                       (topic_id, callback) NOT IN (SELECT topic_id, callback FROM verification_in_progress_active)
+               AND
+                       next_attempt <= (strftime('%s', 'now'))
+       ;
+
+       DELETE FROM _meta_schema_version WHERE major = 1 AND minor = 0 AND patch = 1;
+COMMIT;
+