diff --git a/tables.sql b/tables.sql index 250e1ee..c558fbc 100644 --- a/tables.sql +++ b/tables.sql @@ -1,12 +1,3 @@ -CREATE TABLE IF NOT EXISTS `copies` ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT, - `collection` TEXT NOT NULL DEFAULT 'Default', - `scryfall_id` TEXT, - `isFoil` INTEGER NOT NULL DEFAULT 0, - `language` TEXT, - `condition` TEXT -); - CREATE TABLE IF NOT EXISTS `cards` ( `scryfall_id` TEXT PRIMARY KEY, `name` TEXT NOT NULL, @@ -24,6 +15,20 @@ CREATE TABLE IF NOT EXISTS `cards` ( `oracle_text` TEXT ); +CREATE INDEX `cards_name` ON `cards`(`name` COLLATE nocase); +CREATE INDEX `cards_rarity` ON `cards`(`rarity`); +CREATE INDEX `cards_color_identity` ON `cards`(`color_identity`); + +CREATE TABLE IF NOT EXISTS `copies` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `collection` TEXT NOT NULL DEFAULT 'Default', + `scryfall_id` TEXT, + `isFoil` INTEGER NOT NULL DEFAULT 0, + `language` TEXT, + `condition` TEXT, + FOREIGN KEY (`scryfall_id`) REFERENCES `cards`(`scryfall_id`) +); + CREATE TABLE IF NOT EXISTS `card_prices` ( `scryfall_id` TEXT, `date` TEXT, @@ -32,7 +37,8 @@ CREATE TABLE IF NOT EXISTS `card_prices` ( `eur` TEXT, -- Decimal value `eur_foil` TEXT, -- Decimal value `tix` TEXT, -- Decimal value - PRIMARY KEY (`scryfall_id`, `date`) + PRIMARY KEY (`scryfall_id`, `date`), + FOREIGN KEY (`scryfall_id`) REFERENCES `cards`(`scryfall_id`) ); CREATE TABLE IF NOT EXISTS `sets` (