schema_plus 2.0.0.pre3 → 2.0.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/README.md +4 -28
  4. data/TODO.md +5 -2
  5. data/gemfiles/Gemfile.base +0 -4
  6. data/lib/schema_plus.rb +1 -1
  7. data/lib/schema_plus/version.rb +1 -1
  8. data/lib/schema_plus_db_default.rb +0 -6
  9. data/lib/schema_plus_db_default/active_record/attribute.rb +2 -5
  10. data/lib/schema_plus_db_default/db_default.rb +2 -0
  11. data/lib/schema_plus_db_default/middleware.rb +1 -1
  12. data/lib/schema_plus_default_expr.rb +1 -0
  13. data/lib/schema_plus_default_expr/active_record/connection_adapters/column.rb +14 -0
  14. data/lib/schema_plus_default_expr/active_record/connection_adapters/sqlite3_adapter.rb +0 -16
  15. data/lib/schema_plus_default_expr/middleware.rb +3 -4
  16. data/lib/schema_plus_enums/middleware.rb +2 -2
  17. data/lib/schema_plus_foreign_keys.rb +1 -5
  18. data/lib/schema_plus_foreign_keys/active_record/base.rb +0 -4
  19. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/abstract_adapter.rb +13 -19
  20. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/foreign_key_definition.rb +9 -15
  21. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/mysql2_adapter.rb +4 -12
  22. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/postgresql_adapter.rb +2 -8
  23. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/sqlite3_adapter.rb +2 -8
  24. data/lib/schema_plus_foreign_keys/active_record/migration/command_recorder.rb +3 -9
  25. data/lib/schema_plus_foreign_keys/active_record/schema.rb +3 -12
  26. data/lib/schema_plus_foreign_keys/middleware/dumper.rb +1 -1
  27. data/lib/schema_plus_foreign_keys/middleware/sql.rb +11 -0
  28. data/schema_dev.yml +0 -1
  29. data/schema_plus.gemspec +29 -28
  30. data/spec/schema_plus_foreign_keys/foreign_key_spec.rb +0 -22
  31. metadata +38 -27
  32. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/schema_statements.rb +0 -33
  33. data/lib/schema_plus_views.rb +0 -16
  34. data/lib/schema_plus_views/active_record/connection_adapters/abstract_adapter.rb +0 -41
  35. data/lib/schema_plus_views/active_record/connection_adapters/mysql2_adapter.rb +0 -30
  36. data/lib/schema_plus_views/active_record/connection_adapters/postgresql_adapter.rb +0 -31
  37. data/lib/schema_plus_views/active_record/connection_adapters/sqlite3_adapter.rb +0 -18
  38. data/lib/schema_plus_views/middleware.rb +0 -49
  39. data/spec/schema_plus_views/named_schemas_spec.rb +0 -97
  40. data/spec/schema_plus_views/views_spec.rb +0 -194
@@ -6,14 +6,8 @@ module SchemaPlusForeignKeys
6
6
  # enhancements
7
7
  module PostgresqlAdapter
8
8
 
9
- def self.included(base) #:nodoc:
10
- base.class_eval do
11
- alias_method_chain :rename_table, :schema_plus_foreign_keys
12
- end
13
- end
14
-
15
- def rename_table_with_schema_plus_foreign_keys(oldname, newname) #:nodoc:
16
- rename_table_without_schema_plus_foreign_keys(oldname, newname)
9
+ def rename_table(oldname, newname) #:nodoc:
10
+ super
17
11
  rename_foreign_keys(oldname, newname)
18
12
  end
19
13
 
@@ -8,19 +8,13 @@ module SchemaPlusForeignKeys
8
8
 
9
9
  # :enddoc:
10
10
 
11
- def self.included(base)
12
- base.class_eval do
13
- alias_method_chain :rename_table, :schema_plus_foreign_keys
14
- end
15
- end
16
-
17
11
  def initialize(*args)
18
12
  super
19
13
  execute('PRAGMA FOREIGN_KEYS = ON')
20
14
  end
21
15
 
22
- def rename_table_with_schema_plus_foreign_keys(oldname, newname) #:nodoc:
23
- rename_table_without_schema_plus_foreign_keys(oldname, newname)
16
+ def rename_table(oldname, newname) #:nodoc:
17
+ super
24
18
  rename_foreign_keys(oldname, newname)
