aboutsummaryrefslogtreecommitdiff
path: root/src/db/sql/2-primary-key-question-responses.sql
blob: cb7df215cc1151483ce62cb10b51117992a3e835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;