Sha256: 1ecc532f7b7d3eae06b21284e9db1b2e25ef0226b4bae0d49ca4f4afe0964518

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

module Hanami
  module Sequel
    module CLI
      class Drop < Hanami::CLI::Command
        def call(**options)
          Command.drop
        end
      end
    end

    module Command
      def self.drop
        env = Hanami::Environment.new
        if env.environment == 'production'
          raise 'Command unavailable in the production environment.'
        end

        db_url = ENV.fetch('DATABASE_URL')
        db_conn, _, db_name = db_url.rpartition('/')

        require 'sequel'

        db = ::Sequel.connect("#{db_conn}/postgres",
                              loggers: Logger.new($stdout))
        db.run("DROP DATABASE IF EXISTS #{db_name}")
      end
    end
  end
end

Hanami::CLI.register 'sequel drop', Hanami::Sequel::CLI::Drop

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-sequel-1.1.1 lib/hanami/sequel/commands/drop.rb
hanami-sequel-1.1.0.1 lib/hanami/sequel/commands/drop.rb