declare_schema 0.5.0.pre.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/declare_schema_build.yml +60 -0
  3. data/.gitignore +1 -0
  4. data/Appraisals +21 -4
  5. data/CHANGELOG.md +22 -1
  6. data/Gemfile +0 -2
  7. data/Gemfile.lock +1 -5
  8. data/README.md +4 -4
  9. data/Rakefile +17 -4
  10. data/bin/declare_schema +1 -1
  11. data/declare_schema.gemspec +1 -1
  12. data/gemfiles/rails_4_mysql.gemfile +22 -0
  13. data/gemfiles/{rails_4.gemfile → rails_4_sqlite.gemfile} +1 -2
  14. data/gemfiles/rails_5_mysql.gemfile +22 -0
  15. data/gemfiles/{rails_5.gemfile → rails_5_sqlite.gemfile} +1 -2
  16. data/gemfiles/rails_6_mysql.gemfile +22 -0
  17. data/gemfiles/{rails_6.gemfile → rails_6_sqlite.gemfile} +2 -3
  18. data/lib/declare_schema/command.rb +10 -3
  19. data/lib/declare_schema/model.rb +1 -1
  20. data/lib/declare_schema/model/field_spec.rb +21 -17
  21. data/lib/declare_schema/model/table_options_definition.rb +8 -6
  22. data/lib/declare_schema/version.rb +1 -1
  23. data/lib/generators/declare_schema/migration/migrator.rb +80 -30
  24. data/spec/lib/declare_schema/field_spec_spec.rb +69 -0
  25. data/spec/lib/declare_schema/generator_spec.rb +25 -10
  26. data/spec/lib/declare_schema/interactive_primary_key_spec.rb +8 -2
  27. data/spec/lib/declare_schema/migration_generator_spec.rb +285 -158
  28. data/spec/lib/declare_schema/model/index_definition_spec.rb +4 -5
  29. data/spec/lib/declare_schema/model/table_options_definition_spec.rb +19 -29
  30. data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +17 -22
  31. data/spec/support/acceptance_spec_helpers.rb +3 -3
  32. metadata +14 -10
  33. data/.travis.yml +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f3b9aed36bcc541fb7d929a97e3650358be4da05c33a5d27e8db732633eb8f8
4
- data.tar.gz: 800c945108be2e29301afc2badce461a1302dadad7c393bd39c939368311e874
3
+ metadata.gz: c0108465514c80103fc934c550e911b563d4f3ebe8a1ebfb3a95c7fa10ed3ee8
4
+ data.tar.gz: 60b586c698f62017311bef429896f79312314a61e918a1d6fb60dca60e4f6d15
5
5
  SHA512:
6
- metadata.gz: 821e56fe2ba4e7c9913f630a47cf685a565c19d40fdf282305c3bf0db6f0783b3174aa4e1ca535732e64cc7514cd87a598eaf743fbca0b21fa7041ec62ce82a0
7
- data.tar.gz: c2522286a389e559fda6b635b0d85b1025bdf918a98a5eb27e40946d5eee1e079efca53a0e2ad6f24649a8b05f59d652869cee924dcca7491ff7575d8292519c
6
+ metadata.gz: 2167096015bc12def6ed7f5ab3c45b1de223e79c9b3828d6a322c9a849d08534ac0551033058de9c6059733e344e7f9ab97ff152a11a67227e2490bc1726f022
7
+ data.tar.gz: 173f38d4d7f7aa50904422624ddcec7a65f6f2b5e534b3eab5dd6894056d6166859a332d8ad9f021d5cc14306a6c0503c6a0308491bd5cede23c01934bd7c488
@@ -0,0 +1,60 @@
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:
14
+ - gemfiles/rails_4_mysql.gemfile
15
+ - gemfiles/rails_4_sqlite.gemfile
16
+ - gemfiles/rails_5_mysql.gemfile
17
+ - gemfiles/rails_5_sqlite.gemfile
18
+ - gemfiles/rails_6_mysql.gemfile
19
+ - gemfiles/rails_6_sqlite.gemfile
20
+ exclude:
21
+ - { gemfile: gemfiles/rails_4_mysql.gemfile, ruby: 2.7.1 }
22
+ - { gemfile: gemfiles/rails_4_sqlite.gemfile, ruby: 2.7.1 }
23
+ - { gemfile: gemfiles/rails_5_mysql.gemfile, ruby: 2.4.5 }
24
+ - { gemfile: gemfiles/rails_5_sqlite.gemfile, ruby: 2.4.5 }
25
+ - { gemfile: gemfiles/rails_6_mysql.gemfile, ruby: 2.4.5 }
26
+ - { gemfile: gemfiles/rails_6_sqlite.gemfile, ruby: 2.4.5 }
27
+ env:
28
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
29
+ services:
30
+ mysql:
31
+ image: mysql:5.7
32
+ env:
33
+ MYSQL_ALLOW_EMPTY_PASSWORD: yes
34
+ ports:
35
+ - 3306:3306
36
+ steps:
37
+ - name: Checkout Branch
38
+ id: checkout_branch
39
+ uses: actions/checkout@v2
40
+ - name: Setup Ruby
41
+ id: setup_ruby
42
+ uses: ruby/setup-ruby@v1
43
+ with:
44
+ bundler: 1.17.3
45
+ ruby-version: ${{matrix.ruby}}
46
+ - name: Remove Bundler 2
47
+ id: remove_bundler_2
48
+ if: ${{ matrix.ruby >= '2.6.5' }}
49
+ run: |
50
+ rm -f /opt/hostedtoolcache/Ruby/2.*/x64/lib/ruby/gems/2.*/specifications/default/bundler-2.*.gemspec
51
+ gem install bundler:1.17.3 --force --default
52
+ gem install bundler -v 1.17.3
53
+ - name: Appraisals
54
+ id: appraisals
55
+ run: |
56
+ bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} --gemfile=${{ matrix.gemfile }}
57
+ git config --global user.email "dummy@example.com"
58
+ git config --global user.name "dummy"
59
+ MYSQL_PORT=3306 bundle exec rake test:prepare_testapp[force]
60
+ bundle exec rake test:all < test_responses.txt
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
 
13
13
  # appraisal
