Class: ActiveRecord::Tasks::MySQLDatabaseTasks
- 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
- #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.
14 15 16 17 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 14 def initialize(db_config) @db_config = db_config @configuration_hash = db_config.configuration_hash end |
Class Method Details
.using_database_configurations? ⇒ Boolean
10 11 12 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 10 def self.using_database_configurations? true end |
Instance Method Details
#charset ⇒ Object
35 36 37 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 35 def charset connection.charset end |
#collation ⇒ Object
39 40 41 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 39 def collation connection.collation end |
#create ⇒ Object
19 20 21 22 23 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 19 def create establish_connection(configuration_hash_without_database) connection.create_database(db_config.database, ) establish_connection(db_config) end |
#drop ⇒ Object
25 26 27 28 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 25 def drop establish_connection(db_config) connection.drop_database(db_config.database) end |
#purge ⇒ Object
30 31 32 33 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 30 def purge establish_connection(db_config) connection.recreate_database(db_config.database, ) end |
#structure_dump(filename, extra_flags) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb', line 43 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? 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 'activerecord/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 |