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
    Runner.rollback
  end
end

case ARGV[0]?
when "migrate"
  Jennifer::Migration.run_migrations
when "rollback"
  Jennifer::Migration.rollback_migration
else
  puts "Available commands: migrate, rollback"
end 