-- Migration: add armor plates support
-- Run: sqlite3 tarkov.db < migration_add_plates.sql

PRAGMA foreign_keys = ON;

CREATE TABLE IF NOT EXISTS armor_open_slots (
    carrier_id  TEXT NOT NULL REFERENCES gear_items(id) ON DELETE CASCADE,
    slot_nameid TEXT NOT NULL,
    zones       TEXT,
    PRIMARY KEY (carrier_id, slot_nameid)
);

CREATE TABLE IF NOT EXISTS armor_slot_plates (
    carrier_id  TEXT NOT NULL,
    slot_nameid TEXT NOT NULL,
    plate_id    TEXT NOT NULL REFERENCES gear_items(id) ON DELETE CASCADE,
    PRIMARY KEY (carrier_id, slot_nameid, plate_id),
    FOREIGN KEY (carrier_id, slot_nameid) REFERENCES armor_open_slots(carrier_id, slot_nameid) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_armor_slot_plates_plate ON armor_slot_plates(plate_id);
