DROP TABLE IF EXISTS character_spells;
CREATE TABLE character_spells (
	id             INTEGER PRIMARY KEY,
	char_id        INTEGER NOT NULL DEFAULT 0,
	spell_id       INTEGER NOT NULL DEFAULT 0,
	tier           INTEGER NOT NULL DEFAULT 1,
	knowledge_slot INTEGER NOT NULL DEFAULT -1,
	UNIQUE(char_id, spell_id, tier),
	FOREIGN KEY (char_id) REFERENCES characters(id) ON DELETE CASCADE ON UPDATE CASCADE,
	FOREIGN KEY (spell_id) REFERENCES spells(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX idx_character_spells_spell_id ON character_spells(spell_id);
