Class: Hanami::Model::Migrator::MySQLAdapter Private

Inherits:
Adapter
  • Object
show all
Defined in:
lib/hanami/model/migrator/mysql_adapter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

MySQL adapter

Since:

  • 0.4.0

Constant Summary collapse

PASSWORD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.7.0

'MYSQL_PWD'.freeze
DB_CREATION_ERROR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

'Database creation failed. If the database exists, ' \
'then its console may be open. See this issue for more details: ' \
'https://github.com/hanami/model/issues/250'.freeze

Constants inherited from Adapter

Adapter::MIGRATIONS_TABLE, Adapter::MIGRATIONS_TABLE_VERSION_COLUMN

Instance Method Summary collapse

Methods inherited from Adapter

for, #initialize, #migrate, #rollback, #version

Constructor Details

This class inherits a constructor from Hanami::Model::Migrator::Adapter

Instance Method Details

#createObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.0


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hanami/model/migrator/mysql_adapter.rb', line 21

def create
  new_connection(global: true).run %(CREATE DATABASE `#{database}`;)
rescue Sequel::DatabaseError => e
  message = if e.message.match(/database exists/) # rubocop:disable Performance/RedundantMatch
              DB_CREATION_ERROR
            else
              e.message
            end

  raise MigrationError.new(message)
end

#dropObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.0


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hanami/model/migrator/mysql_adapter.rb', line 35

def drop
  new_connection(global: true).run %(DROP DATABASE `#{database}`;)
rescue Sequel::DatabaseError => e
  message = if e.message.match(/doesn\'t exist/) # rubocop:disable Performance/RedundantMatch
              "Cannot find database: #{database}"
            else
              e.message
            end

  raise MigrationError.new(message)
end

#dumpObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.0


49
50
51
52
# File 'lib/hanami/model/migrator/mysql_adapter.rb', line 49

def dump
  dump_structure
  dump_migrations_data
end

#loadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.0


56
57
58
# File 'lib/hanami/model/migrator/mysql_adapter.rb', line 56

def load
  load_structure
end