Class: ActiveRecord::Tasks::MySQLDatabaseTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/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.



14
15
16
17
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/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

Returns:

  • (Boolean)


10
11
12
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 10

def self.using_database_configurations?
  true
end

Instance Method Details

#charsetObject



35
36
37
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 35

def charset
  connection.charset
end

#collationObject



39
40
41
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 39

def collation
  connection.collation
end

#createObject



19
20
21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 19

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

#dropObject



25
26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 25

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

#purgeObject



30
31
32
33
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 30

def purge
  establish_connection(db_config)
  connection.recreate_database(db_config.database, creation_options)
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 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 43

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?
    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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/mysql_database_tasks.rb', line 61

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