Sha256: 180a42253224dbfdcb4fb218f355acebedc8e2a1b98522dc029d4c5452477cda

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 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?
              tbl.print ", #{format_options(table_options)}"
            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.0 lib/active_record/turntable/active_record_ext/schema_dumper.rb