DROP TABLE IF EXISTS character_items;
CREATE TABLE character_items (
	id              INTEGER PRIMARY KEY,
	type            TEXT    NOT NULL DEFAULT 'NOT-EQUIPPED',
	account_id      INTEGER NOT NULL DEFAULT 0,
	char_id         INTEGER NOT NULL DEFAULT 0,
	bag_id          INTEGER NOT NULL DEFAULT 0,
	slot            INTEGER NOT NULL DEFAULT 0,
	item_id         INTEGER NOT NULL DEFAULT 0,
	creator         TEXT    NOT NULL DEFAULT '',
	condition_      INTEGER NOT NULL DEFAULT 100,
	attuned         INTEGER NOT NULL DEFAULT 0,
	count           INTEGER NOT NULL DEFAULT 1,
	max_sell_value  INTEGER NOT NULL DEFAULT 0,
	login_checksum  INTEGER NOT NULL DEFAULT 0,
	adorn0          INTEGER NOT NULL DEFAULT 0,
	adorn1          INTEGER NOT NULL DEFAULT 0,
	adorn2          INTEGER NOT NULL DEFAULT 0,
	adorn1_time     INTEGER NOT NULL DEFAULT 0,
	adorn3          INTEGER NOT NULL DEFAULT 0,
	adorn4          INTEGER NOT NULL DEFAULT 0,
	adorn5          INTEGER NOT NULL DEFAULT 0,
	adorn6          INTEGER NOT NULL DEFAULT 0,
	adorn7          INTEGER NOT NULL DEFAULT 0,
	adorn8          INTEGER NOT NULL DEFAULT 0,
	adorn9          INTEGER NOT NULL DEFAULT 0,
	adorn10         INTEGER NOT NULL DEFAULT 0,
	no_sale         INTEGER NOT NULL DEFAULT 0,
	last_saved      INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
	created         INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
	equip_slot      INTEGER NOT NULL DEFAULT 0,
	UNIQUE(char_id, type, bag_id, slot),
	FOREIGN KEY (char_id) REFERENCES characters(id) ON DELETE CASCADE ON UPDATE CASCADE,
	FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX idx_character_items_item_id ON character_items(item_id);
