declare_schema 1.2.3.pre.ga.11 → 1.3.0.colin.1
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 +5 -39
- data/Gemfile.lock +1 -1
- data/README.md +12 -0
- data/lib/declare_schema/model/index_definition.rb +22 -6
- data/lib/declare_schema/version.rb +1 -1
- data/lib/declare_schema.rb +8 -1
- data/spec/lib/declare_schema/migration_generator_spec.rb +9 -9
- data/spec/lib/declare_schema/model/index_definition_spec.rb +74 -49
- data/spec/lib/declare_schema_spec.rb +44 -14
- 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: a1ca385b5ea18e46f1d2c9faa5f21f05dd1d76783806fcd10041c5102464115b
|
4
|
+
data.tar.gz: f96cbe0cf82a99087f4dbfbc4c35199236d75ec64c79d9f290df2b7f6266920d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a203a826b62f2d37ac5f5cef73f660b5ebb14ec0009ba50d196612090a1445fe9c20e6ce90be9371b005248cf1391fb5565246bf87cb50f261f4f228b63848c2
|
7
|
+
data.tar.gz: 66cda6583ab4b15c0592220369f75a23b9c5cf2467338dca4082ac4e497d787cf40ad3a48b01b1e4b306715a026e1f79f0718b0271a32bbb8a5c4cc8f200c884
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +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.
|
7
|
+
## [1.3.0] - Unreleased
|
8
|
+
### Added
|
9
|
+
- Added `DeclareSchema.max_index_and_constraint_name_length` with default of 64.
|
10
|
+
|
11
|
+
## [1.2.3] - 2023-04-04
|
8
12
|
### Changed
|
9
13
|
- Fixed a bug where renaming a foreign key resulted in an incorrect migration
|
10
14
|
|
@@ -256,41 +260,3 @@ using the appropriate Rails configuration attributes.
|
|
256
260
|
## [0.1.1] - 2020-09-24
|
257
261
|
### Added
|
258
262
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
259
|
-
|
260
|
-
[1.2.1]: https://github.com/Invoca/declare_schema/compare/v1.2.0...v1.2.1
|
261
|
-
[1.2.0]: https://github.com/Invoca/declare_schema/compare/v1.1.0...v1.2.0
|
262
|
-
[1.1.0]: https://github.com/Invoca/declare_schema/compare/v1.0.2...v1.1.0
|
263
|
-
[1.0.2]: https://github.com/Invoca/declare_schema/compare/v1.0.1...v1.0.2
|
264
|
-
[1.0.1]: https://github.com/Invoca/declare_schema/compare/v1.0.0...v1.0.1
|
265
|
-
[1.0.0]: https://github.com/Invoca/declare_schema/compare/v0.14.3...v1.0.0
|
266
|
-
[0.14.3]: https://github.com/Invoca/declare_schema/compare/v0.14.2...v0.14.3
|
267
|
-
[0.14.2]: https://github.com/Invoca/declare_schema/compare/v0.14.1...v0.14.2
|
268
|
-
[0.14.1]: https://github.com/Invoca/declare_schema/compare/v0.14.0...v0.14.1
|
269
|
-
[0.14.0]: https://github.com/Invoca/declare_schema/compare/v0.13.1...v0.14.0
|
270
|
-
[0.13.1]: https://github.com/Invoca/declare_schema/compare/v0.13.0...v0.13.1
|
271
|
-
[0.13.0]: https://github.com/Invoca/declare_schema/compare/v0.12.1...v0.13.0
|
272
|
-
[0.12.1]: https://github.com/Invoca/declare_schema/compare/v0.12.0...v0.12.1
|
273
|
-
[0.12.0]: https://github.com/Invoca/declare_schema/compare/v0.11.1...v0.12.0
|
274
|
-
[0.11.1]: https://github.com/Invoca/declare_schema/compare/v0.11.0...v0.11.1
|
275
|
-
[0.11.0]: https://github.com/Invoca/declare_schema/compare/v0.10.1...v0.11.0
|
276
|
-
[0.10.1]: https://github.com/Invoca/declare_schema/compare/v0.10.0...v0.10.1
|
277
|
-
[0.10.0]: https://github.com/Invoca/declare_schema/compare/v0.9.0...v0.10.0
|
278
|
-
[0.9.0]: https://github.com/Invoca/declare_schema/compare/v0.8.0...v0.9.0
|
279
|
-
[0.8.0]: https://github.com/Invoca/declare_schema/compare/v0.7.1...v0.8.0
|
280
|
-
[0.7.1]: https://github.com/Invoca/declare_schema/compare/v0.7.0...v0.7.1
|
281
|
-
[0.7.0]: https://github.com/Invoca/declare_schema/compare/v0.6.3...v0.7.0
|
282
|
-
[0.6.4]: https://github.com/Invoca/declare_schema/compare/v0.6.3...v0.6.4
|
283
|
-
[0.6.3]: https://github.com/Invoca/declare_schema/compare/v0.6.2...v0.6.3
|
284
|
-
[0.6.2]: https://github.com/Invoca/declare_schema/compare/v0.6.1...v0.6.2
|
285
|
-
[0.6.1]: https://github.com/Invoca/declare_schema/compare/v0.6.0...v0.6.1
|
286
|
-
[0.6.0]: https://github.com/Invoca/declare_schema/compare/v0.5.0...v0.6.0
|
287
|
-
[0.5.0]: https://github.com/Invoca/declare_schema/compare/v0.4.2...v0.5.0
|
288
|
-
[0.4.2]: https://github.com/Invoca/declare_schema/compare/v0.4.1...v0.4.2
|
289
|
-
[0.4.1]: https://github.com/Invoca/declare_schema/compare/v0.4.0...v0.4.1
|
290
|
-
[0.4.0]: https://github.com/Invoca/declare_schema/compare/v0.3.1...v0.4.0
|
291
|
-
[0.3.1]: https://github.com/Invoca/declare_schema/compare/v0.3.0...v0.3.1
|
292
|
-
[0.3.0]: https://github.com/Invoca/declare_schema/compare/v0.2.0...v0.3.0
|
293
|
-
[0.2.0]: https://github.com/Invoca/declare_schema/compare/v0.1.3...v0.2.0
|
294
|
-
[0.1.3]: https://github.com/Invoca/declare_schema/compare/v0.1.2...v0.1.3
|
295
|
-
[0.1.2]: https://github.com/Invoca/declare_schema/compare/v0.1.1...v0.1.2
|
296
|
-
[0.1.1]: https://github.com/Invoca/declare_schema/tree/v0.1.1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -258,6 +258,18 @@ For example:
|
|
258
258
|
]
|
259
259
|
```
|
260
260
|
|
261
|
+
## Maximum Length of Index and Constraint Names
|
262
|
+
|
263
|
+
MySQL limits the length of index and constraint names to 64 characters.
|
264
|
+
Because the migrations generated by `DecleareSchema` are intended to be portable to any database type that
|
265
|
+
ActiveRecord supports, `DeclareSchema` will generate names that do not exceed the
|
266
|
+
configurable value:
|
267
|
+
```ruby
|
268
|
+
DeclareSchema.max_index_and_constraint_name_length = 64
|
269
|
+
```
|
270
|
+
If you know that your migrations will only be used on a database type with a different limit, you can
|
271
|
+
adjust this configuration value. A `nil` value means "unlimited".
|
272
|
+
|
261
273
|
## Declaring Character Set and Collation
|
262
274
|
_Note: This feature currently only works for MySQL database configurations._
|
263
275
|
|
@@ -12,18 +12,17 @@ module DeclareSchema
|
|
12
12
|
class IndexNameTooLongError < RuntimeError; end
|
13
13
|
|
14
14
|
PRIMARY_KEY_NAME = "PRIMARY"
|
15
|
-
MYSQL_INDEX_NAME_MAX_LENGTH = 64
|
16
15
|
|
17
16
|
def initialize(model, fields, **options)
|
18
17
|
@model = model
|
19
18
|
@table = options.delete(:table_name) || model.table_name
|
20
19
|
@fields = Array.wrap(fields).map(&:to_s)
|
21
20
|
@explicit_name = options[:name] unless options.delete(:allow_equivalent)
|
22
|
-
@name = options.delete(:name) || self.class.default_index_name(@fields)
|
21
|
+
@name = options.delete(:name) || self.class.default_index_name(@table, @fields)
|
23
22
|
@unique = options.delete(:unique) || name == PRIMARY_KEY_NAME || false
|
24
23
|
|
25
|
-
if @name.length >
|
26
|
-
raise IndexNameTooLongError, "Index '#{@name}' exceeds
|
24
|
+
if DeclareSchema.max_index_and_constraint_name_length && @name.length > DeclareSchema.max_index_and_constraint_name_length
|
25
|
+
raise IndexNameTooLongError, "Index '#{@name}' exceeds configured limit of #{DeclareSchema.max_index_and_constraint_name_length} characters. Give it a shorter name, or adjust DeclareSchema.max_index_and_constraint_name_length if you know your database can accept longer names."
|
27
26
|
end
|
28
27
|
|
29
28
|
if (where = options[:where])
|
@@ -57,8 +56,25 @@ module DeclareSchema
|
|
57
56
|
index_definitions
|
58
57
|
end
|
59
58
|
|
60
|
-
def default_index_name(
|
61
|
-
|
59
|
+
def default_index_name(table, fields)
|
60
|
+
index_name = nil
|
61
|
+
[:long_index_name, :short_index_name].find do |method_name|
|
62
|
+
index_name = send(method_name, table, fields)
|
63
|
+
if DeclareSchema.max_index_and_constraint_name_length.nil? || index_name.length <= DeclareSchema.max_index_and_constraint_name_length
|
64
|
+
break index_name
|
65
|
+
end
|
66
|
+
end or raise IndexNameTooLongError,
|
67
|
+
"Index '#{index_name}' exceeds configured limit of #{DeclareSchema.max_index_and_constraint_name_length} characters."
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def long_index_name(table_name, columns)
|
73
|
+
"index_#{table_name}_on_#{Array(columns).join("_and_")}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def short_index_name(table_name, columns)
|
77
|
+
"#{table_name}__#{Array(columns).join("_")}"
|
62
78
|
end
|
63
79
|
end
|
64
80
|
|
data/lib/declare_schema.rb
CHANGED
@@ -29,10 +29,12 @@ module DeclareSchema
|
|
29
29
|
@default_generate_foreign_keys = true
|
30
30
|
@default_generate_indexing = true
|
31
31
|
@db_migrate_command = "bundle exec rails db:migrate"
|
32
|
+
@max_index_and_constraint_name_length = 64 # limit for MySQL
|
32
33
|
|
33
34
|
class << self
|
34
35
|
attr_reader :default_charset, :default_collation, :default_text_limit, :default_string_limit, :default_null,
|
35
|
-
:default_generate_foreign_keys, :default_generate_indexing, :db_migrate_command
|
36
|
+
:default_generate_foreign_keys, :default_generate_indexing, :db_migrate_command,
|
37
|
+
:max_index_and_constraint_name_length
|
36
38
|
|
37
39
|
def to_class(type)
|
38
40
|
case type
|
@@ -97,6 +99,11 @@ module DeclareSchema
|
|
97
99
|
db_migrate_command.is_a?(String) or raise ArgumentError, "db_migrate_command must be a string (got #{db_migrate_command.inspect})"
|
98
100
|
@db_migrate_command = db_migrate_command
|
99
101
|
end
|
102
|
+
|
103
|
+
def max_index_and_constraint_name_length=(length)
|
104
|
+
length.is_a?(Integer) || length.nil? or raise ArgumentError, "max_index_and_constraint_name_length must be an Integer or nil (meaning unlimited)"
|
105
|
+
@max_index_and_constraint_name_length = length
|
106
|
+
end
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
@@ -359,12 +359,12 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
359
359
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
360
360
|
migrate_up(<<~EOS.strip)
|
361
361
|
add_column :adverts, :category_id, :integer, limit: 8, null: false
|
362
|
-
add_index :adverts, [:category_id], name: :
|
362
|
+
add_index :adverts, [:category_id], name: :index_adverts_on_category_id
|
363
363
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" if defined?(Mysql2)}
|
364
364
|
EOS
|
365
365
|
.and migrate_down(<<~EOS.strip)
|
366
366
|
#{"remove_foreign_key :adverts, name: :index_adverts_on_category_id" if defined?(Mysql2)}
|
367
|
-
remove_index :adverts, name: :
|
367
|
+
remove_index :adverts, name: :index_adverts_on_category_id
|
368
368
|
remove_column :adverts, :category_id
|
369
369
|
EOS
|
370
370
|
)
|
@@ -383,7 +383,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
383
383
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
384
384
|
migrate_up(<<~EOS.strip)
|
385
385
|
add_column :adverts, :c_id, :integer, limit: 8, null: false
|
386
|
-
add_index :adverts, [:c_id], name: :
|
386
|
+
add_index :adverts, [:c_id], name: :index_adverts_on_c_id
|
387
387
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
|
388
388
|
"add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
|
389
389
|
EOS
|
@@ -477,7 +477,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
477
477
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
478
478
|
migrate_up(<<~EOS.strip)
|
479
479
|
add_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
|
480
|
-
add_index :adverts, [:title], name: :
|
480
|
+
add_index :adverts, [:title], name: :index_adverts_on_title
|
481
481
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
|
482
482
|
"add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
|
483
483
|
EOS
|
@@ -496,7 +496,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
496
496
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
497
497
|
migrate_up(<<~EOS.strip)
|
498
498
|
add_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
|
499
|
-
add_index :adverts, [:title], name: :
|
499
|
+
add_index :adverts, [:title], name: :index_adverts_on_title, unique: true
|
500
500
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
|
501
501
|
"add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
|
502
502
|
EOS
|
@@ -532,7 +532,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
532
532
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
533
533
|
migrate_up(<<~EOS.strip)
|
534
534
|
add_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
|
535
|
-
add_index :adverts, [:title], name: :
|
535
|
+
add_index :adverts, [:title], name: :index_adverts_on_title
|
536
536
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
|
537
537
|
"add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
|
538
538
|
EOS
|
@@ -566,7 +566,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
566
566
|
expect(Generators::DeclareSchema::Migration::Migrator.run).to(
|
567
567
|
migrate_up(<<~EOS.strip)
|
568
568
|
add_column :adverts, :title, :string, limit: 250, null: true#{charset_and_collation}
|
569
|
-
add_index :adverts, [:title, :category_id], name: :
|
569
|
+
add_index :adverts, [:title, :category_id], name: :index_adverts_on_title_and_category_id
|
570
570
|
#{"add_foreign_key :adverts, :categories, column: :category_id, name: :index_adverts_on_category_id\n" +
|
571
571
|
"add_foreign_key :adverts, :categories, column: :c_id, name: :index_adverts_on_c_id" if defined?(Mysql2)}
|
572
572
|
EOS
|
@@ -866,8 +866,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
866
866
|
t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin"
|
867
867
|
t.integer :category_id, limit: 8, null: false
|
868
868
|
end
|
869
|
-
add_index :advertisers, [:category_id], name: :
|
870
|
-
add_index :affiliates, [:category_id], name: :
|
869
|
+
add_index :advertisers, [:category_id], name: :index_adverts_on_category_id
|
870
|
+
add_index :affiliates, [:category_id], name: :index_adverts_on_category_id
|
871
871
|
add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id
|
872
872
|
add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id
|
873
873
|
EOS
|
@@ -40,75 +40,100 @@ RSpec.describe DeclareSchema::Model::IndexDefinition do
|
|
40
40
|
|
41
41
|
it 'has index_definitions' do
|
42
42
|
expect(model_class.index_definitions).to be_kind_of(Array)
|
43
|
-
expect(model_class.index_definitions.map(&:name)).to eq(['
|
43
|
+
expect(model_class.index_definitions.map(&:name)).to eq(['index_index_definition_test_models_on_name'])
|
44
44
|
expect([:name, :fields, :unique].map { |attr| model_class.index_definitions[0].send(attr)}).to eq(
|
45
|
-
|
46
|
-
|
45
|
+
['index_index_definition_test_models_on_name', ['name'], false]
|
46
|
+
)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'has index_definitions_with_primary_key' do
|
50
50
|
expect(model_class.index_definitions_with_primary_key).to be_kind_of(Array)
|
51
51
|
result = model_class.index_definitions_with_primary_key.sort_by(&:name)
|
52
|
-
expect(result.map(&:name)).to eq(['PRIMARY', '
|
52
|
+
expect(result.map(&:name)).to eq(['PRIMARY', 'index_index_definition_test_models_on_name'])
|
53
53
|
expect([:name, :fields, :unique].map { |attr| result[0].send(attr)}).to eq(
|
54
|
-
|
55
|
-
|
54
|
+
['PRIMARY', ['id'], true]
|
55
|
+
)
|
56
56
|
expect([:name, :fields, :unique].map { |attr| result[1].send(attr)}).to eq(
|
57
|
-
|
58
|
-
|
57
|
+
['index_index_definition_test_models_on_name', ['name'], false]
|
58
|
+
)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
ActiveRecord::Base.connection.execute <<~EOS
|
62
|
+
context 'with a migrated database' do
|
63
|
+
before do
|
64
|
+
ActiveRecord::Base.connection.execute <<~EOS
|
65
|
+
CREATE TABLE index_definition_test_models (
|
66
|
+
id INTEGER NOT NULL PRIMARY KEY,
|
67
|
+
name #{if defined?(SQLite3) then 'TEXT' else 'VARCHAR(255)' end} NOT NULL
|
68
|
+
)
|
69
|
+
EOS
|
70
|
+
ActiveRecord::Base.connection.execute <<~EOS
|
72
71
|
CREATE UNIQUE INDEX index_definition_test_models_on_name ON index_definition_test_models(name)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
72
|
+
EOS
|
73
|
+
ActiveRecord::Base.connection.execute <<~EOS
|
74
|
+
CREATE TABLE index_definition_compound_index_models (
|
75
|
+
fk1_id INTEGER NOT NULL,
|
76
|
+
fk2_id INTEGER NOT NULL,
|
77
|
+
PRIMARY KEY (fk1_id, fk2_id)
|
78
|
+
)
|
79
|
+
EOS
|
80
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'for_model' do
|
84
|
+
subject { described_class.for_model(model_class) }
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
expect([:name, :columns, :unique].map { |attr| subject[1].send(attr) }).to eq(
|
94
|
-
['PRIMARY', ['id'], true]
|
95
|
-
)
|
96
|
-
end
|
86
|
+
context 'with single-column PK' do
|
87
|
+
it 'returns the indexes for the model' do
|
88
|
+
expect(subject.size).to eq(2), subject.inspect
|
89
|
+
expect([:name, :columns, :unique].map { |attr| subject[0].send(attr) }).to eq(
|
90
|
+
['index_definition_test_models_on_name', ['name'], true]
|
91
|
+
)
|
92
|
+
expect([:name, :columns, :unique].map { |attr| subject[1].send(attr) }).to eq(
|
93
|
+
['PRIMARY', ['id'], true]
|
94
|
+
)
|
97
95
|
end
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
98
|
+
context 'with compound-column PK' do
|
99
|
+
let(:model_class) { IndexDefinitionCompoundIndexModel }
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
101
|
+
it 'returns the indexes for the model' do
|
102
|
+
expect(subject.size).to eq(1), subject.inspect
|
103
|
+
expect([:name, :columns, :unique].map { |attr| subject[0].send(attr) }).to eq(
|
104
|
+
['PRIMARY', ['fk1_id', 'fk2_id'], true]
|
105
|
+
)
|
108
106
|
end
|
109
107
|
end
|
110
108
|
end
|
111
109
|
end
|
112
110
|
end
|
111
|
+
|
112
|
+
context 'with no side effects' do
|
113
|
+
describe '.default_index_name' do
|
114
|
+
let(:table_name2) { 'users' }
|
115
|
+
let(:columns2) { ['last_name', 'first_name', 'middle_name', ] }
|
116
|
+
subject { described_class.default_index_name(table_name2, columns2) }
|
117
|
+
around do |spec|
|
118
|
+
orig_value = DeclareSchema.max_index_and_constraint_name_length
|
119
|
+
DeclareSchema.max_index_and_constraint_name_length = max_index_and_constraint_name_length
|
120
|
+
spec.run
|
121
|
+
ensure
|
122
|
+
DeclareSchema.max_index_and_constraint_name_length = orig_value
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with unlimited max_index_and_constraint_name_length' do
|
126
|
+
let(:max_index_and_constraint_name_length) { nil }
|
127
|
+
|
128
|
+
it { is_expected.to eq("index_users_on_last_name_and_first_name_and_middle_name") }
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with short max_index_and_constraint_name_length' do
|
132
|
+
let(:max_index_and_constraint_name_length) { 40 }
|
133
|
+
|
134
|
+
it { is_expected.to eq("users__last_name_first_name_middle_name") }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
113
138
|
# TODO: fill out remaining tests
|
114
139
|
end
|
@@ -5,13 +5,13 @@ RSpec.describe DeclareSchema do
|
|
5
5
|
subject { described_class.default_charset }
|
6
6
|
|
7
7
|
context 'when not explicitly set' do
|
8
|
-
it {
|
8
|
+
it { is_expected.to eq("utf8mb4") }
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'when explicitly set' do
|
12
12
|
before { described_class.default_charset = "utf8" }
|
13
13
|
after { described_class.default_charset = "utf8mb4" }
|
14
|
-
it {
|
14
|
+
it { is_expected.to eq("utf8") }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -19,13 +19,13 @@ RSpec.describe DeclareSchema do
|
|
19
19
|
subject { described_class.default_collation }
|
20
20
|
|
21
21
|
context 'when not explicitly set' do
|
22
|
-
it {
|
22
|
+
it { is_expected.to eq("utf8mb4_bin") }
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when explicitly set' do
|
26
26
|
before { described_class.default_collation = "utf8mb4_general_ci" }
|
27
27
|
after { described_class.default_collation = "utf8mb4_bin" }
|
28
|
-
it {
|
28
|
+
it { is_expected.to eq("utf8mb4_general_ci") }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,13 +33,13 @@ RSpec.describe DeclareSchema do
|
|
33
33
|
subject { described_class.default_text_limit }
|
34
34
|
|
35
35
|
context 'when not explicitly set' do
|
36
|
-
it {
|
36
|
+
it { is_expected.to eq(0xffff_ffff) }
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when explicitly set' do
|
40
40
|
before { described_class.default_text_limit = 0xffff }
|
41
41
|
after { described_class.default_text_limit = 0xffff_ffff }
|
42
|
-
it {
|
42
|
+
it { is_expected.to eq(0xffff) }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -47,13 +47,13 @@ RSpec.describe DeclareSchema do
|
|
47
47
|
subject { described_class.default_string_limit }
|
48
48
|
|
49
49
|
context 'when not explicitly set' do
|
50
|
-
it {
|
50
|
+
it { is_expected.to eq(nil) }
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'when explicitly set' do
|
54
54
|
before { described_class.default_string_limit = 225 }
|
55
55
|
after { described_class.default_string_limit = nil }
|
56
|
-
it {
|
56
|
+
it { is_expected.to eq(225) }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,13 +61,13 @@ RSpec.describe DeclareSchema do
|
|
61
61
|
subject { described_class.default_null }
|
62
62
|
|
63
63
|
context 'when not explicitly set' do
|
64
|
-
it {
|
64
|
+
it { is_expected.to eq(false) }
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'when explicitly set' do
|
68
68
|
before { described_class.default_null = true }
|
69
69
|
after { described_class.default_null = false }
|
70
|
-
it {
|
70
|
+
it { is_expected.to eq(true) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,13 +75,13 @@ RSpec.describe DeclareSchema do
|
|
75
75
|
subject { described_class.default_generate_foreign_keys }
|
76
76
|
|
77
77
|
context 'when not explicitly set' do
|
78
|
-
it {
|
78
|
+
it { is_expected.to eq(true) }
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'when explicitly set' do
|
82
82
|
before { described_class.default_generate_foreign_keys = false }
|
83
83
|
after { described_class.default_generate_foreign_keys = true }
|
84
|
-
it {
|
84
|
+
it { is_expected.to eq(false) }
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -89,13 +89,43 @@ RSpec.describe DeclareSchema do
|
|
89
89
|
subject { described_class.default_generate_indexing }
|
90
90
|
|
91
91
|
context 'when not explicitly set' do
|
92
|
-
it {
|
92
|
+
it { is_expected.to eq(true) }
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'when explicitly set' do
|
96
96
|
before { described_class.default_generate_indexing = false }
|
97
97
|
after { described_class.default_generate_indexing = true }
|
98
|
-
it {
|
98
|
+
it { is_expected.to eq(false) }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#max_index_and_constraint_name_length' do
|
103
|
+
subject { described_class.max_index_and_constraint_name_length }
|
104
|
+
|
105
|
+
context 'when not explicitly set' do
|
106
|
+
it { is_expected.to eq(64) }
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when explicitly set' do
|
110
|
+
around do |spec|
|
111
|
+
orig_value = described_class.max_index_and_constraint_name_length
|
112
|
+
described_class.max_index_and_constraint_name_length = max_index_and_constraint_name_length
|
113
|
+
spec.run
|
114
|
+
rescue
|
115
|
+
described_class.max_index_and_constraint_name_length = orig_value
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when set to an Integer' do
|
119
|
+
let(:max_index_and_constraint_name_length) { 255 }
|
120
|
+
|
121
|
+
it { is_expected.to eq(255)}
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when set to nil' do
|
125
|
+
let(:max_index_and_constraint_name_length) { nil }
|
126
|
+
|
127
|
+
it { is_expected.to eq(nil)}
|
128
|
+
end
|
99
129
|
end
|
100
130
|
end
|
101
131
|
end
|
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.
|
4
|
+
version: 1.3.0.colin.1
|
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: 2023-
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -127,7 +127,7 @@ homepage: https://github.com/Invoca/declare_schema
|
|
127
127
|
licenses: []
|
128
128
|
metadata:
|
129
129
|
allowed_push_host: https://rubygems.org
|
130
|
-
post_install_message:
|
130
|
+
post_install_message:
|
131
131
|
rdoc_options: []
|
132
132
|
require_paths:
|
133
133
|
- lib
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: 1.3.6
|
144
144
|
requirements: []
|
145
145
|
rubygems_version: 3.1.6
|
146
|
-
signing_key:
|
146
|
+
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Database schema declaration and migration generator for Rails
|
149
149
|
test_files: []
|