storey 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ spec/config/database.yml
10
10
  spec/dummy/config/database.yml
11
11
  spec/dummy/log/*
12
12
  spec/dummy/tmp
13
+ .rvmrc
@@ -43,12 +43,8 @@ class Storey::Duplicator
43
43
  end
44
44
 
45
45
  def load_schema(options={})
46
- options[:host] ||= Storey.database_config[:host] unless Storey.database_config[:host].blank?
47
- options[:dbname] ||= Storey.database_config[:database]
48
- options[:username] ||= Storey.database_config[:username]
49
46
  options[:file] ||= self.target_file
50
-
51
- switches = options.map { |k, v| "--#{k}=#{v}" }.join(" ")
47
+ switches = Storey.command_line_switches(options)
52
48
 
53
49
  if duplicating_from_default?
54
50
  # Since we are copying the source schema and we're after structure only,
@@ -57,19 +53,33 @@ class Storey::Duplicator
57
53
  ::Storey.create_plain_schema self.target_schema
58
54
  end
59
55
 
60
- source_schema_migrations = ::Storey.switch(self.source_schema) do
61
- ActiveRecord::Migrator.get_all_versions
62
- end
63
-
64
56
  `psql #{switches}`
65
57
 
58
+ copy_source_schema_migrations
59
+
60
+ ENV['PGPASSWORD'] = nil
61
+ end
62
+
63
+ def copy_source_schema_migrations
66
64
  ::Storey.switch self.target_schema do
67
65
  source_schema_migrations.each do |version|
68
- ActiveRecord::Base.connection.execute "INSERT INTO schema_migrations (version) VALUES ('#{version}');"
66
+ unless target_schema_migrations.include?(version)
67
+ ActiveRecord::Base.connection.execute "INSERT INTO schema_migrations (version) VALUES ('#{version}');"
68
+ end
69
69
  end
70
70
  end
71
+ end
71
72
 
72
- ENV['PGPASSWORD'] = nil
73
+ def source_schema_migrations
74
+ ::Storey.switch(self.source_schema) do
75
+ ActiveRecord::Migrator.get_all_versions
76
+ end
77
+ end
78
+
79
+ def target_schema_migrations
80
+ ::Storey.switch(self.target_schema) do
81
+ ActiveRecord::Migrator.get_all_versions
82
+ end
73
83
  end
74
84
 
75
85
  def replace_occurances
@@ -3,4 +3,5 @@ module Storey
3
3
  class SchemaExists < StoreyError; end
4
4
  class SchemaNotFound < StoreyError; end
5
5
  class TableNotFOund < StoreyError; end
6
+ class WithinTransaction < StoreyError; end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module Storey
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/storey.rb CHANGED
@@ -59,7 +59,18 @@ module Storey
59
59
  end
60
60
 
61
61
  def create_plain_schema(schema_name)
62
- ActiveRecord::Base.connection.execute "CREATE SCHEMA #{self.suffixify schema_name}"
62
+ switches = self.command_line_switches(:command => %{"CREATE SCHEMA #{self.suffixify schema_name}"})
63
+ command = "psql #{switches}"
64
+ system(command)
65
+ end
66
+
67
+ def command_line_switches(options={})
68
+ switches = {}
69
+ switches[:host] = self.database_config[:host] if self.database_config.has_key?(:host)
70
+ switches[:dbname] = self.database_config[:database]
71
+ switches[:username] = self.database_config[:username]
72
+ switches = switches.merge(options)
73
+ switches.map {|k, v| "--#{k}=#{v}"}.join(' ')
63
74
  end
64
75
 
65
76
  def schemas(options={})
@@ -102,6 +113,9 @@ module Storey
102
113
  rescue ActiveRecord::StatementInvalid => e
103
114
  if e.to_s =~ /invalid value for parameter "search_path"/
104
115
  fail Storey::SchemaNotFound, %{The schema "#{path}" cannot be found.}
116
+ elsif e.to_s =~ /relation ".*" does not exist at character \d+/
117
+ warn "Still unsure why the following error occurs, but see https://github.com/ramontayag/storey/issues/11"
118
+ raise e
105
119
  else
106
120
  raise e
107
121
  end
data/rvmrc.sample ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p290
@@ -11,16 +11,6 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120115060728) do
15
-
16
- create_table "companies", :force => true do |t|
17
- t.string "name"
18
- t.string "schema_name"
19
- end
20
-
21
- create_table "posts", :force => true do |t|
22
- t.string "name"
23
- t.text "body"
24
- end
14
+ ActiveRecord::Schema.define(:version => 0) do
25
15
 
26
16
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Storey, '.command_line_switches' do
4
+ it 'should build default command line switches for calling the psql command' do
5
+ described_class.stub(:database_config).and_return(:host => 'hoop',
6
+ :database => 'db',
7
+ :username => 'jj')
8
+ described_class.command_line_switches.
9
+ should == "--host=hoop --dbname=db --username=jj"
10
+ end
11
+
12
+ context 'given options' do
13
+ it 'should add the options to the switches, overriding any default' do
14
+ described_class.stub(:database_config).and_return(:host => 'hoop',
15
+ :database => 'db',
16
+ :username => 'jj')
17
+
18
+ described_class.command_line_switches(:a => 'boo', :host => 'loop').
19
+ should == "--host=loop --dbname=db --username=jj --a=boo"
20
+ end
21
+ end
22
+ end
@@ -9,6 +9,15 @@ describe Storey, "#create" do
9
9
  end
10
10
  end
11
11
 
12
+ context 'when in a database transaction and loading the database structure' do
13
+ it 'should not blow up and continue to create the schema' do
14
+ ActiveRecord::Base.transaction do
15
+ Storey.create 'foobar'
16
+ end
17
+ Storey.schemas.should include('foobar')
18
+ end
19
+ end
20
+
12
21
  it "should copy the schema_migrations over" do
13
22
  Storey.create "foobar"
14
23
  public_schema_migrations = Storey.switch { ActiveRecord::Migrator.get_all_versions }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000Z
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
16
- requirement: &82507520 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *82507520
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: pg
27
- requirement: &82506870 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.12.2
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *82506870
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.12.2
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: database_cleaner
38
- requirement: &82506250 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *82506250
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: pry
49
- requirement: &82505580 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *82505580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rails
60
- requirement: &82504910 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: 3.2.2
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *82504910
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.2.2
69
94
  description: Storey aims to simplify the implementation of managing a multi-tenant
70
95
  application.
71
96
  email:
@@ -76,7 +101,6 @@ extra_rdoc_files: []
76
101
  files:
77
102
  - .gitignore
78
103
  - .rspec
79
- - .rvmrc
80
104
  - Gemfile
81
105
  - README.md
82
106
  - Rakefile
@@ -89,6 +113,7 @@ files:
89
113
  - lib/storey/railtie.rb
90
114
  - lib/storey/version.rb
91
115
  - lib/tasks/storey.rake
116
+ - rvmrc.sample
92
117
  - spec/config/database.yml.sample
93
118
  - spec/dummy/Rakefile
94
119
  - spec/dummy/app/assets/javascripts/application.js
@@ -131,6 +156,7 @@ files:
131
156
  - spec/fixtures/.gitkeep
132
157
  - spec/migrator_spec.rb
133
158
  - spec/spec_helper.rb
159
+ - spec/storey/command_line_switches_spec.rb
134
160
  - spec/storey/configuration_spec.rb
135
161
  - spec/storey/create_plain_schema_spec.rb
136
162
  - spec/storey/create_spec.rb
@@ -159,16 +185,80 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
185
  - - ! '>='
160
186
  - !ruby/object:Gem::Version
161
187
  version: '0'
188
+ segments:
189
+ - 0
190
+ hash: 1992492096624626052
162
191
  required_rubygems_version: !ruby/object:Gem::Requirement
163
192
  none: false
164
193
  requirements:
165
194
  - - ! '>='
166
195
  - !ruby/object:Gem::Version
167
196
  version: '0'
197
+ segments:
198
+ - 0
199
+ hash: 1992492096624626052
168
200
  requirements: []
169
201
  rubyforge_project: storey
170
- rubygems_version: 1.8.11
202
+ rubygems_version: 1.8.24
171
203
  signing_key:
172
204
  specification_version: 3
173
205
  summary: Manage multiple PostgreSQL schemas in your multi-tenant app.
174
- test_files: []
206
+ test_files:
207
+ - spec/config/database.yml.sample
208
+ - spec/dummy/Rakefile
209
+ - spec/dummy/app/assets/javascripts/application.js
210
+ - spec/dummy/app/assets/stylesheets/application.css
211
+ - spec/dummy/app/controllers/application_controller.rb
212
+ - spec/dummy/app/helpers/application_helper.rb
213
+ - spec/dummy/app/mailers/.gitkeep
214
+ - spec/dummy/app/models/.gitkeep
215
+ - spec/dummy/app/models/company.rb
216
+ - spec/dummy/app/models/fake.rb
217
+ - spec/dummy/app/models/post.rb
218
+ - spec/dummy/app/views/layouts/application.html.erb
219
+ - spec/dummy/config.ru
220
+ - spec/dummy/config/application.rb
221
+ - spec/dummy/config/boot.rb
222
+ - spec/dummy/config/database.yml.sample
223
+ - spec/dummy/config/environment.rb
224
+ - spec/dummy/config/environments/development.rb
225
+ - spec/dummy/config/environments/production.rb
226
+ - spec/dummy/config/environments/test.rb
227
+ - spec/dummy/config/initializers/backtrace_silencers.rb
228
+ - spec/dummy/config/initializers/inflections.rb
229
+ - spec/dummy/config/initializers/mime_types.rb
230
+ - spec/dummy/config/initializers/secret_token.rb
231
+ - spec/dummy/config/initializers/session_store.rb
232
+ - spec/dummy/config/initializers/wrap_parameters.rb
233
+ - spec/dummy/config/locales/en.yml
234
+ - spec/dummy/config/routes.rb
235
+ - spec/dummy/db/migrate/20120115060713_create_companies.rb
236
+ - spec/dummy/db/migrate/20120115060728_create_posts.rb
237
+ - spec/dummy/db/schema.rb
238
+ - spec/dummy/lib/assets/.gitkeep
239
+ - spec/dummy/log/.gitkeep
240
+ - spec/dummy/log/development.log
241
+ - spec/dummy/public/404.html
242
+ - spec/dummy/public/422.html
243
+ - spec/dummy/public/500.html
244
+ - spec/dummy/public/favicon.ico
245
+ - spec/dummy/script/rails
246
+ - spec/fixtures/.gitkeep
247
+ - spec/migrator_spec.rb
248
+ - spec/spec_helper.rb
249
+ - spec/storey/command_line_switches_spec.rb
250
+ - spec/storey/configuration_spec.rb
251
+ - spec/storey/create_plain_schema_spec.rb
252
+ - spec/storey/create_spec.rb
253
+ - spec/storey/drop_spec.rb
254
+ - spec/storey/dumper_spec.rb
255
+ - spec/storey/duplicate_spec.rb
256
+ - spec/storey/excluded_models_spec.rb
257
+ - spec/storey/hstore_spec.rb
258
+ - spec/storey/persistent_schemas_spec.rb
259
+ - spec/storey/schema_search_path_for_spec.rb
260
+ - spec/storey/schema_spec.rb
261
+ - spec/storey/schemas_spec.rb
262
+ - spec/storey/suffixify_spec.rb
263
+ - spec/storey/switch_spec.rb
264
+ - spec/tasks/storey_rake_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.2-p290@storey --create