Sha256: 3d88f340fb9814aff88cd59d7d27fc9b3a4143974add325d6ed57f686dd17849

Contents?: true

Size: 1.56 KB

Versions: 42

Compression:

Stored size: 1.56 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 database'
  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 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

    Rake::Task['mysql:load_connection'].reenable
    Rake::Task['mysql:load_connection'].invoke
    #puts %(ActiveRecord::Base.connection.instance_variable_get(:@config)=#{(ActiveRecord::Base.connection.instance_variable_get(:@config)).inspect})
    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 => :load_connection do
    ActiveRecord::Base.connection.drop_database(SPEC['database'])
  end

  desc 'Rebuild the MySQL test database'
  task :rebuild_database => [:drop_database, :build_database]
  
  task :load_connection do
    require File.join(PROJECT_ROOT, "test", "connections", "native_mysql", "connection")
    establish_connection
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
composite_primary_keys-7.0.9 tasks/databases/mysql.rake
composite_primary_keys-7.0.8 tasks/databases/mysql.rake
composite_primary_keys-7.0.7 tasks/databases/mysql.rake
composite_primary_keys-7.0.6 tasks/databases/mysql.rake
composite_primary_keys-7.0.5 tasks/databases/mysql.rake
composite_primary_keys-7.0.4 tasks/databases/mysql.rake
composite_primary_keys-7.0.3 tasks/databases/mysql.rake
composite_primary_keys-7.0.2 tasks/databases/mysql.rake
composite_primary_keys-7.0.1 tasks/databases/mysql.rake
composite_primary_keys-7.0.0 tasks/databases/mysql.rake
composite_primary_keys-6.0.6 tasks/databases/mysql.rake
composite_primary_keys-6.0.5 tasks/databases/mysql.rake
composite_primary_keys-6.0.3 tasks/databases/mysql.rake
composite_primary_keys-5.0.14 tasks/databases/mysql.rake
composite_primary_keys-6.0.1 tasks/databases/mysql.rake
composite_primary_keys-6.0.0 tasks/databases/mysql.rake
composite_primary_keys-5.0.13 tasks/databases/mysql.rake
composite_primary_keys-5.0.12 tasks/databases/mysql.rake
composite_primary_keys-5.0.11 tasks/databases/mysql.rake
composite_primary_keys-5.0.10 tasks/databases/mysql.rake