class CreateInitialTables < Jennifer::Migration::Base
  def up
    create_table :users do |t|
      t.string :email, {:null => false}
      t.string :password_hash, {:null => false}
      t.string :name
      t.timestamps
    end

    create_table :api_tokens do |t|
      t.string :token, {:null => false}
      t.belongs_to :user, {:null => false}
      t.timestamps
    end

    create_table :container_deployments do |t|
      t.string :name, {:null => false}
      t.string :source_type, {:null => false}
      t.string :source_url, {:null => false}
      t.string :status, {:null => false, :default => "pending"}
      t.string :cpu
      t.string :memory
      t.string :regions, {:array => true}
      t.belongs_to :user, {:null => false}
      t.timestamps
    end

    # Add indexes
    create_index :users, :email, {:unique => true}
    create_index :api_tokens, :token, {:unique => true}
  end

  def down
    drop_table :container_deployments if table_exists? :container_deployments
    drop_table :api_tokens if table_exists? :api_tokens 
    drop_table :users if table_exists? :users
  end
end 