cassandra_migrations 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTU2OWUzZTUzYjcxMDk1NzMxNjMwZWI4ZjE2NzY0YjcxZjc1ODE0Mw==
5
- data.tar.gz: !binary |-
6
- M2IyMWVkNTc1YjdkMTNiZjZmMjE1YTBkZDdhNzA1ZGVlNTliZWMwYw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NzQxOWNkN2IyZGVlMTgxZWIwMzI3MzYxOTQ0MGEyNDM3MGQyMWU2YWEwZGI0
10
- ZjY3ZGIyMzY2NTc2ZGRjMjVmMzJmODkyODMxNzZhNmU3ZTQ0ZTIyYmJiMWQ0
11
- NTI2OTFhOTljOWVmZjE1MmFjOTIyNzNiYWQ0Y2FlYzUzNjNhMjM=
12
- data.tar.gz: !binary |-
13
- Yzg3NzE4YTEzZmZiYzMyOTI3NzQ2NzEyMjAzYTdlODQwMGU0ZThiNWJhOGU1
14
- NGU0ZGNhYjMwOWMwMjk0NTczODRiNWI1ZWNlMzllZWJhMzAxOGY2YzYwZjdh
15
- MzBhZDAzNDgyNzhjNjBiZGM3NDU4NzM5MGYyNzBjMDk2ZDdhZGU=
2
+ SHA1:
3
+ metadata.gz: 77de13dc274012a0854ed3626d60f4a0ac73af3d
4
+ data.tar.gz: 4a17b0acf23ebaae56d88e4ba1572342fc248b03
5
+ SHA512:
6
+ metadata.gz: aab3f0ddd91d81d590cbe6ad16dcbbff317ca9358f5ef924d099867316f0c145db9f53dcc67db658c077184b23a783a89047f3dc76094571b858e42bdba0526a
7
+ data.tar.gz: 20ab748bf68a98bcbaf5524b1cc5ef7d76ccafff0735559e5c83747b459f0f9ffdd50931b64489265187f00484d5686755d1a8c6f23e3444cbce730794cb8854
@@ -10,15 +10,61 @@ module CassandraMigrations
10
10
  # +create_table+, available on every migration.
11
11
  #
12
12
  # This class is also internally used in the method +add_column+.
13
-
13
+
14
14
  class TableDefinition
15
15
 
16
+ #
17
+ # C* Data Types. See http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/cql_data_types_c.html
18
+ #
19
+
20
+ # Migration | CQL Type | Ruby | Description
21
+ # Type | | Class |
22
+ # ------------------------------------------------------------------------
23
+ # string | varchar | String | UTF-8 encoded string
24
+ # text | text | String | UTF-8 encoded string
25
+ # ascii | ascii | String | US-ASCII character string
26
+ # ------------------------------------------------------------------------
27
+ # integer(4) | int | Integer | 32-bit signed integer
28
+ # integer(8) | bigint | Fixnum | 64-bit signed long
29
+ # varint | varint | Bignum | Arbitrary-precision integer
30
+ # ------------------------------------------------------------------------
31
+ # decimal | decimal | BigDecimal | Variable-precision decimal
32
+ # float(4) | float | | 32-bit IEEE-754 floating point
33
+ # double | double | | Float 64-bit IEEE-754 floating point
34
+ # float(8) | double | |
35
+ # ------------------------------------------------------------------------
36
+ # boolean | boolean | TrueClass | true or false
37
+ # | | FalseClass |
38
+ # ------------------------------------------------------------------------
39
+ # uuid | uuid | Cql::Uuid | A UUID in standard UUID format
40
+ # timeuuid | timeuuid | Cql::TimeUuid | Type 1 UUID only (CQL 3)
41
+ # ------------------------------------------------------------------------
42
+ # inet | inet | IPAddr | IP address string in IPv4 or
43
+ # | | | IPv6 format*
44
+ # ------------------------------------------------------------------------
45
+ # timestamp | timestamp | Time | Date plus time, encoded as 8
46
+ # | | | bytes since epoch
47
+ # datetime | timestamp | |
48
+ # ------------------------------------------------------------------------
49
+ # list | list | Array | A collection of one or more
50
+ # | | | ordered elements
51
+ # map | map | Hash | A JSON-style array of literals:
52
+ # | | | { literal : literal, ... }
53
+ # set | set | Set | A collection of one or more
54
+ # | | | elements
55
+ # binary | blob | | Arbitrary bytes (no validation),
56
+ # | | | expressed as hexadecimal
57
+ # | counter | | Distributed counter value
58
+ # | | | (64-bit long)
59
+
60
+
61
+
16
62
  def initialize()
17
63
  @columns_name_type_hash = {}
18
64
  @primary_keys = []
19
65
  @partition_keys = []
20
66
  end
