declare_schema 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/declare_schema_build.yml +44 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model.rb +1 -1
- data/lib/declare_schema/model/field_spec.rb +9 -5
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +2 -4
- data/spec/lib/declare_schema/field_spec_spec.rb +69 -0
- data/spec/lib/declare_schema/migration_generator_spec.rb +25 -0
- metadata +4 -3
- data/.travis.yml +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0c13793a5b263a2f1134ee19168a42ceb57c472cf8fb656b8e86fcdd9500b79
|
4
|
+
data.tar.gz: ee92620b0a091538958957205ba940d97cd9f67bc606751cb52a8ae44370e541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc0e18dd1b3a998640cc2e983c86182e19b855d8ce42b3f7233b3471a7849d0dc28fa2653d110b42d0544c513267f8066386496b1469085bb507541c068b87a
|
7
|
+
data.tar.gz: 34b9e31862291b85becf7eeb908c4ef1da5b29178b1ab387b35c6678680299cd921fa65b49e0ba89604518a66515092d3e7d6c38678267301c9399b4572d372e
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
name: DeclareSchema Build
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
name: DeclareSchema Build
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: [ 2.4.5, 2.5.8, 2.6.5, 2.7.1 ]
|
13
|
+
gemfile: [ gemfiles/rails_4.gemfile, gemfiles/rails_5.gemfile, gemfiles/rails_6.gemfile ]
|
14
|
+
exclude:
|
15
|
+
- { gemfile: gemfiles/rails_4.gemfile, ruby: 2.7.1 }
|
16
|
+
- { gemfile: gemfiles/rails_5.gemfile, ruby: 2.4.5 }
|
17
|
+
- { gemfile: gemfiles/rails_6.gemfile, ruby: 2.4.5 }
|
18
|
+
env:
|
19
|
+
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
20
|
+
steps:
|
21
|
+
- name: Checkout Branch
|
22
|
+
id: checkout_branch
|
23
|
+
uses: actions/checkout@v2
|
24
|
+
- name: Setup Ruby
|
25
|
+
id: setup_ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
bundler: 1.17.3
|
29
|
+
ruby-version: ${{matrix.ruby}}
|
30
|
+
- name: Remove Bundler 2
|
31
|
+
id: remove_bundler_2
|
32
|
+
if: ${{ matrix.ruby >= '2.6.5' }}
|
33
|
+
run: |
|
34
|
+
rm -f /opt/hostedtoolcache/Ruby/2.*/x64/lib/ruby/gems/2.*/specifications/default/bundler-2.*.gemspec
|
35
|
+
gem install bundler:1.17.3 --force --default
|
36
|
+
gem install bundler -v 1.17.3
|
37
|
+
- name: Appraisals
|
38
|
+
id: appraisals
|
39
|
+
run: |
|
40
|
+
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} --gemfile=${{ matrix.gemfile }}
|
41
|
+
git config --global user.email "dummy@example.com"
|
42
|
+
git config --global user.name "dummy"
|
43
|
+
bundle exec rake test:prepare_testapp[force]
|
44
|
+
bundle exec rake test:all < test_responses.txt
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ 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.6.0] - 2020-12-23
|
8
|
+
### Added
|
9
|
+
- Fields may now be declared with `:bigint` type which is identical to `:integer, limit 8`
|
10
|
+
- FieldSpec#initialize interface now includes `position` keyword argument and `**options` hash.
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Fixed cycle in which FieldSpec#initialize was calling `model.field_specs`
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- Changed ci support from Travis to Github Workflow
|
17
|
+
|
7
18
|
## [0.5.0] - 2020-12-21
|
8
19
|
### Added
|
9
20
|
- Added support for configuring the character set and collation for MySQL databases
|
@@ -73,6 +84,7 @@ using the appropriate Rails configuration attributes.
|
|
73
84
|
### Added
|
74
85
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
75
86
|
|
87
|
+
[0.6.0]: https://github.com/Invoca/declare_schema/compare/v0.5.0...v0.6.0
|
76
88
|
[0.5.0]: https://github.com/Invoca/declare_schema/compare/v0.4.2...v0.5.0
|
77
89
|
[0.4.2]: https://github.com/Invoca/declare_schema/compare/v0.4.1...v0.4.2
|
78
90
|
[0.4.1]: https://github.com/Invoca/declare_schema/compare/v0.4.0...v0.4.1
|
data/Gemfile.lock
CHANGED
data/lib/declare_schema/model.rb
CHANGED
@@ -88,7 +88,7 @@ module DeclareSchema
|
|
88
88
|
add_formatting_for_field(name, type)
|
89
89
|
add_validations_for_field(name, type, args, options)
|
90
90
|
add_index_for_field(name, args, options)
|
91
|
-
field_specs[name] = ::DeclareSchema::Model::FieldSpec.new(self, name, type, options)
|
91
|
+
field_specs[name] = ::DeclareSchema::Model::FieldSpec.new(self, name, type, position: field_specs.size, **options)
|
92
92
|
attr_order << name unless attr_order.include?(name)
|
93
93
|
end
|
94
94
|
|
@@ -33,7 +33,8 @@ module DeclareSchema
|
|
33
33
|
|
34
34
|
attr_reader :model, :name, :type, :position, :options
|
35
35
|
|
36
|
-
def initialize(model, name, type,
|
36
|
+
def initialize(model, name, type, position: 0, **options)
|
37
|
+
# TODO: TECH-5116
|
37
38
|
# Invoca change - searching for the primary key was causing an additional database read on every model load. Assume
|
38
39
|
# "id" which works for invoca.
|
39
40
|
# raise ArgumentError, "you cannot provide a field spec for the primary key" if name == model.primary_key
|
@@ -43,9 +44,8 @@ module DeclareSchema
|
|
43
44
|
@name = name.to_sym
|
44
45
|
type.is_a?(Symbol) or raise ArgumentError, "type must be a Symbol; got #{type.inspect}"
|
45
46
|
@type = type
|
46
|
-
|
47
|
+
@position = position
|
47
48
|
@options = options
|
48
|
-
|
49
49
|
case type
|
50
50
|
when :text
|
51
51
|
@options[:default] and raise "default may not be given for :text field #{model}##{@name}"
|
@@ -54,11 +54,15 @@ module DeclareSchema
|
|
54
54
|
end
|
55
55
|
when :string
|
56
56
|
@options[:limit] or raise "limit must be given for :string field #{model}##{@name}: #{@options.inspect}; do you want `limit: 255`?"
|
57
|
-
|
57
|
+
when :bigint
|
58
|
+
@type = :integer
|
59
|
+
@options = options.merge(limit: 8)
|
60
|
+
end
|
61
|
+
|
62
|
+
unless type.in?([:text, :string])
|
58
63
|
@options[:collation] and raise "collation may only given for :string and :text fields"
|
59
64
|
@options[:charset] and raise "charset may only given for :string and :text fields"
|
60
65
|
end
|
61
|
-
@position = position_option || model.field_specs.length
|
62
66
|
end
|
63
67
|
|
64
68
|
TYPE_SYNONYMS = { timestamp: :datetime }.freeze
|
@@ -37,11 +37,9 @@ module Generators
|
|
37
37
|
|
38
38
|
def field_specs
|
39
39
|
i = 0
|
40
|
-
foreign_keys.
|
41
|
-
|
42
|
-
h[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :integer, position: i, null: false)
|
40
|
+
foreign_keys.each_with_object({}) do |v, result|
|
41
|
+
result[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :integer, position: i, null: false)
|
43
42
|
i += 1
|
44
|
-
h
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe 'DeclareSchema Model FieldSpec' do
|
4
|
+
before do
|
5
|
+
load File.expand_path('prepare_testapp.rb', __dir__)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'There are no model columns to change' do
|
9
|
+
it '#different_to should return false for int8 == int8' do
|
10
|
+
subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :integer, limit: 8, null: false, position: 0)
|
11
|
+
|
12
|
+
case Rails::VERSION::MAJOR
|
13
|
+
when 4
|
14
|
+
cast_type = ActiveRecord::Type::Integer.new(limit: 8)
|
15
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "integer(8)", false)
|
16
|
+
else
|
17
|
+
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "integer(8)", type: :integer, limit: 8)
|
18
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts")
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(subject.different_to?(subject.name, col)).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it '#different_to should return false for bigint == bigint' do
|
25
|
+
subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :bigint, null: false, position: 0)
|
26
|
+
|
27
|
+
case Rails::VERSION::MAJOR
|
28
|
+
when 4
|
29
|
+
cast_type = ActiveRecord::Type::BigInteger.new(limit: 8)
|
30
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "bigint(20)", false)
|
31
|
+
else
|
32
|
+
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "bigint(20)", type: :integer, limit: 8)
|
33
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts")
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(subject.different_to?(subject.name, col)).to eq(false)
|
37
|
+
end
|
38
|
+
|
39
|
+
it '#different_to should return false for int8 == bigint' do
|
40
|
+
subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :integer, limit: 8, null: false, position: 0)
|
41
|
+
|
42
|
+
case Rails::VERSION::MAJOR
|
43
|
+
when 4
|
44
|
+
cast_type = ActiveRecord::Type::BigInteger.new(limit: 8)
|
45
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "bigint(20)", false)
|
46
|
+
else
|
47
|
+
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "bigint(20)", type: :integer, limit: 8)
|
48
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts")
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(subject.different_to?(subject.name, col)).to eq(false)
|
52
|
+
end
|
53
|
+
|
54
|
+
it '#different_to should return false for bigint == int8' do
|
55
|
+
subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :bigint, null: false, position: 0)
|
56
|
+
|
57
|
+
case Rails::VERSION::MAJOR
|
58
|
+
when 4
|
59
|
+
cast_type = ActiveRecord::Type::Integer.new(limit: 8)
|
60
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "integer(8)", false)
|
61
|
+
else
|
62
|
+
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "integer(8)", type: :integer, limit: 8)
|
63
|
+
col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts")
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(subject.different_to?(subject.name, col)).to eq(false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1093,4 +1093,29 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
1093
1093
|
expect(base_class).to eq("(Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)")
|
1094
1094
|
end
|
1095
1095
|
end
|
1096
|
+
|
1097
|
+
context 'Does not generate migrations' do
|
1098
|
+
it 'for aliased fields bigint -> integer limit 8' do
|
1099
|
+
if Rails::VERSION::MAJOR >= 5 || !ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/)
|
1100
|
+
class Advert < active_record_base_class.constantize
|
1101
|
+
fields do
|
1102
|
+
price :bigint
|
1103
|
+
end
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
generate_migrations '-n', '-m'
|
1107
|
+
|
1108
|
+
migrations = Dir.glob('db/migrate/*declare_schema_migration*.rb')
|
1109
|
+
expect(migrations.size).to eq(1), migrations.inspect
|
1110
|
+
|
1111
|
+
class Advert < active_record_base_class.constantize
|
1112
|
+
fields do
|
1113
|
+
price :integer, limit: 8
|
1114
|
+
end
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
expect { generate_migrations '-n', '-g' }.to output("Database and models match -- nothing to change\n").to_stdout
|
1118
|
+
end
|
1119
|
+
end
|
1120
|
+
end
|
1096
1121
|
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: 0.
|
4
|
+
version: 0.6.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: 2020-12-
|
11
|
+
date: 2020-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -33,12 +33,12 @@ extensions: []
|
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
35
|
- ".github/dependabot.yml"
|
36
|
+
- ".github/workflows/declare_schema_build.yml"
|
36
37
|
- ".github/workflows/gem_release.yml"
|
37
38
|
- ".gitignore"
|
38
39
|
- ".rspec"
|
39
40
|
- ".rubocop.yml"
|
40
41
|
- ".ruby-version"
|
41
|
-
- ".travis.yml"
|
42
42
|
- Appraisals
|
43
43
|
- CHANGELOG.md
|
44
44
|
- Gemfile
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/generators/declare_schema/support/thor_shell.rb
|
76
76
|
- spec/lib/declare_schema/api_spec.rb
|
77
77
|
- spec/lib/declare_schema/field_declaration_dsl_spec.rb
|
78
|
+
- spec/lib/declare_schema/field_spec_spec.rb
|
78
79
|
- spec/lib/declare_schema/generator_spec.rb
|
79
80
|
- spec/lib/declare_schema/interactive_primary_key_spec.rb
|
80
81
|
- spec/lib/declare_schema/migration_generator_spec.rb
|
data/.travis.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
---
|
2
|
-
dist: trusty
|
3
|
-
os: linux
|
4
|
-
language: ruby
|
5
|
-
cache: bundler
|
6
|
-
rvm:
|
7
|
-
- 2.4.5
|
8
|
-
- 2.5.8
|
9
|
-
- 2.6.5
|
10
|
-
- 2.7.1
|
11
|
-
- ruby-head
|
12
|
-
gemfile:
|
13
|
-
- gemfiles/rails_4.gemfile
|
14
|
-
- gemfiles/rails_5.gemfile
|
15
|
-
- gemfiles/rails_6.gemfile
|
16
|
-
jobs:
|
17
|
-
fast_finish: false
|
18
|
-
exclude:
|
19
|
-
- gemfile: gemfiles/rails_4.gemfile
|
20
|
-
rvm: 2.7.1
|
21
|
-
- gemfile: gemfiles/rails_5.gemfile
|
22
|
-
rvm: 2.4.5
|
23
|
-
- gemfile: gemfiles/rails_6.gemfile
|
24
|
-
rvm: 2.4.5
|
25
|
-
allow_failures:
|
26
|
-
- rvm: ruby-head
|
27
|
-
before_install:
|
28
|
-
- rm -f /home/travis/.rvm/rubies/ruby-2.*/lib/ruby/gems/2.*/specifications/default/bundler-2.*.gemspec
|
29
|
-
- echo y | rvm @global do gem install bundler -v 1.17.3 --force --default
|
30
|
-
- gem install bundler -v 1.17.3 --force --default
|
31
|
-
- gem install bundler -v 1.17.3
|
32
|
-
install:
|
33
|
-
- bundle --version
|
34
|
-
- bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
35
|
-
script:
|
36
|
-
- bundle exec rake test:prepare_testapp[force]
|
37
|
-
- bundle exec rake test:all < test_responses.txt
|