# Supabase Inventory Tracker

> Track stock levels, process restocks, and adjust quantities after orders without writing SQL. Read current inventory, upsert new products, and get low-stock alerts from your Supabase database.

Source: https://cotera.co/solutions/ops/supabase-inventory-tracker

---

- **Team:** Operations
- **Tools:** Supabase
- **Difficulty:** medium
- **Setup time:** 10 min
- **Time saved:** 1-2 hrs/week

## How it works
1. **Check Stock** — Reads current inventory levels and flags items that are low or out of stock against their reorder points
2. **Upsert Products** — Adds new products to inventory or updates existing ones when shipments arrive, using SKU as the conflict key
3. **Adjust Quantities** — Decrements stock for orders and increments for restocks with before-and-after verification
4. **Generate Reports** — Produces inventory summaries grouped by category with low-stock alerts and total value calculations

## Example requests
- Check inventory levels for all products in the electronics category. Flag anything below its reorder point.
- We just received a shipment: add 200 units of SKU-A100, 150 units of SKU-B200, and 75 units of SKU-C300 to the inventory table.
- Subtract inventory for order #4521: 3 units of SKU-A100 and 1 unit of SKU-B200. Warn me if either goes below the reorder point.

## Prompt

```markdown
## Task

Use @Supabase/Read Records to check current inventory levels, @Supabase/Upsert Record to add new stock entries or update existing ones when shipments arrive, and @Supabase/Update Record to adjust quantities after orders are placed or stock is moved between locations.

## Input

The user provides:
1. The inventory table name in Supabase (defaults to "inventory")
2. The action: check stock, add new products, restock, or adjust after orders
3. Product identifiers: SKU, product_id, or name
4. Quantity changes: units received, units sold, or new quantity to set
5. Optional: warehouse or location for multi-location tracking

**Example:** "Check the current stock for SKU-1234 and SKU-5678. Then add 500 units of SKU-1234 from today's shipment and subtract 12 units of SKU-5678 for order #9901."

## Context

### Checking Inventory Levels

1. Use @Supabase/Read Records to pull current stock for specific SKUs or product IDs
2. Filter by location or warehouse if multi-location tracking is in use
3. Flag items that are below the reorder threshold
4. Report items that are out of stock (quantity = 0)
5. Include last_updated timestamps so the user knows how fresh the data is

### Adding New Products

1. Use @Supabase/Read Records to check if the product already exists in the inventory table
2. Use @Supabase/Upsert Record to insert new products with initial stock quantities
3. Set the conflict resolution column (usually sku or product_id) so existing products get updated instead of duplicated
4. Include all product metadata: name, SKU, category, reorder_point, unit_cost

### Restocking

1. Use @Supabase/Read Records to get the current quantity for the product being restocked
2. Calculate the new quantity: current_quantity + units_received
3. Use @Supabase/Upsert Record to update the quantity and set last_restocked timestamp
4. If the product does not exist, create a new record with the restocked quantity

### Order Adjustments

1. Use @Supabase/Read Records to get the current quantity for ordered items
2. Verify sufficient stock exists before decrementing
3. Use @Supabase/Update Record to subtract the ordered quantity
4. If the adjustment would bring quantity below zero, warn the user and do not apply
5. If the new quantity falls below the reorder_point, flag the item for reorder

### Inventory Reports

When the user asks for a report:
1. Use @Supabase/Read Records to pull all inventory records
2. Group by category or location
3. Highlight low-stock and out-of-stock items
4. Calculate total inventory value (quantity * unit_cost) if cost data is available

### Safety Guidelines

- Never set quantity to a negative number
- Always verify current stock before making adjustments
- Show before and after quantities for every change
- Warn if a restock would exceed a warehouse capacity limit (if defined)

## Output

**Inventory Status:**

**Current Stock Levels:**
| SKU | Product Name | Quantity | Reorder Point | Status |
|-----|-------------|----------|---------------|--------|
| [sku] | [name] | [qty] | [reorder_at] | In Stock / Low / Out of Stock |

**Changes Applied:**
| SKU | Action | Previous Qty | Change | New Qty |
|-----|--------|-------------|--------|---------|
| [sku] | Restock | [old] | +[n] | [new] |
| [sku] | Order adjustment | [old] | -[n] | [new] |

**Alerts:**
- Low stock: [list of items below reorder point]
- Out of stock: [list of items at zero]
- Reorder recommended: [items with suggested order quantities]

**Summary:**
- Products checked: [n]
- Restocked: [n]
- Adjusted for orders: [n]
- New products added: [n]
```

## Related reading
- [Supabase Pricing in 2026: What the Free Tier Actually Gets You](https://cotera.co/articles/supabase-pricing-guide.md)

