deploy_couch 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/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in deploy_couch.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
data/Gemfile.lock CHANGED
@@ -6,9 +6,19 @@ PATH
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.6.0)
11
+ rspec-core (~> 2.6.0)
12
+ rspec-expectations (~> 2.6.0)
13
+ rspec-mocks (~> 2.6.0)
14
+ rspec-core (2.6.4)
15
+ rspec-expectations (2.6.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.6.0)
9
18
 
10
19
  PLATFORMS
11
20
  ruby
12
21
 
13
22
  DEPENDENCIES
14
23
  deploy_couch!
24
+ rspec
data/README CHANGED
@@ -0,0 +1,54 @@
1
+ deploy_couch
2
+ =============
3
+ deploy_couch is db deploy tool for couchdb.
4
+
5
+
6
+ How to install
7
+ =================
8
+ gem install deploy_couch
9
+
10
+
11
+ Usage
12
+ ======
13
+ deploy_couch 'path/to/couchdb.yml' [rollback:(1|2|3|..|all)]
14
+
15
+ [rollback:all] rollbacks all the deltas
16
+
17
+
18
+ Example
19
+ =======
20
+ deploy_couch/spec/couchdb.yml for couchdb.yml config file
21
+ deploy_couch/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
+ doc_type_field: <field name used to identify the document type>
31
+ type_version_field: <deploy_couch uses this field to maintain type version of the document, you can configure the field name>
32
+
33
+ Delta File name format
34
+ =======================
35
+ <Delta Number>_<Description>.yml
36
+ example 1_add_address_to_customer.yml
37
+
38
+
39
+ Delta File content format
40
+ =========================
41
+ type: < document type, example: customer >
42
+ map_function: <map function used to modify customer document. return value 'update' indicates updating the document with changes>
43
+ function map(doc)
44
+ {
45
+ doc.address = "some address";
46
+ return 'update';
47
+ }
48
+ rollback_function: <rollback function used when rolling back applied delta.>
49
+ function map(doc)
50
+ {
51
+ delete doc.address;
52
+ return 'update';
53
+ }
54
+
data/bin/deploy_couch CHANGED
@@ -1,16 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if (ARGV.length != 1)
4
- puts "usage: deploy_couch 'path/to/couchdb.yml' "
3
+ def print_usage
4
+ puts "usage: deploy_couch 'path/to/couchdb.yml' [rollback:(1|2|..|all)]"
5
+ puts "example: deploy_couch 'path/to/couchdb.yml'"
6
+ puts "example: deploy_couch 'path/to/couchdb.yml' rollback:all"
7
+ puts "example: deploy_couch 'path/to/couchdb.yml' rollback:1"
5
8
  exit(-1)
6
9
  end
10
+
11
+ if (ARGV.length < 1 || ARGV.length > 2 )
12
+ print_usage
13
+ end
14
+
15
+ if (ARGV.length == 2 and !ARGV[1].start_with?('rollback:'))
16
+ print_usage
17
+ end
18
+
19
+ no_of_deltas_to_rollback = 0
20
+
21
+ if(ARGV.length == 2)
22
+ if (ARGV[1].split(':')[1] != 'all')
23
+ no_of_deltas_to_rollback = ARGV[1].split(':')[1].to_i
24
+ print_usage if no_of_deltas_to_rollback == 0
25
+ end
26
+ end
27
+
7
28
  if (!File.exists?(ARGV[0]))
8
29
  puts "file '#{ARGV[0]}' does not exist "
9
30
  exit(-1)
10
31
  end
11
32
 
33
+
12
34
  require 'deploy_couch'
13
35
 
14
36
  config = DeployCouch::Config.create_from_file(ARGV[0])
15
37
  deploy = DeployCouch::Deploy.new(config)
16
- deploy.run
38
+ deploy.run if ARGV.length == 1
39
+ deploy.rollback(no_of_deltas_to_rollback) if ARGV.length == 2
@@ -39,20 +39,21 @@ module DeployCouch
39
39
  deltas
40
40
  end
41
41
 
42
- def rollback
42
+ def rollback(no_of_deltas_to_rollback=0)
43
43
  repository = Repository.new(@config)
44
44
  delta_loader = DeltaLoader.new(@config.delta_path)
45
45
  deltas_map = delta_loader.get_deltas
46
46
  couch_schema = DbSchema.load_or_create(@config,repository)
47
47
  applied_deltas = couch_schema.applied_deltas.sort.reverse
48
+ no_of_deltas_to_rollback = applied_deltas.length if no_of_deltas_to_rollback == 0
48
49
 
49
50
  deltas = []
50
51
  puts "Already applied deltas #{applied_deltas}"
51
- puts "Rolling back deltas #{applied_deltas}"
52
+ puts "Rolling back deltas #{applied_deltas[0..(no_of_deltas_to_rollback-1)]}"
52
53
  puts ""
53
54
  puts "Start rolling back deltas"
54
55
 
55
- applied_deltas.each do |key|
56
+ applied_deltas[0..(no_of_deltas_to_rollback-1)].each do |key|
56
57
  delta = deltas_map[key]
57
58
  type = couch_schema.get_next_type_version_for(delta.type)
58
59
  DeltaProcessor.new(type,@config,delta,repository).rollback
@@ -1,3 +1,3 @@
1
1
  module DeployCouch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/deploy_couch.rb CHANGED
@@ -9,5 +9,5 @@ require 'deploy_couch/delta_processor'
9
9
  require 'deploy_couch/delta_loader'
10
10
  require 'deploy_couch/delta'
11
11
  require 'deploy_couch/deploy'
12
- require 'deploy_couch/couch_db_schema'
12
+ require 'deploy_couch/db_schema'
13
13
  require 'deploy_couch/http_client'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_couch
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,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-23 00:00:00.000000000 +05:30
12
+ date: 2011-07-26 00:00:00.000000000 +05:30
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: dbDeploy for couchdb
@@ -30,7 +30,7 @@ files:
30
30
  - deploy_couch.rake
31
31
  - lib/deploy_couch.rb
32
32
  - lib/deploy_couch/config.rb
33
- - lib/deploy_couch/couch_db_schema.rb
33
+ - lib/deploy_couch/db_schema.rb
34
34
  - lib/deploy_couch/delta.rb
35
35
  - lib/deploy_couch/delta_loader.rb
36
36
  - lib/deploy_couch/delta_processor.rb