Sha256: 2886a9241d3493fdd1266c25d6f51c6ac07265cf3426711fc1d43c8be0251268

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# -*- coding: utf-8 -*-
module ActiveRecord::Turntable
  module ActiveRecordExt
    module SchemaDumper
      SEQUENCE_TABLE_REGEXP = /\A(.*)_id_seq\z/

      private

        # @note Override to dump database sequencer method
        def table(table, stream)
          unless matchdata = table.match(SEQUENCE_TABLE_REGEXP)
            return super
          end

          begin
            tbl = StringIO.new

            tbl.print "  create_sequence_for #{remove_prefix_and_suffix(matchdata[1]).inspect}"
            tbl.print ", force: :cascade"

            table_options = @connection.table_options(table)
            if table_options.present?
              options = respond_to?(:format_options) ? format_options(table_options) : table_options.inspect
              tbl.print ", options: #{options}"
            end

            if comment = @connection.table_comment(table).presence
              tbl.print ", comment: #{comment.inspect}"
            end
            tbl.puts

            tbl.rewind
            stream.print tbl.read
          rescue => e
            stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}"
            stream.puts "#   #{e.message}"
            stream.puts
          end

          stream
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-turntable-3.0.1 lib/active_record/turntable/active_record_ext/schema_dumper.rb