This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Adds migration and schema.rb support to postgres custom enum types, tested on rails 4.2 | |
# The implementation is quite fragile against ActiveRecord version upgrades since it touches many core AR classes. | |
# The following code should be placed in an initializer | |
# On migrations: | |
# | |
# create_enum(:mood, %w(happy great been_better)) | |
# create_table :person do | |
# t.enum :person_mood, enum_name: :mood | |
# end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'logger' | |
require 'active_record' | |
namespace :db do | |
def create_database config | |
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'} | |
create_db = lambda do |config| | |
ActiveRecord::Base.establish_connection config.merge('database' => nil) |