schema_plus_foreign_keys 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92096a0a42cf0026642c8ff73b8076c42cf25f85
4
- data.tar.gz: f3d60f8304240085ec49cf8cfb395e050c4fd345
3
+ metadata.gz: 3c82c1e41e5b9f6ca1cfb1f5d4df97db636f573f
4
+ data.tar.gz: ae9f1d6d16f4e77f36dd5b8246873b50da4d8ba8
5
5
  SHA512:
6
- metadata.gz: 491625f5bcc6fe7ce45ecacc83c6d1296b41c946316e783e7d2fe96a3d286fcf0039847d2eafd10a5603cca9018c34e6fe28932e81bfd94d722688cf90b22f3b
7
- data.tar.gz: 8710875bd68becc5666cbca804721ffbe4e6a550cd67be1cc1e7fa4e329bf26a56fb7048f5f7689be0ebf7b6da6c7b13dc26552749fff4e591e63219bf835635
6
+ metadata.gz: c88017019c8f44d10b3b833e8f19e1612f0311f5a07c0c05af87046c87e238081cfc0811af6e813a68365d523ec51c4343e7e6ebe30024cd3577c9f0aaef6e68
7
+ data.tar.gz: 12e0728c42a03ba247ddd28e3885e1cfc1f3948ecbb46bb10baafb389db218952358d0762c4e79ef5ddff280457fd63ba289cd1fb81258ea8c67190a42a90a0f
@@ -5,7 +5,7 @@
5
5
  ---
6
6
  sudo: false
7
7
  rvm:
8
- - 2.1.8
8
+ - 2.3.1
9
9
  gemfile:
10
10
  - gemfiles/activerecord-4.2.0/Gemfile.mysql2
11
11
  - gemfiles/activerecord-4.2.0/Gemfile.postgresql
@@ -16,6 +16,9 @@ gemfile:
16
16
  - gemfiles/activerecord-4.2.6/Gemfile.mysql2
17
17
  - gemfiles/activerecord-4.2.6/Gemfile.postgresql
18
18
  - gemfiles/activerecord-4.2.6/Gemfile.sqlite3
19
+ - gemfiles/activerecord-5.0/Gemfile.mysql2
20
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
21
+ - gemfiles/activerecord-5.0/Gemfile.sqlite3
19
22
  env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
20
23
  addons:
