-- Run this if you already have a database from an older schema.sql (before customer login).
USE shuddhatam;

CREATE TABLE IF NOT EXISTS customers (
  id VARCHAR(36) PRIMARY KEY DEFAULT (UUID()),
  email VARCHAR(255) UNIQUE NOT NULL,
  password_hash VARCHAR(255) NOT NULL,
  full_name VARCHAR(255) NOT NULL,
  phone VARCHAR(20) DEFAULT '',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Skip the next line if `customer_id` already exists on orders
ALTER TABLE orders ADD COLUMN customer_id VARCHAR(36) DEFAULT NULL;

-- Add FK (may fail if it already exists — safe to ignore)
ALTER TABLE orders ADD CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE SET NULL;
