-- Kayıtlı teslimat adresleri (shop_customers).
-- USE: run-database-migrations.sh mysql çağrısında DB_NAME ile seçilir; USE faunamix Railway'de yanlış şemaya yazardı.

CREATE TABLE IF NOT EXISTS shop_customer_addresses (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  customer_id BIGINT UNSIGNED NOT NULL,
  label VARCHAR(64) NOT NULL DEFAULT 'Ev',
  full_name VARCHAR(255) NOT NULL,
  phone VARCHAR(64) NOT NULL,
  city VARCHAR(128) NOT NULL,
  district VARCHAR(128) NOT NULL DEFAULT '',
  address_line TEXT NOT NULL,
  postal_code VARCHAR(32) NOT NULL DEFAULT '',
  is_default TINYINT(1) NOT NULL DEFAULT 0,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_shop_cust_addr_customer (customer_id),
  CONSTRAINT fk_shop_cust_addr_customer FOREIGN KEY (customer_id) REFERENCES shop_customers(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
