Class: ActiveRecord::Tasks::MySQLDatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::Tasks::MySQLDatabaseTasks
- Defined in:
- lib/active_record/tasks/mysql_database_tasks.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #charset ⇒ Object
- #collation ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(db_config) ⇒ MySQLDatabaseTasks
constructor
A new instance of MySQLDatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename, extra_flags) ⇒ Object
- #structure_load(filename, extra_flags) ⇒ Object
Constructor Details
#initialize(db_config) ⇒ MySQLDatabaseTasks
Returns a new instance of MySQLDatabaseTasks.
10 11 12 13 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 10 def initialize(db_config) @db_config = db_config @configuration_hash = db_config.configuration_hash end |
Class Method Details
.using_database_configurations? ⇒ Boolean
6 7 8 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 6 def self.using_database_configurations? true end |
Instance Method Details
#charset ⇒ Object
32 33 34 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 32 def charset connection.charset end |
#collation ⇒ Object
36 37 38 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 36 def collation connection.collation end |
#create ⇒ Object
15 16 17 18 19 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 15 def create establish_connection(configuration_hash_without_database) connection.create_database(db_config.database, ) establish_connection end |
#drop ⇒ Object
21 22 23 24 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 21 def drop establish_connection connection.drop_database(db_config.database) end |
#purge ⇒ Object
26 27 28 29 30 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 26 def purge establish_connection(configuration_hash_without_database) connection.recreate_database(db_config.database, ) establish_connection end |
#structure_dump(filename, extra_flags) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 40 def structure_dump(filename, extra_flags) args = 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
59 60 61 62 63 64 65 66 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 59 def structure_load(filename, extra_flags) args = 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 |