schema_plus 1.5.1 → 1.5.3
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/CHANGELOG.md +134 -0
- data/README.md +43 -114
- data/gemfiles/rails-4.1/Gemfile.base +1 -1
- data/lib/schema_plus/active_record/column_options_handler.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/table_definition.rb +2 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +2 -2
- data/schema_plus.gemspec +2 -2
- data/spec/column_default_spec.rb +156 -0
- data/spec/column_spec.rb +20 -20
- data/spec/connection_spec.rb +1 -1
- data/spec/foreign_key_definition_spec.rb +3 -3
- data/spec/foreign_key_spec.rb +14 -12
- data/spec/index_definition_spec.rb +23 -23
- data/spec/index_spec.rb +34 -34
- data/spec/migration_spec.rb +132 -120
- data/spec/named_schemas_spec.rb +15 -15
- data/spec/schema_dumper_spec.rb +36 -36
- data/spec/schema_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/matchers/have_index.rb +20 -13
- data/spec/support/matchers/reference.rb +3 -3
- data/spec/views_spec.rb +17 -17
- metadata +10 -9
- data/spec/column_definition_spec.rb +0 -212
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98695abbf9f44e746dda323f7312d0b206b74b33
|
|
4
|
+
data.tar.gz: f9402bff3980025c1f6a1b6e052f9ec1cf0f2bfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ac7c8fb9f854adb5bd455b19e93427829dffab2ceccbf59044116f1bdee8783acb5d98ede537a9af118e1d44a7872e306700e8ae9f4153c4d523ba7c4da4803
|
|
7
|
+
data.tar.gz: 521da3cda682a2ab9dc0126a093c3f6b21e5a49a19d7dded7662a5c7d8729671f9a71aa672e01150d4078cf2b076d20974a7a41e825a4616f7c5fae3386bcb72
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# SchemaPlus
|
|
2
|
+
|
|
3
|
+
## Change Log
|
|
4
|
+
|
|
5
|
+
### 1.5.3
|
|
6
|
+
|
|
7
|
+
* No longer limited to rails 4.1.1 (issue #159)
|
|
8
|
+
* Bug fix: multiple competing indexes created for `t.references... index: :unique` (issue #157)
|
|
9
|
+
* Now works with rspec 3 (thanks to [@robababa](https://github.com/robababa) (issue #160)
|
|
10
|
+
* Improvements to ./runspecs (thanks to [@robababa](https://github.com/robababa) (issue #162)
|
|
11
|
+
|
|
12
|
+
### 1.5.2
|
|
13
|
+
|
|
14
|
+
* For now, pin to rspec 2.* and limit rails to 4.1.1 (issue #158)
|
|
15
|
+
|
|
16
|
+
### 1.5.1
|
|
17
|
+
|
|
18
|
+
* Now respects ActiveRecord::SchemaDumper.ignore_tables for views (issue #153)
|
|
19
|
+
|
|
20
|
+
### 1.5.0
|
|
21
|
+
* Can now be used with activerecord standalone, doesn't need all of rails.
|
|
22
|
+
* `views` ignores postgres internal views, thanks to [@everplays](https://github.com/everplays) (issue #147)
|
|
23
|
+
|
|
24
|
+
### 1.4.1
|
|
25
|
+
|
|
26
|
+
* Bug fixes `migration.add_references` with `polymophic: true` (issue #145 and others)
|
|
27
|
+
|
|
28
|
+
### 1.4.0
|
|
29
|
+
|
|
30
|
+
* Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
|
|
31
|
+
* Works with MRI ruby & rails 4.1.0beta3
|
|
32
|
+
* Run tests against MRI 2.1.0
|
|
33
|
+
|
|
34
|
+
### 1.3.3
|
|
35
|
+
|
|
36
|
+
* Bug fix, dump unique index with expression (Issue #142)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### 1.3.2
|
|
40
|
+
|
|
41
|
+
* Bug fix, remove_index with if_exists but no name
|
|
42
|
+
* Sort indexes alphabetically when dumping, like rails does
|
|
43
|
+
|
|
44
|
+
### 1.3.1
|
|
45
|
+
|
|
46
|
+
* Regression bug fix, non-option arguemnts to remove_index
|
|
47
|
+
|
|
48
|
+
### 1.3.0
|
|
49
|
+
|
|
50
|
+
* Added :if_exists option for remove_index
|
|
51
|
+
* Initial jruby support (rails 3.2, postgresql), due to efforts of [@donv](https://github.com/donv)
|
|
52
|
+
* Preliminatry groundwork for rails 4.1, due to efforts of [@tovodeverett](https://github.com/tovodeverett)
|
|
53
|
+
* Bug fix for change_table
|
|
54
|
+
* Bug fix for schema_dump postgresql non-btree indexes
|
|
55
|
+
* Bug fix regarding expressions that cast non-string columns to strings in a lower()
|
|
56
|
+
|
|
57
|
+
### 1.2.0
|
|
58
|
+
* Now works with rails 4, due to efforts of [@tovodeverett](https://github.com/tovodeverett)
|
|
59
|
+
* Test against MRI ruby 2.0.0, no longer test against 1.9.2
|
|
60
|
+
|
|
61
|
+
### 1.1.2
|
|
62
|
+
* Now works with rails 3.2.13 (fixed railtie initialization)
|
|
63
|
+
|
|
64
|
+
### 1.1.1
|
|
65
|
+
|
|
66
|
+
* Dependency constraint to rails 3.2.12 max, since schema_plus doesn't
|
|
67
|
+
currently work with 3.2.13.rc2
|
|
68
|
+
|
|
69
|
+
### 1.1.0
|
|
70
|
+
|
|
71
|
+
* Add support for drop_table :cascade => true. Note that until now,
|
|
72
|
+
:cascade was implicitly true. So this change might break existing code
|
|
73
|
+
that relied on the incorrect implicit cascade behavior.
|
|
74
|
+
* Add support for :deferrable => :initially_deferred (thanks to
|
|
75
|
+
[@bhavinkamani](https://github.com/bhavinkamani))
|
|
76
|
+
* Works with PostGIS (thanks to [@pete](https://github.com/pete))
|
|
77
|
+
* Bug fix: Circular Reference/Stack Level Too Deep in Column#to_json.
|
|
78
|
+
Thanks to [@robdimarco](https://github.com/robdimarco) for tracking down the problem
|
|
79
|
+
* Bug fix: More robust handling of foreign keys with schema namespaces
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### 1.0.1
|
|
83
|
+
|
|
84
|
+
* README cleanups (thanks to [@denispeplin](https://github.com/denispeplin))
|
|
85
|
+
* Now raises ArgumentError if index has both :case_sensitive => false and an
|
|
86
|
+
:expression
|
|
87
|
+
* Now creates consistent default name for foreign key constraints
|
|
88
|
+
* Bug fix: respect :length keyword for index (thanks to [@teleological](https://github.com/teleological))
|
|
89
|
+
* Bug fix: renaming table with multiple foreign key constraints (thanks to
|
|
90
|
+
[@teleological](https://github.com/teleological))
|
|
91
|
+
* Bug fix: don't dump :case_sensitive => false for index with an expression
|
|
92
|
+
that includes "lower(name)".
|
|
93
|
+
* Bug fix: Properly dump multi-column case-insensitive indexes
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### 1.0.0
|
|
97
|
+
|
|
98
|
+
* No longer support rails < 3.2 and ruby < 1.9
|
|
99
|
+
* New feature: specify foreign key constraints using :foreign_key => { ...
|
|
100
|
+
}, motivated in particular to support :name (suggested by [@daniele-m](https://github.com/daniele-m))
|
|
101
|
+
* New feature: create view using ActiveRecord relation
|
|
102
|
+
* New feature: `ActiveRecord::DB_DEFAULT` (suggested by
|
|
103
|
+
[@zaadjis](https://github.com/zaadjis))
|
|
104
|
+
* New feature: renaming a table renames its indexes and constraints
|
|
105
|
+
correspondingly.
|
|
106
|
+
* Bug fix for postgres :kind index attribute (thanks to [@eugenebolshakov](https://github.com/eugenebolshakov))
|
|
107
|
+
* Sort fks in dump for stability (thanks to [@zephyr-dev](https://github.com/zephyr-dev))
|
|
108
|
+
* Bug fix: change_column should maintain foreign key constraints even when
|
|
109
|
+
config.foreign_keys.auto_create is false
|
|
110
|
+
* Bug fix: quote default expressions in schema dump (thanks to [@jonleighton](https://github.com/jonleighton))
|
|
111
|
+
* Bug fix: when removing a foreign key constraint, remove its auto-generated
|
|
112
|
+
index.
|
|
113
|
+
* Bug fix: SchemaDumper.ignore_tables needs to support regexps (suggested by
|
|
114
|
+
[@mtalcott](https://github.com/mtalcott))
|
|
115
|
+
* Bug fix: More robust handling of Postgresql schema_search path (suggested
|
|
116
|
+
by [@mtalcott](https://github.com/mtalcott))
|
|
117
|
+
* Bug fix: Only get index, view, and foreign key information from current
|
|
118
|
+
schema (thanks to [@bhavinkamani](https://github.com/bhavinkamani))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
### Earlier releases
|
|
122
|
+
* 0.4.1 - Bug fix: don't attempt foreign key creation for t.belongs_to ...
|
|
123
|
+
:polymorphic => true
|
|
124
|
+
* 0.4.0 - Add :force for create_view (suggested by [@greglazarev](https://github.com/greglazarev)). cleanups
|
|
125
|
+
by [@betelgeuse](https://github.com/betelgeuse)
|
|
126
|
+
* 0.3.4 - Bug fix: regression causing :default => false to be ignored
|
|
127
|
+
* 0.3.3 - Bug fix: properly handle boolean defaults in mysql
|
|
128
|
+
* 0.3.2 - Bug fix: make sure rake db:schema:load initializes schema_plus
|
|
129
|
+
* 0.3.1 - Bug fix for PostgreSQL schema dump after change_column_default(...
|
|
130
|
+
nil)
|
|
131
|
+
* 0.3.0 - Add :default => expressions (Thanks to Luke Saunders). support
|
|
132
|
+
rails 3.2 and ruby 1.9.3
|
|
133
|
+
* 0.2.1 - Suppress duplicate add_indexes. compatibility with rails
|
|
134
|
+
3.2.0.rc2
|
data/README.md
CHANGED
|
@@ -17,7 +17,7 @@ For added rails DRYness see also the gems
|
|
|
17
17
|
|
|
18
18
|
SchemaPlus supports all combinations of:
|
|
19
19
|
|
|
20
|
-
* Rails/ActiveRecord 3.2, 4.0, and 4.1
|
|
20
|
+
* Rails/ActiveRecord 3.2, 4.0, and 4.1
|
|
21
21
|
* PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails
|
|
22
22
|
3.2), or SQLite3 (using sqlite3 >= 3.7.7 which has foreign key support)
|
|
23
23
|
* MRI Ruby 1.9.3, 2.0.0, or 2.1.0
|
|
@@ -191,10 +191,10 @@ SchemaPlus extends rails' `drop_table` method to accept these options:
|
|
|
191
191
|
drop_table :table_name, if_exists: true # no error if table doesn't exist
|
|
192
192
|
drop_table :table_name, cascade: true # delete dependencies
|
|
193
193
|
|
|
194
|
-
The `:cascade` option is particularly useful given foreign key constraints.
|
|
194
|
+
The `:cascade` option is particularly useful given foreign key constraints.
|
|
195
195
|
For Postgresql it is implemented using `DROP TABLE...CASCADE` which deletes
|
|
196
196
|
all dependencies. For MySQL, SchemaPlus implements the `:cascade` option to
|
|
197
|
-
delete foreign key references, but does not delete any other dependencies.
|
|
197
|
+
delete foreign key references, but does not delete any other dependencies.
|
|
198
198
|
For Sqlite3, the `:cascade` option is ignored, but Sqlite3 always drops tables
|
|
199
199
|
with cascade-like behavior.
|
|
200
200
|
|
|
@@ -259,7 +259,7 @@ expression). For example:
|
|
|
259
259
|
post.update_attributes(category: ActiveRecord::DB_DEFAULT)
|
|
260
260
|
|
|
261
261
|
(Without `ActiveRecord::DB_DEFAULT`, you can update a value to `NULL` but not
|
|
262
|
-
to its default value.)
|
|
262
|
+
to its default value.)
|
|
263
263
|
|
|
264
264
|
Note that after updating, you would need to reload a record to replace
|
|
265
265
|
`ActiveRecord::DB_DEFAULT` with the value assigned by the database.
|
|
@@ -292,145 +292,74 @@ of foreign key constraints, you can re-enable it:
|
|
|
292
292
|
create_table ...etc...
|
|
293
293
|
end
|
|
294
294
|
|
|
295
|
-
## Release notes:
|
|
296
295
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
* *nothing currently waiting to be released*
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
### 1.5.1
|
|
303
|
-
|
|
304
|
-
* Now respects ActiveRecord::SchemaDumper.ignore_tables for views (issue #153)
|
|
305
|
-
|
|
306
|
-
### 1.5.0
|
|
307
|
-
* Can now be used with activerecord standalone, doesn't need all of rails.
|
|
308
|
-
* `views` ignores postgres internal views, thanks to [@everplays](https://github.com/everplays) (issue #147)
|
|
309
|
-
|
|
310
|
-
### 1.4.1
|
|
311
|
-
|
|
312
|
-
* Bug fixes `migration.add_references` with `polymophic: true` (issue #145 and others)
|
|
313
|
-
|
|
314
|
-
### 1.4.0
|
|
315
|
-
|
|
316
|
-
* Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
|
|
317
|
-
* Works with MRI ruby & rails 4.1.0beta3
|
|
318
|
-
* Run tests against MRI 2.1.0
|
|
296
|
+
## History
|
|
319
297
|
|
|
320
|
-
|
|
298
|
+
* See [CHANGELOG](CHANGELOG.md) for per-version release notes.
|
|
321
299
|
|
|
322
|
-
*
|
|
300
|
+
* SchemaPlus is derived from several "Red Hill On Rails" plugins originally
|
|
301
|
+
created by [@harukizaemon](https://github.com/harukizaemon)
|
|
323
302
|
|
|
303
|
+
* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen)
|
|
324
304
|
|
|
325
|
-
|
|
305
|
+
* And [lots of contributors](https://github.com/lomba/schema_plus/graphs/contributors) since then
|
|
326
306
|
|
|
327
|
-
|
|
328
|
-
* Sort indexes alphabetically when dumping, like rails does
|
|
307
|
+
## Development & Testing
|
|
329
308
|
|
|
330
|
-
|
|
309
|
+
Are you interested in contributing to schema_plus? Thanks!
|
|
331
310
|
|
|
332
|
-
|
|
311
|
+
Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/lomba/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. Here's what you need to know:
|
|
333
312
|
|
|
334
|
-
|
|
313
|
+
#### Required environment:
|
|
335
314
|
|
|
336
|
-
*
|
|
337
|
-
* Initial jruby support (rails 3.2, postgresql), due to efforts of [@donv](https://github.com/donv)
|
|
338
|
-
* Preliminatry groundwork for rails 4.1, due to efforts of [@tovodeverett](https://github.com/tovodeverett)
|
|
339
|
-
* Bug fix for change_table
|
|
340
|
-
* Bug fix for schema_dump postgresql non-btree indexes
|
|
341
|
-
* Bug fix regarding expressions that cast non-string columns to strings in a lower()
|
|
315
|
+
* You must have either [rbenv](https://github.com/sstephenson/rbenv) or [rvm](http://rvm.io) installed and working, whichever you prefer. Within it, have available whichever ruby versions you want to test. The default set is MRI 1.9.3, 2.0.0, 2.1.0, and jruby
|
|
342
316
|
|
|
343
|
-
|
|
344
|
-
* Now works with rails 4, due to efforts of [@tovodeverett](https://github.com/tovodeverett)
|
|
345
|
-
* Test against MRI ruby 2.0.0, no longer test against 1.9.2
|
|
317
|
+
* Of course you must have installed whichever databases you want to test. The default set is: PostgreSQL, MySQL, and SQLite3.
|
|
346
318
|
|
|
347
|
-
|
|
348
|
-
* Now works with rails 3.2.13 (fixed railtie initialization)
|
|
319
|
+
* For PostgreSQL and MySQL the tests need a db user with permissions to create and access databases: The default username used by the specs is 'postgres' for Postgresql and 'schema_plus' for MySQL; you can change them via:
|
|
349
320
|
|
|
350
|
-
|
|
321
|
+
$ export POSTGRES_DB_USER = pgusername
|
|
322
|
+
$ export MYSQL_DB_USER = mysqlusername
|
|
351
323
|
|
|
352
|
-
*
|
|
353
|
-
currently work with 3.2.13.rc2
|
|
324
|
+
* For PostgreSQL and MySQL you must explicitly create the databases used by the tests:
|
|
354
325
|
|
|
355
|
-
|
|
326
|
+
$ rake create_databases # creates both postgresql & mysql
|
|
327
|
+
OR
|
|
328
|
+
$ rake postgresql:create_databases
|
|
329
|
+
$ rake mysql:create_databases
|
|
356
330
|
|
|
357
|
-
|
|
358
|
-
:cascade was implicitly true. So this change might break existing code
|
|
359
|
-
that relied on the incorrect implicit cascade behavior.
|
|
360
|
-
* Add support for :deferrable => :initially_deferred (thanks to
|
|
361
|
-
[@bhavinkamani](https://github.com/bhavinkamani))
|
|
362
|
-
* Works with PostGIS (thanks to [@pete](https://github.com/pete))
|
|
363
|
-
* Bug fix: Circular Reference/Stack Level Too Deep in Column#to_json.
|
|
364
|
-
Thanks to [@robdimarco](https://github.com/robdimarco) for tracking down the problem
|
|
365
|
-
* Bug fix: More robust handling of foreign keys with schema namespaces
|
|
331
|
+
#### Running the tests
|
|
366
332
|
|
|
333
|
+
The tests are run via a script in the repo root. Its args are documented by
|
|
367
334
|
|
|
368
|
-
|
|
335
|
+
$ ./runspecs --help
|
|
369
336
|
|
|
370
|
-
|
|
371
|
-
* Now raises ArgumentError if index has both :case_sensitive => false and an
|
|
372
|
-
:expression
|
|
373
|
-
* Now creates consistent default name for foreign key constraints
|
|
374
|
-
* Bug fix: respect :length keyword for index (thanks to [@teleological](https://github.com/teleological))
|
|
375
|
-
* Bug fix: renaming table with multiple foreign key constraints (thanks to
|
|
376
|
-
[@teleological](https://github.com/teleological))
|
|
377
|
-
* Bug fix: don't dump :case_sensitive => false for index with an expression
|
|
378
|
-
that includes "lower(name)".
|
|
379
|
-
* Bug fix: Properly dump multi-column case-insensitive indexes
|
|
337
|
+
By default it runs on a matrix of postgresql, mysql2, and sqlite3, for all rubies and all versions of rails. But the matrix options `--db`, `--ruby`, and `--rails` options let you limit those. The `--quick` option runs on just one set: postgresql, rails 4.1 and ruby 2.1.0. The `--full` option adds the mysql adapter to the set (in addition to mysql2 adapter).
|
|
380
338
|
|
|
339
|
+
* Install gem dependencies for the sets you'll be testing:
|
|
381
340
|
|
|
382
|
-
|
|
341
|
+
$ ./runspecs [matrix options] --install # runs 'bundle install' for all sets
|
|
342
|
+
e.g.
|
|
343
|
+
$ ./runspecs --db 'posgresql' --ruby '2.1.0' --rails '4.0 4.1' --install
|
|
383
344
|
|
|
384
|
-
*
|
|
385
|
-
* New feature: specify foreign key constraints using :foreign_key => { ...
|
|
386
|
-
}, motivated in particular to support :name (suggested by [@daniele-m](https://github.com/daniele-m))
|
|
387
|
-
* New feature: create view using ActiveRecord relation
|
|
388
|
-
* New feature: `ActiveRecord::DB_DEFAULT` (suggested by
|
|
389
|
-
[@zaadjis](https://github.com/zaadjis))
|
|
390
|
-
* New feature: renaming a table renames its indexes and constraints
|
|
391
|
-
correspondingly.
|
|
392
|
-
* Bug fix for postgres :kind index attribute (thanks to [@eugenebolshakov](https://github.com/eugenebolshakov))
|
|
393
|
-
* Sort fks in dump for stability (thanks to [@zephyr-dev](https://github.com/zephyr-dev))
|
|
394
|
-
* Bug fix: change_column should maintain foreign key constraints even when
|
|
395
|
-
config.foreign_keys.auto_create is false
|
|
396
|
-
* Bug fix: quote default expressions in schema dump (thanks to [@jonleighton](https://github.com/jonleighton))
|
|
397
|
-
* Bug fix: when removing a foreign key constraint, remove its auto-generated
|
|
398
|
-
index.
|
|
399
|
-
* Bug fix: SchemaDumper.ignore_tables needs to support regexps (suggested by
|
|
400
|
-
[@mtalcott](https://github.com/mtalcott))
|
|
401
|
-
* Bug fix: More robust handling of Postgresql schema_search path (suggested
|
|
402
|
-
by [@mtalcott](https://github.com/mtalcott))
|
|
403
|
-
* Bug fix: Only get index, view, and foreign key information from current
|
|
404
|
-
schema (thanks to [@bhavinkamani](https://github.com/bhavinkamani))
|
|
345
|
+
* Run all the tests:
|
|
405
346
|
|
|
347
|
+
$ ./runspecs [matrix options] # runs rspec for each set in the matrix
|
|
348
|
+
e.g.
|
|
349
|
+
$ ./runspecs --db 'posgresql' --ruby '2.1.0' --rails '4.0 4.1'
|
|
406
350
|
|
|
407
|
-
|
|
408
|
-
* 0.4.1 - Bug fix: don't attempt foreign key creation for t.belongs_to ...
|
|
409
|
-
:polymorphic => true
|
|
410
|
-
* 0.4.0 - Add :force for create_view (suggested by [@greglazarev](https://github.com/greglazarev)). cleanups
|
|
411
|
-
by [@betelgeuse](https://github.com/betelgeuse)
|
|
412
|
-
* 0.3.4 - Bug fix: regression causing :default => false to be ignored
|
|
413
|
-
* 0.3.3 - Bug fix: properly handle boolean defaults in mysql
|
|
414
|
-
* 0.3.2 - Bug fix: make sure rake db:schema:load initializes schema_plus
|
|
415
|
-
* 0.3.1 - Bug fix for PostgreSQL schema dump after change_column_default(...
|
|
416
|
-
nil)
|
|
417
|
-
* 0.3.0 - Add :default => expressions (Thanks to Luke Saunders). support
|
|
418
|
-
rails 3.2 and ruby 1.9.3
|
|
419
|
-
* 0.2.1 - Suppress duplicate add_indexes. compatibility with rails
|
|
420
|
-
3.2.0.rc2
|
|
351
|
+
Code coverage information will be in coverage/index.html -- it should be at 100% coverage if you're running against all databases.
|
|
421
352
|
|
|
353
|
+
* To run rspec on just a limited set of specs, you can do:
|
|
422
354
|
|
|
423
|
-
|
|
355
|
+
$ ./runspecs [matrix options] --rspec -- [rspec args]
|
|
356
|
+
e.g.
|
|
357
|
+
$ ./runspecs --quick --rspec -- spec/migration_spec.rb -e 'default name'
|
|
424
358
|
|
|
425
|
-
|
|
426
|
-
created by [@harukizaemon](https://github.com/harukizaemon)
|
|
427
|
-
|
|
428
|
-
* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen)
|
|
359
|
+
Contributions to making the testing process itself easier and better will also be gratefully accepted!
|
|
429
360
|
|
|
430
|
-
* And [lots of
|
|
431
|
-
contributors](https://github.com/lomba/schema_plus/graphs/contributors)
|
|
432
|
-
since then
|
|
433
361
|
|
|
362
|
+
-
|
|
434
363
|
|
|
435
364
|
|
|
436
365
|
[](https://bitdeli.com/free "Bitdeli Badge")
|
|
@@ -14,6 +14,7 @@ module SchemaPlus::ActiveRecord
|
|
|
14
14
|
|
|
15
15
|
# create index if requested explicity or implicitly due to auto_index
|
|
16
16
|
index = column_options[:index]
|
|
17
|
+
index = column_options[:_index] if column_options.include? :_index
|
|
17
18
|
if index.nil? and fk_args && config.foreign_keys.auto_index?
|
|
18
19
|
index = { :name => auto_index_name(table_name, column_name) }
|
|
19
20
|
end
|
|
@@ -55,7 +55,7 @@ module SchemaPlus
|
|
|
55
55
|
# The default as_jon includes all instance variables. but
|
|
56
56
|
# @model can't be dumped (it contains circular references)
|
|
57
57
|
def as_json(options=nil)
|
|
58
|
-
instance_values.except "model"
|
|
58
|
+
instance_values.except "model", "adapter"
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
|
@@ -11,6 +11,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
|
11
11
|
|
|
12
12
|
def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
|
|
13
13
|
options[:references] = nil if options[:polymorphic]
|
|
14
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
|
14
15
|
add_reference_without_schema_plus(table_name, ref_name, options)
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -109,6 +109,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
|
109
109
|
def references_with_schema_plus(*args) #:nodoc:
|
|
110
110
|
options = args.extract_options!
|
|
111
111
|
options[:references] = nil if options[:polymorphic]
|
|
112
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
|
112
113
|
args << options
|
|
113
114
|
references_without_schema_plus(*args)
|
|
114
115
|
end
|
|
@@ -118,6 +119,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
|
118
119
|
def belongs_to_with_schema_plus(*args) #:nodoc:
|
|
119
120
|
options = args.extract_options!
|
|
120
121
|
options[:references] = nil if options[:polymorphic]
|
|
122
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
|
121
123
|
args << options
|
|
122
124
|
belongs_to_without_schema_plus(*args)
|
|
123
125
|
end
|
data/lib/schema_plus/version.rb
CHANGED
data/runspecs
CHANGED
|
@@ -89,8 +89,8 @@ else
|
|
|
89
89
|
# rbenv, we already have various environment variables set up. need
|
|
90
90
|
# strip those out so that the forked shell can run a diifferent ruby
|
|
91
91
|
# version than the one we're in now.
|
|
92
|
-
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{
|
|
93
|
-
ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{
|
|
92
|
+
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv/(?!shims)}}.join(':')
|
|
93
|
+
ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv}}.join(':') unless ENV['GEM_PATH'].nil?
|
|
94
94
|
ENV['RBENV_DIR'] = nil
|
|
95
95
|
ENV['RBENV_HOOK_PATH'] = nil
|
|
96
96
|
|
data/schema_plus.gemspec
CHANGED
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.add_dependency("valuable")
|
|
26
26
|
|
|
27
27
|
s.add_development_dependency("rake")
|
|
28
|
-
s.add_development_dependency("rspec")
|
|
28
|
+
s.add_development_dependency("rspec", "~> 3.0.0")
|
|
29
29
|
s.add_development_dependency("rdoc")
|
|
30
30
|
s.add_development_dependency("simplecov")
|
|
31
|
-
s.add_development_dependency("simplecov-gem-
|
|
31
|
+
s.add_development_dependency("simplecov-gem-profile")
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
describe "Column definition" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
define_schema(:auto_create => true) do
|
|
7
|
+
create_table :models, :force => true do |t|
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
class Model < ::ActiveRecord::Base ; end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
subject {
|
|
14
|
+
Model.connection.execute("INSERT INTO models (dummy) values (1)")
|
|
15
|
+
Model.last.reload.test_column
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
context "text columns" do
|
|
19
|
+
|
|
20
|
+
before(:each) do
|
|
21
|
+
@nowish = /(#{Time.now.utc.to_s.sub(/:[^:]+$/, '')}|#{Time.now.to_s.sub(/:[^:]+$/,'')}).*/
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "just default passed" do
|
|
25
|
+
before(:each) do
|
|
26
|
+
define_test_column(:string, :default => "2011-12-11 00:00:00")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should use the normal default" do
|
|
30
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "just default passed in hash" do
|
|
35
|
+
before(:each) do
|
|
36
|
+
define_test_column(:string, :default => { :value => "2011-12-11 00:00:00" })
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should use the normal default" do
|
|
40
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "default passed with no nulls" do
|
|
45
|
+
before(:each) do
|
|
46
|
+
define_test_column(:string, :default => "2011-12-11 00:00:00", null: false)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should use the normal default" do
|
|
50
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "default passed in hash with no nulls" do
|
|
55
|
+
before(:each) do
|
|
56
|
+
define_test_column(:string, :default => { :value => "2011-12-11 00:00:00" }, null: false)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should use the normal default" do
|
|
60
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "default function passed as :now" do
|
|
65
|
+
before(:each) do
|
|
66
|
+
begin
|
|
67
|
+
define_test_column(:string, :default => :now)
|
|
68
|
+
rescue ArgumentError => e
|
|
69
|
+
@raised_argument_error = e
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if SchemaPlusHelpers.mysql?
|
|
74
|
+
it "should raise an error" do
|
|
75
|
+
expect(@raised_argument_error).to be_a ArgumentError
|
|
76
|
+
end
|
|
77
|
+
else
|
|
78
|
+
it "should use NOW() as the default" do
|
|
79
|
+
is_expected.to match @nowish
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "default function passed as now with no nulls" do
|
|
85
|
+
before(:each) do
|
|
86
|
+
begin
|
|
87
|
+
define_test_column(:string, :default => :now, null: false)
|
|
88
|
+
rescue ArgumentError => e
|
|
89
|
+
@raised_argument_error = e
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if SchemaPlusHelpers.mysql?
|
|
94
|
+
it "should raise an error" do
|
|
95
|
+
expect(@raised_argument_error).to be_a ArgumentError
|
|
96
|
+
end
|
|
97
|
+
else
|
|
98
|
+
it "should use NOW() as the default" do
|
|
99
|
+
is_expected.to match @nowish
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "valid expr passed as default" do
|
|
105
|
+
if SchemaPlusHelpers.mysql?
|
|
106
|
+
it "raises an error" do
|
|
107
|
+
expect {
|
|
108
|
+
define_test_column(:string, :default => { :expr => "(replace('THIS IS A TEST', 'TEST', 'DOG'))" })
|
|
109
|
+
}.to raise_error ArgumentError
|
|
110
|
+
end
|
|
111
|
+
else
|
|
112
|
+
it "uses the expression" do
|
|
113
|
+
define_test_column(:string, :default => { :expr => "(replace('THIS IS A TEST', 'TEST', 'DOG'))" })
|
|
114
|
+
is_expected.to eq "THIS IS A DOG"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "boolean column" do
|
|
122
|
+
|
|
123
|
+
context "passed as boolean false" do
|
|
124
|
+
before(:each) do
|
|
125
|
+
define_test_column :boolean, :default => false
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "should give the default as false" do
|
|
129
|
+
is_expected.to eq false
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "passed as boolean true" do
|
|
134
|
+
before(:each) do
|
|
135
|
+
define_test_column :boolean, :default => true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "should give the default as true" do
|
|
139
|
+
is_expected.to eq true
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def define_test_column(type, *args)
|
|
147
|
+
ActiveRecord::Migration.suppress_messages do
|
|
148
|
+
ActiveRecord::Migration.create_table Model.table_name, :force => true do |t|
|
|
149
|
+
t.send type, :test_column, *args
|
|
150
|
+
t.integer :dummy
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
Model.reset_column_information
|
|
154
|
+
@column = Model.columns.first()
|
|
155
|
+
end
|
|
156
|
+
end
|