Sha256: 669caaaaaf8e3b40e660a3581a1225b35ed383ac37d9e40e4a5739da8399390b

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      class SchemaDumper < ConnectionAdapters::SchemaDumper
        SQLSEVER_NO_LIMIT_TYPES = [
          "text",
          "ntext",
          "varchar(max)",
          "nvarchar(max)",
          "varbinary(max)"
        ].freeze

        private

        def explicit_primary_key_default?(column)
          column.type == :integer && !column.is_identity?
        end

        def schema_limit(column)
          return if SQLSEVER_NO_LIMIT_TYPES.include?(column.sql_type)

          super
        end

        def schema_collation(column)
          return unless column.collation

          # use inspect to ensure collation is dumped as string. Without this it's dumped as
          # a constant ('collation: SQL_Latin1_General_CP1_CI_AS')
          collation = column.collation.inspect
          # use inspect to ensure string comparison
          default_collation = @connection.collation.inspect

          collation if collation != default_collation
        end

        def default_primary_key?(column)
          super && column.is_identity?
        end

        def schemas(stream)
          schema_names = @connection.schema_names

          if schema_names.any?
            schema_names.sort.each do |name|
              stream.puts "  create_schema #{name.inspect}"
            end
            stream.puts
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.1.11 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.2.4 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-8.0.2 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.10 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.2.3 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-8.0.1 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-8.0.0 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.2.2 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.9 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.8 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.2.1 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.2.0 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.7 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.6 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb
activerecord-sqlserver-adapter-7.1.5 lib/active_record/connection_adapters/sqlserver/schema_dumper.rb