method
table
v8.1.1 -
Show latest stable
-
0 notes -
Class: ActiveRecord::SchemaDumper
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- 7.2.3 (0)
- 8.0.0 (0)
- 8.1.1 (0)
- What's this?
table(table, stream)
private
Hide source
# File activerecord/lib/active_record/schema_dumper.rb, line 158 def table(table, stream) columns = @connection.columns(table) begin self.table_name = table tbl = StringIO.new # first dump primary key column pk = @connection.primary_key(table) tbl.print " create_table #{relation_name(remove_prefix_and_suffix(table)).inspect}" case pk when String tbl.print ", primary_key: #{pk.inspect}" unless pk == "id" pkcol = columns.detect { |c| c.name == pk } pkcolspec = column_spec_for_primary_key(pkcol) unless pkcolspec.empty? if pkcolspec != pkcolspec.slice(:id, :default) pkcolspec = { id: { type: pkcolspec.delete(:id), **pkcolspec }.compact } end tbl.print ", #{format_colspec(pkcolspec)}" end when Array tbl.print ", primary_key: #{pk.inspect}" else tbl.print ", id: false" end table_options = @connection.table_options(table) if table_options.present? tbl.print ", #{format_options(table_options)}" end tbl.puts ", force: :cascade do |t|" # then dump all non-primary key columns columns.sort_by(&:name).each do |column| raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type) next if column.name == pk type, colspec = column_spec(column) if type.is_a?(Symbol) tbl.print " t.#{type} #{column.name.inspect}" else tbl.print " t.column #{column.name.inspect}, #{type.inspect}" end tbl.print ", #{format_colspec(colspec)}" if colspec.present? tbl.puts end indexes_in_create(table, tbl) remaining = check_constraints_in_create(table, tbl) if @connection.supports_check_constraints? exclusion_constraints_in_create(table, tbl) if @connection.supports_exclusion_constraints? unique_constraints_in_create(table, tbl) if @connection.supports_unique_constraints? tbl.puts " end" if remaining tbl.puts tbl.print remaining.string end stream.print tbl.string rescue => e stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}" stream.puts "# #{e.message}" stream.puts ensure self.table_name = nil end end

