class ActiveSnapshot::MigrationGenerator
Basic structure to support a generator that builds a migration
Constants
- MYSQL_ADAPTERS
Public Class Methods
next_migration_number(dirname)
click to toggle source
# File lib/generators/active_snapshot/migration_generator.rb, line 9 def self.next_migration_number(dirname) ::ActiveRecord::Generators::Base.next_migration_number(dirname) end
Protected Instance Methods
add_migration(template_name, opts = {})
click to toggle source
# File lib/generators/active_snapshot/migration_generator.rb, line 15 def add_migration(template_name, opts = {}) @template_name = template_name @migration_path ||= "db/migrate" if self.class.migration_exists?(@migration_path, template_name) Kernel.warn "Migration already exists: #{template_name}" else migration_template( "#{template_name}.rb.erb", File.join(@migration_path, "#{template_name}.rb"), { migration_version: migration_version, }.merge(opts) ) end end
migration_name()
click to toggle source
# File lib/generators/active_snapshot/migration_generator.rb, line 37 def migration_name @template_name.titleize.gsub(' ', '') end
migration_version()
click to toggle source
# File lib/generators/active_snapshot/migration_generator.rb, line 33 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end
Private Instance Methods
mysql?()
click to toggle source
# File lib/generators/active_snapshot/migration_generator.rb, line 48 def mysql? MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name) end
table_options()
click to toggle source
Even modern versions of MySQL still use `latin1` as the default character encoding. Many users are not aware of this, and run into trouble when they try to use PaperTrail in apps that otherwise tend to use UTF-8. Postgres, by comparison, uses UTF-8 except in the unusual case where the OS is configured with a custom locale.
Furthermore, MySQL's original implementation of UTF-8 was flawed, and had to be fixed later by introducing a new charset, `utf8mb4`.
# File lib/generators/active_snapshot/migration_generator.rb, line 67 def table_options if mysql? ', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }' else "" end end