21
-
67
+
22
68
  def to_create_cql
23
69
  cql = []
24
70
 
@@ -38,10 +84,10 @@ module CassandraMigrations
38
84
  else
39
85
  raise Errors::MigrationDefinitionError, 'No primary key defined.'
40
86
  end
41
-
87
+
42
88
  cql.join(', ')
43
89
  end
44
-
90
+
45
91
  def to_add_column_cql
46
92
  cql = ""
47
93
 
@@ -52,61 +98,76 @@ module CassandraMigrations
52
98
  else
53
99
  raise Errors::MigrationDefinitionError, 'Only one column can be added at once.'
54
100
  end
55
-
101
+
56
102
  cql
57
103
  end
58
-
104
+
59
105
  def boolean(column_name, options={})
60
106
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:boolean, options)
61
107
  define_primary_keys(column_name) if options[:primary_key]
62
108
  end
63
-
109
+
64
110
  def integer(column_name, options={})
65
- @columns_name_type_hash[column_name.to_sym] = column_type_for(:integer, options)
111
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:integer, options)
66
112
  define_primary_keys(column_name) if options[:primary_key]
67
113
  end
68
-
114
+
115
+ def decimal(column_name, options={})
116
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:decimal, options)
117
+ define_primary_keys(column_name) if options[:primary_key]
118
+ end
119
+
69
120
  def float(column_name, options={})
70
- @columns_name_type_hash[column_name.to_sym] = column_type_for(:float, options)
121
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:float, options)
71
122
  define_primary_keys(column_name) if options[:primary_key]
72
123
  end
73
-
124
+
74
125
  def double(column_name, options={})
75
126
  options[:limit] = 8
76
- @columns_name_type_hash[column_name.to_sym] = column_type_for(:float, options)
127
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:float, options)
77
128
  define_primary_keys(column_name) if options[:primary_key]
78
129
  end
79
-
130
+
80
131
  def string(column_name, options={})
81
132
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:string, options)
82
133
  define_primary_keys(column_name) if options[:primary_key]
83
134
  end
84
-
135
+
85
136
  def text(column_name, options={})
86
137
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:text, options)
87
138
  define_primary_keys(column_name) if options[:primary_key]
88
139
  end
89
-
140
+
141
+ def ascii(column_name, options={})
142
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:ascii, options)
143
+ define_primary_keys(column_name) if options[:primary_key]
144
+ end
145
+
90
146
  def datetime(column_name, options={})
91
147
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:datetime, options)
92
148
  define_primary_keys(column_name) if options[:primary_key]
93
149
  end
94
-
150
+
95
151
  def timestamp(column_name, options={})
96
152
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:timestamp, options)
97
153
  define_primary_keys(column_name) if options[:primary_key]
98
154
  end
99
-
155
+
100
156
  def uuid(column_name, options={})
101
157
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:uuid, options)
102
158
  define_primary_keys(column_name) if options[:primary_key]
103
159
  end
104
-
160
+
105
161
  def timeuuid(column_name, options={})
106
162
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:timeuuid, options)
107
163
  define_primary_keys(column_name) if options[:primary_key]
108
164
  end
109
-
165
+
166
+ def binary(column_name, options={})
167
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:binary, options)
168
+ define_primary_keys(column_name) if options[:primary_key]
169
+ end
170
+
110
171
  def list(column_name, options={})
111
172
  type = options[:type]
112
173
  if type.nil?
@@ -119,7 +180,7 @@ module CassandraMigrations
119
180
  end
120
181
  @columns_name_type_hash[column_name.to_sym] = :"list<#{column_type_for(type)}>"
121
182
  end
122
-
183
+
123
184
  def set(column_name, options={})
124
185
  type = options[:type]
125
186
  if type.nil?
@@ -132,12 +193,12 @@ module CassandraMigrations
132
193
  end
133
194
  @columns_name_type_hash[column_name.to_sym] = :"set<#{column_type_for(type)}>"
134
195
  end
135
-
196
+
136
197
  def map(column_name, options={})
137
198
  key_type, value_type = options[:key_type], options[:value_type]
138
199
  [key_type, value_type].each_with_index do |type, index|
139
200
  if type.nil?
140
- raise Errors::MigrationDefinitionError, "A map must define a #{index = 0 ? 'key' : 'value'} type."
201
+ raise Errors::MigrationDefinitionError, "A map must define a #{index = 0 ? 'key' : 'value'} type."
141
202
  elsif !self.respond_to?(type)
142
203
  raise Errors::MigrationDefinitionError, "Type '#{type}' is not valid for cassandra migration."
143
204
  end
@@ -146,14 +207,14 @@ module CassandraMigrations
146
207
  if options[:primary_key]
147
208
  raise Errors::MigrationDefinitionError, 'A collection cannot be used as a primary key.'
