ALTER TABLE inventory_items
  ADD COLUMN IF NOT EXISTS inventory_group_code TEXT NOT NULL DEFAULT '';

CREATE INDEX IF NOT EXISTS idx_inventory_items_group_lookup
  ON inventory_items(sku_code, credential_type, inventory_group_code, status, id);

CREATE TABLE IF NOT EXISTS admin_user_inventory_group_bindings (
  id BIGSERIAL PRIMARY KEY,
  admin_user_id BIGINT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
  inventory_group_code TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL,
  updated_at TIMESTAMPTZ NOT NULL,
  UNIQUE(admin_user_id, inventory_group_code)
);

CREATE INDEX IF NOT EXISTS idx_admin_user_inventory_group_bindings_user_id
  ON admin_user_inventory_group_bindings(admin_user_id, inventory_group_code);
