Sha256: 9d0429548b1c3bfef1047a142e2f24e6ff550e07d12d9bbaca0ef69e332b96c0

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

require_relative 'config'

dbms = SchemaDev::Config.load.dbms

DATABASES = %w[schema_plus_test]

if dbms.any?
  {
    postgresql: { uservar: 'POSTGRESQL_DB_USER', defaultuser: 'schema_plus', create: "createdb -U '%{user}' %{dbname}", drop: "dropdb -U '%{user}' %{dbname}" },
    mysql:      { uservar: 'MYSQL_DB_USER', defaultuser: 'schema_plus', create: "mysqladmin -u '%{user}' create %{dbname}", drop: "mysqladmin -u '%{user}' -f drop %{dbname}" }
  }.slice(*dbms).each do |dbm, info|
    namespace dbm do
      user = ENV.fetch info[:uservar], info[:defaultuser]
      task :create_databases do
        DATABASES.each do |dbname|
          system(info[:create] % {user: user, dbname: dbname})
        end
      end
      task :drop_databases do
        DATABASES.each do |dbname|
          system(info[:drop] % {user: user, dbname: dbname})
        end
      end
    end
  end

  desc 'Create test databases'
  task :create_databases do
    invoke_multiple(dbms, "create_databases")
  end

  desc 'Drop test databases'
  task :drop_databases do
    invoke_multiple(dbms, "drop_databases")
  end

  def invoke_multiple(namespaces, task)
    failed = namespaces.reject { |adapter|
      begin
        Rake::Task["#{adapter}:#{task}"].invoke
        true
      rescue => e
        warn "\n#{e}\n"
        false
      end
    }
    fail "Failure in: #{failed.join(', ')}" if failed.any?
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
schema_dev-1.1.0 lib/schema_dev/tasks.rb
schema_dev-1.0.3 lib/schema_dev/tasks.rb
schema_dev-1.0.2 lib/schema_dev/tasks.rb
schema_dev-1.0.1 lib/schema_dev/tasks.rb
schema_dev-1.0.0 lib/schema_dev/tasks.rb
schema_dev-0.1.6 lib/schema_dev/tasks.rb