diff options
author | Joris | 2022-02-06 19:30:53 +0100 |
---|---|---|
committer | Joris | 2022-02-06 19:30:53 +0100 |
commit | 20cfe717065fa53953e9799036a9972880fec801 (patch) | |
tree | 7fc2a7b4a43eb6d280d52c468927592c12798cb0 /src/db/sql | |
parent | dc0f32017cceabb6c683b6e1b4a2ae0248c37dbf (diff) |
Replace a card whenever the front or the back changed
Diffstat (limited to 'src/db/sql')
-rw-r--r-- | src/db/sql/2-primary-key-question-responses.sql | 20 |
1 files changed, 20 insertions, 0 deletions
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; |