declare_schema 0.13.0.pre.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -2
- data/Gemfile.lock +51 -53
- data/README.md +8 -2
- data/lib/declare_schema.rb +12 -4
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +5 -3
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +2 -2
- data/spec/lib/declare_schema/migration_generator_spec.rb +27 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3a8974d1b6642065c32bf892d5b8eb2a7da63064bcc74a5b6f4982a21ac1771
|
4
|
+
data.tar.gz: d1cd0489a73e399b4ed21ec3e83c761d5edf821bcc1435d4f42e171700ccc27c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8926952cc9aec61b28cc9fe74d5766d3c67f35734b9bec4d93a767e58966a48bccc8bd49b919f9699c9d0e386f0ae2b9d43ffa65fec764959e6389b3daf92496
|
7
|
+
data.tar.gz: 9149635173ede506625904d2ffa6aa4864c7dae69c0edf1dba776a60c5a46e77c95ccbb711d8db6c2aef63e4f38ae58e795686bbcce1574fc1ace064077eb593
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,18 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.13.
|
7
|
+
## [0.13.2] - 2021-08-04
|
8
|
+
### Fixed
|
9
|
+
- Fixed issue with disable_auto_increment support for new tables.
|
10
|
+
|
11
|
+
## [0.13.1] - 2021-08-02
|
12
|
+
### Fixed
|
13
|
+
- Fixed migration file indentation bug in Rails 5 where the first line was indented an extra 4 characters.
|
14
|
+
And fixed the longstanding triple-spacing bug to use double spacing.
|
15
|
+
|
16
|
+
## [0.13.0] - 2021-06-11
|
8
17
|
### Added
|
9
|
-
- Added support for `default_schema
|
18
|
+
- Added support for `default_schema` block to apply a default schema to every model, unless disabled for that model with `default_schema: false`.
|
10
19
|
|
11
20
|
## [0.12.1] - 2021-05-10
|
12
21
|
### Fixed
|
@@ -183,6 +192,7 @@ using the appropriate Rails configuration attributes.
|
|
183
192
|
### Added
|
184
193
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
185
194
|
|
195
|
+
[0.13.1]: https://github.com/Invoca/declare_schema/compare/v0.13.0...v0.13.1
|
186
196
|
[0.13.0]: https://github.com/Invoca/declare_schema/compare/v0.12.1...v0.13.0
|
187
197
|
[0.12.1]: https://github.com/Invoca/declare_schema/compare/v0.12.0...v0.12.1
|
188
198
|
[0.12.0]: https://github.com/Invoca/declare_schema/compare/v0.11.1...v0.12.0
|
data/Gemfile.lock
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
declare_schema (0.13.
|
4
|
+
declare_schema (0.13.2)
|
5
5
|
rails (>= 4.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (5.2.
|
11
|
-
actionpack (= 5.2.
|
10
|
+
actioncable (5.2.6)
|
11
|
+
actionpack (= 5.2.6)
|
12
12
|
nio4r (~> 2.0)
|
13
13
|
websocket-driver (>= 0.6.1)
|
14
|
-
actionmailer (5.2.
|
15
|
-
actionpack (= 5.2.
|
16
|
-
actionview (= 5.2.
|
17
|
-
activejob (= 5.2.
|
14
|
+
actionmailer (5.2.6)
|
15
|
+
actionpack (= 5.2.6)
|
16
|
+
actionview (= 5.2.6)
|
17
|
+
activejob (= 5.2.6)
|
18
18
|
mail (~> 2.5, >= 2.5.4)
|
19
19
|
rails-dom-testing (~> 2.0)
|
20
|
-
actionpack (5.2.
|
21
|
-
actionview (= 5.2.
|
22
|
-
activesupport (= 5.2.
|
20
|
+
actionpack (5.2.6)
|
21
|
+
actionview (= 5.2.6)
|
22
|
+
activesupport (= 5.2.6)
|
23
23
|
rack (~> 2.0, >= 2.0.8)
|
24
24
|
rack-test (>= 0.6.3)
|
25
25
|
rails-dom-testing (~> 2.0)
|
26
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
-
actionview (5.2.
|
28
|
-
activesupport (= 5.2.
|
27
|
+
actionview (5.2.6)
|
28
|
+
activesupport (= 5.2.6)
|
29
29
|
builder (~> 3.1)
|
30
30
|
erubi (~> 1.4)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
-
activejob (5.2.
|
34
|
-
activesupport (= 5.2.
|
33
|
+
activejob (5.2.6)
|
34
|
+
activesupport (= 5.2.6)
|
35
35
|
globalid (>= 0.3.6)
|
36
|
-
activemodel (5.2.
|
37
|
-
activesupport (= 5.2.
|
38
|
-
activerecord (5.2.
|
39
|
-
activemodel (= 5.2.
|
40
|
-
activesupport (= 5.2.
|
36
|
+
activemodel (5.2.6)
|
37
|
+
activesupport (= 5.2.6)
|
38
|
+
activerecord (5.2.6)
|
39
|
+
activemodel (= 5.2.6)
|
40
|
+
activesupport (= 5.2.6)
|
41
41
|
arel (>= 9.0)
|
42
|
-
activestorage (5.2.
|
43
|
-
actionpack (= 5.2.
|
44
|
-
activerecord (= 5.2.
|
45
|
-
marcel (~> 0.
|
46
|
-
activesupport (5.2.
|
42
|
+
activestorage (5.2.6)
|
43
|
+
actionpack (= 5.2.6)
|
44
|
+
activerecord (= 5.2.6)
|
45
|
+
marcel (~> 1.0.0)
|
46
|
+
activesupport (5.2.6)
|
47
47
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
48
|
i18n (>= 0.7, < 2)
|
49
49
|
minitest (~> 5.1)
|
@@ -60,33 +60,31 @@ GEM
|
|
60
60
|
byebug (11.1.3)
|
61
61
|
climate_control (0.2.0)
|
62
62
|
coderay (1.1.3)
|
63
|
-
concurrent-ruby (1.1.
|
63
|
+
concurrent-ruby (1.1.9)
|
64
64
|
crass (1.0.6)
|
65
65
|
diff-lcs (1.4.4)
|
66
66
|
erubi (1.10.0)
|
67
|
-
ffi (1.
|
67
|
+
ffi (1.15.1)
|
68
68
|
globalid (0.4.2)
|
69
69
|
activesupport (>= 4.2.0)
|
70
|
-
i18n (1.8.
|
70
|
+
i18n (1.8.10)
|
71
71
|
concurrent-ruby (~> 1.0)
|
72
|
-
listen (3.
|
72
|
+
listen (3.5.1)
|
73
73
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
74
74
|
rb-inotify (~> 0.9, >= 0.9.10)
|
75
|
-
loofah (2.
|
75
|
+
loofah (2.10.0)
|
76
76
|
crass (~> 1.0.2)
|
77
77
|
nokogiri (>= 1.5.9)
|
78
78
|
mail (2.7.1)
|
79
79
|
mini_mime (>= 0.1.1)
|
80
|
-
marcel (0.
|
81
|
-
mimemagic (~> 0.3.2)
|
80
|
+
marcel (1.0.1)
|
82
81
|
method_source (1.0.0)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
minitest (5.14.3)
|
82
|
+
mini_mime (1.1.0)
|
83
|
+
mini_portile2 (2.5.3)
|
84
|
+
minitest (5.14.4)
|
87
85
|
msgpack (1.4.2)
|
88
|
-
nio4r (2.5.
|
89
|
-
nokogiri (1.11.
|
86
|
+
nio4r (2.5.7)
|
87
|
+
nokogiri (1.11.7)
|
90
88
|
mini_portile2 (~> 2.5.0)
|
91
89
|
racc (~> 1.4)
|
92
90
|
parallel (1.19.2)
|
@@ -102,33 +100,33 @@ GEM
|
|
102
100
|
rack (2.2.3)
|
103
101
|
rack-test (1.1.0)
|
104
102
|
rack (>= 1.0, < 3)
|
105
|
-
rails (5.2.
|
106
|
-
actioncable (= 5.2.
|
107
|
-
actionmailer (= 5.2.
|
108
|
-
actionpack (= 5.2.
|
109
|
-
actionview (= 5.2.
|
110
|
-
activejob (= 5.2.
|
111
|
-
activemodel (= 5.2.
|
112
|
-
activerecord (= 5.2.
|
113
|
-
activestorage (= 5.2.
|
114
|
-
activesupport (= 5.2.
|
103
|
+
rails (5.2.6)
|
104
|
+
actioncable (= 5.2.6)
|
105
|
+
actionmailer (= 5.2.6)
|
106
|
+
actionpack (= 5.2.6)
|
107
|
+
actionview (= 5.2.6)
|
108
|
+
activejob (= 5.2.6)
|
109
|
+
activemodel (= 5.2.6)
|
110
|
+
activerecord (= 5.2.6)
|
111
|
+
activestorage (= 5.2.6)
|
112
|
+
activesupport (= 5.2.6)
|
115
113
|
bundler (>= 1.3.0)
|
116
|
-
railties (= 5.2.
|
114
|
+
railties (= 5.2.6)
|
117
115
|
sprockets-rails (>= 2.0.0)
|
118
116
|
rails-dom-testing (2.0.3)
|
119
117
|
activesupport (>= 4.2.0)
|
120
118
|
nokogiri (>= 1.6)
|
121
119
|
rails-html-sanitizer (1.3.0)
|
122
120
|
loofah (~> 2.3)
|
123
|
-
railties (5.2.
|
124
|
-
actionpack (= 5.2.
|
125
|
-
activesupport (= 5.2.
|
121
|
+
railties (5.2.6)
|
122
|
+
actionpack (= 5.2.6)
|
123
|
+
activesupport (= 5.2.6)
|
126
124
|
method_source
|
127
125
|
rake (>= 0.8.7)
|
128
126
|
thor (>= 0.19.0, < 2.0)
|
129
127
|
rainbow (3.0.0)
|
130
128
|
rake (13.0.3)
|
131
|
-
rb-fsevent (0.
|
129
|
+
rb-fsevent (0.11.0)
|
132
130
|
rb-inotify (0.10.1)
|
133
131
|
ffi (~> 1.0)
|
134
132
|
regexp_parser (1.8.0)
|
@@ -174,7 +172,7 @@ GEM
|
|
174
172
|
tzinfo (1.2.9)
|
175
173
|
thread_safe (~> 0.1)
|
176
174
|
unicode-display_width (1.7.0)
|
177
|
-
websocket-driver (0.7.
|
175
|
+
websocket-driver (0.7.4)
|
178
176
|
websocket-extensions (>= 0.1.0)
|
179
177
|
websocket-extensions (0.1.5)
|
180
178
|
yard (0.9.26)
|
data/README.md
CHANGED
@@ -72,10 +72,10 @@ end
|
|
72
72
|
|
73
73
|
### default_schema
|
74
74
|
If there are default columns you would like in the schema for every model, you can define them in a block that is registered with
|
75
|
-
`DeclareSchema.default_schema
|
75
|
+
`DeclareSchema.default_schema`. For example:
|
76
76
|
|
77
77
|
```ruby
|
78
|
-
DeclareSchema.default_schema
|
78
|
+
DeclareSchema.default_schema do
|
79
79
|
timestamps
|
80
80
|
optimistic_lock
|
81
81
|
end
|
@@ -90,6 +90,12 @@ class User < ActiveRecord::Base
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
+
### clear_default_schema
|
94
|
+
This method clears out any previously declared `default_schema`.
|
95
|
+
```ruby
|
96
|
+
DeclareSchema.clear_default_schema
|
97
|
+
```
|
98
|
+
|
93
99
|
### Global Configuration
|
94
100
|
Configurations can be set at the global level to customize default declaration for the following values:
|
95
101
|
|
data/lib/declare_schema.rb
CHANGED
@@ -37,7 +37,7 @@ module DeclareSchema
|
|
37
37
|
|
38
38
|
class << self
|
39
39
|
attr_reader :default_charset, :default_collation, :default_text_limit, :default_string_limit, :default_null,
|
40
|
-
:default_generate_foreign_keys, :default_generate_indexing, :
|
40
|
+
:default_generate_foreign_keys, :default_generate_indexing, :db_migrate_command
|
41
41
|
|
42
42
|
def to_class(type)
|
43
43
|
case type
|
@@ -85,9 +85,17 @@ module DeclareSchema
|
|
85
85
|
@default_generate_indexing = generate_indexing
|
86
86
|
end
|
87
87
|
|
88
|
-
def default_schema
|
89
|
-
|
90
|
-
|
88
|
+
def default_schema(&block)
|
89
|
+
if block.nil?
|
90
|
+
@default_schema # equivalent to attr_reader :default_schema
|
91
|
+
else
|
92
|
+
block.respond_to?(:call) or raise "default_schema must be passed a block that responds to call"
|
93
|
+
@default_schema = block
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def clear_default_schema
|
98
|
+
@default_schema = nil
|
91
99
|
end
|
92
100
|
|
93
101
|
def db_migrate_command=(db_migrate_command)
|
@@ -226,7 +226,9 @@ module Generators
|
|
226
226
|
|
227
227
|
primary_key_definition =
|
228
228
|
if disable_auto_increment
|
229
|
-
[:integer, :id, limit: 8, auto_increment: false, primary_key: true]
|
229
|
+
[[:integer, :id, limit: 8, auto_increment: false, primary_key: true]]
|
230
|
+
else
|
231
|
+
[]
|
230
232
|
end
|
231
233
|
|
232
234
|
field_definitions = model.field_specs.values.sort_by(&:position).map do |f|
|
@@ -237,7 +239,7 @@ module Generators
|
|
237
239
|
table_options = create_table_options(model, disable_auto_increment)
|
238
240
|
|
239
241
|
table_add = ::DeclareSchema::SchemaChange::TableAdd.new(t,
|
240
|
-
|
242
|
+
primary_key_definition + field_definitions,
|
241
243
|
table_options,
|
242
244
|
sql_options: table_options_definition.settings)
|
243
245
|
[
|
@@ -299,7 +301,7 @@ module Generators
|
|
299
301
|
up = migration_commands.map(&:up ).select(&:present?)
|
300
302
|
down = migration_commands.map(&:down).select(&:present?).reverse
|
301
303
|
|
302
|
-
[up * "\n
|
304
|
+
[up * "\n", down * "\n"]
|
303
305
|
end
|
304
306
|
|
305
307
|
def create_table_options(model, disable_auto_increment)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class <%= @migration_class_name %> < (ActiveSupport::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
|
2
2
|
def self.up
|
3
|
-
|
3
|
+
<%= @up.presence or raise "no @up given!" %>
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.down
|
7
|
-
|
7
|
+
<%= @down.presence or raise "no @down given!" %>
|
8
8
|
end
|
9
9
|
end
|
@@ -803,9 +803,34 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
803
803
|
EOS
|
804
804
|
)
|
805
805
|
|
806
|
+
Advert.connection.schema_cache.clear!
|
807
|
+
Advert.reset_column_information
|
808
|
+
|
806
809
|
nuke_model_class(Advert)
|
807
810
|
ActiveRecord::Base.connection.execute("drop table `adverts`;")
|
808
811
|
|
812
|
+
class Advert < ActiveRecord::Base
|
813
|
+
def self.disable_auto_increment
|
814
|
+
true
|
815
|
+
end
|
816
|
+
|
817
|
+
fields do
|
818
|
+
description :text, limit: 250, null: true
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
up, _ = Generators::DeclareSchema::Migration::Migrator.run.tap do |migrations|
|
823
|
+
expect(migrations).to(
|
824
|
+
migrate_up(<<~EOS.strip)
|
825
|
+
create_table :adverts, id: false do |t|
|
826
|
+
t.integer :id, limit: 8, auto_increment: false, primary_key: true
|
827
|
+
t.text :description, limit: nil, null: true
|
828
|
+
end
|
829
|
+
EOS
|
830
|
+
.and migrate_down("drop_table :adverts")
|
831
|
+
)
|
832
|
+
end
|
833
|
+
|
809
834
|
## DSL
|
810
835
|
|
811
836
|
# The DSL allows lambdas and constants
|
@@ -2507,11 +2532,11 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
2507
2532
|
end
|
2508
2533
|
|
2509
2534
|
before do
|
2510
|
-
DeclareSchema.default_schema
|
2535
|
+
DeclareSchema.default_schema(&default_schema_block)
|
2511
2536
|
end
|
2512
2537
|
|
2513
2538
|
after do
|
2514
|
-
DeclareSchema.
|
2539
|
+
DeclareSchema.clear_default_schema
|
2515
2540
|
end
|
2516
2541
|
|
2517
2542
|
context 'when unset' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declare_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -128,7 +128,7 @@ homepage: https://github.com/Invoca/declare_schema
|
|
128
128
|
licenses: []
|
129
129
|
metadata:
|
130
130
|
allowed_push_host: https://rubygems.org
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: 1.3.6
|
145
145
|
requirements: []
|
146
146
|
rubygems_version: 3.0.3
|
147
|
-
signing_key:
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Database schema declaration and migration generator for Rails
|
150
150
|
test_files: []
|