dynamodb-migration 0.3.0 → 0.4.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: 74e3e254ecd09009114274031548f14690803466
4
- data.tar.gz: abfbffb5f2a6612f483e5e7958e3fa36ac70e5a6
3
+ metadata.gz: 5dcad159e3025aaac1ec6e9cc97458875305c5e3
4
+ data.tar.gz: 77bb1576c448f3bbf3bf32bf26c80d3acd10c3ab
5
5
  SHA512:
6
- metadata.gz: b0631860e3d249170eceb2b7b295dbda23986f7006b43a11e1770011306d0a67e493fc36b5cea13f0c9d0ce35471d5f4b8ac3d6f8729686bb55f1aedd62de17c
7
- data.tar.gz: d7108c070a794dae4769ad5ad8a463a5b99a572834060b9ca8d8c8cd97c94d0c32c61f0855fce7e56186b2b4b553b2a2d67cdf85ecb7db57b00ea698c081299b
6
+ metadata.gz: 0b25d44cb893e76b70d750e63c5f859cd16f5edeb41d554b46873cb1d1fe56566873fe27c7ac559608161e40e181c65758790a6686f822b5a54f5f7734b5a600
7
+ data.tar.gz: 944824a9cc82b84f98da673db93530ed290d101be8ea585dbc35e7c4faf28e005f1d8069934e203dd87079be2ee79044db44e6d5279f85d11cfe81870350e259
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- [![Gem Version](https://badge.fury.io/rb/dynamodb-client.svg)](https://badge.fury.io/rb/dynamodb-client)
1
+ [![Gem Version](https://badge.fury.io/rb/dynamodb-migration.svg)](https://badge.fury.io/rb/dynamodb-migration)
2
2
  # DynamoDB::Migration
3
3
 
4
- Allows for the creation of simple DynamoDB commands that will be executed only
5
- once against a DynamoDB database to allow you to "migrate" the schema of the
6
- database over time. This is a simple implementation for DynamoDB, similar to
7
- tools such as FlywayDB and Active Record Migrations.
4
+ Allows for the creation of simple DynamoDB migrations that will be executed
5
+ only once against a DynamoDB database to allow you to "migrate" the schema of
6
+ the database over time. This is a simple implementation for DynamoDB, similar
7
+ to tools such as FlywayDB and Active Record Migrations.
8
8
 
9
9
  ## Installation
10
10
 
@@ -30,8 +30,9 @@ In a rake task or in your applications start up, simply add:
30
30
  require 'dynamodb/migration'
31
31
 
32
32
  options = {
33
- client: dynamodb_client, # an Aws::DynamoDB::Client instance
34
- path: '~/my_project/migrations' # the full path to the folder where your migration classes will live
33
+ client: dynamodb_client, # an Aws::DynamoDB::Client instance
34
+ path: '/app/my_project/migrations' # the full path to the folder where your migration classes will live
35
+ migration_table_name: 'migrations' # optional, the name of the table to use for migrations, default is "migrations"
35
36
  }
36
37
  DynamoDB::Migration.run_all_migrations(options)
37
38
  ```
@@ -46,6 +47,10 @@ require 'dynamodb/migration'
46
47
  # next to config.ru
47
48
  set :migrations_path, File.join(File.dirname(__FILE__), 'migrations')
48
49
 
50
+ # optional, the name of the table to use for migrations, default is
51
+ # "migrations"
52
+ set :migration_table_name, 'migrations'
53
+
49
54
  # registering the below requires the "dynamodb-client" gem, alternatively
50
55
  # you can return a Aws::DynamoDB::Client instance from a method named
51
56
  # `dynamodb_client`
@@ -93,8 +98,9 @@ end
93
98
  ```
94
99
 
95
100
  DynamoDB::Migration will detect this class and execute once against your
96
- DynamoDB instance. It will record the execution in a table called `migrations`
97
- which it creates and maintains internally.
101
+ DynamoDB instance. It will record the execution in a table specified by the
102
+ option `:migration_table_name` (`migrations` by default) which it
103
+ creates and maintains internally.
98
104
 
99
105
  ## Development
100
106
 
@@ -116,9 +122,7 @@ be a safe, welcoming space for collaboration, and contributors are expected to
116
122
  adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
117
123
  conduct.
118
124
 
119
-
120
125
  ## License
121
126
 
122
127
  The gem is available as open source under the terms of the [MIT
123
128
  License](http://opensource.org/licenses/MIT).
124
-
@@ -4,20 +4,23 @@ require "dynamodb/migration/unit"
4
4
 
5
5
  module DynamoDB
6
6
  module Migration
7
- def self.registered(app)
8
- options = {
9
- client: app.dynamodb_client,
10
- path: app.settings.migrations_path,
11
- }
12
- run_all_migrations(options)
13
- end
7
+ class << self
8
+ def registered(app)
9
+ options = {
10
+ client: app.dynamodb_client,
11
+ path: app.settings.migrations_path,
12
+ migration_table_name: app.settings.migration_table_name,
13
+ }
14
+ run_all_migrations(options)
15
+ end
14
16
 
15
- def self.run_all_migrations(options)
16
- Dir.glob("#{options[:path]}/**/*.rb").each do |file|
17
- require file
17
+ def run_all_migrations(options)
18
+ Dir.glob("#{options[:path]}/**/*.rb").each do |file|
19
+ require file
20
+ end
21
+ Execute.new(options[:client], options[:migration_table_name])
22
+ .update_all
18
23
  end
19
- Execute.new(options[:client])
20
- .update_all
21
24
  end
22
25
  end
23
26
  end
@@ -1,8 +1,11 @@
1
1
  module DynamoDB
2
2
  module Migration
3
3
  class Execute
4
- def initialize(client)
4
+ DEFAULT_MIGRATION_TABLE_NAME = 'migrations'
5
+
6
+ def initialize(client, migration_table_name)
5
7
  @client = client
8
+ @migration_table_name = migration_table_name
6
9
  end
7
10
 
8
11
  def update_all
@@ -30,7 +33,7 @@ module DynamoDB
30
33
 
31
34
  def record_failed_migration(clazz)
32
35
  client.delete_item({
33
- table_name: "migrations",
36
+ table_name: migration_table_name,
34
37
  key: {
35
38
  "file" => clazz_filename(clazz),
36
39
  },
@@ -43,7 +46,7 @@ module DynamoDB
43
46
 
44
47
  def record_start_migration(clazz)
45
48
  client.put_item({
46
- table_name: "migrations",
49
+ table_name: migration_table_name,
47
50
  item: {
48
51
  "file" => clazz_filename(clazz),
49
52
  "executed_at" => Time.now.iso8601,
@@ -57,7 +60,7 @@ module DynamoDB
57
60
 
58
61
  def record_successful_migration(clazz)
59
62
  client.update_item({
60
- table_name: "migrations",
63
+ table_name: migration_table_name,
61
64
  key: {
62
65
  "file" => clazz_filename(clazz),
63
66
  },
@@ -87,7 +90,7 @@ module DynamoDB
87
90
 
88
91
  def migration_executed?(clazz)
89
92
  client.get_item({
90
- table_name: "migrations",
93
+ table_name: migration_table_name,
91
94
  key: {
92
95
  "file" => clazz_filename(clazz),
93
96
  },
@@ -98,7 +101,7 @@ module DynamoDB
98
101
 
99
102
  def ensure_migrations_table_exists
100
103
  client.create_table(
101
- table_name: "migrations",
104
+ table_name: migration_table_name,
102
105
  attribute_definitions: [
103
106
  {
104
107
  attribute_name: "file",
@@ -119,7 +122,7 @@ module DynamoDB
119
122
  stream_enabled: true,
120
123
  stream_view_type: "NEW_AND_OLD_IMAGES",
121
124
  },
122
- ) unless table_exists?(client, 'migrations')
125
+ ) unless table_exists?(client, migration_table_name)
123
126
  end
124
127
 
125
128
  def table_exists?(client, table_name)
@@ -127,6 +130,12 @@ module DynamoDB
127
130
  rescue Aws::DynamoDB::Errors::ResourceNotFoundException => e
128
131
  false
129
132
  end
133
+
134
+ def migration_table_name
135
+ @migration_table_name ||
136
+ ENV['DYNAMODB_MIGRATION_TABLE_NAME'] ||
137
+ DEFAULT_MIGRATION_TABLE_NAME
138
+ end
130
139
  end
131
140
  end
132
141
  end
@@ -1,5 +1,5 @@
1
1
  module DynamoDB
2
2
  module Migration
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Lawson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-21 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk