declare_schema 1.3.4 → 1.3.5.colin.1

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: 1f5ae7cf20a27eeced3466430509637a9df81ff7456678b129333392bb317985
4
- data.tar.gz: cb1b3ddef5eefac4eb1f8bacbe62751900f869ea8577932ab85cd1c2b2cbc59e
3
+ metadata.gz: b87dca056e85242e1d681247cce6acdfcc9ff4896f5e74e8f170aad94ad92172
4
+ data.tar.gz: 9169a1be8735996bb9a1c9a22ed8af926dbe99a405c4fee9f679263823603423
5
5
  SHA512:
6
- metadata.gz: 11150b8dc1fd0a21c5b6ea2570a4bc12ce87eb4b48fa9926f67cb61537c26dc1156061b6308f796029bd9d2caeea632b71b0f28198b7a20e0959ccb1c7369f7c
7
- data.tar.gz: 30d9e498f22dbb47c2f10f7d107d257ccae6b507bb6a5cd82d17c18e0074723e7551223f75bd4335f5a7453017016774fb1a10739484fdd713fa2aae91175f81
6
+ metadata.gz: ca2d456cffd1cfb8a6413dfe228078568d476804818d0103a5ebda165f99ea5c7851d0def54026c8f2a0268726a34c2e783d50079ab05782b7e55b25092623d6
7
+ data.tar.gz: e0ba451918f3814de9c7534cbd0a6e0db8a82621ae03614957b7cf6278c79a6d272e6f241a1324c85fb175d1ceb56b93f04a756280827ee0facaccbecb3d32b5
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ 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
+ ## [1.3.5] - 2024-01-22
8
+ ### Fixed
9
+ - Make `default_charset=` and `default_collation=` lazy so they don't use the database connection to check the
10
+ MySQL version. Instead, that is checked the first time `default_charset` or `default_collation` is called.
11
+
7
12
  ## [1.3.4] - 2024-01-18
8
13
  ### Fixed
9
14
  - Add test for migrating `has_and_belongs_to_many` associations and fix them to properly declare their
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.3.4)
4
+ declare_schema (1.3.5.colin.1)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.3.4"
4
+ VERSION = "1.3.5.colin.1"
5
5
  end
@@ -36,7 +36,7 @@ module DeclareSchema
36
36
 
37
37
  class << self
38
38
  attr_writer :mysql_version
39
- attr_reader :default_charset, :default_collation, :default_text_limit, :default_string_limit, :default_null,
39
+ attr_reader :default_text_limit, :default_string_limit, :default_null,
40
40
  :default_generate_foreign_keys, :default_generate_indexing, :db_migrate_command,
41
41
  :max_index_and_constraint_name_length
42
42
 
@@ -81,12 +81,22 @@ module DeclareSchema
81
81
 
82
82
  def default_charset=(charset)
83
83
  charset.is_a?(String) or raise ArgumentError, "charset must be a string (got #{charset.inspect})"
84
- @default_charset = normalize_charset(charset)
84
+ @default_charset_before_normalization = charset
85
+ @default_charset = nil
86
+ end
87
+
88
+ def default_charset
89
+ @default_charset || normalize_charset(@default_charset_before_normalization)
85
90
  end
86
91
 
87
92
  def default_collation=(collation)
88
93
  collation.is_a?(String) or raise ArgumentError, "collation must be a string (got #{collation.inspect})"
89
- @default_collation = normalize_collation(collation)
94
+ @default_collation_before_normalization = collation
95
+ @default_collation = nil
96
+ end
97
+
98
+ def default_collation
99
+ @default_collation || normalize_collation(@default_collation_before_normalization)
90
100
  end
91
101
 
92
102
  def default_text_limit=(text_limit)
@@ -37,6 +37,27 @@ RSpec.describe DeclareSchema do
37
37
  it { is_expected.to eq("utf8mb3") }
38
38
  end
39
39
  end
40
+
41
+ context 'when MySQL version not known yet' do
42
+ before { described_class.remove_instance_variable('@mysql_version') rescue nil }
43
+ after { described_class.remove_instance_variable('@mysql_version') rescue nil }
44
+
45
+ context 'when set' do
46
+ let(:connection) { double("connection", select_value: "8.0.21") }
47
+
48
+ it "is lazy, so it doesn't use the database connection until read" do
49
+ @connection_called = false
50
+ expect(ActiveRecord::Base).to receive(:connection) do
51
+ @connection_called = true
52
+ connection
53
+ end
54
+ described_class.default_charset = "utf8"
55
+ expect(@connection_called).to eq(false)
56
+ described_class.default_charset
57
+ expect(@connection_called).to eq(true)
58
+ end
59
+ end
60
+ end
40
61
  end
41
62
 
42
63
  describe '#default_collation' do
@@ -81,6 +102,27 @@ RSpec.describe DeclareSchema do
81
102
  it { is_expected.to eq("utf8mb3_general_ci") }
82
103
  end
83
104
  end
105
+
106
+ context 'when MySQL version not known yet' do
107
+ before { described_class.remove_instance_variable('@mysql_version') rescue nil }
108
+ after { described_class.remove_instance_variable('@mysql_version') rescue nil }
109
+
110
+ context 'when set' do
111
+ let(:connection) { double("connection", select_value: "8.0.21") }
112
+
113
+ it "is lazy, so it doesn't use the database connection until read" do
114
+ @connection_called = false
115
+ expect(ActiveRecord::Base).to receive(:connection) do
116
+ @connection_called = true
117
+ connection
118
+ end
119
+ described_class.default_collation = "utf8_general_ci"
120
+ expect(@connection_called).to eq(false)
121
+ described_class.default_collation
122
+ expect(@connection_called).to eq(true)
123
+ end
124
+ end
125
+ end
84
126
  end
85
127
 
86
128
  describe '#default_text_limit' 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: 1.3.4
4
+ version: 1.3.5.colin.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-20 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails