-- Girişli müşteri sepeti (sunucu tarafı). idempotent

CREATE TABLE IF NOT EXISTS shop_cart_lines (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  customer_id BIGINT UNSIGNED NOT NULL,
  product_id INT UNSIGNED NOT NULL,
  quantity INT UNSIGNED NOT NULL DEFAULT 1,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE KEY uq_shop_cart_customer_product (customer_id, product_id),
  KEY idx_shop_cart_customer (customer_id),
  CONSTRAINT fk_shop_cart_customer FOREIGN KEY (customer_id) REFERENCES shop_customers(id) ON DELETE CASCADE,
  CONSTRAINT fk_shop_cart_product FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
