DROP TABLE IF EXISTS currency;

CREATE TABLE currency (id INTEGER PRIMARY KEY
  AUTOINCREMENT NOT NULL, currency TEXT);

ALTER TABLE rate ADD COLUMN currency_id INTEGER;

INSERT INTO currency (currency) SELECT currency FROM rate GROUP BY
currency;

UPDATE rate SET currency_id = currency.id FROM currency WHERE
rate.currency = currency.currency;

ALTER TABLE rate DROP COLUMN currency;
