Class: ActiveRecord::PostgreSQL::UUIDColumn::Setup

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/active_record/postgresql/uuid_column.rb

Overview

Creates the hstore:setup generator. This generator creates a migration that adds hstore support for your database. If fact, it’s just the sql from the contrib inside a migration. But it’ s handy, isn’t it?

To use your generator, simply run it in your project:

rails g hstore:setup

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/active_record/postgresql/uuid_column.rb', line 33

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

.source_rootObject



29
30
31
# File 'lib/active_record/postgresql/uuid_column.rb', line 29

def self.source_root
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#create_migration_fileObject



41
42
43
44
45
46
47
48
# File 'lib/active_record/postgresql/uuid_column.rb', line 41

def create_migration_file
  pgversion = ActiveRecord::Base.connection.send(:postgresql_version)
  if pgversion < 90100
    raise RuntimeError, "UUID is not supported on Postgress < 9.1"
  else
    migration_template 'setup_uuid_91.rb', 'db/migrate/setup_uuid.rb'
  end
end