21
24
  postgresql: '9.4'
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/schema_plus_foreign_keys.svg)](http://badge.fury.io/rb/schema_plus_foreign_keys)
2
2
  [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_foreign_keys.svg)](http://travis-ci.org/SchemaPlus/schema_plus_foreign_keys)
3
3
  [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_foreign_keys.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_foreign_keys)
4
- [![Dependency Status](https://gemnasium.com/lomba/schema_plus_foreign_keys.svg)](https://gemnasium.com/SchemaPlus/schema_plus_foreign_keys)
5
4
 
6
5
  # SchemaPlus::ForeignKeys
7
6
 
@@ -142,14 +141,16 @@ SchemaPlus::ForeignKeys is tested on:
142
141
 
143
142
  <!-- SCHEMA_DEV: MATRIX - begin -->
144
143
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
145
- * ruby **2.1.8** with activerecord **4.2.0**, using **mysql2**, **sqlite3** or **postgresql**
146
- * ruby **2.1.8** with activerecord **4.2.1**, using **mysql2**, **sqlite3** or **postgresql**
147
- * ruby **2.1.8** with activerecord **4.2.6**, using **mysql2**, **sqlite3** or **postgresql**
144
+ * ruby **2.3.1** with activerecord **4.2.0**, using **mysql2**, **sqlite3** or **postgresql**
145
+ * ruby **2.3.1** with activerecord **4.2.1**, using **mysql2**, **sqlite3** or **postgresql**
146
+ * ruby **2.3.1** with activerecord **4.2.6**, using **mysql2**, **sqlite3** or **postgresql**
147
+ * ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql**
148
148
 
149
149
  <!-- SCHEMA_DEV: MATRIX - end -->
150
150
 
151
151
  ## History
152
152
 
153
+ * 0.1.7 - Compatibility with ActiveRecord 5.0.
153
154
  * 0.1.6 - Missing require
154
155
  * 0.1.5 - Explicit gem dependencies
155
156
  * 0.1.4 - Upgrade schema_plus_core dependency
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "activerecord", "~> 5.0.0"
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -1,4 +1,5 @@
1
1
  require 'schema_plus/core'
2
+ require 'schema_plus_compatibility'
2
3
  require 'its-it'
3
4
  require 'valuable'
4
5
 
@@ -0,0 +1,29 @@
1
+ module SchemaPlus
2
+ module Core
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module AbstractAdapter
6
+ module SchemaCreation
7
+
8
+ def visit_ForeignKeyDefinition(o)
9
+ # schema_plus_foreign_keys already implements a superior
10
+ # conversion of ForeignKeyDefinitions to SQL
11
+ o.to_sql
12
+ end
13
+
14
+ # The TableDefinition::foreign_keys attribute contains ForeignKeyDefinitions instead of
15
+ # [to_table, options] tuples when using schema_plus_foreign_keys.
16
+ # This function happily accepts to_table and options arguments anyway, so we just ignore
17
+ # all arguments and treat to_table as the ForeignKeyDefinition and convert it to SQL
18
+ # directly.
19
+ def foreign_key_in_create(from_table, to_table, options)
20
+ accept to_table # This is the ForeignKeyDefinition
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -1,3 +1,5 @@
1
+ require_relative 'abstract/schema_creation'
2
+
1
3
  module SchemaPlus::ForeignKeys
2
4
  module ActiveRecord
3
5
  # SchemaPlus::ForeignKeys adds several methods to the connection adapter (as returned by ActiveRecordBase#connection). See AbstractAdapter for details.
@@ -8,6 +8,12 @@ module SchemaPlus::ForeignKeys
8
8
 
9
9
  # :enddoc:
10
10
 
11
+ # Even though SQLite3 has limited support for foreign keys, ActiveRecord does not
12
+ # enable it by default.
13
+ def supports_foreign_keys?
14
+ true
15
+ end
16
+
11
17
  def add_foreign_key(table_name, to_table, options = {})
12
18
  raise NotImplementedError, "Sqlite3 does not support altering a table to add foreign key constraints (table #{table_name.inspect} to #{to_table.inspect})"
13
19
  end
@@ -14,7 +14,7 @@ module SchemaPlus::ForeignKeys
14
14
  @inline_fks = Hash.new{ |h, k| h[k] = [] }
15
15
  @backref_fks = Hash.new{ |h, k| h[k] = [] }
16
16
 
17
- env.connection.tables.each do |table|
17
+ env.connection.tables_only.each do |table|
18
18
  if (fks = env.connection.foreign_keys(table)).any?
19
19
  env.dump.data.has_fks = true
20
20
  @inline_fks[table] = fks
@@ -2,22 +2,23 @@ module SchemaPlus::ForeignKeys
2
2
  module Middleware
3
3
  module Sql
4
4
  module Table
5
- def after(env)
6
- foreign_keys = if env.table_definition.foreign_keys.is_a? Array
7
- env.table_definition.foreign_keys
8
- else
9
- env.table_definition.foreign_keys.values.tap { |v| v.flatten! }
10
- end
5
+ if Gem::Requirement.new('< 5.0.0.alpha.1').satisfied_by?(::ActiveRecord.version)
6
+ def after(env)
7
+ foreign_keys = if env.table_definition.foreign_keys.is_a? Array
8
+ env.table_definition.foreign_keys
9
+ else
10
+ env.table_definition.foreign_keys.values.tap { |v| v.flatten! }
11
+ end
11
12
 
12
- # create foreign key constraints inline in table definition
13
- env.sql.body = ([env.sql.body] + foreign_keys.map(&:to_sql)).join(', ')
13
+ # create foreign key constraints inline in table definition
14
+ env.sql.body = ([env.sql.body] + foreign_keys.map(&:to_sql)).join(', ')
14
15
 
15
- # prevents AR >= 4.2.1 from emitting add_foreign_key after the table
16
- env.table_definition.foreign_keys.clear
16
+ # prevents AR >= 4.2.1 from emitting add_foreign_key after the table
17
+ env.table_definition.foreign_keys.clear
18
+ end
17
19
  end
18
20
 
19
21
  module SQLite3
20
-
21
22
  def before(env)
22
23
  env.connection.execute('PRAGMA FOREIGN_KEYS = ON') if env.table_definition.foreign_keys.any?
23
24
  end
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module ForeignKeys
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
5
5
  end
@@ -1,9 +1,10 @@
1
1
  ruby:
2
- - 2.1.8
2
+ - 2.3.1
3
3
  activerecord:
4
4
  - 4.2.0
5
5
  - 4.2.1
6
6
  - 4.2.6
7
+ - 5.0
7
8
  db:
8
9
  - mysql2
9
10
  - sqlite3
@@ -18,8 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency "activerecord", "~> 4.2"
22
- gem.add_dependency "schema_plus_core", "~> 1.0"
21
+ gem.add_dependency "activerecord", ">= 4.2", "< 5.1"
22
+ gem.add_dependency "schema_plus_core"
23
+ gem.add_dependency "schema_plus_compatibility", "~> 0.2"
23
24
  gem.add_dependency "valuable"
24
25
  gem.add_dependency "its-it", "~> 1.2"
25
26
 
@@ -122,6 +122,7 @@ describe 'Deprecations' do
122
122
 
123
123
  it "deprecates :set_null" do
124
124
  expect(ActiveSupport::Deprecation).to receive(:warn).with(/set_null.*nullify/)
125
+ allow(ActiveSupport::Deprecation).to receive(:warn).with(/table_exists\? currently checks/)
125
126
  define_schema do
126
127
  create_table :posts
127
128
  create_table :comments do |t|
@@ -136,6 +137,7 @@ describe 'Deprecations' do
136
137
  describe "in table definition" do
137
138
  it "deprecates 3-column form" do
138
139
  expect(ActiveSupport::Deprecation).to receive(:warn).with(/positional arg.*primary_key/)
140
+ allow(ActiveSupport::Deprecation).to receive(:warn).with(/table_exists\? currently checks/)
139
141
  define_schema do
140
142
  create_table :posts, primary_key: :funky
141
143
  create_table :comments do |t|
@@ -329,7 +329,7 @@ describe ActiveRecord::Migration do
329
329
  it "should remove a foreign key constraint"+suffix, :sqlite3 => :skip do
330
330
  Comment.reset_column_information
331
331
  expect(Comment).to reference(:users, :id).on(:user_id)
332
- migration = Class.new ::ActiveRecord::Migration do
332
+ migration = Class.new ::ActiveRecord::Migration.latest_version do
333
333
  define_method(:change) {
334
334
  change_table("comments", :bulk => bulk) do |t|
335
335
  t.integer :user_id, foreign_key: true
@@ -6,7 +6,7 @@ describe "Schema dump" do
6
6
  before(:each) do
7
7
  ActiveRecord::Migration.suppress_messages do
8
8
  ActiveRecord::Schema.define do
9
- connection.tables.each do |table| drop_table table, force: :cascade end
9
+ connection.tables_only.each do |table| drop_table table, force: :cascade end
10
10
 
11
11
  create_table :users, :force => true do |t|
12
12
  t.string :login
@@ -143,7 +143,7 @@ describe "Schema dump" do
143
143
 
144
144
  ActiveRecord::Migration.suppress_messages do
145
145
  ActiveRecord::Schema.define do
146
- connection.tables.each do |table| drop_table table, force: :cascade end
146
+ connection.tables_only.each do |table| drop_table table, force: :cascade end
147
147
 
148
148
  create_table :grade_systems, force: true do |t|
149
149
  t.string :name
@@ -22,7 +22,7 @@ RSpec.configure do |config|
22
22
  begin
23
23
  example.run
24
24
  ensure
25
- ActiveRecord::Base.connection.tables.each do |table|
25
+ ActiveRecord::Base.connection.tables_only.each do |table|
26
26
  ActiveRecord::Migration.drop_table table, force: :cascade
27
27
  end
28
28
  end
@@ -48,7 +48,7 @@ def define_schema(config={}, &block)
48
48
  with_fk_config(config) do
49
49
  ActiveRecord::Migration.suppress_messages do
50
50
  ActiveRecord::Schema.define do
51
- connection.tables.each do |table|
51
+ connection.tables_only.each do |table|
52
52
  drop_table table, force: :cascade
53
53
  end
54
54
  instance_eval &block
metadata CHANGED
@@ -1,43 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_foreign_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: schema_plus_core
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: schema_plus_compatibility
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '1.0'
53
+ version: '0.2'
34
54
  type: :runtime
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '1.0'
60
+ version: '0.2'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: valuable
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -178,8 +198,13 @@ files:
178
198
  - gemfiles/activerecord-4.2.6/Gemfile.mysql2
179
199
  - gemfiles/activerecord-4.2.6/Gemfile.postgresql
180
200
  - gemfiles/activerecord-4.2.6/Gemfile.sqlite3
201
+ - gemfiles/activerecord-5.0/Gemfile.base
202
+ - gemfiles/activerecord-5.0/Gemfile.mysql2
203
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
204
+ - gemfiles/activerecord-5.0/Gemfile.sqlite3
181
205
  - lib/schema_plus/foreign_keys.rb
182
206
  - lib/schema_plus/foreign_keys/active_record/base.rb
207
+ - lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract/schema_creation.rb
183
208
  - lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb
184
209
  - lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
185
210
  - lib/schema_plus/foreign_keys/active_record/connection_adapters/mysql2_adapter.rb
@@ -224,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
249
  version: '0'
225
250
  requirements: []
226
251
  rubyforge_project:
227
- rubygems_version: 2.2.2
252
+ rubygems_version: 2.5.1
228
253
  signing_key:
229
254
  specification_version: 4
230
255
  summary: Extended support for foreign key constraints in ActiveRecord