Class: ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveRecord::ConnectionAdapters::SchemaDumper
|
Defined in: | activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb |
Constant Summary
Class Attribute Summary
::ActiveRecord::SchemaDumper
- Inherited
.chk_ignore_pattern | Specify a custom regular expression matching check constraints which name should not be dumped to db/schema.rb. |
.excl_ignore_pattern | Specify a custom regular expression matching exclusion constraints which name should not be dumped to db/schema.rb. |
.fk_ignore_pattern | Specify a custom regular expression matching foreign keys which name should not be dumped to db/schema.rb. |
.ignore_tables | A list of tables which should not be dumped to the schema. |
.unique_ignore_pattern | Specify a custom regular expression matching unique constraints which name should not be dumped to db/schema.rb. |
Class Method Summary
::ActiveRecord::ConnectionAdapters::SchemaDumper
- Inherited
::ActiveRecord::SchemaDumper
- Inherited
Instance Attribute Summary
::ActiveRecord::SchemaDumper
- Inherited
Instance Method Summary
- #default_primary_key?(column) ⇒ Boolean private
- #exclusion_constraints_in_create(table, stream) private
- #explicit_primary_key_default?(column) ⇒ Boolean private
- #extensions(stream) private
- #extract_expression_for_virtual_column(column) private
- #prepare_column_options(column) private
- #schema_expression(column) private
- #schema_type(column) private
- #schemas(stream) private
- #types(stream) private
- #unique_constraints_in_create(table, stream) private
::ActiveRecord::ConnectionAdapters::SchemaDumper
- Inherited
::ActiveRecord::SchemaDumper
- Inherited
#dump, #check_constraints_in_create, #define_params, | |
#extensions | extensions are only supported by |
#foreign_keys, #format_colspec, #format_index_parts, #format_options, | |
#formatted_version | turns 20170404131909 into “2017_04_04_131909”. |
#header, #ignored?, #index_parts, | |
#indexes | Keep it for indexing materialized views. |
#indexes_in_create, #remove_prefix_and_suffix, | |
#schemas | schemas are only supported by |
#table, #tables, #trailer, | |
#types | (enum) types are only supported by |
#virtual_tables | virtual tables are only supported by SQLite. |
Constructor Details
This class inherits a constructor from ActiveRecord::SchemaDumper
Instance Method Details
#default_primary_key?(column) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 100
def default_primary_key?(column) schema_type(column) == :bigserial end
#exclusion_constraints_in_create(table, stream) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 42
def exclusion_constraints_in_create(table, stream) if (exclusion_constraints = @connection.exclusion_constraints(table)).any? add_exclusion_constraint_statements = exclusion_constraints.map do |exclusion_constraint| parts = [ "t.exclusion_constraint #{exclusion_constraint.expression.inspect}" ] parts << "where: #{exclusion_constraint.where.inspect}" if exclusion_constraint.where parts << "using: #{exclusion_constraint.using.inspect}" if exclusion_constraint.using parts << "deferrable: #{exclusion_constraint.deferrable.inspect}" if exclusion_constraint.deferrable if exclusion_constraint.export_name_on_schema_dump? parts << "name: #{exclusion_constraint.name.inspect}" end " #{parts.join(', ')}" end stream.puts add_exclusion_constraint_statements.sort.join("\n") end end
#explicit_primary_key_default?(column) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 104
def explicit_primary_key_default?(column) column.type == :uuid || (column.type == :integer && !column.serial?) end
#extensions(stream) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 8
def extensions(stream) extensions = @connection.extensions if extensions.any? stream.puts " # These are extensions that must be enabled in order to support this database" extensions.sort.each do |extension| stream.puts " enable_extension #{extension.inspect}" end stream.puts end end
#extract_expression_for_virtual_column(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 122
def extract_expression_for_virtual_column(column) column.default_function.inspect end
#prepare_column_options(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 85
def (column) spec = super spec[:array] = "true" if column.array? if @connection.supports_virtual_columns? && column.virtual? spec[:as] = extract_expression_for_virtual_column(column) spec[:stored] = true spec = { type: schema_type(column).inspect }.merge!(spec) end spec[:enum_type] = column.sql_type.inspect if column.enum? spec end
#schema_expression(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 118
def schema_expression(column) super unless column.serial? end
#schema_type(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 108
def schema_type(column) return super unless column.serial? if column.bigint? :bigserial else :serial end end
#schemas(stream) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 31
def schemas(stream) schema_names = @connection.schema_names - ["public"] if schema_names.any? schema_names.sort.each do |name| stream.puts " create_schema #{name.inspect}" end stream.puts end end
#types(stream) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 19
def types(stream) types = @connection.enum_types if types.any? stream.puts " # Custom types defined in this database." stream.puts " # Note that some types may not work with other database engines. Be careful if changing database." types.sort.each do |name, values| stream.puts " create_enum #{name.inspect}, #{values.split(",").inspect}" end stream.puts end end
#unique_constraints_in_create(table, stream) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb', line 64
def unique_constraints_in_create(table, stream) if (unique_constraints = @connection.unique_constraints(table)).any? add_unique_constraint_statements = unique_constraints.map do |unique_constraint| parts = [ "t.unique_constraint #{unique_constraint.column.inspect}" ] parts << "nulls_not_distinct: #{unique_constraint.nulls_not_distinct.inspect}" if unique_constraint.nulls_not_distinct parts << "deferrable: #{unique_constraint.deferrable.inspect}" if unique_constraint.deferrable if unique_constraint.export_name_on_schema_dump? parts << "name: #{unique_constraint.name.inspect}" end " #{parts.join(', ')}" end stream.puts add_unique_constraint_statements.sort.join("\n") end end