/*
  # Create servers table for Proxmox dashboard

  1. New Tables
    - `servers`
      - `id` (uuid, primary key)
      - `name` (text, server name)
      - `model` (text, server model)
      - `cpu_model` (text, CPU model)
      - `cpu_cores` (integer, number of CPU cores)
      - `ram_gb` (integer, RAM in GB)
      - `created_at` (timestamp)
      - `updated_at` (timestamp)

  2. Security
    - Enable RLS on `servers` table
    - Add policies for authenticated users to manage their servers
*/

CREATE TABLE IF NOT EXISTS servers (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  name text NOT NULL,
  model text NOT NULL,
  cpu_model text NOT NULL,
  cpu_cores integer NOT NULL,
  ram_gb integer NOT NULL,
  created_at timestamptz DEFAULT now(),
  updated_at timestamptz DEFAULT now()
);

ALTER TABLE servers ENABLE ROW LEVEL SECURITY;

-- Allow authenticated users to read all servers
CREATE POLICY "Users can read all servers"
  ON servers
  FOR SELECT
  TO authenticated
  USING (true);

-- Allow authenticated users to insert their own servers
CREATE POLICY "Users can insert servers"
  ON servers
  FOR INSERT
  TO authenticated
  WITH CHECK (true);

-- Allow authenticated users to update their own servers
CREATE POLICY "Users can update their own servers"
  ON servers
  FOR UPDATE
  TO authenticated
  USING (true)
  WITH CHECK (true);