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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fef97a705f29e37659ade688c2c64b30f0df1eabc76ab47ceb1272f2eec10845
4
- data.tar.gz: 3602d932b5bae67c6cfd367750e399d44ab65afa4fd19c4923ff5e447b79ca40
3
+ metadata.gz: e3a8974d1b6642065c32bf892d5b8eb2a7da63064bcc74a5b6f4982a21ac1771
4
+ data.tar.gz: d1cd0489a73e399b4ed21ec3e83c761d5edf821bcc1435d4f42e171700ccc27c
5
5
  SHA512:
6
- metadata.gz: 770d10d283e399d3ca37537e7ed4c68d0dde1a6ba28e033148ed7ed86d0e0833256d0b2446688538ef34f39cac9c1fe535914824d4bf7e6de17d11554b876ec2
7
- data.tar.gz: 134add2558ab3374d741e04839913257eb48e8b98d4b80a3bc3c35927369032fd9549d9a1dd2768c702386f44b4265c0379475cd01f8097288cad53b479a4ee9
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.0] - Unreleased
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 =` to apply a default schema to every model, unless disabld for that model with `declare_schema: false`.
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.0.pre.1)
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.4.5)
11
- actionpack (= 5.2.4.5)
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.4.5)
15
- actionpack (= 5.2.4.5)
16
- actionview (= 5.2.4.5)
17
- activejob (= 5.2.4.5)
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.4.5)
21
- actionview (= 5.2.4.5)
22
- activesupport (= 5.2.4.5)
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.4.5)
28
- activesupport (= 5.2.4.5)
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.4.5)
34
- activesupport (= 5.2.4.5)
33
+ activejob (5.2.6)
34
+ activesupport (= 5.2.6)
35
35
  globalid (>= 0.3.6)
36
- activemodel (5.2.4.5)
37
- activesupport (= 5.2.4.5)
38
- activerecord (5.2.4.5)
39
- activemodel (= 5.2.4.5)
40
- activesupport (= 5.2.4.5)
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.4.5)
43
- actionpack (= 5.2.4.5)
44
- activerecord (= 5.2.4.5)
45
- marcel (~> 0.3.1)
46
- activesupport (5.2.4.5)
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.8)
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.14.2)
67
+ ffi (1.15.1)
68
68
  globalid (0.4.2)
69
69
  activesupport (>= 4.2.0)
70
- i18n (1.8.9)
70
+ i18n (1.8.10)
71
71
  concurrent-ruby (~> 1.0)
72
- listen (3.4.1)
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.9.0)
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.3.3)
81
- mimemagic (~> 0.3.2)
80
+ marcel (1.0.1)
82
81
  method_source (1.0.0)
83
- mimemagic (0.3.5)
84
- mini_mime (1.0.2)
85
- mini_portile2 (2.5.0)
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.5)
89
- nokogiri (1.11.1)
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.4.5)
106
- actioncable (= 5.2.4.5)
107
- actionmailer (= 5.2.4.5)
108
- actionpack (= 5.2.4.5)
109
- actionview (= 5.2.4.5)
110
- activejob (= 5.2.4.5)
111
- activemodel (= 5.2.4.5)
112
- activerecord (= 5.2.4.5)
113
- activestorage (= 5.2.4.5)
114
- activesupport (= 5.2.4.5)
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.4.5)
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.4.5)
124
- actionpack (= 5.2.4.5)
125
- activesupport (= 5.2.4.5)
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.10.4)
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.3)
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 =`. For example:
75
+ `DeclareSchema.default_schema`. For example:
76
76
 
77
77
  ```ruby
78
- DeclareSchema.default_schema = -> do
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
 
@@ -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, :default_schema, :db_migrate_command
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=(default_schema)
89
- default_schema.nil? || default_schema.respond_to?(:call) or raise "default_schema must be nil or a block that responds to call"
90
- @default_schema = default_schema
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "0.13.0.pre.1"
4
+ VERSION = "0.13.2"
5
5
  end
@@ -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
- Array(primary_key_definition) + field_definitions,
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\n", down * "\n\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
- <%= @up.presence or raise "no @up given!" %>
3
+ <%= @up.presence or raise "no @up given!" %>
4
4
  end
5
5
 
6
6
  def self.down
7
- <%= @down.presence or raise "no @down given!" %>
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 = default_schema_block
2535
+ DeclareSchema.default_schema(&default_schema_block)
2511
2536
  end
2512
2537
 
2513
2538
  after do
2514
- DeclareSchema.default_schema = nil
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.0.pre.1
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-06-06 00:00:00.000000000 Z
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: []