schema_plus 2.0.0.pre10 → 2.0.0.pre11
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 +19 -31
- data/lib/schema_plus/version.rb +1 -1
- data/schema_plus.gemspec +1 -0
- metadata +16 -8
- data/lib/schema_plus/db_default.rb +0 -7
- data/lib/schema_plus/db_default/active_record/attribute.rb +0 -16
- data/lib/schema_plus/db_default/db_default.rb +0 -19
- data/lib/schema_plus/db_default/middleware.rb +0 -30
- data/spec/schema_plus_db_default/column_spec.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18fb53e5cdb54375f9ebd2f978833266b7b61f38
|
4
|
+
data.tar.gz: c2b17dd83a109cdb32f10c7883447f14b85f9ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c9f95715df96aca11804ab355833bfd61d624e5bf8d493ed00d3dc265dd06b089921b0aaeb745e6c209bc8594e72b3b7599dfa668d90a2a5e1670139aea22e
|
7
|
+
data.tar.gz: 7519c544165bf8324754dee3e5249b99bf9943d7734e8dc976f06813f8bf89a1f32ed90f5861567d09d72c4f2f4f035469f564d28a03772760c91fec3289be6e
|
data/README.md
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
|
2
|
-
> ## This is the README for SchemaPlus 2.0.0 (prelease)
|
3
|
-
> which is under development in the master branch, and which supports Rails >= 4.2. For info about the stable 1.x releases which support Rails 3.1, 4.0, 4.1, and 4.2, see the [schema_plus 1.x](https://github.com/SchemaPlus/schema_plus/tree/1.x) branch
|
4
2
|
|
5
|
-
---
|
6
3
|
|
7
|
-
|
8
|
-
[](http://travis-ci.org/SchemaPlus/schema_plus)
|
9
|
-
[](https://coveralls.io/r/SchemaPlus/schema_plus)
|
10
|
-
[](https://gemnasium.com/SchemaPlus/schema_plus)
|
4
|
+
# SchemaPlus family
|
11
5
|
|
12
|
-
|
6
|
+
The SchemaPlus family of gems provide various extensions and enhancements to ActiveRecord.
|
13
7
|
|
14
|
-
|
8
|
+
Listed alphabetically:
|
15
9
|
|
16
10
|
Gem | Description | Included In `schema_plus` gem?
|
17
11
|
----| ----------- |:------------------------------:
|
18
12
|
[schema_associations](https://github.com/SchemaPlus/schema_associations) | Automatically defines model associations based on foreign key relations |
|
19
13
|
<p style="color:grey">schema_auto_foreign_keys</p> | Automatically creates foreign keys on referencing columns | Y
|
20
14
|
[schema_plus_columns](https://github.com/SchemaPlus/schema_plus_columns) | Column attributes including `column.indexes` and `column.unique?` | Y
|
21
|
-
|
15
|
+
[schema_plus_db_default](https://github.com/SchemaPlus/schema_plus_db_default) | Use `ActiveRecord::DB_DEFAULT` to set an attribute to the database default | Y
|
22
16
|
<p style="color:grey">schema_plus_default_expr</p> | Use SQL expressions for database default values | Y
|
23
17
|
[schema_plus_enums](https://github.com/SchemaPlus/schema_plus_enums) | Define enum types in migrations | Y
|
24
18
|
<p style="color:grey">schema_plus_foreign_keys | Extended support for foreign keys, including creation as column options, `:deferrable`, and SQLite3 support | Y
|
@@ -32,10 +26,22 @@ See detailed documentation in each gem's README.
|
|
32
26
|
|
33
27
|
*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)!!
|
34
28
|
|
29
|
+
---
|
30
|
+
# The `schema_plus` gem
|
31
|
+
|
32
|
+
[](http://badge.fury.io/rb/schema_plus)
|
33
|
+
[](http://travis-ci.org/SchemaPlus/schema_plus)
|
34
|
+
[](https://coveralls.io/r/SchemaPlus/schema_plus)
|
35
|
+
[](https://gemnasium.com/SchemaPlus/schema_plus)
|
36
|
+
|
37
|
+
|
38
|
+
> ## This is the README for schema_plus 2.0.0 (prelease)
|
39
|
+
> which is under development in the master branch, and which supports Rails >= 4.2. For info about the stable 1.x releases which support Rails 3.1, 4.0, 4.1, and 4.2.0, see the [schema_plus 1.x](https://github.com/SchemaPlus/schema_plus/tree/1.x) branch
|
40
|
+
|
41
|
+
---
|
35
42
|
|
36
|
-
## The `schema_plus` gem
|
37
43
|
|
38
|
-
The `schema_plus` gem is a wrapper that pulls in a common collection of
|
44
|
+
The `schema_plus` gem is a wrapper that pulls in a common collection of gems from the SchemaPlus family. But you can feel free to mix and match to get just the gems you want.
|
39
45
|
|
40
46
|
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
47
|
|
@@ -112,7 +118,7 @@ or in a Gemfile
|
|
112
118
|
# Prerelease: Documentation of features still be moved into separate feature gems
|
113
119
|
|
114
120
|
|
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
|
121
|
+
> **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) 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
122
|
|
117
123
|
### Foreign Key Constraints
|
118
124
|
|
@@ -208,25 +214,7 @@ If you are using Postgresql with a `json` column, the default value may be an un
|
|
208
214
|
|
209
215
|
t.json :fields, default: { field1: 'a', field2: 'b' }
|
210
216
|
t.json :fields, default: { value: { field1: 'a', field2: 'b' } }
|
211
|
-
|
212
|
-
|
213
|
-
### Column Defaults: Using
|
214
|
-
|
215
|
-
SchemaPlus introduces a constant `ActiveRecord::DB_DEFAULT` that you can use
|
216
|
-
to explicitly instruct the database to use the column default value (or
|
217
|
-
expression). For example:
|
218
|
-
|
219
|
-
Post.create(category: ActiveRecord::DB_DEFAULT)
|
220
|
-
post.update_attributes(category: ActiveRecord::DB_DEFAULT)
|
221
|
-
|
222
|
-
(Without `ActiveRecord::DB_DEFAULT`, you can update a value to `NULL` but not
|
223
|
-
to its default value.)
|
224
|
-
|
225
|
-
Note that after updating, you would need to reload a record to replace
|
226
|
-
`ActiveRecord::DB_DEFAULT` with the value assigned by the database.
|
227
217
|
|
228
|
-
Note also that Sqlite3 does not support `ActiveRecord::DB_DEFAULT`; attempting
|
229
|
-
to use it will raise `ActiveRecord::StatementInvalid`
|
230
218
|
|
231
219
|
### Schema Dump and Load (schema.rb)
|
232
220
|
|
data/lib/schema_plus/version.rb
CHANGED
data/schema_plus.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |gem|
|
|
27
27
|
gem.add_dependency "schema_monkey", "~> 2.1"
|
28
28
|
gem.add_dependency "schema_plus_columns", "~> 0.1"
|
29
29
|
gem.add_dependency "schema_plus_enums", "~> 0.1"
|
30
|
+
gem.add_dependency "schema_plus_db_default", "~> 0.1"
|
30
31
|
gem.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
|
31
32
|
gem.add_dependency "schema_plus_pg_indexes", "~> 0.1", ">= 0.1.3"
|
32
33
|
gem.add_dependency "schema_plus_tables", "~> 0.1"
|
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.pre11
|
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-03-
|
12
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -95,6 +95,20 @@ dependencies:
|
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0.1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: schema_plus_db_default
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.1'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.1'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: schema_plus_indexes
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,10 +290,6 @@ files:
|
|
276
290
|
- gemfiles/activerecord-4.2.1/Gemfile.postgresql
|
277
291
|
- gemfiles/activerecord-4.2.1/Gemfile.sqlite3
|
278
292
|
- lib/schema_plus.rb
|
279
|
-
- lib/schema_plus/db_default.rb
|
280
|
-
- lib/schema_plus/db_default/active_record/attribute.rb
|
281
|
-
- lib/schema_plus/db_default/db_default.rb
|
282
|
-
- lib/schema_plus/db_default/middleware.rb
|
283
293
|
- lib/schema_plus/default_expr.rb
|
284
294
|
- lib/schema_plus/default_expr/active_record/connection_adapters/column.rb
|
285
295
|
- lib/schema_plus/default_expr/active_record/connection_adapters/mysql2_adapter.rb
|
@@ -307,7 +317,6 @@ files:
|
|
307
317
|
- schema_plus.gemspec
|
308
318
|
- spec/schema/auto_schema.rb
|
309
319
|
- spec/schema/core_schema.rb
|
310
|
-
- spec/schema_plus_db_default/column_spec.rb
|
311
320
|
- spec/schema_plus_default_expr/column_default_spec.rb
|
312
321
|
- spec/schema_plus_default_expr/migration_spec.rb
|
313
322
|
- spec/schema_plus_default_expr/schema_dumper_spec.rb
|
@@ -350,7 +359,6 @@ summary: Enhances ActiveRecord schema mechanism, including more DRY index creati
|
|
350
359
|
test_files:
|
351
360
|
- spec/schema/auto_schema.rb
|
352
361
|
- spec/schema/core_schema.rb
|
353
|
-
- spec/schema_plus_db_default/column_spec.rb
|
354
362
|
- spec/schema_plus_default_expr/column_default_spec.rb
|
355
363
|
- spec/schema_plus_default_expr/migration_spec.rb
|
356
364
|
- spec/schema_plus_default_expr/schema_dumper_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module SchemaPlus::DbDefault
|
2
|
-
module ActiveRecord
|
3
|
-
module Attribute
|
4
|
-
|
5
|
-
def original_value
|
6
|
-
# prevent attempts to cast DB_DEFAULT to the attributes type.
|
7
|
-
# We want to keep it as DB_DEFAULT so that we can handle it when
|
8
|
-
# generating the sql.
|
9
|
-
return DB_DEFAULT if value_before_type_cast.equal? DB_DEFAULT
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
|
-
module SchemaPlus::DbDefault
|
4
|
-
class DbDefault
|
5
|
-
include Singleton
|
6
|
-
def to_s
|
7
|
-
'DEFAULT'
|
8
|
-
end
|
9
|
-
def id
|
10
|
-
self
|
11
|
-
end
|
12
|
-
def quoted_id
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
DB_DEFAULT = DbDefault.instance
|
17
|
-
end
|
18
|
-
|
19
|
-
::ActiveRecord.const_set :DB_DEFAULT, SchemaPlus::DbDefault::DB_DEFAULT
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module SchemaPlus::DbDefault
|
2
|
-
module Middleware
|
3
|
-
|
4
|
-
module Query
|
5
|
-
module Exec
|
6
|
-
|
7
|
-
module Postgresql
|
8
|
-
|
9
|
-
# Middleware to replace each ActiveRecord::DB_DEFAULT with a literal
|
10
|
-
# DEFAULT in the sql string, for postgresql. The underlying pg gem provides no
|
11
|
-
# way to bind a value that will replace $n with DEFAULT.
|
12
|
-
def before(env)
|
13
|
-
if env.binds.any?{ |col, val| val.equal? ::ActiveRecord::DB_DEFAULT}
|
14
|
-
j = 0
|
15
|
-
env.binds.each_with_index do |(col, val), i|
|
16
|
-
if val.equal? ::ActiveRecord::DB_DEFAULT
|
17
|
-
env.sql = env.sql.sub(/\$#{i+1}/, 'DEFAULT')
|
18
|
-
else
|
19
|
-
env.sql = env.sql.sub(/\$#{i+1}/, "$#{j+1}") if i != j
|
20
|
-
j += 1
|
21
|
-
end
|
22
|
-
end
|
23
|
-
env.binds = env.binds.reject{|col, val| val.equal? ::ActiveRecord::DB_DEFAULT}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SchemaPlus::DbDefault do
|
4
|
-
|
5
|
-
let(:migration) { ::ActiveRecord::Migration }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
class User < ::ActiveRecord::Base ; end
|
9
|
-
create_table(User, :alpha => { :default => "gabba" }, :beta => {})
|
10
|
-
end
|
11
|
-
|
12
|
-
context "uses db default value", :sqlite3 => :skip do
|
13
|
-
|
14
|
-
it "when creating a record with DB_DEFAULT" do
|
15
|
-
User.create!(:alpha => ActiveRecord::DB_DEFAULT, :beta => "hello")
|
16
|
-
expect(User.last.alpha).to eq("gabba")
|
17
|
-
expect(User.last.beta).to eq("hello")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "when updating a record with DB_DEFAULT" do
|
21
|
-
u = User.create!(:alpha => "hey", :beta => "hello")
|
22
|
-
u.reload
|
23
|
-
expect(u.alpha).to eq("hey")
|
24
|
-
expect(u.beta).to eq("hello")
|
25
|
-
u.update_attributes(:alpha => ActiveRecord::DB_DEFAULT, :beta => "goodbye")
|
26
|
-
u.reload
|
27
|
-
expect(u.alpha).to eq("gabba")
|
28
|
-
expect(u.beta).to eq("goodbye")
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
context "raises an error", :sqlite3 => :only do
|
34
|
-
|
35
|
-
it "when creating a record with DB_DEFAULT" do
|
36
|
-
expect { User.create!(:alpha => ActiveRecord::DB_DEFAULT, :beta => "hello") }.to raise_error ActiveRecord::StatementInvalid
|
37
|
-
end
|
38
|
-
|
39
|
-
it "when updating a record with DB_DEFAULT" do
|
40
|
-
u = User.create!(:alpha => "hey", :beta => "hello")
|
41
|
-
expect { u.update_attributes(:alpha => ActiveRecord::DB_DEFAULT, :beta => "goodbye") }.to raise_error ActiveRecord::StatementInvalid
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
def create_table(model, columns_with_options)
|
48
|
-
migration.suppress_messages do
|
49
|
-
migration.create_table model.table_name, :force => :cascade do |t|
|
50
|
-
columns_with_options.each_pair do |column, options|
|
51
|
-
t.send :string, column, options
|
52
|
-
end
|
53
|
-
end
|
54
|
-
model.reset_column_information
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|