require "jennifer"
require "jennifer/adapter/postgres"

# Configure Jennifer
Jennifer::Config.configure do |conf|
  conf.host = ENV["DATABASE_URL"]
  conf.port = (ENV["DB_PORT"]? || "5432").to_i
  conf.db = ENV["DB_NAME"] || "default_db_name"
  conf.adapter = "postgres"
  conf.user = ENV["DB_USER"]
  conf.password = ENV["DB_PASSWORD"]
end

# Load models
require "../models/**"

module Jennifer::Migration
  def self.run_migrations
    Runner.migrate
  end

  def self.rollback_migration
    # Rollback one migration by default
    Runner.rollback({:count => 1})
  end
end

case ARGV[0]?
when "migrate"
  Jennifer::Migration.run_migrations
when "rollback"
  # Allow specifying number of migrations to rollback
  count = (ARGV[1]? || "1").to_i
  Runner.rollback({:count => count})
else
  puts "Available commands:"
  puts "  migrate           - Run pending migrations"
  puts "  rollback [count] - Rollback last N migrations (default: 1)"
end 