schema_plus_core 2.2.1 → 3.0.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/prs.yml +134 -0
- data/.gitignore +1 -0
- data/.simplecov +20 -0
- data/Gemfile +2 -0
- data/README.md +10 -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/lib/schema_plus/core/active_record/base.rb +6 -4
- data/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb +15 -13
- data/lib/schema_plus/core/active_record/connection_adapters/mysql2_adapter.rb +8 -6
- data/lib/schema_plus/core/active_record/connection_adapters/postgresql/schema_dumper.rb +3 -2
- data/lib/schema_plus/core/active_record/connection_adapters/postgresql_adapter.rb +9 -25
- data/lib/schema_plus/core/active_record/connection_adapters/sqlite3_adapter.rb +6 -4
- data/lib/schema_plus/core/active_record/connection_adapters/table_definition.rb +8 -8
- 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 +56 -27
- data/lib/schema_plus/core/middleware.rb +2 -0
- data/lib/schema_plus/core/schema_dump.rb +6 -3
- 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 +3 -4
- data/schema_dev.yml +5 -5
- data/schema_plus_core.gemspec +9 -10
- data/spec/column_spec.rb +3 -2
- data/spec/dumper_spec.rb +25 -0
- data/spec/index_spec.rb +2 -0
- data/spec/middleware_spec.rb +5 -2
- data/spec/spec_helper.rb +9 -2
- data/spec/sql_struct_spec.rb +2 -0
- data/spec/support/enableable.rb +2 -4
- data/spec/support/test_reporter.rb +3 -1
- metadata +33 -87
- 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
- data/gemfiles/activerecord-5.1/Gemfile.sqlite3 +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7652a3a8995b2ceb95a9c67ed8e03dc2f5281414b2495c5dbb715b7ca5946fb
|
4
|
+
data.tar.gz: 225bc856147f2e0cb1bdf32571d4e36d3cd4fd181a1dd2e7b385d8203383fef4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369dca1de7a89d21963f3de3ba8b045b7c09c4f80188e63981c2c0b9cc0ed1d82618d372e42070390e75ca778a3b7d107a3d3991d6907ce05a6b0d00022f5508
|
7
|
+
data.tar.gz: a1be30796efe7e9d767168a686b723f482f525df6ab19108eba7a64df1c07207a4dddde7ba2991d3e583174fd488f06b605d2a95c35cbbad6a442e16de7d5bd6
|
@@ -0,0 +1,134 @@
|
|
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
|
+
activerecord:
|
26
|
+
- '5.2'
|
27
|
+
- '6.0'
|
28
|
+
db:
|
29
|
+
- mysql2
|
30
|
+
- sqlite3
|
31
|
+
- skip
|
32
|
+
dbversion:
|
33
|
+
- skip
|
34
|
+
exclude:
|
35
|
+
- ruby: '3.0'
|
36
|
+
activerecord: '5.2'
|
37
|
+
- db: skip
|
38
|
+
dbversion: skip
|
39
|
+
include:
|
40
|
+
- ruby: '2.5'
|
41
|
+
activerecord: '5.2'
|
42
|
+
db: postgresql
|
43
|
+
dbversion: '9.6'
|
44
|
+
- ruby: '2.5'
|
45
|
+
activerecord: '6.0'
|
46
|
+
db: postgresql
|
47
|
+
dbversion: '9.6'
|
48
|
+
- ruby: '2.7'
|
49
|
+
activerecord: '5.2'
|
50
|
+
db: postgresql
|
51
|
+
dbversion: '9.6'
|
52
|
+
- ruby: '2.7'
|
53
|
+
activerecord: '6.0'
|
54
|
+
db: postgresql
|
55
|
+
dbversion: '9.6'
|
56
|
+
- ruby: '3.0'
|
57
|
+
activerecord: '6.0'
|
58
|
+
db: postgresql
|
59
|
+
dbversion: '9.6'
|
60
|
+
env:
|
61
|
+
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
|
62
|
+
POSTGRESQL_DB_HOST: 127.0.0.1
|
63
|
+
POSTGRESQL_DB_USER: schema_plus_test
|
64
|
+
POSTGRESQL_DB_PASS: database
|
65
|
+
MYSQL_DB_HOST: 127.0.0.1
|
66
|
+
MYSQL_DB_USER: root
|
67
|
+
MYSQL_DB_PASS: database
|
68
|
+
steps:
|
69
|
+
- uses: actions/checkout@v2
|
70
|
+
- name: Set up Ruby
|
71
|
+
uses: ruby/setup-ruby@v1
|
72
|
+
with:
|
73
|
+
ruby-version: "${{ matrix.ruby }}"
|
74
|
+
bundler-cache: true
|
75
|
+
- name: Run bundle update
|
76
|
+
run: bundle update
|
77
|
+
- name: Start Postgresql
|
78
|
+
if: matrix.db == 'postgresql'
|
79
|
+
run: |
|
80
|
+
docker run --rm --detach \
|
81
|
+
-e POSTGRES_USER=$POSTGRESQL_DB_USER \
|
82
|
+
-e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
|
83
|
+
-p 5432:5432 \
|
84
|
+
--health-cmd "pg_isready -q" \
|
85
|
+
--health-interval 5s \
|
86
|
+
--health-timeout 5s \
|
87
|
+
--health-retries 5 \
|
88
|
+
--name database postgres:${{ matrix.dbversion }}
|
89
|
+
- name: Start Mysql
|
90
|
+
if: matrix.db == 'mysql2'
|
91
|
+
run: |
|
92
|
+
docker run --rm --detach \
|
93
|
+
-e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
|
94
|
+
-p 3306:3306 \
|
95
|
+
--health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
|
96
|
+
--health-interval 5s \
|
97
|
+
--health-timeout 5s \
|
98
|
+
--health-retries 5 \
|
99
|
+
--name database mysql:5.6
|
100
|
+
- name: Wait for database to start
|
101
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
102
|
+
run: |
|
103
|
+
COUNT=0
|
104
|
+
ATTEMPTS=20
|
105
|
+
until [[ $COUNT -eq $ATTEMPTS ]]; do
|
106
|
+
[ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
|
107
|
+
echo $(( COUNT++ )) > /dev/null
|
108
|
+
sleep 2
|
109
|
+
done
|
110
|
+
- name: Create testing database
|
111
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
112
|
+
run: bundle exec rake create_ci_database
|
113
|
+
- name: Run tests
|
114
|
+
run: bundle exec rake spec
|
115
|
+
- name: Shutdown database
|
116
|
+
if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
|
117
|
+
run: docker stop database
|
118
|
+
- name: Coveralls Parallel
|
119
|
+
if: "${{ !env.ACT }}"
|
120
|
+
uses: coverallsapp/github-action@master
|
121
|
+
with:
|
122
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
123
|
+
flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
|
124
|
+
parallel: true
|
125
|
+
finish:
|
126
|
+
needs: test
|
127
|
+
runs-on: ubuntu-latest
|
128
|
+
steps:
|
129
|
+
- name: Coveralls Finished
|
130
|
+
if: "${{ !env.ACT }}"
|
131
|
+
uses: coverallsapp/github-action@master
|
132
|
+
with:
|
133
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
134
|
+
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
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,11 @@ 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 **
|
31
|
-
* ruby **2.5.1** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql**
|
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.7** with activerecord **5.2**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
29
|
+
* ruby **2.7** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
30
|
+
* ruby **3.0** with activerecord **6.0**, using **postgresql:9.6**, **mysql2** or **sqlite3**
|
32
31
|
|
33
32
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
34
33
|
|
@@ -444,6 +443,9 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
|
|
444
443
|
|
445
444
|
## Release Notes
|
446
445
|
|
446
|
+
* 3.0.0 Drop AR < 5.2 and add AR 6.0 support. Drop Ruby < 2.5 and add Ruby 3.0 support.
|
447
|
+
* 2.2.3 Fix dumping complex expression based indexes in AR 5.x
|
448
|
+
* 2.2.2 Fixed dumping tables in postgresql in AR 5.2 when the PK is not a bigint.
|
447
449
|
* 2.2.1 Fixed expression index handling in AR5.x.
|
448
450
|
* 2.2.0 Added AR5.2 support. Thanks to [@jeremyyap](https://github.com/jeremyyap)
|
449
451
|
* 2.1.1 Bug fix: Don't lose habtm options. Thanks to [@iagopiimenta ](https://github.com/iagopiimenta)
|
@@ -476,7 +478,7 @@ Some things to know about to help you develop and test:
|
|
476
478
|
* **schema_dev**: SchemaPlus::Core uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
477
479
|
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
478
480
|
versions that the gem supports, both locally and on
|
479
|
-
[
|
481
|
+
[github actions](https://github.com/SchemaPlus/schema_plus_core/actions)
|
480
482
|
|
481
483
|
To to run rspec locally on the full matrix, do:
|
482
484
|
|
@@ -488,7 +490,6 @@ Some things to know about to help you develop and test:
|
|
488
490
|
The matrix of configurations is specified in `schema_dev.yml` in
|
489
491
|
the project root.
|
490
492
|
|
491
|
-
|
492
493
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
493
494
|
|
494
495
|
<!-- 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,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,37 +1,39 @@
|
|
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
8
|
|
7
|
-
def add_column(table_name, name, type, options
|
9
|
+
def add_column(table_name, name, type, **options)
|
8
10
|
options = options.deep_dup
|
9
11
|
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
|
12
|
+
super env.table_name, env.column_name, env.type, **env.options
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def add_index_options(table_name, column_names, options
|
16
|
+
def add_index_options(table_name, column_names, **options)
|
15
17
|
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.
|
18
|
+
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
|
19
|
+
}.sql.to_h.values
|
18
20
|
end
|
19
21
|
|
20
|
-
def add_reference(table_name, name, options
|
22
|
+
def add_reference(table_name, name, **options)
|
21
23
|
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)
|
24
|
+
super env.table_name, env.column_name.sub(/_id$/, ''), **env.options.merge(_implements_reference: true)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
def create_table(table_name, options
|
28
|
+
def create_table(table_name, **options, &block)
|
27
29
|
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
|
30
|
+
super env.table_name, **env.options, &env.block
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
def drop_table(table_name, options
|
34
|
+
def drop_table(table_name, **options)
|
33
35
|
SchemaMonkey::Middleware::Migration::DropTable.start(connection: self, table_name: table_name, options: options.dup) do |env|
|
34
|
-
super env.table_name, env.options
|
36
|
+
super env.table_name, **env.options
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -44,7 +46,7 @@ module SchemaPlus
|
|
44
46
|
output_columns << column
|
45
47
|
else
|
46
48
|
quoted = {column.to_sym => quote_column_name(column).dup}
|
47
|
-
output_columns.concat add_options_for_index_columns(quoted, options).values
|
49
|
+
output_columns.concat add_options_for_index_columns(quoted, **options).values
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -56,7 +58,7 @@ module SchemaPlus
|
|
56
58
|
module SchemaCreation
|
57
59
|
|
58
60
|
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|
|
61
|
+
sql << +" " + SchemaMonkey::Middleware::Sql::ColumnOptions.start(caller: self, connection: self.instance_variable_get('@conn'), sql: +"", column: options[:column], options: options.except(:column)) { |env|
|
60
62
|
super env.sql, env.options.merge(column: env.column)
|
61
63
|
}.sql.lstrip
|
62
64
|
end
|
@@ -1,24 +1,26 @@
|
|
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 Mysql2Adapter
|
6
8
|
|
7
|
-
def change_column(table_name, name, type, options
|
9
|
+
def change_column(table_name, name, type, **options)
|
8
10
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :change, table_name: table_name, column_name: name, type: type, options: options.deep_dup) do |env|
|
9
|
-
super env.table_name, env.column_name, env.type, env.options
|
11
|
+
super env.table_name, env.column_name, env.type, **env.options
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
def add_index(table_name, column_names, options={})
|
15
|
+
def add_index(table_name, column_names, options = {})
|
14
16
|
SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :add, table_name: table_name, column_names: column_names, options: options.deep_dup) do |env|
|
15
|
-
super env.table_name, env.column_names, env.options
|
17
|
+
super env.table_name, env.column_names, **env.options
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def drop_table(table_name, options
|
21
|
+
def drop_table(table_name, **options)
|
20
22
|
SchemaMonkey::Middleware::Migration::DropTable.start(connection: self, table_name: table_name, options: options.dup) do |env|
|
21
|
-
super env.table_name, env.options
|
23
|
+
super env.table_name, **env.options
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
@@ -5,7 +7,6 @@ module SchemaPlus
|
|
5
7
|
module PostgreSQL
|
6
8
|
module PostgreSQL # need two PostgreSQLs because the first gets stripped by schema_monkey
|
7
9
|
module SchemaDumper
|
8
|
-
|
9
10
|
# quick hack fix quoting of column default functions to allow eval() when we
|
10
11
|
# capture the stream.
|
11
12
|
#
|
@@ -20,7 +21,7 @@ module SchemaPlus
|
|
20
21
|
#
|
21
22
|
def prepare_column_options(column, *) # :nodoc:
|
22
23
|
spec = super
|
23
|
-
spec[:default] = "%q{#{column.default_function}}" if column.default_function
|
24
|
+
spec[:default] = "%q{#{column.default_function}}" if column.default_function && !column.serial?
|
24
25
|
spec
|
25
26
|
end
|
26
27
|
|
@@ -1,42 +1,26 @@
|
|
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 PostgresqlAdapter
|
6
|
-
|
7
|
-
|
8
|
-
# capture the stream.
|
9
|
-
#
|
10
|
-
# AR's PostgresqlAdapter#prepare_column_options wraps the
|
11
|
-
# function in double quotes, which doesn't work because the
|
12
|
-
# function itself may have doublequotes in it which don't get
|
13
|
-
# escaped properly.
|
14
|
-
#
|
15
|
-
# Arguably that's a bug in AR, but then again default function
|
16
|
-
# expressions don't work well in AR anyway. (hence
|
17
|
-
# schema_plus_default_expr )
|
18
|
-
#
|
19
|
-
def prepare_column_options(column, *) # :nodoc:
|
20
|
-
spec = super
|
21
|
-
spec[:default] = "%q{#{column.default_function}}" if column.default_function
|
22
|
-
spec
|
23
|
-
end
|
24
|
-
|
25
|
-
def change_column(table_name, name, type, options = {})
|
8
|
+
|
9
|
+
def change_column(table_name, name, type, **options)
|
26
10
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :change, table_name: table_name, column_name: name, type: type, options: options.deep_dup) do |env|
|
27
|
-
super env.table_name, env.column_name, env.type, env.options
|
11
|
+
super env.table_name, env.column_name, env.type, **env.options
|
28
12
|
end
|
29
13
|
end
|
30
14
|
|
31
|
-
def add_index(table_name, column_names, options={})
|
15
|
+
def add_index(table_name, column_names, options = {})
|
32
16
|
SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :add, table_name: table_name, column_names: column_names, options: options.deep_dup) do |env|
|
33
|
-
super env.table_name, env.column_names, env.options
|
17
|
+
super env.table_name, env.column_names, **env.options
|
34
18
|
end
|
35
19
|
end
|
36
20
|
|
37
|
-
def drop_table(table_name, options
|
21
|
+
def drop_table(table_name, **options)
|
38
22
|
SchemaMonkey::Middleware::Migration::DropTable.start(connection: self, table_name: table_name, options: options.dup) do |env|
|
39
|
-
super env.table_name, env.options
|
23
|
+
super env.table_name, **env.options
|
40
24
|
end
|
41
25
|
end
|
42
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
@@ -10,15 +12,15 @@ module SchemaPlus
|
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
def change_column(table_name, name, type, options
|
15
|
+
def change_column(table_name, name, type, **options)
|
14
16
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :change, table_name: table_name, column_name: name, type: type, options: options.deep_dup) do |env|
|
15
|
-
super env.table_name, env.column_name, env.type, env.options
|
17
|
+
super env.table_name, env.column_name, env.type, **env.options
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def add_index(table_name, column_names, options={})
|
21
|
+
def add_index(table_name, column_names, options = {})
|
20
22
|
SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :add, table_name: table_name, column_names: column_names, options: options.deep_dup) do |env|
|
21
|
-
super env.table_name, env.column_names, env.options
|
23
|
+
super env.table_name, env.column_names, **env.options
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
@@ -7,27 +9,25 @@ module SchemaPlus
|
|
7
9
|
def column(name, type, options = {})
|
8
10
|
options = options.deep_dup
|
9
11
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: name, type: type, implements_reference: options.delete(:_implements_reference), options: options) do |env|
|
10
|
-
super env.column_name, env.type, env.options
|
12
|
+
super env.column_name, env.type, **env.options
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def references(name, options
|
16
|
+
def references(name, **options)
|
15
17
|
options = options.deep_dup
|
16
18
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options) do |env|
|
17
|
-
super env.column_name.sub(/_id$/, ''), env.options.merge(_implements_reference: true)
|
19
|
+
super env.column_name.sub(/_id$/, ''), **env.options.merge(_implements_reference: true)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
def belongs_to(name, options
|
23
|
+
def belongs_to(name, **options)
|
22
24
|
options = options.deep_dup
|
23
25
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options) do |env|
|
24
|
-
super env.column_name.sub(/_id$/, ''), env.options.merge(_implements_reference: true)
|
26
|
+
super env.column_name.sub(/_id$/, ''), **env.options.merge(_implements_reference: true)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
def index(
|
29
|
-
options = args.extract_options!
|
30
|
-
column_name = args.first
|
30
|
+
def index(column_name, options = {})
|
31
31
|
SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :define, table_name: self.name, column_names: column_name, options: options.deep_dup) do |env|
|
32
32
|
super env.column_names, env.options
|
33
33
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus
|
2
4
|
module Core
|
3
5
|
module ActiveRecord
|
4
6
|
module Migration
|
5
7
|
module CommandRecorder
|
6
8
|
|
7
|
-
def add_column(table_name, column_name, type, options
|
9
|
+
def add_column(table_name, column_name, type, **options)
|
8
10
|
SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :record, table_name: table_name, column_name: column_name, type: type, options: options.deep_dup) do |env|
|
9
|
-
super env.table_name, env.column_name, env.type, env.options
|
11
|
+
super env.table_name, env.column_name, env.type, **env.options
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|