Class: ActiveRecord::Tasks::MySQLDatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::Tasks::MySQLDatabaseTasks
- Defined in:
- lib/active_record/tasks/mysql_database_tasks.rb
Overview
:nodoc:
Instance Method Summary collapse
- #charset ⇒ Object
- #collation ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(configuration) ⇒ MySQLDatabaseTasks
constructor
A new instance of MySQLDatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename, extra_flags) ⇒ Object
- #structure_load(filename, extra_flags) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ MySQLDatabaseTasks
Returns a new instance of MySQLDatabaseTasks.
8 9 10 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 8 def initialize(configuration) @configuration = configuration 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
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 12 def create establish_connection configuration_without_database connection.create_database configuration["database"], establish_connection configuration rescue ActiveRecord::StatementInvalid => error if error..include?("database exists") raise DatabaseAlreadyExists else raise end end |
#drop ⇒ Object
24 25 26 27 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 24 def drop establish_connection configuration connection.drop_database configuration["database"] end |
#purge ⇒ Object
29 30 31 32 |
# File 'lib/active_record/tasks/mysql_database_tasks.rb', line 29 def purge establish_connection configuration connection.recreate_database configuration["database"], end |
#structure_dump(filename, extra_flags) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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? args += ignore_tables.map { |table| "--ignore-table=#{configuration['database']}.#{table}" } end args.concat(["#{configuration['database']}"]) 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 'lib/active_record/tasks/mysql_database_tasks.rb', line 60 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", "#{configuration['database']}"]) args.unshift(*extra_flags) if extra_flags run_cmd("mysql", args, "loading") end |