-- 0011_soft_delete.sql — 统一软删（is_deleted）+ 操作日志完善
-- 所有数据表加 is_deleted 标志，DELETE 改为 UPDATE SET is_deleted=1
-- 恢复：UPDATE SET is_deleted=0（操作日志已存完整快照）

ALTER TABLE vehicles           ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE wash_records        ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE chemical_usage      ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE maintenance_records  ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE refuel_records      ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE charging_records    ADD COLUMN is_deleted INTEGER DEFAULT 0;
ALTER TABLE insurance_records   ADD COLUMN is_deleted INTEGER DEFAULT 0;

-- 索引加速
CREATE INDEX IF NOT EXISTS ix_vehicles_is_deleted         ON vehicles(is_deleted);
CREATE INDEX IF NOT EXISTS ix_wash_records_is_deleted      ON wash_records(is_deleted);
CREATE INDEX IF NOT EXISTS ix_maintenance_is_deleted       ON maintenance_records(is_deleted);
CREATE INDEX IF NOT EXISTS ix_refuel_is_deleted            ON refuel_records(is_deleted);
CREATE INDEX IF NOT EXISTS ix_charging_is_deleted          ON charging_records(is_deleted);
CREATE INDEX IF NOT EXISTS ix_insurance_is_deleted         ON insurance_records(is_deleted);
