couch-migrate 1.0.0 → 1.1.0
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 +122 -3
- data/VERSION +1 -1
- data/couch-migrate.gemspec +2 -2
- data/lib/couch-migrate.rb +3 -1
- data/lib/couch_migrate/couchrest_model/extend.rb +8 -6
- metadata +15 -15
data/README.rdoc
CHANGED
@@ -1,9 +1,128 @@
|
|
1
1
|
= couch-migrate
|
2
2
|
|
3
|
-
|
3
|
+
A simple migration system for CouchDB.
|
4
|
+
|
5
|
+
This gem was created because we needed something more than what "rake
|
6
|
+
db:seed" could provide.
|
7
|
+
|
8
|
+
== Example Migration File
|
9
|
+
|
10
|
+
# File: db/migrate/1_name_of_migration.rb
|
11
|
+
up do
|
12
|
+
puts "this will be run when rake executes an 'up'"
|
13
|
+
end
|
14
|
+
|
15
|
+
down do
|
16
|
+
puts "this will be run when rake executes a 'down'"
|
17
|
+
end
|
18
|
+
|
19
|
+
== Example Migration File Using CouchRest::Model
|
20
|
+
|
21
|
+
# File: db/migrate/2_another_migration.rb
|
22
|
+
|
23
|
+
# In order to lock model definitions to a point in time (so
|
24
|
+
# migrations will work in the future even after models change),
|
25
|
+
# classes can be defined in a migration, that are namespaced
|
26
|
+
# automatically yet still work with CouchDB's usage of the 'type'
|
27
|
+
# field. In order to use CouchRest::Models, include this line:
|
28
|
+
# use_couchrest_model
|
29
|
+
|
30
|
+
use_couchrest_model # this must appear before any class definitions
|
31
|
+
|
32
|
+
# Defined in app/models/account.rb, but duplicated here without any
|
33
|
+
# validations or domain logic, in order to lock the model definition
|
34
|
+
# to this point in time.
|
35
|
+
class Account < CouchRest::Model::Base
|
36
|
+
property :name, String
|
37
|
+
property :description, String
|
38
|
+
collection_of :things, class_name: Thing
|
39
|
+
end
|
40
|
+
|
41
|
+
class Thing < CouchRest::Model::Base
|
42
|
+
belongs_to :account, class_name: Account
|
43
|
+
property :name, String
|
44
|
+
property :characteristics, [String]
|
45
|
+
timestamps!
|
46
|
+
design do
|
47
|
+
view :by_name # views work as expected
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
up do
|
52
|
+
# an example of limiting whether a migration runs or not. In this
|
53
|
+
# case, only run this migration if the CouchDB database is
|
54
|
+
# approximately empty.
|
55
|
+
begin
|
56
|
+
threshold = 5
|
57
|
+
db = Account.database # the db url, obtained however you feel
|
58
|
+
if db.info['doc_count'] > threshold
|
59
|
+
puts "Database (#{db.to_s}) has more than #{threshold} documents. This migration will not run"
|
60
|
+
return
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
|
65
|
+
Account.create! do |a|
|
66
|
+
a.name = "A new account"
|
67
|
+
|
68
|
+
a.things << Thing.create! do |t|
|
69
|
+
t.name = "Thing # 1"
|
70
|
+
t.characteristics << "Awesome"
|
71
|
+
t.characteristics << "Joy bringing"
|
72
|
+
t.hidden = false
|
73
|
+
end
|
74
|
+
# example code. not tested
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
== Example Rake Task
|
80
|
+
|
81
|
+
def migrater
|
82
|
+
couch_db_url = 'http://127.0.0.1:5984/couch-migrate_test'
|
83
|
+
# or, if you are using CouchRest::Model
|
84
|
+
# require 'your_couchreset_model_class'
|
85
|
+
# couch_db_url = YourCouchRestModelClass.database.to_s
|
86
|
+
CouchMigrate::CouchMigrater.new(couch_db_url)
|
87
|
+
end
|
88
|
+
|
89
|
+
namespace :db do
|
90
|
+
desc 'migrate all pending migrations'
|
91
|
+
task :migrate => ['migrate:up']
|
92
|
+
|
93
|
+
namespace :migrate do
|
94
|
+
desc 'couchdb migration up'
|
95
|
+
task 'up' => [:environment, :url] do
|
96
|
+
migrater.migrate(:up)
|
97
|
+
end
|
98
|
+
|
99
|
+
desc 'couchdb migration down'
|
100
|
+
task 'down' => [:environment, :url] do
|
101
|
+
migrater.migrate(:down)
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'couchdb migration down, then up'
|
105
|
+
task 'redo' => [:environment, :url] do
|
106
|
+
migrater.migrate(:down)
|
107
|
+
migrater.migrate(:up)
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'print couchdb URL'
|
111
|
+
task 'url' => :environment do
|
112
|
+
$stderr.puts("CouchDB URL: #{CloudProvider.database.to_s}")
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
== Thanks
|
119
|
+
|
120
|
+
Thanks to OpenLogic (http://openlogic.com), a great company that
|
121
|
+
focuses on supporting the Open Source market, for allowing this work to
|
122
|
+
be open sourced.
|
4
123
|
|
5
124
|
== Contributing to couch-migrate
|
6
|
-
|
125
|
+
|
7
126
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
127
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
128
|
* Fork the project
|
@@ -14,6 +133,6 @@ Description goes here.
|
|
14
133
|
|
15
134
|
== Copyright
|
16
135
|
|
17
|
-
Copyright (c) 2011 Greg Edwards. See LICENSE.txt for
|
136
|
+
Copyright (c) 2011 OpenLogic, Inc. and Greg Edwards. See LICENSE.txt for
|
18
137
|
further details.
|
19
138
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/couch-migrate.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{couch-migrate}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Greg Edwards"]
|
12
|
-
s.date = %q{2011-09-
|
12
|
+
s.date = %q{2011-09-21}
|
13
13
|
s.description = %q{A simple migration system for CouchDB.}
|
14
14
|
s.email = %q{greg@greglearns.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/couch-migrate.rb
CHANGED
@@ -1,2 +1,4 @@
|
|
1
1
|
require_relative 'couch_migrate_railtie.rb' if defined?(Rails)
|
2
|
-
Dir["#{File.dirname(__FILE__)}/couch_migrate/**/*.rb"]
|
2
|
+
list = Dir["#{File.dirname(__FILE__)}/couch_migrate/**/*.rb"]
|
3
|
+
skip = Dir["#{File.dirname(__FILE__)}/couch_migrate/couchrest_model/**/*.rb"]
|
4
|
+
(list - skip).each {|f| require f}
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# use "use_couchrest_model" in the DSL or
|
2
2
|
# include this module in a migration to use CouchRest::Model
|
3
|
-
if defined?(
|
4
|
-
module CouchRest
|
3
|
+
if defined?(::CouchRest::Model)
|
4
|
+
module ::CouchRest
|
5
5
|
module Model
|
6
6
|
class Base
|
7
|
-
|
7
|
+
class << self
|
8
|
+
alias to_s_original to_s
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def to_s
|
11
|
+
to_s_original.sub(/CouchMigrate::BaseExecuter::Namespaced::/, '')
|
12
|
+
end
|
12
13
|
end
|
14
|
+
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-21 00:00:00.000000000 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: couchrest
|
17
|
-
requirement: &
|
17
|
+
requirement: &2159120560 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2159120560
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &2159119800 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 2.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2159119800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: yard
|
39
|
-
requirement: &
|
39
|
+
requirement: &2159082100 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.6.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2159082100
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &2159081060 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.0.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2159081060
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &2159079780 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 1.6.4
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2159079780
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rcov
|
72
|
-
requirement: &
|
72
|
+
requirement: &2159078720 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2159078720
|
81
81
|
description: A simple migration system for CouchDB.
|
82
82
|
email: greg@greglearns.com
|
83
83
|
executables: []
|
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: 4097235762935568490
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|