db migration 1.0.2, now stores and indexes date of content delivered to subscriber...
[websub-hub] / src / db / sqlite / sql / schema / 1.0.2 / revert.sql
diff --git a/src/db/sqlite/sql/schema/1.0.2/revert.sql b/src/db/sqlite/sql/schema/1.0.2/revert.sql
new file mode 100644 (file)
index 0000000..45d3ef1
--- /dev/null
@@ -0,0 +1,21 @@
+BEGIN;
+       DROP INDEX subscription_latest_content_delivered_idx;
+       DROP VIEW subscription_delivery_needed;
+       ALTER TABLE subscription
+               DROP COLUMN latest_content_delivered
+       ;
+       CREATE INDEX subscription_content_delivered_idx ON subscription(content_delivered);
+       CREATE VIEW subscription_delivery_needed AS
+               SELECT s.*
+               FROM subscription s JOIN topic t ON s.topic_id = t.id
+               WHERE
+                       s.expires > strftime('%s', 'now')
+               AND
+                       s.content_delivered < t.content_updated
+               AND
+                       s.delivery_next_attempt < strftime('%s', 'now')
+               AND
+                       s.id NOT IN (SELECT id FROM subscription_delivery_in_progress_active)
+       ;
+       DELETE FROM _meta_schema_version WHERE major = 1 AND minor = 0 AND patch = 2;
+COMMIT;