25
19
  end
26
20
 
@@ -5,20 +5,13 @@ module SchemaPlusForeignKeys
5
5
 
6
6
  attr_accessor :schema_plus_config #:nodoc:
7
7
 
8
- def self.included(base) #:nodoc:
9
- base.class_eval do
10
- alias_method_chain :add_reference, :schema_plus_foreign_keys
11
- alias_method_chain :invert_add_index, :schema_plus_foreign_keys
12
- end
13
- end
14
-
15
8
  # seems like this is fixing a rails bug:
16
9
  # change_table foo, :bulk => true { |t| t.references :bar }
17
10
  # results in an 'unknown method :add_reference_sql' (with mysql2)
18
11
  #
19
12
  # should track it down separately and submit a patch/fix to rails
20
13
  #
21
- def add_reference_with_schema_plus_foreign_keys(table_name, ref_name, options = {}) #:nodoc:
14
+ def add_reference(table_name, ref_name, options = {}) #:nodoc:
22
15
  polymorphic = options.delete(:polymorphic)
23
16
  options[:references] = nil if polymorphic
24
17
  # ugh. copying and pasting code from ::ActiveRecord::ConnectionAdapters::SchemaStatements#add_reference
@@ -30,7 +23,8 @@ module SchemaPlusForeignKeys
30
23
  self
31
24
  end
32
25
 
33
- def invert_add_index_with_schema_plus_foreign_keys(args)
26
+ # overrides to add if_exists option
27
+ def invert_add_index(args)
34
28
  table, columns, options = *args
35
29
  [:remove_index, [table, (options||{}).merge(column: columns, if_exists: true)]]
36
30
  end
@@ -1,23 +1,14 @@
1
1
  module SchemaPlusForeignKeys
2
2
  module ActiveRecord
3
- module Schema #:nodoc: all
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
3
+ module Schema
8
4
  module ClassMethods
9
- def self.extended(base)
10
- class << base
11
- alias_method_chain :define, :schema_plus_foreign_keys
12
- end
13
- end
14
5
 
15
- def define_with_schema_plus_foreign_keys(info={}, &block)
6
+ def define(*args)
16
7
  fk_override = { :auto_create => false, :auto_index => false }
17
8
  save = Hash[fk_override.keys.collect{|key| [key, SchemaPlusForeignKeys.config.send(key)]}]
18
9
  begin
19
10
  SchemaPlusForeignKeys.config.update_attributes(fk_override)
20
- define_without_schema_plus_foreign_keys(info, &block)
11
+ super
21
12
  ensure
22
13
  SchemaPlusForeignKeys.config.update_attributes(save)
23
14
  end
@@ -34,7 +34,7 @@ module SchemaPlusForeignKeys
34
34
 
35
35
  # Ignore the foreign key dumps at the end of the schema; we'll put them in/near their tables
36
36
  def after(env)
37
- env.dump.foreign_keys = []
37
+ env.dump.final.reject!(&it =~/foreign_key/)
38
38
  end
39
39
 
40
40
  private
@@ -0,0 +1,11 @@
1
+ module SchemaPlusForeignKeys
2
+ module Middleware
3
+ module Sql
4
+ module Table
5
+ def after(env)
6
+ env.sql.body = ([env.sql.body] + env.table_definition.foreign_keys.map(&:to_sql)).join(', ')
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
data/schema_dev.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ruby:
2
- - 1.9.3
3
2
  - 2.1.5
4
3
  activerecord:
5
4
  - 4.2
