Sha256: f532463c3f86988491227bdeb24e35f274c3852f23523978ab79105b4b6423cf

Contents?: true

Size: 751 Bytes

Versions: 2

Compression:

Stored size: 751 Bytes

Contents

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

    module Command
      def self.create
        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("CREATE DATABASE #{db_name}")
      end
    end
  end
end

Hanami::CLI.register 'sequel create', Hanami::Sequel::CLI::Create

Version data entries

2 entries across 2 versions & 1 rubygems

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