declare_schema 1.0.0 → 1.1.0
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/.github/CODEOWNERS +1 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model/foreign_key_definition.rb +1 -1
- data/lib/declare_schema/model/habtm_model_shim.rb +6 -2
- data/lib/declare_schema/model/index_definition.rb +7 -4
- data/lib/declare_schema/schema_change/all.rb +1 -0
- data/lib/declare_schema/version.rb +1 -1
- data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +1 -6
- metadata +4 -4
- data/.github/dependabot.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e974685df9b53809688f8903ceb82a475e50b24a4725275c3cde5949396fcd85
|
4
|
+
data.tar.gz: 6efca4e93e98e3880418821c2f3969600a8ac48b8b967a96fcc959824fd0e1fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2dac19cdac8a2a5b59f7d20f34c6230e69981a89b180e47080f5c77ba047962ed1f1badeeb69230b14c8a074e96b0588bb9ff9e2430ff2a5496c1d60318cc9
|
7
|
+
data.tar.gz: 90098f7d95782c943e17f04b8fc4f1ed23a4cecf63f6208b54fdfff60af19ca4c43ab661eacd055319ca5ec290b1ac1591586a8ec852eda41375d2b2d020346a
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @Invoca/octothorpe
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,20 @@ 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.1.0] - 2022-07-22
|
8
|
+
### Changed
|
9
|
+
- Fixed a bug where `DeclareSchema::Model::HabtmModelShim` `indexes` and `integer limits` were not being generated properly. Use `limit 8` for ids and primary composite key for habtm model.
|
10
|
+
- `index_definitions_with_primary_key`
|
11
|
+
|
12
|
+
## [1.0.2] - 2022-07-18
|
13
|
+
### Fixed
|
14
|
+
- Fixed a bug where `SchemaChange::ColumnRemove` was not loaded and causing an exception to raise
|
15
|
+
when a column was being removed during migration generation
|
16
|
+
|
17
|
+
## [1.0.1] - 2022-07-12
|
18
|
+
### Fixed
|
19
|
+
- Remove lingering usage of `fallback_find_primary_key` method that was removed in `0.14.0`
|
20
|
+
|
7
21
|
## [1.0.0] - 2022-03-28
|
8
22
|
### Added
|
9
23
|
- Added support for Ruby 3+
|
@@ -215,6 +229,9 @@ using the appropriate Rails configuration attributes.
|
|
215
229
|
### Added
|
216
230
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
217
231
|
|
232
|
+
[1.1.0]: https://github.com/Invoca/declare_schema/compare/v1.0.2...v1.1.0
|
233
|
+
[1.0.2]: https://github.com/Invoca/declare_schema/compare/v1.0.1...v1.0.2
|
234
|
+
[1.0.1]: https://github.com/Invoca/declare_schema/compare/v1.0.0...v1.0.1
|
218
235
|
[1.0.0]: https://github.com/Invoca/declare_schema/compare/v0.14.3...v1.0.0
|
219
236
|
[0.14.3]: https://github.com/Invoca/declare_schema/compare/v0.14.2...v0.14.3
|
220
237
|
[0.14.2]: https://github.com/Invoca/declare_schema/compare/v0.14.1...v0.14.2
|
data/Gemfile.lock
CHANGED
@@ -36,7 +36,7 @@ module DeclareSchema
|
|
36
36
|
parent_table: parent_table,
|
37
37
|
foreign_key: foreign_key
|
38
38
|
}
|
39
|
-
options[:dependent] = :delete if fkc['ON DELETE CASCADE']
|
39
|
+
options[:dependent] = :delete if fkc['ON DELETE CASCADE'] || model.is_a?(DeclareSchema::Model::HabtmModelShim)
|
40
40
|
|
41
41
|
new(model, foreign_key, **options)
|
42
42
|
end
|
@@ -37,9 +37,13 @@ module DeclareSchema
|
|
37
37
|
join_table
|
38
38
|
end
|
39
39
|
|
40
|
+
def index_name
|
41
|
+
"index_#{table_name}_on_#{foreign_keys.first}_#{foreign_keys.last}"
|
42
|
+
end
|
43
|
+
|
40
44
|
def field_specs
|
41
45
|
foreign_keys.each_with_index.each_with_object({}) do |(v, position), result|
|
42
|
-
result[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :
|
46
|
+
result[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :bigint, position: position, null: false)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -53,7 +57,7 @@ module DeclareSchema
|
|
53
57
|
|
54
58
|
def index_definitions_with_primary_key
|
55
59
|
[
|
56
|
-
IndexDefinition.new(self, foreign_keys, unique: true, name:
|
60
|
+
IndexDefinition.new(self, foreign_keys, unique: true, name: index_name), # creates a primary composite key on both foriegn keys
|
57
61
|
IndexDefinition.new(self, foreign_keys.last) # not unique by itself; combines with primary key to be unique
|
58
62
|
]
|
59
63
|
end
|
@@ -33,11 +33,14 @@ module DeclareSchema
|
|
33
33
|
|
34
34
|
class << self
|
35
35
|
# extract IndexSpecs from an existing table
|
36
|
-
# always includes the PRIMARY KEY index
|
36
|
+
# always includes the PRIMARY KEY index for Model unless it is a HABTM Model.
|
37
37
|
def for_model(model, old_table_name = nil)
|
38
38
|
t = old_table_name || model.table_name
|
39
39
|
|
40
|
-
|
40
|
+
habtm_model = model.is_a?(DeclareSchema::Model::HabtmModelShim)
|
41
|
+
|
42
|
+
primary_key_columns = Array(model.connection.primary_key(t)).presence
|
43
|
+
primary_key_columns || habtm_model or
|
41
44
|
raise "could not find primary key for table #{t} in #{model.connection.columns(t).inspect}"
|
42
45
|
|
43
46
|
primary_key_found = false
|
@@ -47,14 +50,14 @@ module DeclareSchema
|
|
47
50
|
i.columns == primary_key_columns && i.unique or
|
48
51
|
raise "primary key on #{t} was not unique on #{primary_key_columns} (was unique=#{i.unique} on #{i.columns})"
|
49
52
|
primary_key_found = true
|
50
|
-
elsif i.columns == primary_key_columns && i.unique
|
53
|
+
elsif i.columns == primary_key_columns && i.unique && !habtm_model
|
51
54
|
# skip this primary key index since we'll create it below, with PRIMARY_KEY_NAME
|
52
55
|
next
|
53
56
|
end
|
54
57
|
new(model, i.columns, name: i.name, unique: i.unique, where: i.where, table_name: old_table_name)
|
55
58
|
end.compact
|
56
59
|
|
57
|
-
if !primary_key_found
|
60
|
+
if !primary_key_found && !habtm_model
|
58
61
|
index_definitions << new(model, primary_key_columns, name: PRIMARY_KEY_NAME, unique: true, where: nil, table_name: old_table_name)
|
59
62
|
end
|
60
63
|
index_definitions
|
@@ -7,6 +7,7 @@ module DeclareSchema
|
|
7
7
|
autoload :Base, 'declare_schema/schema_change/base'
|
8
8
|
autoload :ColumnAdd, 'declare_schema/schema_change/column_add'
|
9
9
|
autoload :ColumnChange, 'declare_schema/schema_change/column_change'
|
10
|
+
autoload :ColumnRemove, 'declare_schema/schema_change/column_remove'
|
10
11
|
autoload :ColumnRename, 'declare_schema/schema_change/column_rename'
|
11
12
|
autoload :ForeignKeyAdd, 'declare_schema/schema_change/foreign_key_add'
|
12
13
|
autoload :ForeignKeyRemove, 'declare_schema/schema_change/foreign_key_remove'
|
@@ -102,14 +102,9 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
|
|
102
102
|
expect(result.size).to eq(2), result.inspect
|
103
103
|
|
104
104
|
expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
|
105
|
-
expect(result.first.name).to eq('
|
105
|
+
expect(result.first.name).to eq('index_parent_1_parent_2_on_parent_1_id_parent_2_id')
|
106
106
|
expect(result.first.fields).to eq(['parent_1_id', 'parent_2_id'])
|
107
107
|
expect(result.first.unique).to be_truthy
|
108
|
-
|
109
|
-
expect(result.last).to be_a(::DeclareSchema::Model::IndexDefinition)
|
110
|
-
expect(result.last.name).to eq('on_parent_2_id')
|
111
|
-
expect(result.last.unique).to be_falsey
|
112
|
-
expect(result.last.fields).to eq(['parent_2_id'])
|
113
108
|
end
|
114
109
|
end
|
115
110
|
|
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.1.0
|
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: 2022-
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -32,7 +32,7 @@ executables:
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- ".github/
|
35
|
+
- ".github/CODEOWNERS"
|
36
36
|
- ".github/workflows/declare_schema_build.yml"
|
37
37
|
- ".github/workflows/gem_release.yml"
|
38
38
|
- ".gitignore"
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: 1.3.6
|
143
143
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.3.11
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Database schema declaration and migration generator for Rails
|
data/.github/dependabot.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
updates:
|
3
|
-
- package-ecosystem: bundler
|
4
|
-
directory: "/"
|
5
|
-
schedule:
|
6
|
-
interval: weekly
|
7
|
-
day: friday
|
8
|
-
time: "22:00"
|
9
|
-
timezone: PST8PDT
|
10
|
-
open-pull-requests-limit: 99
|
11
|
-
versioning-strategy: lockfile-only
|
12
|
-
commit-message:
|
13
|
-
prefix: No-Jira
|
14
|
-
include: scope
|