Sha256: 150b68ecf57254f6cebbdbc1513e2982e6110b5c23c7df0305b86a07735cbdbc

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 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?
              if respond_to?(:format_options, true)
                tbl.print ", #{format_options(table_options)}"
              else
                tbl.print ", options: #{table_options.inspect}"
              end
            end

            if Util.ar_version_earlier_than?("5.0.1") && 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

7 entries across 7 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.1 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-4.4.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-4.1.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-4.0.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb
activerecord-turntable-3.1.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb