-- Migration: Create stock_reservations table
CREATE TABLE IF NOT EXISTS stock_reservations (
    id UUID PRIMARY KEY,
    product_id UUID NOT NULL REFERENCES products(id),
    inventory_item_id UUID NOT NULL REFERENCES inventory_items(id),
    buyer_id UUID NOT NULL REFERENCES users(id),
    quantity BIGINT NOT NULL,
    expires_at TIMESTAMPTZ NOT NULL,
    created_at TIMESTAMPTZ DEFAULT (NOW() AT TIME ZONE 'utc'),
    status TEXT NOT NULL DEFAULT 'active' -- 'active', 'completed', 'expired'
);

CREATE INDEX idx_stock_reservations_expires_at ON stock_reservations(expires_at) WHERE status = 'active';
