Sha256: f0d3faa9e71873e0386f174fbc4806c5a73527ee5cd2d891e1fcb52cf50dfd0a

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

module ActiveRecord
  module PGCollation
    register :schema_statements do
      require "active_record/connection_adapters/postgresql/schema_statements"
      ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(SchemaStatements)
    end
  end

  module SchemaStatements
    # Create a collation
    #
    # CREATE COLLATION [ IF NOT EXISTS ] name (
    #   [ LOCALE = locale, ]
    #   [ LC_COLLATE = lc_collate, ]
    #   [ LC_CTYPE = lc_ctype, ]
    #   [ PROVIDER = provider, ]
    #   [ DETERMINISTIC = boolean, ]
    #   [ VERSION = version ]
    # )
    def create_collation(name, options = {})
      query_options = options.map {|k,v| %Q{#{k} = '#{v}'} }.join(", ")
      execute(%Q{CREATE COLLATION IF NOT EXISTS #{name} (#{query_options})}).tap {reload_type_map}
    end

    # Create a collation from
    #
    # CREATE COLLATION [ IF NOT EXISTS ] name FROM existing_collation
    def create_collation_from(name, existing_collation)
      execute(%Q{CREATE COLLATION IF NOT EXISTS #{name} FROM "#{existing_collation}"}).tap {reload_type_map}
    end

    # Drop a collation
    #
    # DROP COLLATION [ IF EXISTS ] name [ CASCADE | RESTRICT ]
    def drop_collation(name, option = "RESTRICT")
      execute(%Q{DROP COLLATION IF EXISTS #{name} #{option}}).tap {reload_type_map}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-pg_collation-0.1.2 lib/active_record/pg_collation/schema_statements.rb
activerecord-pg_collation-0.1.1 lib/active_record/pg_collation/schema_statements.rb
activerecord-pg_collation-0.1.0 lib/active_record/pg_collation/schema_statements.rb