data/schema_plus.gemspec CHANGED
@@ -2,37 +2,38 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "schema_plus/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "schema_plus"
7
- s.version = SchemaPlus::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.required_ruby_version = ">= 1.9.2"
10
- s.authors = ["Ronen Barzel", "Michal Lomnicki"]
11
- s.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
12
- s.homepage = "https://github.com/SchemaPlus/schema_plus"
13
- s.summary = "Enhances ActiveRecord schema mechanism, including more DRY index creation and support for foreign key constraints and views."
14
- s.description = "SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views."
15
- s.license = 'MIT'
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "schema_plus"
7
+ gem.version = SchemaPlus::VERSION
8
+ gem.platform = Gem::Platform::RUBY
9
+ gem.required_ruby_version = ">= 1.9.2"
10
+ gem.authors = ["Ronen Barzel", "Michal Lomnicki"]
11
+ gem.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
12
+ gem.homepage = "https://github.com/SchemaPlus/schema_plus"
13
+ gem.summary = "Enhances ActiveRecord schema mechanism, including more DRY index creation and support for foreign key constraints and views."
14
+ gem.description = "SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views."
15
+ gem.license = 'MIT'
16
16
 
17
- s.rubyforge_project = "schema_plus"
17
+ gem.rubyforge_project = "schema_plus"
18
18
 
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ gem.require_paths = ["lib"]
23
23
 
24
- s.add_dependency "activerecord", "~> 4.2"
25
- s.add_dependency "valuable"
26
- s.add_dependency "schema_monkey", "~> 1.0", ">= 1.0.1"
27
- s.add_dependency "schema_monkey_rails", "~> 0.1", ">= 0.1.1"
28
- s.add_dependency "schema_plus_indexes", "~> 0.1"
29
- s.add_dependency "schema_plus_pg_indexes", "~> 0.1"
24
+ gem.add_dependency "activerecord", "~> 4.2"
25
+ gem.add_dependency "valuable"
26
+ gem.add_dependency "schema_plus_core", "~> 0.1"
27
+ gem.add_dependency "schema_monkey_rails", "~> 0.1", ">= 0.1.2"
28
+ gem.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.2"
29
+ gem.add_dependency "schema_plus_pg_indexes", "~> 0.1", ">= 0.1.3"
30
+ gem.add_dependency "schema_plus_views", "~> 0.1"
30
31
 
31
- s.add_development_dependency "schema_dev", "~> 3.0"
32
- s.add_development_dependency "rake"
33
- s.add_development_dependency "rspec", "~> 3.0.0"
34
- s.add_development_dependency "rdoc"
35
- s.add_development_dependency "simplecov"
36
- s.add_development_dependency "simplecov-gem-profile"
32
+ gem.add_development_dependency "schema_dev", "~> 3.1"
33
+ gem.add_development_dependency "rake"
34
+ gem.add_development_dependency "rspec", "~> 3.0"
35
+ gem.add_development_dependency "rdoc"
36
+ gem.add_development_dependency "simplecov"
37
+ gem.add_development_dependency "simplecov-gem-profile"
37
38
  end
38
39
 
@@ -29,28 +29,6 @@ describe "Foreign Key" do
29
29
 
30
30
  end
31
31
 
