schema_plus 2.0.0.pre5 → 2.0.0.pre6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -51
- data/lib/schema_plus.rb +10 -10
- data/lib/schema_plus/db_default.rb +7 -0
- data/lib/{schema_plus_db_default → schema_plus/db_default}/active_record/attribute.rb +1 -1
- data/lib/{schema_plus_db_default → schema_plus/db_default}/db_default.rb +2 -2
- data/lib/{schema_plus_db_default → schema_plus/db_default}/middleware.rb +1 -1
- data/lib/{schema_plus_default_expr.rb → schema_plus/default_expr.rb} +8 -8
- data/lib/{schema_plus_default_expr → schema_plus/default_expr}/active_record/connection_adapters/column.rb +1 -1
- data/lib/{schema_plus_default_expr → schema_plus/default_expr}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/{schema_plus_default_expr → schema_plus/default_expr}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/{schema_plus_default_expr → schema_plus/default_expr}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/{schema_plus_default_expr → schema_plus/default_expr}/middleware.rb +1 -1
- data/lib/schema_plus/enums.rb +6 -0
- data/lib/{schema_plus_enums → schema_plus/enums}/active_record.rb +1 -1
- data/lib/{schema_plus_enums → schema_plus/enums}/middleware.rb +1 -1
- data/lib/{schema_plus_foreign_keys.rb → schema_plus/foreign_keys.rb} +21 -21
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/base.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/abstract_adapter.rb +5 -5
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/foreign_key_definition.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/mysql2_adapter.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/postgresql_adapter.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/sqlite3_adapter.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/connection_adapters/table_definition.rb +8 -8
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/migration/command_recorder.rb +1 -1
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/active_record/schema.rb +4 -4
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/middleware/dumper.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/middleware/migration.rb +2 -2
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/middleware/model.rb +1 -1
- data/lib/{schema_plus_foreign_keys → schema_plus/foreign_keys}/middleware/sql.rb +1 -1
- data/lib/schema_plus/foreign_keys/version.rb +3 -0
- data/lib/schema_plus/tables.rb +15 -0
- data/lib/{schema_plus_tables → schema_plus/tables}/active_record/connection_adapters/abstract_adapter.rb +2 -2
- data/lib/{schema_plus_tables → schema_plus/tables}/active_record/connection_adapters/mysql2_adapter.rb +2 -2
- data/lib/{schema_plus_tables → schema_plus/tables}/active_record/connection_adapters/postgresql_adapter.rb +2 -2
- data/lib/{schema_plus_tables → schema_plus/tables}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/schema_plus/version.rb +1 -1
- data/schema_plus.gemspec +2 -1
- data/spec/schema_plus_db_default/column_spec.rb +1 -1
- data/spec/schema_plus_default_expr/schema_dumper_spec.rb +1 -1
- data/spec/schema_plus_foreign_keys/migration_spec.rb +13 -13
- data/spec/schema_plus_foreign_keys/schema_dumper_spec.rb +78 -11
- data/spec/schema_plus_foreign_keys/schema_spec.rb +6 -6
- data/spec/spec_helper.rb +5 -5
- data/spec/support/helpers.rb +1 -1
- data/spec/support/matchers/have_index.rb +1 -1
- data/spec/support/matchers/reference.rb +1 -1
- metadata +51 -42
- data/lib/schema_plus_columns.rb +0 -7
- data/lib/schema_plus_columns/active_record/connection_adapters/column.rb +0 -65
- data/lib/schema_plus_columns/middleware/model.rb +0 -16
- data/lib/schema_plus_db_default.rb +0 -7
- data/lib/schema_plus_enums.rb +0 -6
- data/lib/schema_plus_foreign_keys/version.rb +0 -3
- data/lib/schema_plus_tables.rb +0 -15
- data/spec/schema_plus_columns/column_spec.rb +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00ceb73134fe17d30d0eea3cc3c4d1176a790e9
|
4
|
+
data.tar.gz: 009e690b13ef1abb8633048f8b791588934ecf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4824b1d4d83099b03c1e1b053cc49f65083851080292a4d186575f970ebfca6a98e89b5485dc1f4f2c6ceaca7df43b277d808c4f88e1c98f3299a46b317d3c6
|
7
|
+
data.tar.gz: 9fed9ef9efc18014d2f0315245f2af09a1654f8b2d3db048ffa40eb408703a12ecce328989a8b6289a93f3598614cd1c021d24c877b6049e031585c778162db3
|
data/README.md
CHANGED
@@ -9,40 +9,48 @@
|
|
9
9
|
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus.svg)](https://coveralls.io/r/SchemaPlus/schema_plus)
|
10
10
|
[![Dependency Status](https://gemnasium.com/lomba/schema_plus.svg)](https://gemnasium.com/SchemaPlus/schema_plus)
|
11
11
|
|
12
|
-
# SchemaPlus
|
12
|
+
# SchemaPlus
|
13
13
|
|
14
|
-
|
14
|
+
The SchemaPlus family of gems provide various extensions and enhancements to ActiveRecord. Listed alphabetically:
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
Gem | Description | Included In `schema_plus` gem?
|
17
|
+
----| ----------- |:------------------------------:
|
18
|
+
[schema_associations](https://github.com/SchemaPlus/schema_associations) | Automatically defines model associations based on foreign key relations |
|
19
|
+
<p style="color:grey">schema_auto_foreign_keys</p> | Automatically creates foreign keys on referencing columns | Y
|
20
|
+
[schema_plus_columns](https://github.com/SchemaPlus/schema_plus_columns) | Column attributes including `column.indexes` and `column.unique?` | Y
|
21
|
+
<p style="color:grey">schema_plus_db_default</p> | Use `ActiveRecord::DB_DEFAULT` to set an attribute to the database default | Y
|
22
|
+
<p style="color:grey">schema_plus_default_expr</p> | Use SQL expressions for database default values | Y
|
23
|
+
<p style="color:grey">schema_plus_enums</p> | Use enum types in migrations | Y
|
24
|
+
<p style="color:grey">schema_plus_foreign_keys | Extended support for foreign keys, including creation as column options, `:deferrable`, and SQLite3 support | Y
|
25
|
+
[schema_plus_indexes](https://github.com/SchemaPlus/schema_plus_indexes) | Convenience and consistency in using indexes | Y
|
26
|
+
[schema_plus_pg_indexes](https://github.com/SchemaPlus/schema_plus_pg_indexes) |PostgreSQL index features: `case_insenstive`, `expression` and `operator_class` | Y
|
27
|
+
<p style="color:grey">schema_plus_tables</p> | Convenience and consistency in using tables | Y
|
28
|
+
[schema_plus_views](https://github.com/SchemaPlus/schema_plus_views) | Create and drop views in migrations | Y
|
29
|
+
[schema_validations](https://github.com/SchemaPlus/schema_validations) | Automatically defines ActiveRecord validations based on database constraints |
|
19
30
|
|
20
|
-
See detailed documentation in each
|
31
|
+
See detailed documentation in each gem's README.
|
21
32
|
|
22
|
-
|
23
|
-
>
|
24
|
-
> * schema_plus_columns -- Extra Column features, including `column.indexes` and `column.unique?`
|
25
|
-
> * schema_plus_db_default -- Supports `update_attributes!(my_attr: ActiveRecord::DB_DEFAULT)` to set a column back to the default in the database schema.
|
26
|
-
> * schema_plus_default_expr -- Supports using SQL expressions for database default values
|
27
|
-
> * schema_plus_enums -- Support for enum types
|
28
|
-
> * schema_plus_foreign_keys -- Extends support for foreign keys
|
29
|
-
> * schema_plus_tables -- Convenience and consistency in defining and manipulating tables
|
30
|
-
> * schema_auto_foreign_keys -- Automatic foreign key creation
|
33
|
+
*Is there some other capability you wish SchemaPlus had a gem for?* Open an issue here. Or try implementing it yourself -- creating ActiveRecord extensions is easy and fun using SchemaPlus's tools [schema_monkey](https://github.com/SchemaPlus/schema_monkey) and [schema_plus_core](https://github.com/SchemaPlus/schema_plus_core)!!
|
31
34
|
|
32
|
-
>
|
33
|
-
> The documentation for these features is at the end of this README
|
34
|
-
>
|
35
|
-
> If you'd like to follow or contribute to the discussion of this refactoring, take a look at issue SchemaPlus/schema_plus/197
|
36
35
|
|
36
|
+
## The `schema_plus` gem
|
37
37
|
|
38
|
-
|
38
|
+
The `schema_plus` gem is a wrapper that pulls in a common collection of those gems. But you can feel free to mix and match to get just the gems you want.
|
39
39
|
|
40
|
-
|
40
|
+
Note: Prior to version 2.0, `schema_plus` was a single monolothic gem that implemented in itself all the features that are now included by the wrapper.
|
41
|
+
|
42
|
+
|
43
|
+
> **IN PROGRESS:** In the prerelease versions of SchemaPlus 2.0, some features have yet to be migrated out to their own gems, and their code is still in the body of schema_plus. Those gems are greyed out in the list above. The documentation for their features is at the end of this README.
|
44
|
+
|
45
|
+
|
46
|
+
### Upgrading from `schema_plus` 1.8.x
|
47
|
+
|
48
|
+
`schema_plus` 2.0 intends to be a completely backwards-compatible drop-in replacement for SchemaPlus 1.8.x, through restricted to ActiveRecord >= 4.2 and Ruby >= 2.1
|
41
49
|
|
42
50
|
If you find any incompatibilities, please report an issue!
|
43
51
|
|
44
|
-
|
45
|
-
In cases where
|
52
|
+
#### Deprecations
|
53
|
+
In cases where ActiveRecord 4.2 has introduced features previously supported only by SchemaPlus, but using different names, the SchemaPlus 2.0 family of gems now issue deprecation warnings in favor of the rails form. The complete list of deprecations:
|
46
54
|
|
47
55
|
* Index definition deprecates these options:
|
48
56
|
* `:conditions` => `:where`
|
@@ -54,13 +62,13 @@ In cases where rails 4.2 has introduced features previously supported only by Sc
|
|
54
62
|
* `add_foreign_key` and `remove_foreign_key` deprecate the method signature:
|
55
63
|
* `(from_table, columns, to_table, primary_keys, options)` => `(from_table, to_table, options)`
|
56
64
|
|
57
|
-
* `ForeignKeyDefinition` deprecates accessors:
|
65
|
+
* `ForeignKeyDefinition` deprecates accessors:
|
58
66
|
* `#table_name` in favor of `#from_table`
|
59
67
|
* `#column_names` in favor of `Array.wrap(#column)`
|
60
68
|
* `#references_column_names` in favor of `#primary_key`
|
61
69
|
* `#references_table_name in favor of `#to_table`
|
62
70
|
|
63
|
-
* `IndexDefinition` deprecates accessors:
|
71
|
+
* `IndexDefinition` deprecates accessors:
|
64
72
|
* `#conditions` in favor of `#where`
|
65
73
|
* `#kind` in favor of `#using.to_s`
|
66
74
|
|
@@ -83,44 +91,26 @@ Install from http://rubygems.org via
|
|
83
91
|
or in a Gemfile
|
84
92
|
|
85
93
|
gem "schema_plus"
|
86
|
-
|
94
|
+
|
95
|
+
`schema_plus` includes [schema_monkey_rails](https://github.com/SchemaPlus/schema_monkey_rails) so it will automatically be inserted in Rails apps. To use with Padrino, see [schema_monkey_padrino](https://github.com/SchemaPlus/schema_monkey_padrino)
|
96
|
+
|
87
97
|
## History
|
88
98
|
|
89
99
|
* See [CHANGELOG](CHANGELOG.md) for per-version release notes.
|
90
100
|
|
91
|
-
* SchemaPlus
|
92
|
-
created by [@harukizaemon](https://github.com/harukizaemon)
|
101
|
+
* SchemaPlus was originally derived from several "Red Hill On Rails" plugins created by [@harukizaemon](https://github.com/harukizaemon)
|
93
102
|
|
94
103
|
* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen)
|
95
104
|
|
96
105
|
* And [lots of contributors](https://github.com/SchemaPlus/schema_plus/graphs/contributors) since then.
|
97
106
|
|
98
|
-
|
99
|
-
|
100
|
-
Are you interested in contributing to schema_plus? Thanks!
|
101
|
-
|
102
|
-
Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus) runs the tests on the full matrix of supported versions of ruby, rails, and db adapters. But you can also test all or some part of the matrix locally before you push your changes, using
|
103
|
-
|
104
|
-
$ schema_dev rspec
|
105
|
-
|
106
|
-
|
107
|
-
For more details, see the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
|
108
|
-
|
109
|
-
---
|
107
|
+
---
|
110
108
|
---
|
111
109
|
|
112
110
|
# Prerelease: Documentation of features still be moved into separate feature gems
|
113
111
|
|
114
|
-
|
115
|
-
> **NOTE** The documentation in this README is leftover from the 1.x branch; the functionality is the same, but some of the core features of schema_plus (such as foreign keys & inline index definition) are now provided by ActiveRecord 4.2. schema_plus still provides extra functionality beyond AR 4.2, but the documentation needs to be updated to be clear what's an enhancement of AR 4.2 capabilities rather than completely new features.
|
116
|
-
|
117
|
-
### Columns
|
118
112
|
|
119
|
-
|
120
|
-
When you query column information using ActiveRecord::Base#columns, SchemaPlus
|
121
|
-
analogously provides index information relevant to each column: which indexes
|
122
|
-
reference the column, whether the column must be unique, etc. See doc for
|
123
|
-
[SchemaPlus::ActiveRecord::ConnectionAdapters::Column](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/Column).
|
113
|
+
> **NOTE** The documentation in this README is leftover from the 1.x branch; the functionality is the same, but some of the core features of schema_plus (such as foreign keys & inline index definition) are now provided by ActiveRecord 4.2. schema_plus still provides extra functionality beyond AR 4.2, but the documentation needs to be updated to be clear what's an enhancement of AR 4.2 capabilities rather than completely new features.
|
124
114
|
|
125
115
|
### Foreign Key Constraints
|
126
116
|
|
@@ -288,8 +278,8 @@ your schema.rb file by hand, and would like to take advantage of auto-creation
|
|
288
278
|
of foreign key constraints, you can re-enable it:
|
289
279
|
|
290
280
|
ActiveRecord::Schema.define do
|
291
|
-
|
292
|
-
|
281
|
+
SchemaPlus::ForeignKeys.config.auto_create = true
|
282
|
+
SchemaPlus::ForeignKeys.config.auto_index = true
|
293
283
|
|
294
284
|
create_table ...etc...
|
295
285
|
end
|
data/lib/schema_plus.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'schema_monkey_rails'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require 'schema_plus_tables'
|
2
|
+
require 'schema_plus/columns'
|
3
|
+
require 'schema_plus/db_default'
|
4
|
+
require 'schema_plus/default_expr'
|
5
|
+
require 'schema_plus/enums'
|
6
|
+
require 'schema_plus/foreign_keys'
|
7
|
+
require 'schema_plus/indexes'
|
8
|
+
require 'schema_plus/tables'
|
10
9
|
require 'schema_plus/views'
|
10
|
+
require 'schema_plus_pg_indexes'
|
11
11
|
|
12
12
|
require_relative 'schema_plus/version'
|
13
13
|
|
14
14
|
module SchemaPlus
|
15
15
|
class DeprecatedConfig
|
16
16
|
def foreign_keys
|
17
|
-
|
17
|
+
SchemaPlus::ForeignKeys.config
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.setup # :yields: config
|
22
|
-
ActiveSupport::Deprecation.
|
22
|
+
ActiveSupport::Deprecation.warn "SchemaPlus.setup is deprecated. Use SchemaPlus::ForeignKeys.setup instead"
|
23
23
|
yield DeprecatedConfig.new
|
24
24
|
end
|
25
25
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
|
3
|
-
module
|
3
|
+
module SchemaPlus::DbDefault
|
4
4
|
class DbDefault
|
5
5
|
include Singleton
|
6
6
|
def to_s
|
@@ -16,4 +16,4 @@ module SchemaPlusDbDefault
|
|
16
16
|
DB_DEFAULT = DbDefault.instance
|
17
17
|
end
|
18
18
|
|
19
|
-
::ActiveRecord.const_set :DB_DEFAULT,
|
19
|
+
::ActiveRecord.const_set :DB_DEFAULT, SchemaPlus::DbDefault::DB_DEFAULT
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'schema_plus/core'
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
3
|
+
require_relative 'default_expr/middleware'
|
4
|
+
require_relative 'default_expr/active_record/connection_adapters/column'
|
5
5
|
|
6
|
-
module
|
6
|
+
module SchemaPlus::DefaultExpr
|
7
7
|
module ActiveRecord
|
8
8
|
module ConnectionAdapters
|
9
9
|
#
|
@@ -23,11 +23,11 @@ module SchemaPlusDefaultExpr
|
|
23
23
|
# Currently, the only function to support is :now, which should
|
24
24
|
# return a DATETIME object for the current time.
|
25
25
|
#
|
26
|
-
autoload :Mysql2Adapter, '
|
27
|
-
autoload :PostgresqlAdapter, '
|
28
|
-
autoload :Sqlite3Adapter, '
|
26
|
+
autoload :Mysql2Adapter, 'schema_plus/default_expr/active_record/connection_adapters/mysql2_adapter'
|
27
|
+
autoload :PostgresqlAdapter, 'schema_plus/default_expr/active_record/connection_adapters/postgresql_adapter'
|
28
|
+
autoload :Sqlite3Adapter, 'schema_plus/default_expr/active_record/connection_adapters/sqlite3_adapter'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
SchemaMonkey.register
|
33
|
+
SchemaMonkey.register SchemaPlus::DefaultExpr
|
@@ -1,31 +1,31 @@
|
|
1
|
-
require '
|
1
|
+
require 'schema_plus/core'
|
2
2
|
require 'valuable'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
require_relative 'foreign_keys/version'
|
5
|
+
require_relative 'foreign_keys/active_record/base'
|
6
|
+
require_relative 'foreign_keys/active_record/connection_adapters/abstract_adapter'
|
7
|
+
require_relative 'foreign_keys/active_record/connection_adapters/table_definition'
|
8
|
+
require_relative 'foreign_keys/active_record/schema'
|
9
|
+
require_relative 'foreign_keys/active_record/connection_adapters/foreign_key_definition'
|
10
|
+
require_relative 'foreign_keys/active_record/migration/command_recorder'
|
11
|
+
require_relative 'foreign_keys/middleware/dumper'
|
12
|
+
require_relative 'foreign_keys/middleware/migration'
|
13
|
+
require_relative 'foreign_keys/middleware/model'
|
14
|
+
require_relative 'foreign_keys/middleware/sql'
|
15
15
|
|
16
|
-
module
|
16
|
+
module SchemaPlus::ForeignKeys
|
17
17
|
module ActiveRecord
|
18
18
|
module ConnectionAdapters
|
19
|
-
autoload :Mysql2Adapter, '
|
20
|
-
autoload :PostgresqlAdapter, '
|
21
|
-
autoload :Sqlite3Adapter, '
|
19
|
+
autoload :Mysql2Adapter, 'schema_plus/foreign_keys/active_record/connection_adapters/mysql2_adapter'
|
20
|
+
autoload :PostgresqlAdapter, 'schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter'
|
21
|
+
autoload :Sqlite3Adapter, 'schema_plus/foreign_keys/active_record/connection_adapters/sqlite3_adapter'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# This global configuation options for
|
25
|
+
# This global configuation options for SchemaPlus::ForeignKeys.
|
26
26
|
# Set them in +config/initializers/schema_plus_foreign_keys.rb+ using:
|
27
27
|
#
|
28
|
-
#
|
28
|
+
# SchemaPlus::ForeignKeys.setup do |config|
|
29
29
|
# ...
|
30
30
|
# end
|
31
31
|
#
|
@@ -75,11 +75,11 @@ module SchemaPlusForeignKeys
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# Initialization block is passed a global Config instance that can be
|
78
|
-
# used to configure
|
78
|
+
# used to configure SchemaPlus::ForeignKeys behavior. E.g., if you want to disable
|
79
79
|
# automation creation of foreign key constraints for columns name *_id,
|
80
80
|
# put the following in config/initializers/schema_plus_foreign_keys.rb :
|
81
81
|
#
|
82
|
-
#
|
82
|
+
# SchemaPlus::ForeignKeys.setup do |config|
|
83
83
|
# config.auto_create = false
|
84
84
|
# end
|
85
85
|
#
|
@@ -89,4 +89,4 @@ module SchemaPlusForeignKeys
|
|
89
89
|
|
90
90
|
end
|
91
91
|
|
92
|
-
SchemaMonkey.register
|
92
|
+
SchemaMonkey.register SchemaPlus::ForeignKeys
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module SchemaPlus::ForeignKeys
|
2
2
|
module ActiveRecord
|
3
3
|
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# SchemaPlus::ForeignKeys adds several methods to ActiveRecord::Base
|
6
6
|
#
|
7
7
|
module Base
|
8
8
|
module ClassMethods #:nodoc:
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module SchemaPlus::ForeignKeys
|
2
2
|
module ActiveRecord
|
3
|
-
#
|
3
|
+
# SchemaPlus::ForeignKeys adds several methods to the connection adapter (as returned by ActiveRecordBase#connection). See AbstractAdapter for details.
|
4
4
|
module ConnectionAdapters
|
5
5
|
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# SchemaPlus::ForeignKeys adds several methods to
|
8
8
|
# ActiveRecord::ConnectionAdapters::AbstractAdapter. In most cases
|
9
9
|
# you don't call these directly, but rather the methods that define
|
10
10
|
# things are called by schema statements, and methods that query
|
@@ -20,7 +20,7 @@ module SchemaPlusForeignKeys
|
|
20
20
|
drop_table(table, if_exists: true, cascade: true) if options.delete(:force)
|
21
21
|
|
22
22
|
super(table, options) do |table_definition|
|
23
|
-
table_definition.schema_plus_config =
|
23
|
+
table_definition.schema_plus_config = SchemaPlus::ForeignKeys.config.merge(config_options)
|
24
24
|
yield table_definition if block_given?
|
25
25
|
end
|
26
26
|
end
|
@@ -126,7 +126,7 @@ module SchemaPlusForeignKeys
|
|
126
126
|
if fk = fks.detect { |fk| fk.match(test_fk) }
|
127
127
|
fk.name
|
128
128
|
else
|
129
|
-
raise "
|
129
|
+
raise "SchemaPlus::ForeignKeys: no foreign key constraint found on #{from_table.inspect} matching #{[to_table, options].inspect}" unless options[:if_exists]
|
130
130
|
nil
|
131
131
|
end
|
132
132
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'active_record/connection_adapters/abstract/schema_definitions'
|
2
2
|
|
3
|
-
module
|
3
|
+
module SchemaPlus::ForeignKeys
|
4
4
|
module ActiveRecord
|
5
5
|
module ConnectionAdapters
|
6
6
|
# Instances of this class are returned by the queries ActiveRecord::Base#foreign_keys and ActiveRecord::Base#reverse_foreign_keys (via AbstractAdapter#foreign_keys and AbstractAdapter#reverse_foreign_keys)
|
@@ -73,7 +73,7 @@ module SchemaPlusForeignKeys
|
|
73
73
|
|
74
74
|
# Dumps a definition of foreign key.
|
75
75
|
def to_dump(column: nil, inline: nil)
|
76
|
-
dump = case
|
76
|
+
dump = case
|
77
77
|
when column then "foreign_key: {references:"
|
78
78
|
when inline then "t.foreign_key"
|
79
79
|
else "add_foreign_key #{from_table.inspect},"
|