Sha256: 549d7dfba8663a26080be295c948d7ea917bfece3da4ba6c5fcdc7b350808e17

Contents?: true

Size: 1.49 KB

Versions: 18

Compression:

Stored size: 1.49 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      class SchemaCreation < AbstractAdapter::SchemaCreation

        private

        def visit_ColumnDefinition(o)
          sql = super
          if o.primary_key? && o.type == :uuid
            sql << ' PRIMARY KEY '
            add_column_options!(sql, column_options(o))
          end
          sql
        end

        def visit_TableDefinition(o)
          if o.as
            table_name = quote_table_name(o.temporary ? "##{o.name}" : o.name)
            projections, source = @conn.to_sql(o.as).match(%r{SELECT\s+(.*)?\s+FROM\s+(.*)?}).captures
            select_into = "SELECT #{projections} INTO #{table_name} FROM #{source}"
          else
            o.instance_variable_set :@as, nil
            super
          end
        end

        def add_column_options!(sql, options)
          column = options.fetch(:column) { return super }
          if (column.type == :uuid || column.type == :uniqueidentifier) && options[:default] =~ /\(\)/
            sql << " DEFAULT #{options.delete(:default)}"
          else
            super
          end
        end

        def action_sql(action, dependency)
          case dependency
          when :restrict
            raise ArgumentError, <<-MSG.strip_heredoc
              '#{dependency}' is not supported for :on_update or :on_delete.
              Supported values are: :nullify, :cascade
            MSG
          else
            super
          end
        end

      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
activerecord-sqlserver-adapter-4.2.18 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.17 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.16 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter_new-4.2.15 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.15 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.13 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.12 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.11 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.10 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.9 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.8 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.6 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.5 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.4 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.3 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.2 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.1 lib/active_record/connection_adapters/sqlserver/schema_creation.rb
activerecord-sqlserver-adapter-4.2.0 lib/active_record/connection_adapters/sqlserver/schema_creation.rb