32
- context "with modifications to SQL generated by upstream visit_TableDefinition" do
33
- before(:each) do
34
- allow_any_instance_of(ActiveRecord::Base.connection.class.const_get(:SchemaCreation))
35
- .to receive(:visit_TableDefinition_without_schema_plus_foreign_keys)
36
- .and_return('this is unexpected')
37
- end
38
-
39
- it "raises an exception when attempting to create a table" do
40
- expect {
41
- define_schema(:auto_create => true) do
42
- create_table :users, :force => true do |t|
43
- t.string :login
44
- end
45
- create_table :comments, :force => true do |t|
46
- t.integer :user_id
47
- t.foreign_key :user_id, :users
48
- end
49
- end
50
- }.to raise_error(RuntimeError, /Internal Error: Can't find.*Rails internals have changed/)
51
- end
52
- end
53
-
54
32
  context "modification" do
55
33
 
56
34
  before(:each) 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: 2.0.0.pre3
4
+ version: 2.0.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-03 00:00:00.000000000 Z
12
+ date: 2015-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -40,27 +40,41 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: schema_monkey
43
+ name: schema_plus_core
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.0'
48
+ version: '0.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: schema_monkey_rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.1'
49
63
  - - ">="
50
64
  - !ruby/object:Gem::Version
51
- version: 1.0.1
65
+ version: 0.1.2
52
66
  type: :runtime
53
67
  prerelease: false
54
68
  version_requirements: !ruby/object:Gem::Requirement
55
69
  requirements:
56
70
  - - "~>"
57
71
  - !ruby/object:Gem::Version
58
- version: '1.0'
72
+ version: '0.1'
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 1.0.1
75
+ version: 0.1.2
62
76
  - !ruby/object:Gem::Dependency
63
- name: schema_monkey_rails
77
+ name: schema_plus_indexes
64
78
  requirement: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
@@ -68,7 +82,7 @@ dependencies:
68
82
  version: '0.1'
69
83
  - - ">="
70
84
  - !ruby/object:Gem::Version
71
- version: 0.1.1
85
+ version: 0.1.2
72
86
  type: :runtime
73
87
  prerelease: false
74
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -78,14 +92,17 @@ dependencies:
78
92
  version: '0.1'
79
93
  - - ">="
80
94
  - !ruby/object:Gem::Version
81
- version: 0.1.1
95
+ version: 0.1.2
82
96
  - !ruby/object:Gem::Dependency
83
- name: schema_plus_indexes
97
+ name: schema_plus_pg_indexes
84
98
  requirement: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0.1'
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 0.1.3
89
106
  type: :runtime
90
107
  prerelease: false
91
108
  version_requirements: !ruby/object:Gem::Requirement
@@ -93,8 +110,11 @@ dependencies:
93
110
  - - "~>"
94
111
  - !ruby/object:Gem::Version
95
112
  version: '0.1'
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 0.1.3
96
116
  - !ruby/object:Gem::Dependency
97
- name: schema_plus_pg_indexes
117
+ name: schema_plus_views
98
118
  requirement: !ruby/object:Gem::Requirement
99
119
  requirements:
100
120
  - - "~>"
@@ -113,14 +133,14 @@ dependencies:
113
133
  requirements:
114
134
  - - "~>"
115
135
  - !ruby/object:Gem::Version
116
- version: '3.0'
136
+ version: '3.1'
117
137
  type: :development
118
138
  prerelease: false
119
139
  version_requirements: !ruby/object:Gem::Requirement
120
140
  requirements:
121
141
  - - "~>"
122
142
  - !ruby/object:Gem::Version
123
- version: '3.0'
143
+ version: '3.1'
124
144
  - !ruby/object:Gem::Dependency
125
145
  name: rake
126
146
  requirement: !ruby/object:Gem::Requirement
@@ -141,14 +161,14 @@ dependencies:
141
161
  requirements:
142
162
  - - "~>"
143
163
  - !ruby/object:Gem::Version
144
- version: 3.0.0
164
+ version: '3.0'
145
165
  type: :development
146
166
  prerelease: false
147
167
  version_requirements: !ruby/object:Gem::Requirement
148
168
  requirements:
149
169
  - - "~>"
150
170
  - !ruby/object:Gem::Version
151
- version: 3.0.0
171
+ version: '3.0'
152
172
  - !ruby/object:Gem::Dependency
153
173
  name: rdoc
154
174
  requirement: !ruby/object:Gem::Requirement
@@ -225,6 +245,7 @@ files:
225
245
  - lib/schema_plus_db_default/db_default.rb
226
246
  - lib/schema_plus_db_default/middleware.rb
227
247
  - lib/schema_plus_default_expr.rb
248
+ - lib/schema_plus_default_expr/active_record/connection_adapters/column.rb
228
249
  - lib/schema_plus_default_expr/active_record/connection_adapters/mysql2_adapter.rb
229
250
  - lib/schema_plus_default_expr/active_record/connection_adapters/postgresql_adapter.rb
230
251
  - lib/schema_plus_default_expr/active_record/connection_adapters/sqlite3_adapter.rb
@@ -238,7 +259,6 @@ files:
238
259
  - lib/schema_plus_foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
239
260
  - lib/schema_plus_foreign_keys/active_record/connection_adapters/mysql2_adapter.rb
240
261
  - lib/schema_plus_foreign_keys/active_record/connection_adapters/postgresql_adapter.rb
241
- - lib/schema_plus_foreign_keys/active_record/connection_adapters/schema_statements.rb
242
262
  - lib/schema_plus_foreign_keys/active_record/connection_adapters/sqlite3_adapter.rb
243
263
  - lib/schema_plus_foreign_keys/active_record/connection_adapters/table_definition.rb
244
264
  - lib/schema_plus_foreign_keys/active_record/migration/command_recorder.rb
@@ -246,18 +266,13 @@ files:
246
266
  - lib/schema_plus_foreign_keys/middleware/dumper.rb
247
267
  - lib/schema_plus_foreign_keys/middleware/migration.rb
248
268
  - lib/schema_plus_foreign_keys/middleware/model.rb
269
+ - lib/schema_plus_foreign_keys/middleware/sql.rb
249
270
  - lib/schema_plus_foreign_keys/version.rb
250
271
  - lib/schema_plus_tables.rb
251
272
  - lib/schema_plus_tables/active_record/connection_adapters/abstract_adapter.rb
252
273
  - lib/schema_plus_tables/active_record/connection_adapters/mysql2_adapter.rb
253
274
  - lib/schema_plus_tables/active_record/connection_adapters/postgresql_adapter.rb
254
275
  - lib/schema_plus_tables/active_record/connection_adapters/sqlite3_adapter.rb
255
- - lib/schema_plus_views.rb
256
- - lib/schema_plus_views/active_record/connection_adapters/abstract_adapter.rb
257
- - lib/schema_plus_views/active_record/connection_adapters/mysql2_adapter.rb
258
- - lib/schema_plus_views/active_record/connection_adapters/postgresql_adapter.rb
259
- - lib/schema_plus_views/active_record/connection_adapters/sqlite3_adapter.rb
260
- - lib/schema_plus_views/middleware.rb
261
276
  - schema_dev.yml
262
277
  - schema_plus.gemspec
263
278
  - spec/schema/auto_schema.rb
@@ -275,8 +290,6 @@ files:
275
290
  - spec/schema_plus_foreign_keys/named_schemas_spec.rb
276
291
  - spec/schema_plus_foreign_keys/schema_dumper_spec.rb
277
292
  - spec/schema_plus_foreign_keys/schema_spec.rb
278
- - spec/schema_plus_views/named_schemas_spec.rb
279
- - spec/schema_plus_views/views_spec.rb
280
293
  - spec/spec_helper.rb
281
294
  - spec/support/helpers.rb
282
295
  - spec/support/matchers/automatic_foreign_key_matchers.rb
@@ -323,8 +336,6 @@ test_files:
323
336
  - spec/schema_plus_foreign_keys/named_schemas_spec.rb
324
337
  - spec/schema_plus_foreign_keys/schema_dumper_spec.rb
325
338
  - spec/schema_plus_foreign_keys/schema_spec.rb
326
- - spec/schema_plus_views/named_schemas_spec.rb
327
- - spec/schema_plus_views/views_spec.rb
328
339
  - spec/spec_helper.rb
329
340
  - spec/support/helpers.rb
330
341
  - spec/support/matchers/automatic_foreign_key_matchers.rb
@@ -1,33 +0,0 @@
1
- module SchemaPlusForeignKeys::ActiveRecord::ConnectionAdapters
2
- module SchemaStatements
3
-
4
- def self.included(base) #:nodoc:
5
- base.class_eval do
6
- alias_method_chain :create_table, :schema_plus_foreign_keys
7
- end
8
- end
9
-
10
- ##
11
- # :method: create_table
12
- #
13
- # SchemaPlusForeignKeys extends SchemaStatements::create_table to allow you to specify configuration options per table. Pass them in as a hash keyed by configuration set (see SchemaPlusForeignKeys::Config),
14
- # for example:
15
- #
16
- # create_table :widgets, :foreign_keys => {:auto_create => true, :on_delete => :cascade} do |t|
17
- # ...
18
- # end
19
- def create_table_with_schema_plus_foreign_keys(table, options = {})
20
- options = options.dup
21
- config_options = options.delete(:foreign_keys) || {}
22
-
23
- # override rails' :force to cascade
24
- drop_table(table, if_exists: true, cascade: true) if options.delete(:force)
25
-
26
- create_table_without_schema_plus_foreign_keys(table, options) do |table_definition|
27
- table_definition.schema_plus_config = SchemaPlusForeignKeys.config.merge(config_options)
28
- yield table_definition if block_given?
29
- end
30
- end
31
- end
32
-
33
- end