Module: Glueby::Generator::MigrateGenerator

Defined Under Namespace

Modules: ClassMethod

Constant Summary collapse

MYSQL_ADAPTERS =
[
  "ActiveRecord::ConnectionAdapters::MysqlAdapter",
  "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
].freeze

Instance Method Summary collapse

Instance Method Details

#migration_versionObject



18
19
20
21
22
23
# File 'lib/glueby/generator/migrate_generator.rb', line 18

def migration_version
  major = ::Rails::VERSION::MAJOR
  if major >= 5
    "[#{major}.#{::Rails::VERSION::MINOR}]"
  end
end

#mysql?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/glueby/generator/migrate_generator.rb', line 25

def mysql?
  MYSQL_ADAPTERS.include?(::ActiveRecord::Base.connection.class.name)
end

#table_optionsObject



29
30
31
32
33
34
35
# File 'lib/glueby/generator/migrate_generator.rb', line 29

def table_options
  if mysql?
    ', :options => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"'
  else
    ""
  end
end