schema_plus_core 2.2.2 → 3.1.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/prs.yml +173 -0
- data/.gitignore +1 -0
- data/.simplecov +20 -0
- data/Gemfile +4 -1
- data/README.md +17 -9
- data/Rakefile +2 -0
- data/gemfiles/Gemfile.base +1 -1
- data/gemfiles/activerecord-5.2/Gemfile.base +2 -1
- data/gemfiles/activerecord-5.2/Gemfile.mysql2 +2 -2
- data/gemfiles/activerecord-5.2/Gemfile.postgresql +2 -2
- data/gemfiles/activerecord-5.2/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-6.0/Gemfile.base +4 -0
- data/gemfiles/activerecord-6.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-6.0/Gemfile.postgresql +10 -0
- data/gemfiles/{activerecord-5.0 → activerecord-6.0}/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-6.1/Gemfile.base +4 -0
- data/gemfiles/activerecord-6.1/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-6.1/Gemfile.postgresql +10 -0
- data/gemfiles/{activerecord-5.1 → activerecord-6.1}/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-7.0/Gemfile.base +4 -0
- data/gemfiles/activerecord-7.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-7.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-7.0/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/core/active_record/base.rb +6 -4
- data/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb +65 -26
- data/lib/schema_plus/core/active_record/connection_adapters/mysql2_adapter.rb +17 -7
- data/lib/schema_plus/core/active_record/connection_adapters/postgresql/schema_dumper.rb +11 -5
- data/lib/schema_plus/core/active_record/connection_adapters/postgresql_adapter.rb +24 -32
- data/lib/schema_plus/core/active_record/connection_adapters/sqlite3_adapter.rb +15 -5
- data/lib/schema_plus/core/active_record/connection_adapters/table_definition.rb +18 -10
- data/lib/schema_plus/core/active_record/migration/command_recorder.rb +4 -2
- data/lib/schema_plus/core/active_record/schema.rb +2 -0
- data/lib/schema_plus/core/active_record/schema_dumper.rb +70 -29
- data/lib/schema_plus/core/middleware.rb +3 -1
- data/lib/schema_plus/core/schema_dump.rb +14 -5
- data/lib/schema_plus/core/sql_struct.rb +4 -2
- data/lib/schema_plus/core/version.rb +3 -1
- data/lib/schema_plus/core.rb +4 -4
- data/schema_dev.yml +8 -5
- data/schema_plus_core.gemspec +9 -10
- data/spec/column_spec.rb +3 -2
- data/spec/dumper_spec.rb +33 -9
- data/spec/index_spec.rb +2 -0
- data/spec/middleware_spec.rb +5 -2
- data/spec/spec_helper.rb +3 -3
- data/spec/sql_struct_spec.rb +2 -0
- data/spec/support/enableable.rb +2 -4
- data/spec/support/test_reporter.rb +3 -1
- metadata +43 -89
- data/.travis.yml +0 -25
- data/gemfiles/activerecord-5.0/Gemfile.base +0 -3
- data/gemfiles/activerecord-5.0/Gemfile.mysql2 +0 -10
- data/gemfiles/activerecord-5.0/Gemfile.postgresql +0 -10
- data/gemfiles/activerecord-5.1/Gemfile.base +0 -3
- data/gemfiles/activerecord-5.1/Gemfile.mysql2 +0 -10
- data/gemfiles/activerecord-5.1/Gemfile.postgresql +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4586a053807f1a6935ef1198491c6ab3c9ea3a1a11869f18b042ca4b380d20b3
|
4
|
+
data.tar.gz: 89c538ce9a32abf2150e5cea263fbbfe8c526e5b225494be653e09a03bbe3525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf582e7744f5d17225ae48033a912cc0b2f27e3c9bea09cf5fe02334dc794b821281bc5c5ae89391a6385c4aca407f1a31d0a54076396b337ac8e3e5c68fd2c2
|
7
|
+
data.tar.gz: 2d9cd2b0b7ee4f326cf98366b3f20fb1acf7fd37f40614ac6e66e9c7379493afbcf68757f511e90663b4ccb64cb0acefb6225ec61ad8408407b8c1448bb88aac
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
+
# ./schema_dev.yml
|
3
|
+
# Please do not edit this file; any changes will be overwritten next time
|
4
|
+
# schema_dev gets run.
|
5
|
+
---
|
6
|
+
name: CI PR Builds
|
7
|
+
'on':
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
pull_request:
|
12
|
+
concurrency:
|
13
|
+
group: ci-${{ github.ref }}
|
14
|
+
cancel-in-progress: true
|
15
|
+
jobs:
|
16
|
+
test:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby:
|
22
|
+
- '2.5'
|
23
|
+
- '2.7'
|
24
|
+
- '3.0'
|
25
|
+
- '3.1'
|
26
|
+
activerecord:
|
27
|
+
- '5.2'
|
28
|
+
- '6.0'
|
29
|
+
- '6.1'
|
30
|
+
- '7.0'
|
31
|
+
db:
|
32
|
+
- mysql2
|
33
|
+
- sqlite3
|
34
|
+
- skip
|
35
|
+
dbversion:
|
36
|
+
- skip
|
37
|
+
exclude:
|
38
|
+
- ruby: '3.0'
|
39
|
+
activerecord: '5.2'
|
40
|
+
- ruby: '3.1'
|
41
|
+
activerecord: '5.2'
|
42
|
+
- ruby: '2.5'
|
43
|
+
activerecord: '7.0'
|
44
|
+
- db: skip
|
45
|
+
dbversion: skip
|
46
|
+
include:
|
47
|
+
- ruby: '2.5'
|
48
|
+
activerecord: '5.2'
|
49
|
+
db: postgresql
|
50
|
+
dbversion: '9.6'
|
51
|
+
- ruby: '2.5'
|
52
|
+
activerecord: '6.0'
|
53
|
+
db: postgresql
|
54
|
+
dbversion: '9.6'
|
55
|
+
- ruby: '2.5'
|
56
|
+
activerecord: '6.1'
|
57
|
+
db: postgresql
|
58
|
+
dbversion: '9.6'
|
59
|
+
- ruby: '2.7'
|
60
|
+
activerecord: '5.2'
|
61
|
+
db: postgresql
|
62
|
+
dbversion: '9.6'
|
63
|
+
- ruby: '2.7'
|
64
|
+
activerecord: '6.0'
|
65
|
+
db: postgresql
|
66
|
+
dbversion: '9.6'
|
67
|
+
- ruby: '2.7'
|
68
|
+
activerecord: '6.1'
|
69
|
+
db: postgresql
|
70
|
+
dbversion: '9.6'
|
71
|
+
- ruby: '2.7'
|
72
|
+
activerecord: '7.0'
|
73
|
+
db: postgresql
|
74
|
+
dbversion: '9.6'
|
75
|
+
- ruby: '3.0'
|
76
|
+
activerecord: '6.0'
|
77
|
+
db: postgresql
|
78
|
+
dbversion: '9.6'
|
79
|
+
- ruby: '3.0'
|
80
|
+
activerecord: '6.1'
|
81
|
+
db: postgresql
|
82
|
+
dbversion: '9.6'
|
83
|
+
- ruby: '3.0'
|
84
|
+
activerecord: '7.0'
|
85
|
+
db: postgresql
|
86
|
+
dbversion: '9.6'
|
87
|
+
- ruby: '3.1'
|
88
|
+
activerecord: '6.0'
|
89
|
+
db: postgresql
|
90
|
+
dbversion: '9.6'
|
91
|
+
- ruby: '3.1'
|
92
|
+
activerecord: '6.1'
|
93
|
+
db: postgresql
|
94
|
+
dbversion: '9.6'
|
95
|
+
- ruby: '3.1'
|
96
|
+
activerecord: '7.0'
|
97
|
+
db: postgresql
|
98
|
+
dbversion: '9.6'
|
99
|
+
env:
|
100
|
+
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
|
101
|
+
POSTGRESQL_DB_HOST: 127.0.0.1
|
102
|
+
POSTGRESQL_DB_USER: schema_plus_test
|
103
|
+
POSTGRESQL_DB_PASS: database
|
104
|
+
MYSQL_DB_HOST: 127.0.0.1
|
105
|
+
MYSQL_DB_USER: root
|
106
|
+
MYSQL_DB_PASS: database
|
107
|
+
steps:
|
108
|
+
- uses: actions/checkout@v2
|
109
|
+
- name: Set up Ruby
|
110
|
+
uses: ruby/setup-ruby@v1
|
111
|
+
with:
|
112
|
+
ruby-version: "${{ matrix.ruby }}"
|
113
|
+
bundler-cache: true
|
114
|
+
- name: Run bundle update
|
115
|
+
run: bundle update
|
116
|
+
- name: Start Postgresql
|
117
|
+
if: matrix.db == 'postgresql'
|
118
|
+
run: |
|
119
|
+
docker run --rm --detach \
|
120
|
+
-e POSTGRES_USER=$POSTGRESQL_DB_USER \
|
121
|
+
-e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
|
122
|
+
-p 5432:5432 \
|
123
|
+
--health-cmd "pg_isready -q" \
|
124
|
+
--health-interval 5s \
|
125
|
+
--health-timeout 5s \
|
126
|
+
--health-retries 5 \
|
127
|
+
--name database postgres:${{ matrix.dbversion }}
|
128
|
+
- name: Start Mysql
|
129
|
+
if: matrix.db == 'mysql2'
|
130
|
+
run: |
|
131
|
+
docker run --rm --detach \
|
132
|
+
-e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
|
133
|
+
-p 3306:3306 \
|
134
|
+
--health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
|
135
|
+
--health-interval 5s \
|
136
|
+
--health-timeout 5s \
|
137
|
+
--health-retries 5 \
|
138
|
+
--name database mysql:5.6
|
139
|
+
- name: Wait for database to start
|
140
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
141
|
+
run: |
|
142
|
+
COUNT=0
|
143
|
+
ATTEMPTS=20
|
144
|
+
until [[ $COUNT -eq $ATTEMPTS ]]; do
|
145
|
+
[ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
|
146
|
+
echo $(( COUNT++ )) > /dev/null
|
147
|
+
sleep 2
|
148
|
+
done
|
149
|
+
- name: Create testing database
|
150
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
151
|
+
run: bundle exec rake create_ci_database
|
152
|
+
- name: Run tests
|
153
|
+
run: bundle exec rake spec
|
154
|
+
- name: Shutdown database
|
155
|
+
if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
|
156
|
+
run: docker stop database
|
157
|
+
- name: Coveralls Parallel
|
158
|
+
if: "${{ !env.ACT }}"
|
159
|
+
uses: coverallsapp/github-action@master
|
160
|
+
with:
|
161
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
162
|
+
flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
|
163
|
+
parallel: true
|
164
|
+
finish:
|
165
|
+
needs: test
|
166
|
+
runs-on: ubuntu-latest
|
167
|
+
steps:
|
168
|
+
- name: Coveralls Finished
|
169
|
+
if: "${{ !env.ACT }}"
|
170
|
+
uses: coverallsapp/github-action@master
|
171
|
+
with:
|
172
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
173
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.simplecov
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.configure do
|
4
|
+
enable_coverage :branch
|
5
|
+
add_filter '/spec/'
|
6
|
+
|
7
|
+
add_group 'Binaries', '/bin/'
|
8
|
+
add_group 'Libraries', '/lib/'
|
9
|
+
|
10
|
+
if ENV['CI']
|
11
|
+
require 'simplecov-lcov'
|
12
|
+
|
13
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
14
|
+
c.report_with_single_file = true
|
15
|
+
c.single_report_path = 'coverage/lcov.info'
|
16
|
+
end
|
17
|
+
|
18
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
19
|
+
end
|
20
|
+
end
|
data/Gemfile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "http://rubygems.org"
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
|
7
|
+
gemfile_local = File.expand_path '../Gemfile.local', __FILE__
|
8
|
+
eval File.read(gemfile_local), binding, gemfile_local if File.exist? gemfile_local
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/schema_plus_core.svg)](http://badge.fury.io/rb/schema_plus_core)
|
2
|
-
[![Build Status](https://
|
2
|
+
[![Build Status](https://github.com/SchemaPlus/schema_plus_core/actions/workflows/prs.yml/badge.svg)](https://github.com/SchemaPlus/schema_plus_core/actions)
|
3
3
|
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_core.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_core)
|
4
4
|
|
5
5
|
# SchemaPlus::Core
|
@@ -23,12 +23,19 @@ SchemaPlus::Core is tested on:
|
|
23
23
|
|
24
24
|
<!-- SCHEMA_DEV: MATRIX - begin -->
|
25
25
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
26
|
-
* ruby **2.
|
27
|
-
* ruby **2.
|
28
|
-
* ruby **2.
|
29
|
-
* ruby **2.
|
30
|
-
* ruby **2.
|
31
|
-
* ruby **2.
|
26
|
+
* ruby **2.5** with activerecord **5.2**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
27
|
+
* ruby **2.5** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
28
|
+
* ruby **2.5** with activerecord **6.1**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
29
|
+
* ruby **2.7** with activerecord **5.2**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
30
|
+
* ruby **2.7** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
31
|
+
* ruby **2.7** with activerecord **6.1**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
32
|
+
* ruby **2.7** with activerecord **7.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
33
|
+
* ruby **3.0** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
34
|
+
* ruby **3.0** with activerecord **6.1**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
35
|
+
* ruby **3.0** with activerecord **7.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
36
|
+
* ruby **3.1** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
37
|
+
* ruby **3.1** with activerecord **6.1**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
38
|
+
* ruby **3.1** with activerecord **7.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
32
39
|
|
33
40
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
34
41
|
|
@@ -444,6 +451,8 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
|
|
444
451
|
|
445
452
|
## Release Notes
|
446
453
|
|
454
|
+
* 3.0.0 Drop AR < 5.2 and add AR 6.0 support. Drop Ruby < 2.5 and add Ruby 3.0 support.
|
455
|
+
* 2.2.3 Fix dumping complex expression based indexes in AR 5.x
|
447
456
|
* 2.2.2 Fixed dumping tables in postgresql in AR 5.2 when the PK is not a bigint.
|
448
457
|
* 2.2.1 Fixed expression index handling in AR5.x.
|
449
458
|
* 2.2.0 Added AR5.2 support. Thanks to [@jeremyyap](https://github.com/jeremyyap)
|
@@ -477,7 +486,7 @@ Some things to know about to help you develop and test:
|
|
477
486
|
* **schema_dev**: SchemaPlus::Core uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
478
487
|
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
479
488
|
versions that the gem supports, both locally and on
|
480
|
-
[
|
489
|
+
[github actions](https://github.com/SchemaPlus/schema_plus_core/actions)
|
481
490
|
|
482
491
|
To to run rspec locally on the full matrix, do:
|
483
492
|
|
@@ -489,7 +498,6 @@ Some things to know about to help you develop and test:
|
|
489
498
|
The matrix of configurations is specified in `schema_dev.yml` in
|
490
499
|
the project root.
|
491
500
|
|
492
|
-
|
493
501
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
494
502
|
|
495
503
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin -->
|
data/Rakefile
CHANGED
data/gemfiles/Gemfile.base
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
@@ -22,25 +24,25 @@ module SchemaPlus
|
|
22
24
|
# relies on the undocumented return value.
|
23
25
|
def has_many(name, scope = nil, **options, &extension)
|
24
26
|
SchemaMonkey::Middleware::Model::Association::Declaration.start(model: self, name: name, scope: scope, options: options, extension: extension) do |env|
|
25
|
-
env.result = super(env.name, env.scope, env.options, &env.extension)
|
27
|
+
env.result = super(env.name, env.scope, **env.options, &env.extension)
|
26
28
|
end.result
|
27
29
|
end
|
28
30
|
|
29
31
|
def has_one(name, scope = nil, **options, &extension)
|
30
32
|
SchemaMonkey::Middleware::Model::Association::Declaration.start(model: self, name: name, scope: scope, options: options, extension: extension) do |env|
|
31
|
-
env.result = super(env.name, env.scope, env.options, &env.extension)
|
33
|
+
env.result = super(env.name, env.scope, **env.options, &env.extension)
|
32
34
|
end.result
|
33
35
|
end
|
34
36
|
|
35
37
|
def has_and_belongs_to_many(name, scope = nil, **options, &extension)
|
36
38
|
SchemaMonkey::Middleware::Model::Association::Declaration.start(model: self, name: name, scope: scope, options: options, extension: extension) do |env|
|
37
|
-
env.result = super(env.name, env.scope, env.options, &env.extension)
|
39
|
+
env.result = super(env.name, env.scope, **env.options, &env.extension)
|
38
40
|
end.result
|
39
41
|
end
|
40
42
|
|
41
43
|
def belongs_to(name, scope = nil, **options, &extension)
|
42
44
|
SchemaMonkey::Middleware::Model::Association::Declaration.start(model: self, name: name, scope: scope, options: options, extension: extension) do |env|
|
43
|
-
env.result = super(env.name, env.scope, env.options, &env.extension)
|
45
|
+
env.result = super(env.name, env.scope, **env.options, &env.extension)
|
44
46
|
end.result
|
45
47
|
end
|
46
48
|
end
|
@@ -1,62 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
4
6
|
module ConnectionAdapters
|
5
7
|
module AbstractAdapter
|
6
|
-
|
7
|
-
def add_column(table_name, name, type, options = {})
|
8
|
+
def add_column(table_name, name, type, **options)
|
8
9
|
options = options.deep_dup
|
9
10
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :add, table_name: table_name, column_name: name, type: type, implements_reference: options.delete(:_implements_reference), options: options) do |env|
|
10
|
-
super env.table_name, env.column_name, env.type, env.options
|
11
|
+
super env.table_name, env.column_name, env.type, **env.options
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
def add_index_options(table_name, column_names, options
|
15
|
+
def add_index_options(table_name, column_names, **options)
|
15
16
|
SchemaMonkey::Middleware::Sql::IndexComponents.start(connection: self, table_name: table_name, column_names: Array.wrap(column_names), options: options.deep_dup, sql: SqlStruct::IndexComponents.new) { |env|
|
16
|
-
env.sql.name, env.sql.type, env.sql.columns, env.sql.options, env.sql.algorithm, env.sql.using = super env.table_name, env.column_names, env.options
|
17
|
-
}.sql.
|
17
|
+
env.sql.name, env.sql.type, env.sql.columns, env.sql.options, env.sql.algorithm, env.sql.using = super env.table_name, env.column_names, **env.options
|
18
|
+
}.sql.to_h.values
|
18
19
|
end
|
19
20
|
|
20
|
-
def add_reference(table_name, name, options
|
21
|
+
def add_reference(table_name, name, **options)
|
21
22
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :add, table_name: table_name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
|
22
|
-
super env.table_name, env.column_name.sub(/_id$/, ''), env.options.merge(_implements_reference: true)
|
23
|
+
super env.table_name, env.column_name.sub(/_id$/, ''), **env.options.merge(_implements_reference: true)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
def create_table(table_name, options
|
27
|
+
def create_table(table_name, **options, &block)
|
27
28
|
SchemaMonkey::Middleware::Migration::CreateTable.start(connection: self, table_name: table_name, options: options.deep_dup, block: block) do |env|
|
28
|
-
super env.table_name, env.options, &env.block
|
29
|
+
super env.table_name, **env.options, &env.block
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
def drop_table(table_name, options
|
33
|
+
def drop_table(table_name, **options)
|
33
34
|
SchemaMonkey::Middleware::Migration::DropTable.start(connection: self, table_name: table_name, options: options.dup) do |env|
|
34
|
-
super env.table_name, env.options
|
35
|
+
super env.table_name, **env.options
|
35
36
|
end
|
36
37
|
end
|
38
|
+
end
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
if Gem::Version.new(::ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1')
|
42
|
+
module ConnectionAdapters
|
43
|
+
module AbstractAdapter
|
44
|
+
# replaced version to handle array of columns with expressions
|
45
|
+
def quoted_columns_for_index(column_names, **options)
|
46
|
+
output_columns = []
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
column_names.each do |column|
|
49
|
+
if column.is_a?(String) && column.include?('(')
|
50
|
+
output_columns << column
|
51
|
+
else
|
52
|
+
quoted = {column.to_sym => quote_column_name(column).dup}
|
53
|
+
output_columns.concat add_options_for_index_columns(quoted, **options).values
|
54
|
+
end
|
48
55
|
end
|
56
|
+
|
57
|
+
output_columns
|
49
58
|
end
|
50
59
|
|
51
|
-
|
52
|
-
end
|
53
|
-
private :quoted_columns_for_index
|
60
|
+
private :quoted_columns_for_index
|
54
61
|
|
62
|
+
module SchemaCreation
|
55
63
|
|
56
|
-
|
64
|
+
def add_column_options!(sql, options)
|
65
|
+
sql << +" " + SchemaMonkey::Middleware::Sql::ColumnOptions.start(caller: self, connection: self.instance_variable_get('@conn'), sql: +"", column: options[:column], options: options.except(:column)) { |env|
|
66
|
+
super env.sql, env.options.merge(column: env.column)
|
67
|
+
}.sql.lstrip
|
68
|
+
end
|
57
69
|
|
70
|
+
def visit_TableDefinition(o)
|
71
|
+
SchemaMonkey::Middleware::Sql::Table.start(caller: self, connection: self.instance_variable_get('@conn'), table_definition: o, sql: SqlStruct::Table.new) { |env|
|
72
|
+
env.sql.parse! super env.table_definition
|
73
|
+
}.sql.assemble
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
else
|
79
|
+
# In AR 6.1+ quoted_columns_for_index has slightly different paramater style and a different return type
|
80
|
+
# Also SchemaCreation is no longer nested beneath AbstractAdapter
|
81
|
+
module ConnectionAdapters
|
82
|
+
module AbstractAdapter
|
83
|
+
# replaced version to handle array of columns with expressions
|
84
|
+
def quoted_columns_for_index(column_names, options)
|
85
|
+
column_names.each_with_object([]) do |column, output_columns|
|
86
|
+
if column.is_a?(String) && column.include?('(')
|
87
|
+
output_columns << column
|
88
|
+
else
|
89
|
+
quoted = {column.to_sym => quote_column_name(column).dup}
|
90
|
+
output_columns.concat add_options_for_index_columns(quoted, **options).values
|
91
|
+
end
|
92
|
+
end.join(', ')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module SchemaCreation
|
58
97
|
def add_column_options!(sql, options)
|
59
|
-
sql << " " + SchemaMonkey::Middleware::Sql::ColumnOptions.start(caller: self, connection: self.instance_variable_get('@conn'), sql: "", column: options[:column], options: options.except(:column)) { |env|
|
98
|
+
sql << +" " + SchemaMonkey::Middleware::Sql::ColumnOptions.start(caller: self, connection: self.instance_variable_get('@conn'), sql: +"", column: options[:column], options: options.except(:column)) { |env|
|
60
99
|
super env.sql, env.options.merge(column: env.column)
|
61
100
|
}.sql.lstrip
|
62
101
|
end
|