dynamodb_framework 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff8e6f5d3252c7d7f7fc350782ad9c7689309997
4
- data.tar.gz: bbac0b9607e11cf29f46aec856bbcb7dc8b52c19
3
+ metadata.gz: 268ec65869479fc7cfd56bf6db3fb6d0e41face7
4
+ data.tar.gz: 20d864ef78226dfae909c20117218f3ff8c12f53
5
5
  SHA512:
6
- metadata.gz: c04ba250aae2a2a3efcbccf17e37bf0db2522a5168132df18ac4042a838ee8a7c9206b6187af3b2cb4fc920b586f7a077761c668637fee79dad1a80c8a307e17
7
- data.tar.gz: e18e93c53750607c79f57180d9cec66e92f3f8be7121457c039b0905530b7032ff38bb8fdb625c0ea946a92d08b90a47b1542df2d2baf5846c0f40198ba9d7c8
6
+ metadata.gz: c6d8869280658ec89d14ce67b2240f0b66e1a7986e9ce1bf54d8bf5bb51737579f8da0add78450f723d8a0b9f1411040b2fa7d69d3c152f816ffb1cbb5c7a65a
7
+ data.tar.gz: 44af1f3645c22cca4a122f9af2e7337d134f95974198dd7a9645970b7a2de3a88a294685250d6a2f3dae6739484dcf74996f3b43b4f322b2a1d0b6a9fc576c93
data/.gitignore CHANGED
@@ -8,4 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store*
11
+ .idea/*
11
12
  .idea
13
+ pkg
14
+
@@ -7,5 +7,6 @@ require_relative 'dynamodb_framework/dynamodb_migration_manager'
7
7
  require_relative 'dynamodb_framework/dynamodb_migration_script'
8
8
  require_relative 'dynamodb_framework/dynamodb_logger'
9
9
  require_relative 'dynamodb_framework/hash_helper'
10
+ require_relative 'dynamodb_framework/dynamodb_namespace_migration_manager'
10
11
 
11
12
  require 'date'
@@ -0,0 +1,94 @@
1
+ module DynamoDbFramework
2
+ module Namespace
3
+ class MigrationManager
4
+
5
+ attr_reader :dynamodb_table_manager
6
+ attr_reader :dynamodb_repository
7
+
8
+ def initialize(store)
9
+ @dynamodb_repository = DynamoDbFramework::Repository.new(store)
10
+ @dynamodb_table_manager = DynamoDbFramework::TableManager.new(store)
11
+ end
12
+
13
+ def connect
14
+
15
+ DynamoDbFramework.logger.info "[#{self.class}] - Connecting to DynamoDb instance"
16
+
17
+ migration_table_name = 'dynamodb_framework_migration_history'
18
+
19
+ #check if migration table exists
20
+ if !@dynamodb_table_manager.exists?(migration_table_name)
21
+ #migration table not found so create it
22
+ builder = DynamoDbFramework::AttributesBuilder.new
23
+ builder.add(:namespace, :S, :partition)
24
+ builder.add(:timestamp, :S, :range)
25
+ @dynamodb_table_manager.create_table(name: migration_table_name, attributes: builder.attributes)
26
+ end
27
+
28
+ #set the table name for the repository
29
+ @dynamodb_repository.table_name = migration_table_name
30
+
31
+ DynamoDbFramework.logger.info "[#{self.class}] - Connected."
32
+
33
+ end
34
+
35
+ def get_executed_scripts
36
+ scripts = @dynamodb_repository.all()
37
+ if scripts.length > 0
38
+ return scripts.sort { |a,b| b['timestamp'] <=> a['timestamp'] }.map { |i| i['timestamp'] }
39
+ end
40
+
41
+ return nil
42
+ end
43
+
44
+ def apply
45
+
46
+ DynamoDbFramework.logger.info "[#{self.class}] - Applying migration scripts"
47
+
48
+ executed_scripts = get_executed_scripts()
49
+
50
+ scripts = []
51
+ DynamoDbFramework::MigrationScript.descendants.each do |ms|
52
+ script = ms.new
53
+ scripts.push(script)
54
+ end
55
+
56
+ scripts.sort { |a,b| a.timestamp <=> b.timestamp }.each do |script|
57
+ if executed_scripts == nil || !executed_scripts.include?(script.timestamp)
58
+ DynamoDbFramework.logger.info "[#{self.class}] - Applying script: #{script.timestamp}....."
59
+ script.apply
60
+ @dynamodb_repository.put({ :timestamp => script.timestamp })
61
+ end
62
+ end
63
+
64
+ DynamoDbFramework.logger.info "[#{self.class}] - Migration scripts applied."
65
+
66
+ end
67
+
68
+ def rollback
69
+
70
+ DynamoDbFramework.logger.info "[#{self.class}] - Rolling back started."
71
+
72
+ executed_scripts = get_executed_scripts()
73
+
74
+ scripts = []
75
+ DynamoDbFramework::MigrationScript.descendants.each do |ms|
76
+ script = ms.new
77
+ scripts.push(script)
78
+ end
79
+
80
+ scripts.sort { |a,b| a.timestamp <=> b.timestamp }.each do |script|
81
+ if executed_scripts != nil && executed_scripts.length > 0 && executed_scripts.include?(script.timestamp)
82
+ script.undo
83
+ @dynamodb_repository.delete({ :timestamp => script.timestamp })
84
+ return
85
+ end
86
+ end
87
+
88
+ DynamoDbFramework.logger.info "[#{self.class}] - Rollback complete."
89
+
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -60,9 +60,9 @@ module DynamoDbFramework
60
60
  dynamodb.client.update_table(table)
61
61
 
62
62
  # wait for table to be updated
63
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Waiting for table: [#{table_name}] to be updated."
63
+ DynamoDbFramework.logger.info "[#{self.class}] -Waiting for table: [#{table_name}] to be updated."
64
64
  wait_until_active(table_name)
65
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{table_name}] updated."
65
+ DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] updated."
66
66
 
67
67
  end
68
68
 
@@ -85,9 +85,9 @@ module DynamoDbFramework
85
85
  dynamodb.client.update_table(table)
86
86
 
87
87
  # wait for table to be updated
88
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Adding global index: #{global_index[:index_name]}."
88
+ DynamoDbFramework.logger.info "[#{self.class}] -Adding global index: #{global_index[:index_name]}."
89
89
  wait_until_index_active(table_name, global_index[:index_name])
90
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Index added."
90
+ DynamoDbFramework.logger.info "[#{self.class}] -Index added."
91
91
  end
92
92
 
93
93
  def update_index_throughput(table_name, index_name, read_capacity, write_capacity)
@@ -104,15 +104,15 @@ module DynamoDbFramework
104
104
  ]
105
105
  }
106
106
 
107
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Updating throughput for global index: #{index_name}."
107
+ DynamoDbFramework.logger.info "[#{self.class}] -Updating throughput for global index: #{index_name}."
108
108
 
109
109
  dynamodb.client.update_table(table)
110
110
 
111
111
  # wait for table to be updated
112
112
 
113
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Waiting for table: [#{table_name}] to be updated."
113
+ DynamoDbFramework.logger.info "[#{self.class}] -Waiting for table: [#{table_name}] to be updated."
114
114
  wait_until_active(table_name)
115
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{table_name}] updated."
115
+ DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] updated."
116
116
  end
117
117
 
118
118
  def drop_index(table_name, index_name)
@@ -128,9 +128,9 @@ module DynamoDbFramework
128
128
  dynamodb.client.update_table(table)
129
129
 
130
130
  # wait for table to be updated
131
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Deleting global index: #{index_name}."
131
+ DynamoDbFramework.logger.info "[#{self.class}] -Deleting global index: #{index_name}."
132
132
  wait_until_index_dropped(table_name, index_name)
133
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Index: [#{index_name}] dropped."
133
+ DynamoDbFramework.logger.info "[#{self.class}] -Index: [#{index_name}] dropped."
134
134
  end
135
135
 
136
136
  def get_status(table_name)
@@ -243,9 +243,9 @@ module DynamoDbFramework
243
243
  dynamodb.client.create_table(table)
244
244
 
245
245
  # wait for table to be created
246
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Waiting for table: [#{table_name}] to be created."
246
+ DynamoDbFramework.logger.info "[#{self.class}] -Waiting for table: [#{table_name}] to be created."
247
247
  dynamodb.client.wait_until(:table_exists, table_name: table_name)
248
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{table_name}] created."
248
+ DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] created."
249
249
  end
250
250
 
251
251
  def create_table(options = {})
@@ -254,6 +254,11 @@ module DynamoDbFramework
254
254
  raise 'A valid table name must be specified.'
255
255
  end
256
256
 
257
+ table_name = options[:name]
258
+ if options[:namespace] != nil
259
+ table_name = "#{options[:namespace]}.#{options[:name]}"
260
+ end
261
+
257
262
  if exists?(options[:name])
258
263
  return
259
264
  end
@@ -281,7 +286,7 @@ module DynamoDbFramework
281
286
  end
282
287
 
283
288
  table = {
284
- :table_name => options[:name],
289
+ :table_name => table_name,
285
290
  :attribute_definitions => attribute_definitions,
286
291
  :key_schema => key_schema,
287
292
  :provisioned_throughput => {
@@ -297,9 +302,9 @@ module DynamoDbFramework
297
302
  dynamodb.client.create_table(table)
298
303
 
299
304
  # wait for table to be created
300
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Waiting for table: [#{options[:name]}] to be created."
301
- dynamodb.client.wait_until(:table_exists, table_name: options[:name])
302
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{options[:name]}] created."
305
+ DynamoDbFramework.logger.info "[#{self.class}] - Waiting for table: [#{table_name}] to be created."
306
+ dynamodb.client.wait_until(:table_exists, table_name: table_name)
307
+ DynamoDbFramework.logger.info "[#{self.class}] - Table: [#{table_name}] created."
303
308
  end
304
309
 
305
310
  def create_global_index(name, partition_key, range_key = nil, read_capacity = 20, write_capacity = 10)
@@ -332,9 +337,9 @@ module DynamoDbFramework
332
337
  return
333
338
  end
334
339
 
335
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Dropping table: [#{table_name}]."
340
+ DynamoDbFramework.logger.info "[#{self.class}] -Dropping table: [#{table_name}]."
336
341
  dynamodb.client.delete_table({ table_name: table_name })
337
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{table_name}] dropped."
342
+ DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] dropped."
338
343
  end
339
344
 
340
345
  def drop_table(table_name)
@@ -343,9 +348,9 @@ module DynamoDbFramework
343
348
  return
344
349
  end
345
350
 
346
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Dropping table: [#{table_name}]."
351
+ DynamoDbFramework.logger.info "[#{self.class}] -Dropping table: [#{table_name}]."
347
352
  dynamodb.client.delete_table({ table_name: table_name })
348
- DynamoDbFramework.logger.info "[DynamoDbFramework] - Table: [#{table_name}] dropped."
353
+ DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] dropped."
349
354
  end
350
355
 
351
356
  end
@@ -1,3 +1,3 @@
1
1
  module DynamoDbFramework
2
- VERSION = '1.0.9'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  dynamodb:
2
- image: codeguru/dynamodb:local
3
- container_name: dynamodb
2
+ image: codeguru/dynamodb:1.0.0
3
+ command: -port 8000
4
4
  ports:
5
5
  - "8000:8000"
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hash_kit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: aws-sdk-core
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: A lightweight framework to provide managers for working with aws dynamodb
@@ -102,15 +102,14 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - .gitignore
106
- - .idea/.name
107
- - .idea/.rakeTasks
108
- - .idea/dynamodb_framework.iml
109
- - .idea/encodings.xml
110
- - .idea/misc.xml
111
- - .idea/modules.xml
112
- - .idea/vcs.xml
113
- - .rspec
105
+ - ".gitignore"
106
+ - ".idea/.name"
107
+ - ".idea/.rakeTasks"
108
+ - ".idea/encodings.xml"
109
+ - ".idea/misc.xml"
110
+ - ".idea/modules.xml"
111
+ - ".idea/vcs.xml"
112
+ - ".rspec"
114
113
  - CODE_OF_CONDUCT.md
115
114
  - Gemfile
116
115
  - LICENSE.txt
@@ -124,6 +123,7 @@ files:
124
123
  - lib/dynamodb_framework/dynamodb_logger.rb
125
124
  - lib/dynamodb_framework/dynamodb_migration_manager.rb
126
125
  - lib/dynamodb_framework/dynamodb_migration_script.rb
126
+ - lib/dynamodb_framework/dynamodb_namespace_migration_manager.rb
127
127
  - lib/dynamodb_framework/dynamodb_repository.rb
128
128
  - lib/dynamodb_framework/dynamodb_store.rb
129
129
  - lib/dynamodb_framework/dynamodb_table_manager.rb
@@ -145,17 +145,17 @@ require_paths:
145
145
  - lib
146
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - '>='
148
+ - - ">="
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - '>='
153
+ - - ">="
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.0.14.1
158
+ rubygems_version: 2.5.1
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: A lightweight framework to provide managers for working with aws dynamodb
@@ -1,39 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="FacetManager">
4
- <facet type="gem" name="Ruby Gem">
5
- <configuration>
6
- <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
- <option name="GEM_APP_TEST_PATH" value="" />
8
- <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
- </configuration>
10
- </facet>
11
- </component>
12
- <component name="NewModuleRootManager">
13
- <content url="file://$MODULE_DIR$" />
14
- <orderEntry type="inheritedJdk" />
15
- <orderEntry type="sourceFolder" forTests="false" />
16
- <orderEntry type="library" scope="PROVIDED" name="activesupport (v4.2.5.2, rbenv: 2.1.5) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="aws-sdk-core (v2.2.28, rbenv: 2.1.5) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.11.2, rbenv: 2.1.5) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.1, rbenv: 2.1.5) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 2.1.5) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="i18n (v0.7.0, rbenv: 2.1.5) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="jmespath (v1.1.3, rbenv: 2.1.5) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, rbenv: 2.1.5) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="method_source (v0.8.2, rbenv: 2.1.5) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.8.4, rbenv: 2.1.5) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="pry (v0.10.3, rbenv: 2.1.5) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="rack (v1.6.4, rbenv: 2.1.5) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="rack-test (v0.6.3, rbenv: 2.1.5) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, rbenv: 2.1.5) [gem]" level="application" />
30
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.4.0, rbenv: 2.1.5) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.4.4, rbenv: 2.1.5) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.4.0, rbenv: 2.1.5) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.4.1, rbenv: 2.1.5) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.4.1, rbenv: 2.1.5) [gem]" level="application" />
35
- <orderEntry type="library" scope="PROVIDED" name="slop (v3.6.0, rbenv: 2.1.5) [gem]" level="application" />
36
- <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.5, rbenv: 2.1.5) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, rbenv: 2.1.5) [gem]" level="application" />
38
- </component>
39
- </module>