From 20cfe717065fa53953e9799036a9972880fec801 Mon Sep 17 00:00:00 2001
From: Joris
Date: Sun, 6 Feb 2022 19:30:53 +0100
Subject: Replace a card whenever the front or the back changed

---
 src/db/sql/2-primary-key-question-responses.sql | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 src/db/sql/2-primary-key-question-responses.sql

(limited to 'src/db/sql/2-primary-key-question-responses.sql')

diff --git a/src/db/sql/2-primary-key-question-responses.sql b/src/db/sql/2-primary-key-question-responses.sql
new file mode 100644
index 0000000..cb7df21
--- /dev/null
+++ b/src/db/sql/2-primary-key-question-responses.sql
@@ -0,0 +1,20 @@
+/* Allows to use ON CONFLICT on (question, responses) when inserting a card. */
+
+CREATE TABLE IF NOT EXISTS cards_copy (
+  question VARCHAR NOT NULL,
+  responses VARCHAR NOT NULL,
+  state VARCHAR NOT NULL,
+  created TIMESTAMP NOT NULL,
+  updated TIMESTAMP NULL,
+  deleted TIMESTAMP NULL,
+  deck_read TIMESTAMP NOT NULL,
+  ready TIMESTAMP NOT NULL,
+  PRIMARY KEY (question, responses)
+);
+
+INSERT INTO cards_copy (question, responses, state, created, updated, deleted, deck_read, ready)
+   SELECT question, responses, state, created, updated, deleted, deck_read, ready FROM cards;
+
+DROP TABLE cards;
+
+ALTER TABLE cards_copy RENAME TO cards;
-- 
cgit v1.2.3

