<commit_before>require "micrate"
require "pg"
require "mysql"
require "sqlite3"

module Amber::CMD
  class MainCommand < Cli::Supercommand
    command "db", aliased: "database"

    class Database < Cli::Command
      command_name "database"

      class Options
        arg_array "commands", desc: "drop create migrate rollback redo status version seed"
      end

      class Help
        caption "# Performs database maintenance tasks"
      end

      def run
        Micrate::Cli.setup_logger
        Micrate::DB.connection_url = database_url
        args.commands.each do |command|
          begin
            case command
            when "create"
              uri = URI.parse(database_url)
              if name = uri.path
                name = name.gsub("/", "")
                Micrate::DB.connection_url = database_url.gsub(name, uri.scheme)
                create_database(name)
                puts "Created database #{name}"
              end
            when "drop"
              uri = URI.parse(database_url)
              if name = uri.path
                name = name.gsub("/", "")
                drop_database(name)
                puts "Dropped database #{name}"
              end
            when "seed"
              `crystal db/seeds.cr`
              puts "Seeded database"
            when "migrate"
              Micrate::Cli.run_up
            when "rollback"
              Micrate::Cli.run_down
            when "redo"
              Micrate::Cli.run_redo
            when "status"
              Micrate::Cli.run_status
            when "version"
              Micrate::Cli.run_dbversion
            else
              Micrate::Cli.print_help
            end
          rescue e : Micrate::UnorderedMigrationsException
            Micrate::Cli.report_unordered_migrations(e.versions)
            exit 1
          rescue e : DB::ConnectionRefused
            puts "Connection refused: #{Micrate::DB.connection_url}"
            exit 1
          rescue e : Exception
            puts e.message
            exit 1
          end
        end<commit_msg>fix bug with database_url not being reset<commit_after>require "micrate"
require "pg"
require "mysql"
require "sqlite3"

module Amber::CMD
  class MainCommand < Cli::Supercommand
    command "db", aliased: "database"

    class Database < Cli::Command
      command_name "database"

      class Options
        arg_array "commands", desc: "drop create migrate rollback redo status version seed"
      end

      class Help
        caption "# Performs database maintenance tasks"
      end

      def run
        args.commands.each do |command|
          Micrate::Cli.setup_logger
          Micrate::DB.connection_url = database_url
          begin
            case command
            when "drop"
              uri = URI.parse(database_url)
              if name = uri.path
                name = name.gsub("/", "")
                Micrate::DB.connection_url = database_url.gsub(name, uri.scheme)
                drop_database(name)
                puts "Dropped database #{name}"
              end
            when "create"
              uri = URI.parse(database_url)
              if name = uri.path
                name = name.gsub("/", "")
                Micrate::DB.connection_url = database_url.gsub(name, uri.scheme)
                create_database(name)
                puts "Created database #{name}"
              end
            when "seed"
              `crystal db/seeds.cr`
              puts "Seeded database"
            when "migrate"
              Micrate::Cli.run_up
            when "rollback"
              Micrate::Cli.run_down
            when "redo"
              Micrate::Cli.run_redo
            when "status"
              Micrate::Cli.run_status
            when "version"
              Micrate::Cli.run_dbversion
            else
              Micrate::Cli.print_help
            end
          rescue e : Micrate::UnorderedMigrationsException
            Micrate::Cli.report_unordered_migrations(e.versions)
            exit 1
          rescue e : DB::ConnectionRefused
            puts "Connection refused: #{Micrate::DB.connection_url}"
            exit 1
          rescue e : Exception
            puts e.message
            exit 1
          end
        end
{'fraction_non_alphanumeric': 0.07944691820951488, 'fraction_numerical': 0.0018748535270681978, 'mean_word_length': 1.4900816802800467, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379266', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1098, 'n_words': 282}