Sha256: 6cc89ccea2a1bd725d2aaa4e51e7bb26b1284f7ddaf72aff976749285a8d8f6e

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

namespace :mysql do
  task :setup do
    require 'bundler'
    Bundler.require(:default, :mysql)
  end

  task :create_database => :setup do
    spec = CompositePrimaryKeys::ConnectionSpec['mysql']
    ActiveRecord::Base.clear_all_connections!
    new_spec = spec.dup
    new_spec.delete('database')
    connection = ActiveRecord::Base.establish_connection(new_spec)
    ActiveRecord::Base.connection.create_database(spec['database'], charset: spec['charset'] || 'utf8mb4')
    ActiveRecord::Base.clear_all_connections!
  end

  desc 'Build the MySQL test database'
  task :build_database => [:create_database] do
    path = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'mysql.sql')
    sql = File.open(path, 'rb') do |file|
      file.read
    end

    spec = CompositePrimaryKeys::ConnectionSpec['mysql']
    connection = ActiveRecord::Base.establish_connection(spec)
    sql.split(";").each do |statement|
      ActiveRecord::Base.connection.execute(statement) unless statement.strip.length == 0
    end
  end

  desc 'Drop the MySQL test database'
  task :drop_database => :setup do
    spec = CompositePrimaryKeys::ConnectionSpec['mysql']
    connection = ActiveRecord::Base.establish_connection(spec)
    ActiveRecord::Base.connection.drop_database(spec['database'])
  end

  desc 'Rebuild the MySQL test database'
  task :rebuild_database => [:drop_database, :build_database]
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.9 tasks/databases/mysql.rake
composite_primary_keys-14.0.8 tasks/databases/mysql.rake
composite_primary_keys-13.0.8 tasks/databases/mysql.rake
composite_primary_keys-14.0.7 tasks/databases/mysql.rake
composite_primary_keys-14.0.6 tasks/databases/mysql.rake
composite_primary_keys-13.0.7 tasks/databases/mysql.rake
composite_primary_keys-13.0.6 tasks/databases/mysql.rake
composite_primary_keys-14.0.5 tasks/databases/mysql.rake
composite_primary_keys-13.0.5 tasks/databases/mysql.rake
composite_primary_keys-13.0.4 tasks/databases/mysql.rake
composite_primary_keys-14.0.4 tasks/databases/mysql.rake
composite_primary_keys-14.0.3 tasks/databases/mysql.rake
composite_primary_keys-13.0.3 tasks/databases/mysql.rake
composite_primary_keys-14.0.2 tasks/databases/mysql.rake
composite_primary_keys-13.0.2 tasks/databases/mysql.rake
composite_primary_keys-14.0.1 tasks/databases/mysql.rake