deploy_mongo 0.0.1 → 0.0.2

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.
data/README.rdoc ADDED
@@ -0,0 +1,84 @@
1
+ == deploy_mongo
2
+
3
+ deploy_mongo is db deploy tool for mongodb.
4
+
5
+
6
+ ====How to install
7
+ gem install deploy_mongo
8
+
9
+
10
+ ==== Usage
11
+
12
+ deploy_mongo 'path/to/mongodb.yml' [rollback:(1|2|3|..|all)]
13
+
14
+ [rollback:all] rollbacks all the deltas
15
+
16
+
17
+ ==== Example
18
+
19
+ * deploy_mongo/spec/mongodb.yml for mongodb.yml config file
20
+ * deploy_mongo/spec/integration/deltas for delta files
21
+
22
+
23
+ ==== Config Parameters
24
+
25
+ * hostname: mongodb database server hostname>
26
+ * port: mongodb server port number , by default 27017
27
+ * delta_path: path/to/deltas folder relative to mongodb.yml
28
+ * database: <couchdb database name>
29
+ * mongo_shell_path: full path to mongo shell (can be found in mongodb install folder/bin
30
+
31
+ ==== Delta File name format
32
+
33
+ <Delta Number>_<Description>.js
34
+ example :- 1_add_address_to_customer.js
35
+ 2_add_phone_to_customer.js
36
+ 11_update_phone_with_std_codes.js
37
+ 12_delete_customer_with_name_equal_to_name_1.js
38
+ 13_copy_and_create_new_customer.js
39
+
40
+
41
+ ==== Delta File content format
42
+ <java script command used to modify database>
43
+ //@undo
44
+ <java script rollback command used when rolling back applied delta.>
45
+
46
+
47
+ == Delta File examples
48
+
49
+ ==== Example for adding address field to all customers (1_add_address_to_customer.js)
50
+
51
+ db.customer.update({},{$set: {"address": "some address" } } , false , true );
52
+
53
+ //@undo
54
+
55
+ db.customer.update({},{$unset: {"address": 1}},false,true);
56
+
57
+ ==== Example for modifying phone number of all customers (2_add_phone_to_customer.js)
58
+
59
+ db.customer.update({},{$set: {"phone": "897907979" } } , false , true )
60
+
61
+ //@undo
62
+
63
+ db.customer.update({},{$unset: {"phone": 1}},false,true)
64
+
65
+ ==== Example for creating new document after copying details from another customer (13_copy_and_create_new_customer.js)
66
+
67
+ db.customer.find({ "name" : "name_2" }).forEach(create_customer);
68
+ function create_customer(doc){
69
+ delete doc._id;
70
+ doc.name = "new name";
71
+ db.customer.save(doc);
72
+ }
73
+
74
+ //@undo
75
+
76
+ db.customer.remove({"name" : "new name"})
77
+
78
+ ==== Example for deleteing a document (12_delete_customer_with_name_equal_to_name_1.js)
79
+
80
+ db.customer.remove({ "name" : "name_1" });
81
+
82
+ //@undo
83
+
84
+ db.customer.save({"name" : "name_1", "address" : "some address" , "phone" : "+9168687868" });
@@ -8,13 +8,13 @@ module DeployMongo
8
8
 
9
9
  def apply
10
10
  user_command = @delta.command.gsub("'","''")
11
- shell = MongoShell.new(@config.database)
11
+ shell = MongoShell.new(@config.database,@config.mongo_shell_path)
12
12
  shell.execute(user_command)
13
13
  end
14
14
 
15
15
  def rollback
16
16
  user_rollback_command = @delta.rollback_command.gsub("'","''")
17
- shell = MongoShell.new(@config.database)
17
+ shell = MongoShell.new(@config.database,@config.mongo_shell_path)
18
18
  shell.execute(user_rollback_command)
19
19
  end
20
20
  end
@@ -9,9 +9,9 @@ module DeployMongo
9
9
  repository = Repository.new(@config)
10
10
  delta_loader = DeltaLoader.new(@config.delta_path)
11
11
  deltas_map = delta_loader.get_deltas
12
- couch_schema = DbSchema.load_or_create(@config,repository)
13
- all_delta_keys = deltas_map.keys.sort
14
- applied_deltas = couch_schema.applied_deltas.sort
12
+ db_schema = DbSchema.load_or_create(@config,repository)
13
+ all_delta_keys = deltas_map.keys.sort
14
+ applied_deltas = db_schema.applied_deltas.sort
15
15
  last_applied_delta_id = 0
16
16
  last_applied_delta_id = applied_deltas[-1] if applied_deltas.count > 0
17
17
  delta_keys_to_apply = all_delta_keys.select {|key| key > last_applied_delta_id }
@@ -26,7 +26,7 @@ module DeployMongo
26
26
  delta_keys_to_apply.each do |key|
27
27
  delta = deltas_map[key]
28
28
  DeltaProcessor.new(@config,delta).apply
29
- couch_schema.completed(delta)
29
+ db_schema.completed(delta)
30
30
  deltas.push(delta)
31
31
  puts "applied delta #{delta.file_name}"
32
32
  end
@@ -1,13 +1,14 @@
1
1
  module DeployMongo
2
2
  class MongoShell
3
3
 
4
- def initialize(database)
4
+ def initialize(database,mongo_shell_path)
5
5
  @database = database
6
+ @mongo_shell_path = mongo_shell_path
6
7
  end
7
8
 
8
9
  def execute(command)
9
10
  command = command.gsub("'","''")
10
- mongo_command = "/Users/admin/work/mongodb-osx-x86_64-1.8.2/bin/mongo #{@database} --eval '#{command}'"
11
+ mongo_command = "#{@mongo_shell_path} #{@database} --eval '#{command}'"
11
12
  #puts mongo_command
12
13
  `#{mongo_command}`
13
14
  raise "error" if ($?.to_i != 0)
@@ -8,13 +8,13 @@ module DeployMongo
8
8
  end
9
9
 
10
10
  def get_schema
11
- db = Mongo::Connection.new(@config.hostname,@config.port).db(@config.database)
11
+ db = Mongo::Connection.new(@config.hostname,@config.port,:safe => true).db(@config.database)
12
12
  schema = db.collection("schema").find_one("_id" => "schema__schema_document_key__")
13
13
  schema
14
14
  end
15
15
 
16
16
  def save_schema(json)
17
- db = Mongo::Connection.new(@config.hostname,@config.port).db(@config.database)
17
+ db = Mongo::Connection.new(@config.hostname,@config.port,:safe => true).db(@config.database)
18
18
  json = json.merge("_id" => "schema__schema_document_key__")
19
19
  db.collection("schema").save(json)
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module DeployMongo
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.2"
3
+ end
@@ -19,7 +19,7 @@ module DeployMongo
19
19
  end
20
20
 
21
21
  it "should load mongo shell path" do
22
- Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml').mongo_shell_path.should == "/Users/admin/work/mongodb-osx-x86_64-1.8.2/bin/mongo"
22
+ Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml').mongo_shell_path.should_not == ""
23
23
  end
24
24
 
25
25
  it "should merge config with passed in values" do
@@ -1,7 +1,8 @@
1
1
  module DeployMongo
2
2
  class DatabasePopulator
3
- def initialize(database)
3
+ def initialize(database,mongo_shell_path)
4
4
  @database = database
5
+ @mongo_shell_path = mongo_shell_path
5
6
  end
6
7
 
7
8
  def with_type(doc_type)
@@ -15,7 +16,7 @@ module DeployMongo
15
16
  end
16
17
 
17
18
  def build
18
- mongo_shell = MongoShell.new(@database)
19
+ mongo_shell = MongoShell.new(@database,@mongo_shell_path)
19
20
  mongo_shell.execute("db.dropDatabase();")
20
21
  (1..@no_of_records).each do |i|
21
22
  h = {"name"=> "name_#{i}","type"=>@doc_type}
@@ -6,7 +6,8 @@ module DeployMongo
6
6
  describe DeltaProcessor, "integration" do
7
7
 
8
8
  before :all do
9
- DatabasePopulator.new("test").with_type("customer").with_records(30).build
9
+ config = Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml')
10
+ DatabasePopulator.new(config.database,config.mongo_shell_path).with_type("customer").with_records(30).build
10
11
  end
11
12
 
12
13
 
@@ -6,7 +6,8 @@ module DeployMongo
6
6
  describe Deploy, "load and execute deltas first database" do
7
7
 
8
8
  before :all do
9
- DatabasePopulator.new("test").with_type("customer").with_records(30).build
9
+ config = Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml')
10
+ DatabasePopulator.new(config.database,config.mongo_shell_path).with_type("customer").with_records(30).build
10
11
  end
11
12
 
12
13
  it "load and execute deltas" do
@@ -22,7 +23,8 @@ module DeployMongo
22
23
  describe Deploy, "execute deltas and rollback all deltas" do
23
24
 
24
25
  before :all do
25
- DatabasePopulator.new("test").with_type("customer").with_records(30).build
26
+ config = Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml')
27
+ DatabasePopulator.new(config.database,config.mongo_shell_path).with_type("customer").with_records(30).build
26
28
  end
27
29
 
28
30
  it "load and execute deltas" do
@@ -38,7 +40,8 @@ module DeployMongo
38
40
  describe Deploy, "execute deltas and rollback only 2 deltas" do
39
41
 
40
42
  before :all do
41
- DatabasePopulator.new("test").with_type("customer").with_records(30).build
43
+ config = Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml')
44
+ DatabasePopulator.new(config.database,config.mongo_shell_path).with_type("customer").with_records(30).build
42
45
  end
43
46
 
44
47
  it "load and execute deltas" do
@@ -5,7 +5,8 @@ module DeployMongo
5
5
  describe Repository, "execute a delta" do
6
6
 
7
7
  before :all do
8
- DatabasePopulator.new("test").with_type("customer").with_records(1).build
8
+ config = Config.create_from_file(File.dirname(__FILE__) + '/../mongodb.yml')
9
+ DatabasePopulator.new(config.database,config.mongo_shell_path).with_type("customer").with_records(1).build
9
10
  end
10
11
 
11
12
  it "create schema document if it does not exist and get schema to verify" do
data/spec/mongodb.yml CHANGED
@@ -2,4 +2,4 @@ hostname: localhost
2
2
  port: 27017
3
3
  delta_path: "integration/deltas"
4
4
  database: "test"
5
- mongo_shell_path: "/Users/admin/work/mongodb-osx-x86_64-1.8.2/bin/mongo"
5
+ mongo_shell_path: "/usr/local/bin/mongo"
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../lib/deploy_mongo'
4
4
 
5
5
 
6
6
  def get_couchdb_config
7
- DeployMongo::Config.new({"hostname"=>"localhost","port"=>27017,"database"=>"test",'delta_path'=>"path/to/deltas","config_folder_path" => "/somefolder","doc_type_field"=>"type","type_version_field" => 'type_version' })
7
+ DeployMongo::Config.new({"hostname"=>"localhost","port"=>27017,"database"=>"test",'delta_path'=>"path/to/deltas","config_folder_path" => "/somefolder","doc_type_field"=>"type","type_version_field" => 'type_version','mongo_shell_path' =>"/usr/local/bin/mongo" })
8
8
  end
9
9
 
10
10
  def create_json_response(total_rows,num_of_records,offset=0)
@@ -5,7 +5,8 @@ module DeployMongo
5
5
  describe DeltaProcessor, "execute a delta" do
6
6
  it "should apply delta" do
7
7
  mock_shell = mock(MongoShell)
8
- MongoShell.should_receive(:new).with('test').and_return(mock_shell)
8
+ MongoShell.should_receive(:new)
9
+ .with(get_couchdb_config.database,get_couchdb_config.mongo_shell_path).and_return(mock_shell)
9
10
 
10
11
  command= 'db.customer.update({},{$set: {"address": "some address" } } , false , true )'
11
12
  rollback_command= 'db.customer.update({},{$unset: {"address": 1}},false,true)'
@@ -19,7 +20,8 @@ module DeployMongo
19
20
 
20
21
  it "should rollback delta" do
21
22
  mock_shell = mock(MongoShell)
22
- MongoShell.should_receive(:new).with('test').and_return(mock_shell)
23
+ MongoShell.should_receive(:new)
24
+ .with(get_couchdb_config.database,get_couchdb_config.mongo_shell_path).and_return(mock_shell)
23
25
 
24
26
  command= 'db.customer.update({},{$set: {"address": "some address" } } , false , true )'
25
27
  rollback_command= 'db.customer.update({},{$unset: {"address": 1}},false,true)'
@@ -7,7 +7,7 @@ module DeployMongo
7
7
  it "get schema document" do
8
8
  schema = {"_id"=>"special_key","type"=>"__schema__", 'applied_deltas'=>[1,2], "type_versions"=>{"customer"=>10}}
9
9
  mock_server = mock(Mongo::Connection)
10
- Mongo::Connection.should_receive(:new).with("localhost",27017).and_return(mock_server)
10
+ Mongo::Connection.should_receive(:new).with("localhost",27017,:safe=>true).and_return(mock_server)
11
11
  mock_db = mock(Mongo::DB)
12
12
  mock_server.should_receive(:db).with("test").and_return(mock_db)
13
13
  mock_collection = mock(Mongo::Collection)
@@ -22,7 +22,7 @@ module DeployMongo
22
22
  it "save schema document without id" do
23
23
  schema = {"type"=>"__schema__", 'applied_deltas'=>[1,2], "type_versions"=>{"customer"=>10}}
24
24
  mock_server = mock(Mongo::Connection)
25
- Mongo::Connection.should_receive(:new).with("localhost",27017).and_return(mock_server)
25
+ Mongo::Connection.should_receive(:new).with("localhost",27017,:safe=>true).and_return(mock_server)
26
26
  mock_db = mock(Mongo::DB)
27
27
  mock_server.should_receive(:db).with("test").and_return(mock_db)
28
28
  mock_collection = mock(Mongo::Collection)
@@ -37,7 +37,7 @@ module DeployMongo
37
37
  it "save schema document with id" do
38
38
  schema = {"_id" => "schema__schema_document_key__", "type"=>"__schema__", 'applied_deltas'=>[1,2], "type_versions"=>{"customer"=>10}}
39
39
  mock_server = mock(Mongo::Connection)
40
- Mongo::Connection.should_receive(:new).with("localhost",27017).and_return(mock_server)
40
+ Mongo::Connection.should_receive(:new).with("localhost",27017,:safe=>true).and_return(mock_server)
41
41
  mock_db = mock(Mongo::DB)
42
42
  mock_server.should_receive(:db).with("test").and_return(mock_db)
43
43
  mock_collection = mock(Mongo::Collection)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-26 00:00:00.000000000 +05:30
13
- default_executable:
12
+ date: 2012-12-21 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bson
17
- requirement: &2161041180 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,15 @@ dependencies:
22
21
  version: 1.3.1
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2161041180
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.1
26
30
  - !ruby/object:Gem::Dependency
27
31
  name: bson_ext
28
- requirement: &2161040540 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
30
34
  requirements:
31
35
  - - ! '>='
@@ -33,10 +37,15 @@ dependencies:
33
37
  version: 1.3.1
34
38
  type: :runtime
35
39
  prerelease: false
36
- version_requirements: *2161040540
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.1
37
46
  - !ruby/object:Gem::Dependency
38
47
  name: mongo
39
- requirement: &2161039960 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
40
49
  none: false
41
50
  requirements:
42
51
  - - ! '>='
@@ -44,10 +53,15 @@ dependencies:
44
53
  version: 1.3.1
45
54
  type: :runtime
46
55
  prerelease: false
47
- version_requirements: *2161039960
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.1
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: rspec
50
- requirement: &2161039300 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
51
65
  none: false
52
66
  requirements:
53
67
  - - ! '>='
@@ -55,7 +69,12 @@ dependencies:
55
69
  version: 2.6.0
56
70
  type: :development
57
71
  prerelease: false
58
- version_requirements: *2161039300
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
59
78
  description: dbDeploy for couchdb
60
79
  email:
61
80
  - venkatesh.swdev@gmail.com
@@ -67,7 +86,7 @@ files:
67
86
  - .gitignore
68
87
  - Gemfile
69
88
  - Gemfile.lock
70
- - README
89
+ - README.rdoc
71
90
  - Rakefile
72
91
  - bin/deploy_mongo
73
92
  - deploy_mongo.gemspec
@@ -91,7 +110,6 @@ files:
91
110
  - spec/integration/deltas/13_copy_and_create_new_customer.js
92
111
  - spec/integration/deltas/1_add_address_to_customer.js
93
112
  - spec/integration/deltas/2_add_phone_to_customer.js
94
- - spec/integration/deltas/5_not_a_yaml_file.rb
95
113
  - spec/integration/deploy_spec.rb
96
114
  - spec/integration/repository_spec.rb
97
115
  - spec/mongodb.yml
@@ -100,7 +118,6 @@ files:
100
118
  - spec/unit/delta_processor_spec.rb
101
119
  - spec/unit/deploy_spec.rb
102
120
  - spec/unit/repository_spec.rb
103
- has_rdoc: true
104
121
  homepage: https://github.com/venkateshcm/deploy_mongo
105
122
  licenses: []
106
123
  post_install_message:
@@ -121,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
138
  version: '0'
122
139
  requirements: []
123
140
  rubyforge_project: deploy_mongo
124
- rubygems_version: 1.6.2
141
+ rubygems_version: 1.8.22
125
142
  signing_key:
126
143
  specification_version: 3
127
144
  summary: dbDeploy for couchdb
@@ -135,7 +152,6 @@ test_files:
135
152
  - spec/integration/deltas/13_copy_and_create_new_customer.js
136
153
  - spec/integration/deltas/1_add_address_to_customer.js
137
154
  - spec/integration/deltas/2_add_phone_to_customer.js
138
- - spec/integration/deltas/5_not_a_yaml_file.rb
139
155
  - spec/integration/deploy_spec.rb
140
156
  - spec/integration/repository_spec.rb
141
157
  - spec/mongodb.yml
data/README DELETED
@@ -1,43 +0,0 @@
1
- deploy_mongo
2
- =============
3
- deploy_mongo is db deploy tool for mongodb.
4
-
5
-
6
- How to install
7
- =================
8
- gem install deploy_mongo
9
-
10
-
11
- Usage
12
- ======
13
- deploy_mongo 'path/to/mongodb.yml' [rollback:(1|2|3|..|all)]
14
-
15
- [rollback:all] rollbacks all the deltas
16
-
17
-
18
- Example
19
- =======
20
- deploy_mongo/spec/mongodb.yml for mongodb.yml config file
21
- deploy_mongo/spec/integration/deltas for delta files
22
-
23
-
24
- Config Parameters
25
- ==================
26
- hostname: <couchdb database server hostname>
27
- port: <couchdb server port number , by default 5984>
28
- delta_path: < path/to/deltas folder relative to configdb.yml>
29
- database: <couchdb database name>
30
- mongo_shell_path: < full path to mongo shell (can be found in mongodb install folder/bin )>
31
-
32
- Delta File name format
33
- =======================
34
- <Delta Number>_<Description>.js
35
- example 1_add_address_to_customer.js
36
-
37
-
38
- Delta File content format
39
- =========================
40
- <command used to modify database>
41
- //@undo
42
- <rollback command used when rolling back applied delta.>
43
-
File without changes