Class: Chicago::Database::ConcreteSchemaStrategy Private
- Inherits:
-
Object
- Object
- Chicago::Database::ConcreteSchemaStrategy
- Defined in:
- lib/chicago/database/concrete_schema_strategies.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Generic database strategy.
This supplements Sequel’s type conversion strategy rather than replaces it, so :boolean
will still return :boolean
rather than tinyint(1) in the case of mysql.
Direct Known Subclasses
Class Method Summary collapse
-
.for_db(db) ⇒ ConcreteSchemaStrategy
private
Factory method that returns an appropriate type conversion stratgey for the given database.
Instance Method Summary collapse
-
#column_hash(column) ⇒ Object
private
Returns the hash of the column.
-
#db_type(column) ⇒ Symbol
private
Returns a db type given a column definition.
-
#id_column ⇒ Object
private
Returns the definition of the column which should be used as the primary id column.
-
#indexes(table) ⇒ Object
private
Returns the indexes for the given table.
-
#integer_type(min, max) ⇒ Symbol
private
Returns a database integer column type, big enough to fit values between min and max, or integer if a specific type cannot be found.
-
#migration_options ⇒ Object
private
Returns options to be passed to the Migration Builder.
-
#string_type(min, max) ⇒ Symbol
private
Returns a database type for a string column.
-
#table_options ⇒ Hash
private
Returns sequel table options for a dimension or fact table.
Class Method Details
.for_db(db) ⇒ ConcreteSchemaStrategy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Factory method that returns an appropriate type conversion stratgey for the given database.
If a database-specific strategy cannot be found, returns a generic strategy.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 16 def self.for_db(db) if db.database_type == :mysql MysqlStrategy.new elsif db.database_type == :postgres && db.opts[:adapter] == "redshift" RedshiftStrategy.new else self.new end end |
Instance Method Details
#column_hash(column) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the hash of the column.
46 47 48 49 50 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 46 def column_hash(column) hsh = column.to_hash.merge(:column_type => db_type(column)) hsh.delete(:elements) if hsh.has_key?(:elements) hsh end |
#db_type(column) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a db type given a column definition
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 60 def db_type(column) case column.column_type when :integer then integer_type(column.min, column.max) when :string then string_type(column.min, column.max) when :money then :decimal when :percent then :decimal else column.column_type end end |
#id_column ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the definition of the column which should be used as the primary id column.
29 30 31 32 33 34 35 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 29 def id_column { :name => :id, :column_type => :integer, :unsigned => true } end |
#indexes(table) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the indexes for the given table.
53 54 55 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 53 def indexes(table) IndexGenerator.new(table).indexes end |
#integer_type(min, max) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a database integer column type, big enough to fit values between min and max, or integer if a specific type cannot be found.
95 96 97 98 99 100 101 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 95 def integer_type(min, max) if min && max && in_numeric_range?(min, max, SMALL_INT_MAX) :smallint else :integer end end |
#migration_options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns options to be passed to the Migration Builder.
Empty by default, may be overridden by subclasses for specific databases.
41 42 43 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 41 def {} end |
#string_type(min, max) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a database type for a string column.
84 85 86 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 84 def string_type(min, max) min && max && min == max ? :char : :varchar end |
#table_options ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns sequel table options for a dimension or fact table.
None by default, but database-specific subclasses may override this.
77 78 79 |
# File 'lib/chicago/database/concrete_schema_strategies.rb', line 77 def {} end |