148
209
  end
149
- @columns_name_type_hash[column_name.to_sym] = :"map<#{column_type_for(key_type)},#{column_type_for(value_type)}>"
210
+ @columns_name_type_hash[column_name.to_sym] = :"map<#{column_type_for(key_type)},#{column_type_for(value_type)}>"
150
211
  end
151
-
212
+
152
213
  def define_primary_keys(*keys)
153
214
  if !@primary_keys.empty?
154
215
  raise Errors::MigrationDefinitionError, 'Primary key defined twice for the same table.'
155
216
  end
156
-
217
+
157
218
  @primary_keys = keys.flatten
158
219
  end
159
220
 
@@ -161,39 +222,37 @@ module CassandraMigrations
161
222
  if !@partition_keys.empty?
162
223
  raise Errors::MigrationDefinitionError, 'Partition key defined twice for the same table.'
163
224
  end
164
-
225
+
165
226
  @partition_keys = keys.flatten
166
227
  end
167
228
 
168
229
  private
169
-
170
- def column_type_for(ruby_type, options={})
230
+
231
+ PASSTHROUGH_TYPES = [:text, :ascii, :decimal, :double, :boolean,
232
+ :uuid, :timeuuid, :inet, :timestamp, :list,
233
+ :map, :set]
234
+ TYPES_MAP = { string: :varchar,
235
+ datetime: :timestamp,
236
+ binary: :blob }
237
+
238
+ PRECISION_MAP = {
239
+ integer: { 4 => :int, 8 => :bigint, nil => :int },
240
+ float: { 4 => :float, 8 => :double, nil => :float }
241
+ }
242
+
243
+ def column_type_for(type, options={})
244
+ cql_type = type if PASSTHROUGH_TYPES.include?(type)
245
+ cql_type ||= TYPES_MAP[type]
246
+ if PRECISION_MAP.keys.include?(type)
171
247
  limit = options[:limit]
172
- case ruby_type
173
- when :boolean, :text, :timestamp, :uuid, :timeuuid
174
- ruby_type
175
- when :integer
176
- if limit.nil? || limit == 4
177
- :int
178
- elsif limit == 8
179
- :bigint
180
- else
181
- raise Errors::MigrationDefinitionError, ':limit option should be 4 or 8 for integers.'
182
- end
183
- when :float
184
- if limit.nil? || limit == 4
185
- :float
186
- elsif limit == 8
187
- :double
188
- else
189
- raise Errors::MigrationDefinitionError, ':limit option should be 4 or 8 for floats.'
190
- end
191
- when :string
192
- :varchar
193
- when :datetime
194
- :timestamp
248
+ unless PRECISION_MAP[type].keys.include?(limit)
249
+ raise Errors::MigrationDefinitionError, ":limit option should be #{PRECISION_MAP[type].keys.compact.join(' or ')} for #{type}."
195
250
  end
251
+ cql_type ||= PRECISION_MAP[type][limit]
196
252
  end
253
+ cql_type
254
+ end
255
+
197
256
  end
198
257
  end
199
258
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Gubert
8
+ - Brian Sam-Bodden
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
12
+ date: 2014-04-25 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: cql-rb
@@ -16,169 +17,157 @@ dependencies:
16
17
  requirements:
17
18
  - - '='
18
19
  - !ruby/object:Gem::Version
19
- version: 1.1.2
20
+ version: 2.0.0.pre1
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - '='
25
26
  - !ruby/object:Gem::Version
26
- version: 1.1.2
27
+ version: 2.0.0.pre1
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ~>
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
34
  version: '10'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ~>
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
41
  version: '10'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rails
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ! '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '3.2'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ! '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '3.2'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: colorize
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - ~>
60
+ - - "~>"
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0.5'
62
63
  type: :runtime
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - ~>
67
+ - - "~>"
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0.5'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: rspec
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - ! '>='
74
+ - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '0'
76
+ version: '2.14'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - ! '>='
81
+ - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '0'
83
+ version: '2.14'
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: debugger
85
86
  requirement: !ruby/object:Gem::Requirement
86
87
  requirements:
87
- - - ! '>='
88
+ - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: '0'
90
+ version: '1.6'
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - ! '>='
95
+ - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: '0'
97
+ version: '1.6'
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: bundler
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ~>
102
+ - - "~>"
102
103
  - !ruby/object:Gem::Version
103
104
  version: '1.3'
104
105
  type: :development
105
106
  prerelease: false
106
107
  version_requirements: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - ~>
109
+ - - "~>"
109
110
  - !ruby/object:Gem::Version
110
111
  version: '1.3'
111
- - !ruby/object:Gem::Dependency
112
- name: rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ! '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
112
  - !ruby/object:Gem::Dependency
126
113
  name: simplecov
127
114
  requirement: !ruby/object:Gem::Requirement
