DROP TABLE IF EXISTS character_factions;
CREATE TABLE character_factions (
	id            INTEGER PRIMARY KEY,
	char_id       INTEGER NOT NULL DEFAULT 0,
	faction_id    INTEGER NOT NULL DEFAULT 0,
	faction_level INTEGER NOT NULL DEFAULT 0,
	UNIQUE(char_id, faction_id),
	FOREIGN KEY (char_id) REFERENCES characters(id) ON DELETE CASCADE ON UPDATE CASCADE,
	FOREIGN KEY (faction_id) REFERENCES factions(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX idx_character_factions_faction_id ON character_factions(faction_id);