14
14
  gemfiles/*.lock
15
+ .idea
data/Appraisals CHANGED
@@ -1,14 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'rails-4' do
3
+ appraise 'rails-4-sqlite' do
4
4
  gem 'rails', '~> 4.2'
5
5
  gem 'sqlite3', '~> 1.3.0'
6
6
  end
7
7
 
8
- appraise 'rails-5' do
8
+ appraise 'rails-4-mysql' do
9
+ gem 'rails', '~> 4.2'
10
+ gem 'mysql2'
11
+ end
12
+
13
+ appraise 'rails-5-sqlite' do
14
+ gem 'rails', '~> 5.2'
15
+ gem 'sqlite3'
16
+ end
17
+
18
+ appraise 'rails-5-mysql' do
9
19
  gem 'rails', '~> 5.2'
20
+ gem 'mysql2'
21
+ end
22
+
23
+ appraise 'rails-6-sqlite' do
24
+ gem 'rails', '~> 6.1'
25
+ gem 'sqlite3'
10
26
  end
11
27
 
12
- appraise 'rails-6' do
13
- gem 'rails', '~> 6.0'
28
+ appraise 'rails-6-mysql' do
29
+ gem 'rails', '~> 6.1'
30
+ gem 'mysql2'
14
31
  end
@@ -4,7 +4,26 @@ 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.5.0] - Unreleased
7
+ ## [0.6.1] - 2021-01-06
8
+ ### Added
9
+ - Added Appraisals for MySQL as well as SQLite.
10
+
11
+ ### Fixed
12
+ - Fixed case where primary key index will be gone by the time we get to dropping that primary key
13
+ because all of the existing primary key columns are being removed.
14
+
15
+ ## [0.6.0] - 2020-12-23
16
+ ### Added
17
+ - Fields may now be declared with `:bigint` type which is identical to `:integer, limit 8`
18
+ - FieldSpec#initialize interface now includes `position` keyword argument and `**options` hash.
19
+
20
+ ### Fixed
21
+ - Fixed cycle in which FieldSpec#initialize was calling `model.field_specs`
22
+
23
+ ### Changed
24
+ - Changed ci support from Travis to Github Workflow
25
+
26
+ ## [0.5.0] - 2020-12-21
8
27
  ### Added
9
28
  - Added support for configuring the character set and collation for MySQL databases
10
29
  at the global, table, and field level
@@ -73,6 +92,8 @@ using the appropriate Rails configuration attributes.
73
92
  ### Added
74
93
  - Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
75
94
 
95
+ [0.6.1]: https://github.com/Invoca/declare_schema/compare/v0.6.0...v0.6.1
96
+ [0.6.0]: https://github.com/Invoca/declare_schema/compare/v0.5.0...v0.6.0
76
97
  [0.5.0]: https://github.com/Invoca/declare_schema/compare/v0.4.2...v0.5.0
77
98
  [0.4.2]: https://github.com/Invoca/declare_schema/compare/v0.4.1...v0.4.2
78
99
  [0.4.1]: https://github.com/Invoca/declare_schema/compare/v0.4.0...v0.4.1
data/Gemfile CHANGED
@@ -14,10 +14,8 @@ gem 'bundler', '< 2'
14
14
  gem "climate_control", '~> 0.2'
15
15
  gem 'pry'
16
16
  gem 'pry-byebug'
17
- gem 'mysql2'
18
17
  gem 'rails', '~> 5.2', '>= 5.2.4.3'
19
18
  gem 'responders'
20
19
  gem 'rspec'
21
20
  gem 'rubocop'
22
- gem 'sqlite3'
23
21
  gem 'yard'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (0.5.0.pre.1)
4
+ declare_schema (0.6.1)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
@@ -85,7 +85,6 @@ GEM
85
85
  mini_portile2 (2.4.0)
86
86
  minitest (5.14.2)
87
87
  msgpack (1.3.3)
88
- mysql2 (0.5.3)
89
88
  nio4r (2.5.4)
90
89
  nokogiri (1.10.10)
91
90
  mini_portile2 (~> 2.4.0)
@@ -167,7 +166,6 @@ GEM
167
166
  actionpack (>= 4.0)
168
167
  activesupport (>= 4.0)
169
168
  sprockets (>= 3.0.0)
170
- sqlite3 (1.4.2)
171
169
  thor (1.0.1)
172
170
  thread_safe (0.3.6)
173
171
  tzinfo (1.2.7)
@@ -188,14 +186,12 @@ DEPENDENCIES
188
186
  climate_control (~> 0.2)
189
187
  declare_schema!
190
188
  listen
191
- mysql2
192
189
  pry
193
190
  pry-byebug
194
191
  rails (~> 5.2, >= 5.2.4.3)
195
192
  responders
196
193
  rspec
197
194
  rubocop
198
- sqlite3
199
195
  yard
200
196
 
201
197
  BUNDLED WITH
data/README.md CHANGED
@@ -93,8 +93,8 @@ turn all tables into `utf8mb4` supporting tables:
93
93
  ```ruby
94
94
  # frozen_string_literal: true
95
95
 
96
- Generators::DeclareSchema::Migrator.default_charset = "utf8mb4"
97
- Generators::DeclareSchema::Migrator.default_collation = "utf8mb4_general"
96
+ Generators::DeclareSchema::Migration::Migrator.default_charset = "utf8mb4"
97
+ Generators::DeclareSchema::Migration::Migrator.default_collation = "utf8mb4_bin"
98
98
  ```
99
99
 
100
100
  ### Table Configuration
@@ -109,7 +109,7 @@ like the following:
109
109
  # frozen_string_literal: true
110
110
 
111
111
  class Comment < ActiveRecord::Base
112
- fields charset: "utf8mb4", collation: "utf8mb4_general" do
112
+ fields charset: "utf8mb4", collation: "utf8mb4_bin" do
113
113
  subject :string, limit: 255
114
114
  content :text, limit: 0xffff_ffff
115
115
  end
@@ -131,7 +131,7 @@ look like the following:
131
131
  class Comment < ActiveRecord::Base
132
132
  fields do
133
133
  subject :string, limit: 255
134
- context :text, limit: 0xffff_ffff, charset: "utf8mb4", collation: "utf8mb4_general"
134
+ context :text, limit: 0xffff_ffff, charset: "utf8mb4", collation: "utf8mb4_bin"
135
135
  end
136
136
  end
137
137
  ```
data/Rakefile CHANGED
@@ -30,15 +30,28 @@ namespace "test" do
30
30
  if args.force || !File.directory?(TESTAPP_PATH)
31
31
  FileUtils.remove_entry_secure(TESTAPP_PATH, true)
32
32
  sh %(#{BIN} new #{TESTAPP_PATH} --skip-wizard --skip-bundle)
33
- FileUtils.chdir TESTAPP_PATH
33
+ FileUtils.chdir(TESTAPP_PATH)
34
+ begin
35
+ require 'mysql2'
36
+ if ENV['MYSQL_PORT']
37
+ sh "(echo 'H';
38
+ echo '1,$s/localhost/127.0.0.1/';
39
+ echo '/host:/';
40
+ echo 'a';
41
+ echo ' port: #{ENV['MYSQL_PORT']}';
42
+ echo '.';
43
+ echo w;
44
+ echo q) | ed #{TESTAPP_PATH}/config/database.yml || echo ed failed!"
45
+ end
46
+ rescue LoadError
47
+ end
34
48
  sh "bundle install"
35
49
  sh "(echo '';
36
- echo \"gem 'irt', :group => :development\";
37
- echo \"gem 'therubyracer'\";
38
- echo \"gem 'kramdown'\") > Gemfile"
50
+ echo \"gem 'irb', :group => :development\") >> Gemfile"
39
51
  sh "echo '' > app/models/.gitignore" # because git reset --hard would rm the dir
40
52
  rm ".gitignore" # we need to reset everything in a testapp
41
53
  sh "git init && git add . && git commit -m \"initial commit\""
54
+ sh "rake db:create"
42
55
  puts "The testapp has been created in '#{TESTAPP_PATH}'"
43
56
  else
44
57
  FileUtils.chdir(TESTAPP_PATH)
@@ -8,4 +8,4 @@ require_relative '../lib/declare_schema/version'
8
8
 
9
9
  ARGV.freeze
10
10
 
11
- DeclareSchema::Command.run(:DeclareSchema, ARGV.dup, DeclareSchema::VERSION)
11
+ DeclareSchema::Command.run('declare_schema', ARGV.dup, DeclareSchema::VERSION, path: File.expand_path('..', __dir__))
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.authors = ['Invoca Development adapted from hobo_fields by Tom Locke']
7
7
  s.email = 'development@invoca.com'
8
8
  s.homepage = 'https://github.com/Invoca/declare_schema'
9
- s.summary = 'Database migration generator for Rails'
9
+ s.summary = 'Database schema declaration and migration generator for Rails'
10
10
  s.description = 'Declare your Rails/active_record model schemas and have database migrations generated for you!'
11
11
  s.name = "declare_schema"
12
12
  s.version = DeclareSchema::VERSION
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler", "< 2"
7
+ gem "climate_control", "~> 0.2"
8
+ gem "pry"
9
+ gem "pry-byebug"
10
+ gem "rails", "~> 4.2"
11
+ gem "responders"
12
+ gem "rspec"
13
+ gem "rubocop"
14
+ gem "yard"
15
+ gem "mysql2"
16
+
17
+ group :testapp do
18
+ gem "bootsnap", ">= 1.1.0", require: false
19
+ gem "listen"
20
+ end
21
+
22
+ gemspec path: "../"
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
7
7
  gem "climate_control", "~> 0.2"
8
8
  gem "pry"
9
9
  gem "pry-byebug"
10
- gem "mysql2"
11
10
  gem "rails", "~> 4.2"
12
11
  gem "responders"
13
12
  gem "rspec"
14
13
  gem "rubocop"
15
- gem "sqlite3", "~> 1.3.0"
16
14
  gem "yard"
15
+ gem "sqlite3", "~> 1.3.0"
17
16
 
18
17
  group :testapp do
19
18
  gem "bootsnap", ">= 1.1.0", require: false
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler", "< 2"
7
+ gem "climate_control", "~> 0.2"
8
+ gem "pry"
9
+ gem "pry-byebug"
10
+ gem "rails", "~> 5.2"
11
+ gem "responders"
12
+ gem "rspec"
13
+ gem "rubocop"
14
+ gem "yard"
15
+ gem "mysql2"
16
+
17
+ group :testapp do
18
+ gem "bootsnap", ">= 1.1.0", require: false
19
+ gem "listen"
20
+ end
21
+
22
+ gemspec path: "../"
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
7
7
  gem "climate_control", "~> 0.2"
8
8
  gem "pry"
9
9
  gem "pry-byebug"
10
- gem "mysql2"
11
10
  gem "rails", "~> 5.2"
12
11
  gem "responders"
13
12
  gem "rspec"
14
13
  gem "rubocop"
15
- gem "sqlite3"
16
14
  gem "yard"
15
+ gem "sqlite3"
17
16
 
18
17
  group :testapp do
19
18
  gem "bootsnap", ">= 1.1.0", require: false
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "bundler", "< 2"
7
+ gem "climate_control", "~> 0.2"
8
+ gem "pry"
9
+ gem "pry-byebug"
10
+ gem "rails", "~> 6.1"
11
+ gem "responders"
12
+ gem "rspec"
13
+ gem "rubocop"
14
+ gem "yard"
15
+ gem "mysql2"
16
+
17
+ group :testapp do
18
+ gem "bootsnap", ">= 1.1.0", require: false
19
+ gem "listen"
20
+ end
21
+
22
+ gemspec path: "../"
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
7
7
  gem "climate_control", "~> 0.2"
8
8
  gem "pry"
9
9
  gem "pry-byebug"
10
- gem "mysql2"
11
- gem "rails", "~> 6.0"
10
+ gem "rails", "~> 6.1"
12
11
  gem "responders"
13
12
  gem "rspec"
14
13
  gem "rubocop"
15
- gem "sqlite3"
16
14
  gem "yard"
15
+ gem "sqlite3"
17
16
 
18
17
  group :testapp do
19
18
  gem "bootsnap", ">= 1.1.0", require: false
@@ -16,7 +16,7 @@ module DeclareSchema
16
16
  EOS
17
17
 
18
18
  class << self
19
- def run(gem, args, version)
19
+ def run(gem, args, version, gemfile_options = {})
20
20
  command = args.shift
21
21
 
22
22
  case command
@@ -38,10 +38,17 @@ module DeclareSchema
38
38
  end
39
39
  template_path = File.join(Dir.tmpdir, "declare_schema_app_template")
40
40
  File.open(template_path, 'w') do |file|
41
- file.puts "gem '#{gem}', '>= #{version}'"
41
+ file.puts ["gem '#{gem}', '>= #{version}'", (gemfile_options.inspect unless gemfile_options.empty?)].compact.join(', ')
42
42
  end
43
43
  puts "Generating Rails infrastructure..."
44
- system("rails new #{app_name} #{args * ' '} -m #{template_path}")
44
+ database_option =
45
+ begin
46
+ require 'mysql2'
47
+ ' -d mysql'
48
+ rescue LoadError
49
+ end
50
+ puts("rails new #{app_name} #{args * ' '} -m #{template_path}#{database_option}")
51
+ system("rails new #{app_name} #{args * ' '} -m #{template_path}#{database_option}")
45
52
  File.delete(template_path)
46
53
 
47
54
  when /^(g|generate|destroy)$/
@@ -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
 
@@ -13,7 +13,6 @@ module DeclareSchema
13
13
  MYSQL_TEXT_LIMITS_ASCENDING = [MYSQL_TINYTEXT_LIMIT, MYSQL_TEXT_LIMIT, MYSQL_MEDIUMTEXT_LIMIT, MYSQL_LONGTEXT_LIMIT].freeze
14
14
 
15
15
  class << self
16
- # method for easy stubbing in tests
17
16
  def mysql_text_limits?
18
17
  if defined?(@mysql_text_limits)
19
18
  @mysql_text_limits
@@ -33,7 +32,8 @@ module DeclareSchema
33
32
 
34
33
  attr_reader :model, :name, :type, :position, :options
35
34
 
36
- def initialize(model, name, type, options = {})
35
+ def initialize(model, name, type, position: 0, **options)
36
+ # TODO: TECH-5116
37
37
  # Invoca change - searching for the primary key was causing an additional database read on every model load. Assume
38
38
  # "id" which works for invoca.
39
39
  # raise ArgumentError, "you cannot provide a field spec for the primary key" if name == model.primary_key
@@ -43,9 +43,8 @@ module DeclareSchema
43
43
  @name = name.to_sym
44
44
  type.is_a?(Symbol) or raise ArgumentError, "type must be a Symbol; got #{type.inspect}"
45
45
  @type = type
46
- position_option = options.delete(:position)
46
+ @position = position
47
47
  @options = options
48
-
49
48
  case type
50
49
  when :text
51
50
  @options[:default] and raise "default may not be given for :text field #{model}##{@name}"
@@ -54,11 +53,20 @@ module DeclareSchema
54
53
  end
55
54
  when :string
56
55
  @options[:limit] or raise "limit must be given for :string field #{model}##{@name}: #{@options.inspect}; do you want `limit: 255`?"
56
+ when :bigint
57
+ @type = :integer
58
+ @options = options.merge(limit: 8)
59
+ end
60
+
61
+ if type.in?([:text, :string])
62
+ if ActiveRecord::Base.connection.class.name.match?(/mysql/i)
63
+ @options[:charset] ||= model.table_options[:charset] || Generators::DeclareSchema::Migration::Migrator.default_charset
64
+ @options[:collation] ||= model.table_options[:collation] || Generators::DeclareSchema::Migration::Migrator.default_collation
65
+ end
57
66
  else
58
- @options[:collation] and raise "collation may only given for :string and :text fields"
59
67
  @options[:charset] and raise "charset may only given for :string and :text fields"
68
+ @options[:collation] and raise "collation may only given for :string and :text fields"
60
69
  end
61
- @position = position_option || model.field_specs.length
62
70
  end
63
71
 
64
72
  TYPE_SYNONYMS = { timestamp: :datetime }.freeze
@@ -105,16 +113,12 @@ module DeclareSchema
105
113
  @options[:default]
106
114
  end
107
115
 
108
- def collation
109
- if ActiveRecord::Base.connection.class.name.match?(/mysql/i)
110
- (@options[:collation] || model.table_options[:collation] || Generators::DeclareSchema::Migration::Migrator.default_collation).to_s
111
- end
116
+ def charset
117
+ @options[:charset]
112
118
  end
113
119
 
114
- def charset
115
- if ActiveRecord::Base.connection.class.name.match?(/mysql/i)
116
- (@options[:charset] || model.table_options[:charset] || Generators::DeclareSchema::Migration::Migrator.default_charset).to_s
117
- end
120
+ def collation
121
+ @options[:collation]
118
122
  end
119
123
 
120
124
  def same_type?(col_spec)
@@ -179,9 +183,9 @@ module DeclareSchema
179
183
  defaults = connection.select_one(<<~EOS)
180
184
  SELECT C.character_set_name, C.collation_name
181
185
  FROM information_schema.`COLUMNS` C
182
- WHERE C.table_schema = #{connection.quote_string(database_name)} AND
183
- C.table_name = #{connection.quote_string(table_name)} AND
184
- C.column_name = #{connection.quote_string(column_name)};
186
+ WHERE C.table_schema = '#{connection.quote_string(database_name)}' AND
187
+ C.table_name = '#{connection.quote_string(table_name)}' AND
188
+ C.column_name = '#{connection.quote_string(column_name)}';
185
189
  EOS
186
190
 
187
191
  defaults["character_set_name"] or raise "character_set_name missing from #{defaults.inspect}"