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

# Configure Jennifer
Jennifer::Config.configure do |conf|
  conf.from_uri(ENV["DATABASE_URL"]? || "postgres://development:development@localhost:5432/container_mom_production")
  
  # These will be overridden by from_uri but kept for logging
  conf.logger = Log.for("db")
  conf.logger.level = :debug if ENV["DEBUG"]?
end

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

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

  def self.rollback_migration
    Jennifer::Migration::Runner.rollback({:count => 1})
  end
end

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