Module: Torque::PostgreSQL::Adapter::SchemaCreation
- Defined in:
- lib/torque/postgresql/adapter/schema_creation.rb
Instance Method Summary collapse
-
#visit_TableDefinition(o) ⇒ Object
Redefine original table creation command to ensure PostgreSQL standard.
Instance Method Details
#visit_TableDefinition(o) ⇒ Object
Redefine original table creation command to ensure PostgreSQL standard
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/torque/postgresql/adapter/schema_creation.rb', line 7 def visit_TableDefinition(o) create_sql = +"CREATE#{table_modifier_in_create(o)} TABLE " create_sql << "IF NOT EXISTS " if o.if_not_exists create_sql << "#{quote_table_name(o.name)} " statements = o.columns.map { |c| accept c } statements << accept(o.primary_keys) if o.primary_keys if supports_indexes_in_create? statements.concat(o.indexes.map do |column_name, | index_in_create(o.name, column_name, ) end) end if supports_foreign_keys? statements.concat(o.foreign_keys.map do |to_table, | foreign_key_in_create(o.name, to_table, ) end) end if respond_to?(:supports_check_constraints?) && supports_check_constraints? statements.concat(o.check_constraints.map do |expression, | check_constraint_in_create(o.name, expression, ) end) end create_sql << "(#{statements.join(', ')})" \ if statements.present? || o.inherits.present? = PostgreSQL::AR610 ? o : (o) (create_sql, ) if o.inherits.present? tables = o.inherits.map(&method(:quote_table_name)) create_sql << " INHERITS ( #{tables.join(' , ')} )" end create_sql << " AS #{to_sql(o.as)}" if o.as create_sql end |