-- D1 Database Schema for Server Recommendation System

-- Providers table
CREATE TABLE providers (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  website TEXT
);

-- Servers table
CREATE TABLE servers (
  id TEXT PRIMARY KEY,
  provider_id TEXT NOT NULL,
  name TEXT NOT NULL,
  instance_type TEXT NOT NULL,
  cpu_cores INTEGER NOT NULL,
  cpu_frequency REAL,
  memory_size INTEGER NOT NULL,
  storage_size INTEGER NOT NULL,
  storage_type TEXT NOT NULL,
  network_bandwidth INTEGER NOT NULL,
  sla_percentage REAL DEFAULT 99.9,
  price_monthly REAL NOT NULL,
  FOREIGN KEY (provider_id) REFERENCES providers(id)
);

-- Server regions table
CREATE TABLE server_regions (
  server_id TEXT NOT NULL,
  region_code TEXT NOT NULL,
  PRIMARY KEY (server_id, region_code),
  FOREIGN KEY (server_id) REFERENCES servers(id)
);

-- Indexes for performance optimization
CREATE INDEX idx_servers_provider ON servers(provider_id);
CREATE INDEX idx_servers_specs ON servers(cpu_cores, memory_size);
CREATE INDEX idx_servers_price ON servers(price_monthly);
CREATE INDEX idx_server_regions_region ON server_regions(region_code);