128
115
  requirements:
129
- - - ! '>='
116
+ - - "~>"
130
117
  - !ruby/object:Gem::Version
131
- version: '0'
118
+ version: '0.8'
132
119
  type: :development
133
120
  prerelease: false
134
121
  version_requirements: !ruby/object:Gem::Requirement
135
122
  requirements:
136
- - - ! '>='
123
+ - - "~>"
137
124
  - !ruby/object:Gem::Version
138
- version: '0'
125
+ version: '0.8'
139
126
  - !ruby/object:Gem::Dependency
140
127
  name: coveralls
141
128
  requirement: !ruby/object:Gem::Requirement
142
129
  requirements:
143
- - - ! '>='
130
+ - - "~>"
144
131
  - !ruby/object:Gem::Version
145
- version: '0'
132
+ version: '0.7'
146
133
  type: :development
147
134
  prerelease: false
148
135
  version_requirements: !ruby/object:Gem::Requirement
149
136
  requirements:
150
- - - ! '>='
137
+ - - "~>"
151
138
  - !ruby/object:Gem::Version
152
- version: '0'
139
+ version: '0.7'
153
140
  description: A gem to manage Cassandra database schema for Rails. This gem offers
154
141
  migrations and environment sific databases out-of-the-box for Rails users.
155
- email: guberthenrique@hotmail.com
142
+ email:
143
+ - guberthenrique@hotmail.com
144
+ - bsbodden@integrallis.com
156
145
  executables:
157
146
  - prepare_for_cassandra
158
147
  extensions: []
159
148
  extra_rdoc_files: []
160
149
  files:
150
+ - bin/prepare_for_cassandra
151
+ - lib/cassandra_migrations.rb
152
+ - lib/cassandra_migrations/capistrano.rb
153
+ - lib/cassandra_migrations/cassandra.rb
161
154
  - lib/cassandra_migrations/cassandra/keyspace_operations.rb
162
155
  - lib/cassandra_migrations/cassandra/queries.rb
163
156
  - lib/cassandra_migrations/cassandra/query_result.rb
164
- - lib/cassandra_migrations/migration/table_operations.rb
165
- - lib/cassandra_migrations/migration/table_definition.rb
166
- - lib/cassandra_migrations/migration/column_operations.rb
167
- - lib/cassandra_migrations/migration.rb
168
- - lib/cassandra_migrations/errors.rb
169
- - lib/cassandra_migrations/railtie.rb
170
157
  - lib/cassandra_migrations/config.rb
158
+ - lib/cassandra_migrations/errors.rb
159
+ - lib/cassandra_migrations/migration.rb
160
+ - lib/cassandra_migrations/migration/column_operations.rb
161
+ - lib/cassandra_migrations/migration/table_definition.rb
162
+ - lib/cassandra_migrations/migration/table_operations.rb
171
163
  - lib/cassandra_migrations/migrator.rb
172
- - lib/cassandra_migrations/cassandra.rb
164
+ - lib/cassandra_migrations/railtie.rb
165
+ - lib/cassandra_migrations/railtie/generators/cassandra_migration/USAGE
173
166
  - lib/cassandra_migrations/railtie/generators/cassandra_migration/cassandra_migration_generator.rb
174
167
  - lib/cassandra_migrations/railtie/generators/cassandra_migration/templates/empty_migration.rb.erb
175
- - lib/cassandra_migrations/railtie/generators/cassandra_migration/USAGE
176
- - lib/cassandra_migrations/railtie/tasks.rake
177
168
  - lib/cassandra_migrations/railtie/initializer.rb
178
- - lib/cassandra_migrations/capistrano.rb
179
- - lib/cassandra_migrations.rb
169
+ - lib/cassandra_migrations/railtie/tasks.rake
180
170
  - template/cassandra.yml
181
- - bin/prepare_for_cassandra
182
171
  homepage: https://github.com/hsgubert/cassandra_migrations
183
172
  licenses:
184
173
  - MIT
@@ -189,17 +178,17 @@ require_paths:
189
178
  - lib
190
179
  required_ruby_version: !ruby/object:Gem::Requirement
191
180
  requirements:
192
- - - ! '>='
181
+ - - ">="
193
182
  - !ruby/object:Gem::Version
194
183
  version: '0'
195
184
  required_rubygems_version: !ruby/object:Gem::Requirement
196
185
  requirements:
197
- - - ! '>='
186
+ - - ">="
198
187
  - !ruby/object:Gem::Version
199
188
  version: 1.8.0
200
189
  requirements: []
201
190
  rubyforge_project:
202
- rubygems_version: 2.0.7
191
+ rubygems_version: 2.2.1
203
192
  signing_key:
204
193
  specification_version: 4
205
194
  summary: Cassandra schema management for a multi-environment developer.