schema_plus 2.0.0.pre2 → 2.0.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +2 -0
- data/README.md +4 -4
- data/TODO.md +3 -10
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.base +1 -1
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.mysql2 +0 -0
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.postgresql +0 -0
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.sqlite3 +0 -0
- data/lib/schema_plus.rb +13 -121
- data/lib/schema_plus/version.rb +1 -1
- data/lib/schema_plus_columns.rb +7 -0
- data/lib/{schema_column_plus → schema_plus_columns}/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus_columns/middleware/model.rb +16 -0
- data/lib/schema_plus_db_default.rb +13 -0
- data/lib/{schema_db_default → schema_plus_db_default}/active_record/attribute.rb +4 -4
- data/lib/{schema_db_default → schema_plus_db_default}/db_default.rb +1 -1
- data/lib/schema_plus_db_default/middleware.rb +30 -0
- data/lib/{schema_default_expr.rb → schema_plus_default_expr.rb} +6 -6
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/middleware.rb +21 -19
- data/lib/schema_plus_enums.rb +6 -0
- data/lib/{schema_pg_enums → schema_plus_enums}/active_record.rb +1 -1
- data/lib/schema_plus_enums/middleware.rb +22 -0
- data/lib/schema_plus_foreign_keys.rb +96 -0
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/base.rb +2 -2
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/abstract_adapter.rb +7 -7
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/foreign_key_definition.rb +4 -4
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/mysql2_adapter.rb +9 -9
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/postgresql_adapter.rb +5 -5
- data/lib/schema_plus_foreign_keys/active_record/connection_adapters/schema_statements.rb +33 -0
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/sqlite3_adapter.rb +5 -5
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/table_definition.rb +8 -8
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/migration/command_recorder.rb +5 -5
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/schema.rb +7 -7
- data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/dumper.rb +11 -26
- data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/migration.rb +14 -15
- data/lib/schema_plus_foreign_keys/middleware/model.rb +15 -0
- data/lib/schema_plus_foreign_keys/version.rb +3 -0
- data/lib/schema_plus_views.rb +16 -0
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/abstract_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/schema_plus_views/middleware.rb +49 -0
- data/schema_dev.yml +1 -1
- data/schema_plus.gemspec +3 -2
- data/spec/{schema_column_plus → schema_plus_columns}/column_spec.rb +0 -0
- data/spec/{schema_db_default → schema_plus_db_default}/column_spec.rb +1 -1
- data/spec/{schema_default_expr → schema_plus_default_expr}/column_default_spec.rb +0 -0
- data/spec/schema_plus_default_expr/migration_spec.rb +44 -0
- data/spec/{schema_default_expr → schema_plus_default_expr}/schema_dumper_spec.rb +2 -2
- data/spec/{schema_pg_enums → schema_plus_enums}/enum_spec.rb +0 -0
- data/spec/{schema_pg_enums → schema_plus_enums}/schema_dumper_spec.rb +0 -0
- data/spec/{foreign_key_definition_spec.rb → schema_plus_foreign_keys/foreign_key_definition_spec.rb} +0 -0
- data/spec/{foreign_key_spec.rb → schema_plus_foreign_keys/foreign_key_spec.rb} +2 -2
- data/spec/{migration_spec.rb → schema_plus_foreign_keys/migration_spec.rb} +13 -29
- data/spec/{named_schemas_spec.rb → schema_plus_foreign_keys/named_schemas_spec.rb} +0 -0
- data/spec/{schema_dumper_spec.rb → schema_plus_foreign_keys/schema_dumper_spec.rb} +2 -2
- data/spec/{schema_spec.rb → schema_plus_foreign_keys/schema_spec.rb} +7 -7
- data/spec/{schema_views → schema_plus_views}/named_schemas_spec.rb +7 -7
- data/spec/{schema_views → schema_plus_views}/views_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -3
- metadata +102 -81
- data/init.rb +0 -1
- data/lib/schema_column_plus.rb +0 -7
- data/lib/schema_column_plus/middleware/model.rb +0 -22
- data/lib/schema_db_default.rb +0 -13
- data/lib/schema_db_default/middleware.rb +0 -30
- data/lib/schema_pg_enums.rb +0 -6
- data/lib/schema_pg_enums/middleware.rb +0 -23
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +0 -34
- data/lib/schema_plus/middleware/model.rb +0 -17
- data/lib/schema_views.rb +0 -16
- data/lib/schema_views/middleware.rb +0 -47
- data/spec/connection_spec.rb +0 -10
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
module
|
|
1
|
+
module SchemaPlusForeignKeys
|
|
2
2
|
module Middleware
|
|
3
3
|
module Dumper
|
|
4
4
|
|
|
5
|
-
def self.insert
|
|
6
|
-
SchemaMonkey::Middleware::Dumper::Tables.prepend FkDependencies
|
|
7
|
-
SchemaMonkey::Middleware::Dumper::Tables.append IgnoreActiveRecordFkDumps
|
|
8
|
-
SchemaMonkey::Middleware::Dumper::Table.append ForeignKeys
|
|
9
|
-
end
|
|
10
|
-
|
|
11
5
|
# index and foreign key constraint definitions are dumped
|
|
12
6
|
# inline in the create_table block. (This is done for elegance, but
|
|
13
7
|
# also because Sqlite3 does not allow foreign key constraints to be
|
|
14
8
|
# added to a table after it has been defined.)
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
# Middleware for the collection of tables
|
|
18
|
-
#
|
|
10
|
+
module Tables
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
def before(env)
|
|
21
13
|
|
|
22
|
-
def call(env)
|
|
23
14
|
@inline_fks = Hash.new{ |h, k| h[k] = [] }
|
|
24
15
|
@backref_fks = Hash.new{ |h, k| h[k] = [] }
|
|
25
16
|
|
|
@@ -39,10 +30,15 @@ module SchemaPlus
|
|
|
39
30
|
|
|
40
31
|
env.dump.data.inline_fks = @inline_fks
|
|
41
32
|
env.dump.data.backref_fks = @backref_fks
|
|
33
|
+
end
|
|
42
34
|
|
|
43
|
-
|
|
35
|
+
# Ignore the foreign key dumps at the end of the schema; we'll put them in/near their tables
|
|
36
|
+
def after(env)
|
|
37
|
+
env.dump.foreign_keys = []
|
|
44
38
|
end
|
|
45
39
|
|
|
40
|
+
private
|
|
41
|
+
|
|
46
42
|
def break_fk_cycles(env) #:nodoc:
|
|
47
43
|
env.dump.strongly_connected_components.select{|component| component.size > 1}.each do |tables|
|
|
48
44
|
table = tables.sort.first
|
|
@@ -54,22 +50,11 @@ module SchemaPlus
|
|
|
54
50
|
end
|
|
55
51
|
end
|
|
56
52
|
end
|
|
57
|
-
end
|
|
58
53
|
|
|
59
|
-
class IgnoreActiveRecordFkDumps < SchemaMonkey::Middleware::Base
|
|
60
|
-
# Ignore the foreign key dumps at the end of the schema; we'll put them in/near their tables
|
|
61
|
-
def call(env)
|
|
62
|
-
continue env
|
|
63
|
-
env.dump.foreign_keys = []
|
|
64
|
-
end
|
|
65
54
|
end
|
|
66
55
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
class ForeignKeys < SchemaMonkey::Middleware::Base
|
|
71
|
-
def call(env)
|
|
72
|
-
continue env
|
|
56
|
+
module Table
|
|
57
|
+
def after(env)
|
|
73
58
|
dumped = {}
|
|
74
59
|
env.table.columns.each do |column|
|
|
75
60
|
if (foreign_key = env.dump.data.inline_fks[env.table.name].find(&its.column.to_s == column.name))
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
module
|
|
1
|
+
module SchemaPlusForeignKeys
|
|
2
2
|
module Middleware
|
|
3
3
|
module Migration
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
SchemaMonkey::Middleware::Migration::Column.prepend Shortcuts
|
|
7
|
-
SchemaMonkey::Middleware::Migration::Column.append AddForeignKeys
|
|
8
|
-
end
|
|
5
|
+
module Column
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
#
|
|
8
|
+
# Column option shortcuts
|
|
9
|
+
#
|
|
10
|
+
def before(env)
|
|
12
11
|
fk_options = env.options[:foreign_key]
|
|
13
12
|
|
|
14
13
|
case fk_options
|
|
@@ -37,14 +36,12 @@ module SchemaPlus
|
|
|
37
36
|
fk_options = false if fk_options and fk_options.has_key?(:references) and not fk_options[:references]
|
|
38
37
|
|
|
39
38
|
env.options[:foreign_key] = fk_options
|
|
40
|
-
|
|
41
|
-
continue env
|
|
42
|
-
|
|
43
39
|
end
|
|
44
|
-
end
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
#
|
|
42
|
+
# Add the foreign keys
|
|
43
|
+
#
|
|
44
|
+
def around(env)
|
|
48
45
|
options = env.options
|
|
49
46
|
original_options = options.dup
|
|
50
47
|
|
|
@@ -56,7 +53,7 @@ module SchemaPlus
|
|
|
56
53
|
index = options.delete(:index) unless is_polymorphic
|
|
57
54
|
options[:foreign_key] = false if is_reference
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
yield env
|
|
60
57
|
|
|
61
58
|
return if is_polymorphic
|
|
62
59
|
|
|
@@ -66,13 +63,15 @@ module SchemaPlus
|
|
|
66
63
|
|
|
67
64
|
end
|
|
68
65
|
|
|
66
|
+
private
|
|
67
|
+
|
|
69
68
|
def add_foreign_keys_and_auto_index(env)
|
|
70
69
|
|
|
71
70
|
if (reverting = env.caller.is_a?(::ActiveRecord::Migration::CommandRecorder) && env.caller.reverting)
|
|
72
71
|
commands_length = env.caller.commands.length
|
|
73
72
|
end
|
|
74
73
|
|
|
75
|
-
config = (env.caller.try(:schema_plus_config) ||
|
|
74
|
+
config = (env.caller.try(:schema_plus_config) || SchemaPlusForeignKeys.config)
|
|
76
75
|
fk_args = get_fk_args(env, config)
|
|
77
76
|
|
|
78
77
|
# remove existing fk and auto-generated index in case of change of fk on existing column
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'schema_monkey'
|
|
2
|
+
|
|
3
|
+
require_relative 'schema_plus_views/active_record/connection_adapters/abstract_adapter'
|
|
4
|
+
require_relative 'schema_plus_views/middleware'
|
|
5
|
+
|
|
6
|
+
module SchemaPlusViews
|
|
7
|
+
module ActiveRecord
|
|
8
|
+
module ConnectionAdapters
|
|
9
|
+
autoload :Mysql2Adapter, 'schema_plus_views/active_record/connection_adapters/mysql2_adapter'
|
|
10
|
+
autoload :PostgresqlAdapter, 'schema_plus_views/active_record/connection_adapters/postgresql_adapter'
|
|
11
|
+
autoload :Sqlite3Adapter, 'schema_plus_views/active_record/connection_adapters/sqlite3_adapter'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
SchemaMonkey.register(SchemaPlusViews)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module SchemaPlusViews
|
|
2
|
+
module Middleware
|
|
3
|
+
|
|
4
|
+
module Dumper
|
|
5
|
+
module Tables
|
|
6
|
+
|
|
7
|
+
# Dump views
|
|
8
|
+
def after(env)
|
|
9
|
+
re_view_referent = %r{(?:(?i)FROM|JOIN) \S*\b(\S+)\b}
|
|
10
|
+
env.connection.views.each do |view_name|
|
|
11
|
+
next if env.dumper.ignored?(view_name)
|
|
12
|
+
view = View.new(name: view_name, definition: env.connection.view_definition(view_name))
|
|
13
|
+
env.dump.tables[view.name] = view
|
|
14
|
+
env.dump.depends(view.name, view.definition.scan(re_view_referent).flatten)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# quacks like a SchemaMonkey Dump::Table
|
|
19
|
+
class View < KeyStruct[:name, :definition]
|
|
20
|
+
def assemble(stream)
|
|
21
|
+
stream.puts(" create_view #{name.inspect}, #{definition.inspect}, :force => true\n")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
module Query
|
|
28
|
+
module Tables
|
|
29
|
+
|
|
30
|
+
module Mysql
|
|
31
|
+
def after(env)
|
|
32
|
+
Tables.filter_out_views(env)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
module Sqlite3
|
|
37
|
+
def after(env)
|
|
38
|
+
Tables.filter_out_views(env)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.filter_out_views(env)
|
|
43
|
+
env.tables -= env.connection.views(env.query_name)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
data/schema_dev.yml
CHANGED
data/schema_plus.gemspec
CHANGED
|
@@ -23,11 +23,12 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
|
|
24
24
|
s.add_dependency "activerecord", "~> 4.2"
|
|
25
25
|
s.add_dependency "valuable"
|
|
26
|
-
s.add_dependency "schema_monkey", "~> 0.
|
|
26
|
+
s.add_dependency "schema_monkey", "~> 1.0", ">= 1.0.1"
|
|
27
|
+
s.add_dependency "schema_monkey_rails", "~> 0.1", ">= 0.1.1"
|
|
27
28
|
s.add_dependency "schema_plus_indexes", "~> 0.1"
|
|
28
29
|
s.add_dependency "schema_plus_pg_indexes", "~> 0.1"
|
|
29
30
|
|
|
30
|
-
s.add_development_dependency "schema_dev", "~>
|
|
31
|
+
s.add_development_dependency "schema_dev", "~> 3.0"
|
|
31
32
|
s.add_development_dependency "rake"
|
|
32
33
|
s.add_development_dependency "rspec", "~> 3.0.0"
|
|
33
34
|
s.add_development_dependency "rdoc"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveRecord::Migration do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
define_schema(:auto_create => true) do
|
|
7
|
+
create_table :posts, :force => true do |t|
|
|
8
|
+
t.string :content
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
class Post < ::ActiveRecord::Base ; end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "when table is created" do
|
|
15
|
+
|
|
16
|
+
before(:each) do
|
|
17
|
+
@model = Post
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should properly handle default values for booleans" do
|
|
21
|
+
expect {
|
|
22
|
+
recreate_table(@model) do |t|
|
|
23
|
+
t.boolean :bool, :default => true
|
|
24
|
+
end
|
|
25
|
+
}.to_not raise_error
|
|
26
|
+
expect(@model.create.reload.bool).to be true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should properly handle default values for json (#195)", :postgresql => :only do
|
|
30
|
+
recreate_table(@model) do |t|
|
|
31
|
+
t.json :json, :default => {}
|
|
32
|
+
end
|
|
33
|
+
expect(@model.create.reload.json).to eq({})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def recreate_table(model, opts={}, &block)
|
|
39
|
+
ActiveRecord::Migration.suppress_messages do
|
|
40
|
+
ActiveRecord::Migration.create_table model.table_name, opts.merge(:force => true), &block
|
|
41
|
+
end
|
|
42
|
+
model.reset_column_information
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -4,8 +4,8 @@ require 'stringio'
|
|
|
4
4
|
describe "Schema dump" do
|
|
5
5
|
|
|
6
6
|
before(:all) do
|
|
7
|
-
|
|
8
|
-
config.
|
|
7
|
+
SchemaPlusForeignKeys.setup do |config|
|
|
8
|
+
config.auto_create = false
|
|
9
9
|
end
|
|
10
10
|
ActiveRecord::Migration.suppress_messages do
|
|
11
11
|
ActiveRecord::Schema.define do
|
|
File without changes
|
|
File without changes
|
data/spec/{foreign_key_definition_spec.rb → schema_plus_foreign_keys/foreign_key_definition_spec.rb}
RENAMED
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Foreign Key" do
|
|
4
4
|
|
|
@@ -32,7 +32,7 @@ describe "Foreign Key" do
|
|
|
32
32
|
context "with modifications to SQL generated by upstream visit_TableDefinition" do
|
|
33
33
|
before(:each) do
|
|
34
34
|
allow_any_instance_of(ActiveRecord::Base.connection.class.const_get(:SchemaCreation))
|
|
35
|
-
.to receive(:
|
|
35
|
+
.to receive(:visit_TableDefinition_without_schema_plus_foreign_keys)
|
|
36
36
|
.and_return('this is unexpected')
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -40,22 +40,6 @@ describe ActiveRecord::Migration do
|
|
|
40
40
|
@model = Post
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
it "should properly handle default values for booleans" do
|
|
44
|
-
expect {
|
|
45
|
-
recreate_table(@model) do |t|
|
|
46
|
-
t.boolean :bool, :default => true
|
|
47
|
-
end
|
|
48
|
-
}.to_not raise_error
|
|
49
|
-
expect(@model.create.reload.bool).to be true
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "should properly handle default values for json (#195)", :postgresql => :only do
|
|
53
|
-
recreate_table(@model) do |t|
|
|
54
|
-
t.json :json, :default => {}
|
|
55
|
-
end
|
|
56
|
-
expect(@model.create.reload.json).to eq({})
|
|
57
|
-
end if ActiveRecord::VERSION::MAJOR >= 4
|
|
58
|
-
|
|
59
43
|
it "should create auto foreign keys" do
|
|
60
44
|
recreate_table(@model) do |t|
|
|
61
45
|
t.integer :user_id
|
|
@@ -520,53 +504,53 @@ describe ActiveRecord::Migration do
|
|
|
520
504
|
end
|
|
521
505
|
|
|
522
506
|
it "should auto-index if specified in global options" do
|
|
523
|
-
|
|
507
|
+
SchemaPlusForeignKeys.config.auto_index = true
|
|
524
508
|
add_column(:post_id, :integer) do
|
|
525
509
|
expect(@model).to have_index.on(:post_id)
|
|
526
510
|
end
|
|
527
|
-
|
|
511
|
+
SchemaPlusForeignKeys.config.auto_index = false
|
|
528
512
|
end
|
|
529
513
|
|
|
530
514
|
it "should auto-index foreign keys only" do
|
|
531
|
-
|
|
515
|
+
SchemaPlusForeignKeys.config.auto_index = true
|
|
532
516
|
add_column(:state, :integer) do
|
|
533
517
|
expect(@model).not_to have_index.on(:state)
|
|
534
518
|
end
|
|
535
|
-
|
|
519
|
+
SchemaPlusForeignKeys.config.auto_index = false
|
|
536
520
|
end
|
|
537
521
|
|
|
538
522
|
# MySQL creates an index on foreign key and we can't override that
|
|
539
523
|
it "should allow to overwrite auto_index options in column definition", :mysql => :skip do
|
|
540
|
-
|
|
524
|
+
SchemaPlusForeignKeys.config.auto_index = true
|
|
541
525
|
add_column(:post_id, :integer, :index => false) do
|
|
542
526
|
expect(@model).not_to have_index.on(:post_id)
|
|
543
527
|
end
|
|
544
|
-
|
|
528
|
+
SchemaPlusForeignKeys.config.auto_index = false
|
|
545
529
|
end
|
|
546
530
|
|
|
547
531
|
it "should use default on_update action" do
|
|
548
|
-
|
|
532
|
+
SchemaPlusForeignKeys.config.on_update = :cascade
|
|
549
533
|
add_column(:post_id, :integer) do
|
|
550
534
|
expect(@model).to reference.on(:post_id).on_update(:cascade)
|
|
551
535
|
end
|
|
552
|
-
|
|
536
|
+
SchemaPlusForeignKeys.config.on_update = nil
|
|
553
537
|
end
|
|
554
538
|
|
|
555
539
|
it "should use default on_delete action" do
|
|
556
|
-
|
|
540
|
+
SchemaPlusForeignKeys.config.on_delete = :cascade
|
|
557
541
|
add_column(:post_id, :integer) do
|
|
558
542
|
expect(@model).to reference.on(:post_id).on_delete(:cascade)
|
|
559
543
|
end
|
|
560
|
-
|
|
544
|
+
SchemaPlusForeignKeys.config.on_delete = nil
|
|
561
545
|
end
|
|
562
546
|
|
|
563
547
|
it "should allow to overwrite default actions" do
|
|
564
|
-
|
|
565
|
-
|
|
548
|
+
SchemaPlusForeignKeys.config.on_delete = :cascade
|
|
549
|
+
SchemaPlusForeignKeys.config.on_update = :restrict
|
|
566
550
|
add_column(:post_id, :integer, :foreign_key => { :on_update => :nullify, :on_delete => :nullify}) do
|
|
567
551
|
expect(@model).to reference.on(:post_id).on_delete(:nullify).on_update(:nullify)
|
|
568
552
|
end
|
|
569
|
-
|
|
553
|
+
SchemaPlusForeignKeys.config.on_delete = nil
|
|
570
554
|
end
|
|
571
555
|
|
|
572
556
|
protected
|