schema_plus 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -176,6 +176,7 @@ take advantage of auto-creation of foreign keys, you can re-enable it:
176
176
  == History
177
177
 
178
178
  * Recent Release notes:
179
+ * 0.4.0 - add :force for create_view (suggested by greglazarev[https://github.com/greglazarev]). cleanups by betelgeuse[https://github.com/betelgeuse]
179
180
  * 0.3.4 - bug fix: regression causing :default => false to be ignored
180
181
  * 0.3.3 - bug fix: properly handle boolean defaults in mysql
181
182
  * 0.3.2 - bug fix: make sure rake db:schema:load initializes schema_plus
data/Rakefile CHANGED
@@ -49,7 +49,7 @@ task :build_postgresql_databases => 'postgresql:build_databases'
49
49
  task :drop_postgresql_databases => 'postgresql:drop_databases'
50
50
  task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
51
51
 
52
- MYSQL_DB_USER = 'schema_plus'
52
+ MYSQL_DB_USER = ENV.fetch('MYSQL_DB_USER', 'schema_plus')
53
53
  namespace :mysql do
54
54
  desc 'Build the MySQL test databases'
55
55
  task :build_databases do
@@ -54,8 +54,10 @@ module SchemaPlus
54
54
  extend(SchemaPlus::ActiveRecord::ForeignKeys)
55
55
  end
56
56
 
57
- # Create a view given the SQL definition
58
- def create_view(view_name, definition)
57
+ # Create a view given the SQL definition. Specify :force => true
58
+ # to first drop the view if it already exists.
59
+ def create_view(view_name, definition, options={})
60
+ execute "DROP VIEW IF EXISTS #{quote_table_name(view_name)}" if options[:force]
59
61
  execute "CREATE VIEW #{quote_table_name(view_name)} AS #{definition}"
60
62
  end
61
63
 
@@ -1,7 +1,7 @@
1
1
  module SchemaPlus
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
- # SchemaPlus includes a MySQL implementation of the AbstractAdapater
4
+ # SchemaPlus includes a MySQL implementation of the AbstractAdapter
5
5
  # extensions. (This works with both the <tt>mysql</t> and
6
6
  # <tt>mysql2</tt> gems.)
7
7
  module MysqlAdapter
@@ -10,7 +10,7 @@ module SchemaPlus
10
10
  end
11
11
  end
12
12
 
13
- # SchemaPlus includes an Sqlite3 implementation of the AbstractAdapater
13
+ # SchemaPlus includes an Sqlite3 implementation of the AbstractAdapter
14
14
  # extensions.
15
15
  module Sqlite3Adapter
16
16
 
@@ -53,7 +53,7 @@ module SchemaPlus
53
53
 
54
54
  @connection.views.each do |view_name|
55
55
  definition = @connection.view_definition(view_name)
56
- @table_dumps[view_name] = " create_view #{view_name.inspect}, #{definition.inspect}\n"
56
+ @table_dumps[view_name] = " create_view #{view_name.inspect}, #{definition.inspect}, :force => true\n"
57
57
  end
58
58
 
59
59
  re_view_referent = %r{(?:(?i)FROM|JOIN) \S*\b(#{(@table_dumps.keys).join('|')})\b}
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -47,8 +47,8 @@ describe ActiveRecord do
47
47
 
48
48
 
49
49
  it "should be included in schema dump" do
50
- dump.should match(%r{create_view "a_ones", "SELECT .*b.*,.*s.* FROM .*items.* WHERE .*a.* = 1}i)
51
- dump.should match(%r{create_view "ab_ones", "SELECT .*s.* FROM .*a_ones.* WHERE .*b.* = 1}i)
50
+ dump.should match(%r{create_view "a_ones", "SELECT .*b.*,.*s.* FROM .*items.* WHERE .*a.* = 1.*, :force => true}i)
51
+ dump.should match(%r{create_view "ab_ones", "SELECT .*s.* FROM .*a_ones.* WHERE .*b.* = 1.*, :force => true}i)
52
52
  end
53
53
 
54
54
  it "should be included in schema dump in dependency order" do
@@ -67,6 +67,28 @@ describe ActiveRecord do
67
67
  dump.should_not match(%r{#{connection.quote_table_name(db)}[.]})
68
68
  end
69
69
 
70
+ context "duplicate view creation" do
71
+ around(:each) do |example|
72
+ migration.suppress_messages do
73
+ begin
74
+ migration.create_view('dupe_me', 'SELECT * FROM items WHERE (a=1)')
75
+ example.run
76
+ ensure
77
+ migration.drop_view('dupe_me')
78
+ end
79
+ end
80
+ end
81
+
82
+
83
+ it "should raise an error by default" do
84
+ expect {migration.create_view('dupe_me', 'SELECT * FROM items WHERE (a=2)')}.should raise_error ActiveRecord::StatementInvalid
85
+ end
86
+
87
+ it "should override existing definition if :force true" do
88
+ migration.create_view('dupe_me', 'SELECT * FROM items WHERE (a=2)', :force => true)
89
+ connection.view_definition('dupe_me').should =~ %r{WHERE .*a.*=.*2}i
90
+ end
91
+ end
70
92
 
71
93
  if SchemaPlusHelpers.mysql?
72
94
  context "in mysql" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-28 00:00:00.000000000 Z
13
+ date: 2012-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70148459617200 !ruby/object:Gem::Requirement
17
+ requirement: &70249441590660 !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: *70148459617200
25
+ version_requirements: *70249441590660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: valuable
28
- requirement: &70148459616780 !ruby/object:Gem::Requirement
28
+ requirement: &70249441590200 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70148459616780
36
+ version_requirements: *70249441590200
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &70148459616280 !ruby/object:Gem::Requirement
39
+ requirement: &70249441589680 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.8.7
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70148459616280
47
+ version_requirements: *70249441589680
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70148459615860 !ruby/object:Gem::Requirement
50
+ requirement: &70249441589180 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70148459615860
58
+ version_requirements: *70249441589180
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: pg
61
- requirement: &70148459615400 !ruby/object:Gem::Requirement
61
+ requirement: &70249441588700 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70148459615400
69
+ version_requirements: *70249441588700
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mysql
72
- requirement: &70148459614980 !ruby/object:Gem::Requirement
72
+ requirement: &70249441588240 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70148459614980
80
+ version_requirements: *70249441588240
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: sqlite3
83
- requirement: &70148459614560 !ruby/object:Gem::Requirement
83
+ requirement: &70249441587820 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70148459614560
91
+ version_requirements: *70249441587820
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: simplecov
94
- requirement: &70148459614140 !ruby/object:Gem::Requirement
94
+ requirement: &70249441587360 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70148459614140
102
+ version_requirements: *70249441587360
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov-gem-adapter
105
- requirement: &70148459613720 !ruby/object:Gem::Requirement
105
+ requirement: &70249441586940 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,7 +110,7 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70148459613720
113
+ version_requirements: *70249441586940
114
114
  description: ! 'SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
115
115
  for schema definition and querying, including: enhanced and more DRY index capabilities,
116
116
  support and automation for foreign key constraints, and support for views.'
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  version: '0'
204
204
  requirements: []
205
205
  rubyforge_project: schema_plus
206
- rubygems_version: 1.8.12
206
+ rubygems_version: 1.8.10
207
207
  signing_key:
208
208
  specification_version: 3
209
209
  summary: Enhances ActiveRecord schema mechanism, including more DRY index creation
@@ -236,4 +236,3 @@ test_files:
236
236
  - spec/support/matchers/reference.rb
237
237
  - spec/support/reference.rb
238
238
  - spec/views_spec.rb
239
- has_rdoc: