Class: ActiveRecord::Tasks::MySQLDatabaseTasks

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/tasks/mysql_database_tasks.rb

Overview

:nodoc:

Constant Summary collapse

ER_DB_CREATE_EXISTS =
1007

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_config) ⇒ MySQLDatabaseTasks

Returns a new instance of MySQLDatabaseTasks.



12
13
14
15
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 12

def initialize(db_config)
  @db_config = db_config
  @configuration_hash = db_config.configuration_hash
end

Class Method Details

.using_database_configurations?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 8

def self.using_database_configurations?
  true
end

Instance Method Details

#charsetObject



33
34
35
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 33

def charset
  connection.charset
end

#collationObject



37
38
39
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 37

def collation
  connection.collation
end

#createObject



17
18
19
20
21
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 17

def create
  establish_connection(configuration_hash_without_database)
  connection.create_database(db_config.database, creation_options)
  establish_connection
end

#dropObject



23
24
25
26
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 23

def drop
  establish_connection
  connection.drop_database(db_config.database)
end

#purgeObject



28
29
30
31
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 28

def purge
  establish_connection(configuration_hash_without_database)
  connection.recreate_database(db_config.database, creation_options)
end

#structure_dump(filename, extra_flags) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 41

def structure_dump(filename, extra_flags)
  args = prepare_command_options
  args.concat(["--result-file", "#{filename}"])
  args.concat(["--no-data"])
  args.concat(["--routines"])
  args.concat(["--skip-comments"])

  ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
  if ignore_tables.any?
    ignore_tables = connection.data_sources.select { |table| ignore_tables.any? { |pattern| pattern === table } }
    args += ignore_tables.map { |table| "--ignore-table=#{db_config.database}.#{table}" }
  end

  args.concat([db_config.database.to_s])
  args.unshift(*extra_flags) if extra_flags

  run_cmd("mysqldump", args, "dumping")
end

#structure_load(filename, extra_flags) ⇒ Object



60
61
62
63
64
65
66
67
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 60

def structure_load(filename, extra_flags)
  args = prepare_command_options
  args.concat(["--execute", %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}])
  args.concat(["--database", db_config.database.to_s])
  args.unshift(*extra_flags) if extra_flags

  run_cmd("mysql", args, "loading")
end