/* 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;
