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 +4 -4
- data/.travis.yml +4 -1
- data/README.md +5 -4
- data/gemfiles/activerecord-5.0/Gemfile.base +3 -0
- data/gemfiles/activerecord-5.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-5.0/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/foreign_keys.rb +1 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract/schema_creation.rb +29 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb +2 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/sqlite3_adapter.rb +6 -0
- data/lib/schema_plus/foreign_keys/middleware/dumper.rb +1 -1
- data/lib/schema_plus/foreign_keys/middleware/sql.rb +12 -11
- data/lib/schema_plus/foreign_keys/version.rb +1 -1
- data/schema_dev.yml +2 -1
- data/schema_plus_foreign_keys.gemspec +3 -2
- data/spec/deprecation_spec.rb +2 -0
- data/spec/migration_spec.rb +1 -1
- data/spec/schema_dumper_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- metadata +32 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c82c1e41e5b9f6ca1cfb1f5d4df97db636f573f
|
4
|
+
data.tar.gz: ae9f1d6d16f4e77f36dd5b8246873b50da4d8ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c88017019c8f44d10b3b833e8f19e1612f0311f5a07c0c05af87046c87e238081cfc0811af6e813a68365d523ec51c4343e7e6ebe30024cd3577c9f0aaef6e68
|
7
|
+
data.tar.gz: 12e0728c42a03ba247ddd28e3885e1cfc1f3948ecbb46bb10baafb389db218952358d0762c4e79ef5ddff280457fd63ba289cd1fb81258ea8c67190a42a90a0f
|
data/.travis.yml
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
---
|
6
6
|
sudo: false
|
7
7
|
rvm:
|
8
|
-
- 2.1
|
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
|
146
|
-
* ruby **2.1
|
147
|
-
* ruby **2.1
|
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
|
data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract/schema_creation.rb
ADDED
@@ -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
|
+
|
@@ -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.
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
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
|
data/schema_dev.yml
CHANGED
@@ -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", "
|
22
|
-
gem.add_dependency "schema_plus_core"
|
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
|
|
data/spec/deprecation_spec.rb
CHANGED
@@ -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|
|
data/spec/migration_spec.rb
CHANGED
@@ -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
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -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.
|
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.
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -22,7 +22,7 @@ RSpec.configure do |config|
|
|
22
22
|
begin
|
23
23
|
example.run
|
24
24
|
ensure
|
25
|
-
ActiveRecord::Base.connection.
|
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.
|
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.
|
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-
|
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: '
|
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: '
|
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.
|
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
|