Module: DataMapper::Migrations::SqlserverAdapter::SQL

Included in:
DataMapper::Migrations::SqlserverAdapter
Defined in:
lib/dm-migrations/adapters/dm-sqlserver-adapter.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#character_setObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 108

def character_set
  @character_set ||= show_variable('character_set_connection') || DEFAULT_CHARACTER_SET
end

#collationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



113
114
115
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 113

def collation
  @collation ||= show_variable('collation_connection') || DEFAULT_COLLATION
end

#create_table_statement(connection, model, properties) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 53

def create_table_statement(connection, model, properties)
  statement = <<-SQL.compress_lines
    CREATE TABLE #{quote_name(model.storage_name(name))}
    (#{properties.map { |property| property_schema_statement(connection, property_schema_hash(property)) }.join(', ')}
  SQL

  unless properties.any? { |property| property.serial? }
    statement << ", PRIMARY KEY(#{properties.key.map { |property| quote_name(property.field) }.join(', ')})"
  end

  statement << ')'
  statement
end

#property_schema_hash(property) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 68

def property_schema_hash(property)
  schema = super

  if property.kind_of?(Property::Integer)
    min = property.min
    max = property.max

    schema[:primitive] = integer_column_statement(min..max) if min && max
  end

  if schema[:primitive] == 'TEXT'
    schema.delete(:default)
  end

  schema
end

#property_schema_statement(connection, schema) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 86

def property_schema_statement(connection, schema)
  if supports_serial? && schema[:serial]
    statement = quote_name(schema[:name])
    statement << " #{schema[:primitive]}"

    length = schema[:length]

    if schema[:precision] && schema[:scale]
      statement << "(#{[ :precision, :scale ].map { |key| connection.quote_value(schema[key]) }.join(', ')})"
    elsif length
      statement << "(#{connection.quote_value(length)})"
    end

    statement << ' IDENTITY'
  else
    statement = super
  end

  statement
end

#schema_nameObject Also known as: db_name

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 43

def schema_name
  # TODO: is there a cleaner way to find out the current DB we are connected to?
  @options[:path].split('/').last
end

#show_variable(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



118
119
120
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 118

def show_variable(name)
  raise "SqlserverAdapter#show_variable: Not implemented"
end

#supports_drop_table_if_exists?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


38
39
40
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 38

def supports_drop_table_if_exists?
  false
end

#supports_serial?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


33
34
35
# File 'lib/dm-migrations/adapters/dm-sqlserver-adapter.rb', line 33

def supports_serial?
  true
end