Class: ActiveRecord::Tasks::MySQLDatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::Tasks::MySQLDatabaseTasks
- Defined in:
- 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
- #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.
12 13 14 15 |
# File '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
8 9 10 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 8 def self.using_database_configurations? true end |
Instance Method Details
#charset ⇒ Object
34 35 36 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 34 def charset connection.charset end |
#collation ⇒ Object
38 39 40 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 38 def collation connection.collation end |
#create ⇒ Object
17 18 19 20 21 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 17 def create establish_connection(configuration_hash_without_database) connection.create_database(db_config.database, ) establish_connection end |
#drop ⇒ Object
23 24 25 26 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 23 def drop establish_connection connection.drop_database(db_config.database) end |
#purge ⇒ Object
28 29 30 31 32 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 28 def purge establish_connection(configuration_hash_without_database) connection.recreate_database(db_config.database, ) establish_connection end |
#structure_dump(filename, extra_flags) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 42 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
61 62 63 64 65 66 67 68 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 61 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 |