Sha256: 0519b1febbab4e6b9104d5aa9a5f99cc8f7802f5c16d7341953b0f690b5bdc75

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')

namespace :mysql do
  desc 'Create the MySQL test databases'
  task :create_database do
    ActiveRecord::Base.clear_all_connections!
    spec = CompositePrimaryKeys::ConnectionSpec['mysql'].dup
    database_name = spec.delete('database')
    connection = ActiveRecord::Base.establish_connection(spec)
    ActiveRecord::Base.connection.create_database(database_name)
    ActiveRecord::Base.clear_all_connections!
  end

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

    Rake::Task['mysql:load_connection'].invoke
    ActiveRecord::Base.connection.execute(sql)
  end

  desc 'Drop the MySQL test databases'
  task :drop_databases => :load_connection do
    ActiveRecord::Base.connection.drop_database(SPEC['database'])
  end

  desc 'Rebuild the MySQL test databases'
  task :rebuild_databases => [:drop_databases, :build_databases]
  
  task :load_connection do
    require File.join(PROJECT_ROOT, "test", "connections", "native_mysql", "connection")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
composite_primary_keys-5.0.4 tasks/databases/mysql.rake
composite_primary_keys-5.0.2 tasks/databases/mysql.rake
composite_primary_keys-5.0.1 tasks/databases/mysql.rake
composite_primary_keys-5.0.0 tasks/databases/mysql.rake