schema_plus 2.0.0.pre6 → 2.0.0.pre7
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/README.md +5 -15
- data/lib/schema_plus/foreign_keys.rb +1 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb +1 -1
- data/lib/schema_plus/foreign_keys/middleware/mysql.rb +20 -0
- 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/schema_dumper_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +19 -9
- data/lib/schema_plus/tables.rb +0 -15
- data/lib/schema_plus/tables/active_record/connection_adapters/abstract_adapter.rb +0 -20
- data/lib/schema_plus/tables/active_record/connection_adapters/mysql2_adapter.rb +0 -25
- data/lib/schema_plus/tables/active_record/connection_adapters/postgresql_adapter.rb +0 -13
- data/lib/schema_plus/tables/active_record/connection_adapters/sqlite3_adapter.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaba43d34df0accaa981d624082fa7e8f8179029
|
4
|
+
data.tar.gz: da8fb2f9b6aa8c36e55449889304c07450f639d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c211b1b568712234f41659aae7c42d7aceae6e749c9445453eb115cdb4c9fb20055ee9e25dc1639626d3ba0530f53336bbd7e41ceae20c75d16335fce0335b8
|
7
|
+
data.tar.gz: 368cacb87bd95602fb2b7ab3d641c8f9988553c878d7c1835693411c191adf25ebac4462de0db229e7bc24954f08acbb70615916818a97c1f53de221de11b16e
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Gem | Description | Included In `schema_plus` gem?
|
|
24
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
25
|
[schema_plus_indexes](https://github.com/SchemaPlus/schema_plus_indexes) | Convenience and consistency in using indexes | Y
|
26
26
|
[schema_plus_pg_indexes](https://github.com/SchemaPlus/schema_plus_pg_indexes) |PostgreSQL index features: `case_insenstive`, `expression` and `operator_class` | Y
|
27
|
-
|
27
|
+
[schema_plus_tables](https://github.com/SchemaPlus/schema_plus_views) | Convenience and consistency in using tables | Y
|
28
28
|
[schema_plus_views](https://github.com/SchemaPlus/schema_plus_views) | Create and drop views in migrations | Y
|
29
29
|
[schema_validations](https://github.com/SchemaPlus/schema_validations) | Automatically defines ActiveRecord validations based on database constraints |
|
30
30
|
|
@@ -56,6 +56,9 @@ In cases where ActiveRecord 4.2 has introduced features previously supported onl
|
|
56
56
|
* `:conditions` => `:where`
|
57
57
|
* `:kind` => `:using`
|
58
58
|
|
59
|
+
* `drop_table` deprecates this option:
|
60
|
+
* `cascade: true` => `force: :cascade`
|
61
|
+
|
59
62
|
* Foreign key definitions deprecate options to `:on_update` and `:on_delete`:
|
60
63
|
* `:set_null` => `:nullify`
|
61
64
|
|
@@ -176,20 +179,7 @@ has some information that may be of assistance in resolving these issues.
|
|
176
179
|
|
177
180
|
### Tables
|
178
181
|
|
179
|
-
SchemaPlus extends
|
180
|
-
|
181
|
-
drop_table :table_name # same as rails
|
182
|
-
drop_table :table_name, if_exists: true # no error if table doesn't exist
|
183
|
-
drop_table :table_name, cascade: true # delete dependencies
|
184
|
-
|
185
|
-
The `:cascade` option is particularly useful given foreign key constraints.
|
186
|
-
For Postgresql it is implemented using `DROP TABLE...CASCADE` which deletes
|
187
|
-
all dependencies. For MySQL, SchemaPlus implements the `:cascade` option to
|
188
|
-
delete foreign key references, but does not delete any other dependencies.
|
189
|
-
For Sqlite3, the `:cascade` option is ignored, but Sqlite3 always drops tables
|
190
|
-
with cascade-like behavior.
|
191
|
-
|
192
|
-
SchemaPlus likewise extends `create_table ... force: true` to use `:cascade`
|
182
|
+
SchemaPlus extends `create_table ... force: true` to use `:cascade`
|
193
183
|
|
194
184
|
### Column Defaults: Expressions
|
195
185
|
|
@@ -11,6 +11,7 @@ require_relative 'foreign_keys/active_record/migration/command_recorder'
|
|
11
11
|
require_relative 'foreign_keys/middleware/dumper'
|
12
12
|
require_relative 'foreign_keys/middleware/migration'
|
13
13
|
require_relative 'foreign_keys/middleware/model'
|
14
|
+
require_relative 'foreign_keys/middleware/mysql'
|
14
15
|
require_relative 'foreign_keys/middleware/sql'
|
15
16
|
|
16
17
|
module SchemaPlus::ForeignKeys
|
@@ -17,7 +17,7 @@ module SchemaPlus::ForeignKeys
|
|
17
17
|
config_options = options.delete(:foreign_keys) || {}
|
18
18
|
|
19
19
|
# override rails' :force to cascade
|
20
|
-
drop_table(table, if_exists: true,
|
20
|
+
# drop_table(table, if_exists: true, force: true) if options.delete(:force)
|
21
21
|
|
22
22
|
super(table, options) do |table_definition|
|
23
23
|
table_definition.schema_plus_config = SchemaPlus::ForeignKeys.config.merge(config_options)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SchemaPlus::ForeignKeys
|
2
|
+
module Middleware
|
3
|
+
|
4
|
+
module Mysql
|
5
|
+
module Migration
|
6
|
+
module DropTable
|
7
|
+
|
8
|
+
def around(env)
|
9
|
+
if (env.options[:force] == :cascade)
|
10
|
+
env.connection.reverse_foreign_keys(env.table_name).each do |foreign_key|
|
11
|
+
env.connection.remove_foreign_key(foreign_key.from_table, name: foreign_key.name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
yield env
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/schema_plus/version.rb
CHANGED
data/schema_plus.gemspec
CHANGED
@@ -23,11 +23,12 @@ Gem::Specification.new do |gem|
|
|
23
23
|
|
24
24
|
gem.add_dependency "activerecord", "~> 4.2"
|
25
25
|
gem.add_dependency "valuable"
|
26
|
-
gem.add_dependency "schema_plus_core", "~> 0.
|
26
|
+
gem.add_dependency "schema_plus_core", "~> 0.2"
|
27
27
|
gem.add_dependency "schema_monkey_rails", "~> 0.1", ">= 0.1.2"
|
28
28
|
gem.add_dependency "schema_plus_columns", "~> 0.1"
|
29
29
|
gem.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
|
30
30
|
gem.add_dependency "schema_plus_pg_indexes", "~> 0.1", ">= 0.1.3"
|
31
|
+
gem.add_dependency "schema_plus_tables", "~> 0.1"
|
31
32
|
gem.add_dependency "schema_plus_views", "~> 0.1"
|
32
33
|
|
33
34
|
gem.add_development_dependency "schema_dev", "~> 3.1"
|
@@ -46,7 +46,7 @@ describe SchemaPlus::DbDefault do
|
|
46
46
|
|
47
47
|
def create_table(model, columns_with_options)
|
48
48
|
migration.suppress_messages do
|
49
|
-
migration.create_table model.table_name, :force =>
|
49
|
+
migration.create_table model.table_name, :force => :cascade do |t|
|
50
50
|
columns_with_options.each_pair do |column, options|
|
51
51
|
t.send :string, column, options
|
52
52
|
end
|
@@ -9,7 +9,7 @@ describe "Schema dump" do
|
|
9
9
|
end
|
10
10
|
ActiveRecord::Migration.suppress_messages do
|
11
11
|
ActiveRecord::Schema.define do
|
12
|
-
connection.tables.each do |table| drop_table table, :cascade
|
12
|
+
connection.tables.each do |table| drop_table table, force: :cascade end
|
13
13
|
|
14
14
|
create_table :posts, :force => true do |t|
|
15
15
|
t.text :body
|
@@ -9,7 +9,7 @@ describe "Schema dump" do
|
|
9
9
|
end
|
10
10
|
ActiveRecord::Migration.suppress_messages do
|
11
11
|
ActiveRecord::Schema.define do
|
12
|
-
connection.tables.each do |table| drop_table table, :cascade
|
12
|
+
connection.tables.each do |table| drop_table table, force: :cascade end
|
13
13
|
|
14
14
|
create_table :users, :force => true do |t|
|
15
15
|
t.string :login
|
@@ -135,7 +135,7 @@ describe "Schema dump" do
|
|
135
135
|
end
|
136
136
|
ActiveRecord::Migration.suppress_messages do
|
137
137
|
ActiveRecord::Schema.define do
|
138
|
-
connection.tables.each do |table| drop_table table, :cascade
|
138
|
+
connection.tables.each do |table| drop_table table, force: :cascade end
|
139
139
|
|
140
140
|
create_table :grade_systems, force: true do |t|
|
141
141
|
t.string :name
|
data/spec/spec_helper.rb
CHANGED
@@ -42,7 +42,7 @@ def define_schema(config={}, &block)
|
|
42
42
|
ActiveRecord::Migration.suppress_messages do
|
43
43
|
ActiveRecord::Schema.define do
|
44
44
|
connection.tables.each do |table|
|
45
|
-
drop_table table, :cascade
|
45
|
+
drop_table table, force: :cascade
|
46
46
|
end
|
47
47
|
instance_eval &block
|
48
48
|
end
|
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.
|
4
|
+
version: 2.0.0.pre7
|
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-
|
12
|
+
date: 2015-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.2'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0.
|
55
|
+
version: '0.2'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: schema_monkey_rails
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +127,20 @@ dependencies:
|
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: 0.1.3
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: schema_plus_tables
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0.1'
|
137
|
+
type: :runtime
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0.1'
|
130
144
|
- !ruby/object:Gem::Dependency
|
131
145
|
name: schema_plus_views
|
132
146
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,13 +290,9 @@ files:
|
|
276
290
|
- lib/schema_plus/foreign_keys/middleware/dumper.rb
|
277
291
|
- lib/schema_plus/foreign_keys/middleware/migration.rb
|
278
292
|
- lib/schema_plus/foreign_keys/middleware/model.rb
|
293
|
+
- lib/schema_plus/foreign_keys/middleware/mysql.rb
|
279
294
|
- lib/schema_plus/foreign_keys/middleware/sql.rb
|
280
295
|
- lib/schema_plus/foreign_keys/version.rb
|
281
|
-
- lib/schema_plus/tables.rb
|
282
|
-
- lib/schema_plus/tables/active_record/connection_adapters/abstract_adapter.rb
|
283
|
-
- lib/schema_plus/tables/active_record/connection_adapters/mysql2_adapter.rb
|
284
|
-
- lib/schema_plus/tables/active_record/connection_adapters/postgresql_adapter.rb
|
285
|
-
- lib/schema_plus/tables/active_record/connection_adapters/sqlite3_adapter.rb
|
286
296
|
- lib/schema_plus/version.rb
|
287
297
|
- schema_dev.yml
|
288
298
|
- schema_plus.gemspec
|
data/lib/schema_plus/tables.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'schema_plus/core'
|
2
|
-
|
3
|
-
require_relative 'tables/active_record/connection_adapters/abstract_adapter'
|
4
|
-
|
5
|
-
module SchemaPlus::Tables
|
6
|
-
module ActiveRecord
|
7
|
-
module ConnectionAdapters
|
8
|
-
autoload :Mysql2Adapter, 'schema_plus/tables/active_record/connection_adapters/mysql2_adapter'
|
9
|
-
autoload :PostgresqlAdapter, 'schema_plus/tables/active_record/connection_adapters/postgresql_adapter'
|
10
|
-
autoload :Sqlite3Adapter, 'schema_plus/tables/active_record/connection_adapters/sqlite3_adapter'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
SchemaMonkey.register SchemaPlus::Tables
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module SchemaPlus::Tables
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module AbstractAdapter
|
5
|
-
|
6
|
-
# Extends rails' drop_table to include these options:
|
7
|
-
# :cascade
|
8
|
-
# :if_exists
|
9
|
-
#
|
10
|
-
def drop_table(name, options = {})
|
11
|
-
sql = "DROP TABLE"
|
12
|
-
sql += " IF EXISTS" if options[:if_exists]
|
13
|
-
sql += " #{quote_table_name(name)}"
|
14
|
-
sql += " CASCADE" if options[:cascade]
|
15
|
-
execute sql
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module SchemaPlus::Tables
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module Mysql2Adapter
|
5
|
-
|
6
|
-
# implement cascade by removing foreign keys
|
7
|
-
def drop_table(name, options={})
|
8
|
-
if options[:cascade]
|
9
|
-
reverse_foreign_keys(name).each do |foreign_key|
|
10
|
-
remove_foreign_key(foreign_key.from_table, name: foreign_key.name)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
sql = 'DROP'
|
15
|
-
sql += ' TEMPORARY' if options[:temporary]
|
16
|
-
sql += ' TABLE'
|
17
|
-
sql += ' IF EXISTS' if options[:if_exists]
|
18
|
-
sql += " #{quote_table_name(name)}"
|
19
|
-
|
20
|
-
execute sql
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module SchemaPlus::Tables
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module PostgresqlAdapter
|
5
|
-
# pg gem defines a drop_table with fewer options than our Abstract
|
6
|
-
# one, so use the abstract one instead
|
7
|
-
def drop_table(name, options={})
|
8
|
-
SchemaPlus::Tables::ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_method(:drop_table).bind(self).call(name, options)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|