fx 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +23 -2
- data/Appraisals +27 -14
- data/README.md +4 -0
- data/fx.gemspec +1 -1
- data/gemfiles/rails42.gemfile +2 -1
- data/gemfiles/rails50.gemfile +2 -2
- data/gemfiles/rails51.gemfile +2 -2
- data/gemfiles/rails52.gemfile +2 -2
- data/gemfiles/rails60.gemfile +2 -2
- data/gemfiles/rails61.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile +1 -1
- data/lib/fx/function.rb +1 -1
- data/lib/fx/statements/function.rb +13 -5
- data/lib/fx/statements/trigger.rb +17 -6
- data/lib/fx/version.rb +1 -1
- data/spec/fx/function_spec.rb +20 -7
- data/spec/fx/schema_dumper/function_spec.rb +22 -20
- data/spec/fx/trigger_spec.rb +5 -5
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f602bcfa44f9289edb4ad43379716b554badc5cdd086d04344d9683564b93ede
|
4
|
+
data.tar.gz: cfdb703fb8a27cae0622c8f70a38a35a039677b51363d985018b9f638eb8846c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa2447143558b62d037a7c6515211bfcdae05ca437ced59d949828ef1409f76b79b33dbf71677699b98af53453e5b249de18f76f89c3b9895a6f3705462bb7df
|
7
|
+
data.tar.gz: 4b5380abef9d337368e80ac0f0f61dd3d70a2514bd560f175f8726a9a089136f4760237b3b3a86a58a01af65d2797a200b1a8a4a1efd58a8a4d58de30af0bb5b
|
data/.travis.yml
CHANGED
@@ -19,6 +19,8 @@ language:
|
|
19
19
|
notifications:
|
20
20
|
email: false
|
21
21
|
rvm:
|
22
|
+
- 3.0
|
23
|
+
- 2.7
|
22
24
|
- 2.6
|
23
25
|
- 2.5
|
24
26
|
- 2.4
|
@@ -28,12 +30,31 @@ gemfile:
|
|
28
30
|
- gemfiles/rails51.gemfile
|
29
31
|
- gemfiles/rails52.gemfile
|
30
32
|
- gemfiles/rails60.gemfile
|
33
|
+
- gemfiles/rails61.gemfile
|
31
34
|
- gemfiles/rails_edge.gemfile
|
32
35
|
matrix:
|
33
36
|
allow_failures:
|
34
37
|
- gemfile: gemfiles/rails_edge.gemfile
|
35
38
|
exclude:
|
36
|
-
- rvm: 2.4
|
37
|
-
gemfile: gemfiles/rails_edge.gemfile
|
38
39
|
- rvm: 2.4
|
39
40
|
gemfile: gemfiles/rails60.gemfile
|
41
|
+
- rvm: 2.4
|
42
|
+
gemfile: gemfiles/rails61.gemfile
|
43
|
+
- rvm: 2.4
|
44
|
+
gemfile: gemfiles/rails_edge.gemfile
|
45
|
+
- rvm: 2.5
|
46
|
+
gemfile: gemfiles/rails_edge.gemfile
|
47
|
+
- rvm: 2.6
|
48
|
+
gemfile: gemfiles/rails42.gemfile
|
49
|
+
- rvm: 2.6
|
50
|
+
gemfile: gemfiles/rails_edge.gemfile
|
51
|
+
- rvm: 2.7
|
52
|
+
gemfile: gemfiles/rails42.gemfile
|
53
|
+
- rvm: 3.0
|
54
|
+
gemfile: gemfiles/rails42.gemfile
|
55
|
+
- rvm: 3.0
|
56
|
+
gemfile: gemfiles/rails50.gemfile
|
57
|
+
- rvm: 3.0
|
58
|
+
gemfile: gemfiles/rails51.gemfile
|
59
|
+
- rvm: 3.0
|
60
|
+
gemfile: gemfiles/rails52.gemfile
|
data/Appraisals
CHANGED
@@ -1,32 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
if RUBY_VERSION < "2.6.0"
|
2
|
+
appraise "rails42" do
|
3
|
+
gem "activerecord", "~> 4.2.0"
|
4
|
+
gem "railties", "~> 4.2.0"
|
5
|
+
gem "pg", "~> 0.15.0"
|
6
|
+
gem "bigdecimal", "1.3.5"
|
7
|
+
end
|
5
8
|
end
|
6
9
|
|
7
|
-
if RUBY_VERSION
|
10
|
+
if RUBY_VERSION >= "2.2.0" and RUBY_VERSION < "3.0.0"
|
8
11
|
appraise "rails50" do
|
9
|
-
gem "activerecord", "~> 5.0"
|
10
|
-
gem "railties", "~> 5.0"
|
12
|
+
gem "activerecord", "~> 5.0.0"
|
13
|
+
gem "railties", "~> 5.0.0"
|
11
14
|
end
|
12
15
|
|
13
16
|
appraise "rails51" do
|
14
|
-
gem "activerecord", "~> 5.1"
|
15
|
-
gem "railties", "~> 5.1"
|
17
|
+
gem "activerecord", "~> 5.1.0"
|
18
|
+
gem "railties", "~> 5.1.0"
|
16
19
|
end
|
17
20
|
|
18
21
|
appraise "rails52" do
|
19
|
-
gem "activerecord", "~> 5.2"
|
20
|
-
gem "railties", "~> 5.2"
|
22
|
+
gem "activerecord", "~> 5.2.0"
|
23
|
+
gem "railties", "~> 5.2.0"
|
21
24
|
end
|
22
25
|
|
26
|
+
end
|
27
|
+
|
28
|
+
if RUBY_VERSION >= "2.5.0"
|
23
29
|
appraise "rails60" do
|
24
|
-
gem "activerecord", "~> 6.0"
|
25
|
-
gem "railties", "~> 6.0"
|
30
|
+
gem "activerecord", "~> 6.0.0"
|
31
|
+
gem "railties", "~> 6.0.0"
|
26
32
|
end
|
27
33
|
|
34
|
+
appraise "rails61" do
|
35
|
+
gem "activerecord", "~> 6.1.0"
|
36
|
+
gem "railties", "~> 6.1.0"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if RUBY_VERSION >= "2.7.0"
|
28
41
|
appraise "rails-edge" do
|
29
|
-
gem "rails", github: "rails/rails"
|
42
|
+
gem "rails", github: "rails/rails", branch: "main"
|
30
43
|
gem "arel", :github => "rails/arel"
|
31
44
|
end
|
32
45
|
end
|
data/README.md
CHANGED
@@ -108,6 +108,10 @@ end
|
|
108
108
|
That's how you tell Rails to use the default as a literal SQL for the default
|
109
109
|
column value instead of a plain string.
|
110
110
|
|
111
|
+
## Plugins/Adapters
|
112
|
+
|
113
|
+
- [SQLserver](https://github.com/tarellel/fx-sqlserver-adapter)
|
114
|
+
|
111
115
|
## Contributing
|
112
116
|
|
113
117
|
See [contributing](CONTRIBUTING.md) for more details.
|
data/fx.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^spec/})
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency "appraisal"
|
23
|
+
spec.add_development_dependency "appraisal", '~> 2.3.0'
|
24
24
|
spec.add_development_dependency "bundler", '>= 1.5'
|
25
25
|
spec.add_development_dependency "database_cleaner"
|
26
26
|
spec.add_development_dependency "rake"
|
data/gemfiles/rails42.gemfile
CHANGED
data/gemfiles/rails50.gemfile
CHANGED
data/gemfiles/rails51.gemfile
CHANGED
data/gemfiles/rails52.gemfile
CHANGED
data/gemfiles/rails60.gemfile
CHANGED
data/gemfiles/rails_edge.gemfile
CHANGED
data/lib/fx/function.rb
CHANGED
@@ -11,7 +11,7 @@ module Fx
|
|
11
11
|
# find the definition file in `db/functions`. This defaults to `1` if
|
12
12
|
# not provided.
|
13
13
|
# @param sql_definition [String] The SQL query for the function schema.
|
14
|
-
# If both `
|
14
|
+
# If both `sql_definition` and `version` are provided,
|
15
15
|
# `sql_definition` takes prescedence.
|
16
16
|
# @return The database response from executing the create statement.
|
17
17
|
#
|
@@ -29,7 +29,10 @@ module Fx
|
|
29
29
|
# $$ LANGUAGE plpgsql;
|
30
30
|
# SQL
|
31
31
|
#
|
32
|
-
def create_function(name,
|
32
|
+
def create_function(name, options = {})
|
33
|
+
version = options.fetch(:version, 1)
|
34
|
+
sql_definition = options[:sql_definition]
|
35
|
+
|
33
36
|
if version.nil? && sql_definition.nil?
|
34
37
|
raise(
|
35
38
|
ArgumentError,
|
@@ -53,7 +56,8 @@ module Fx
|
|
53
56
|
# @example Drop a function, rolling back to version 2 on rollback
|
54
57
|
# drop_function(:uppercase_users_name, revert_to_version: 2)
|
55
58
|
#
|
56
|
-
def drop_function(name,
|
59
|
+
def drop_function(name, options = {})
|
60
|
+
revert_to_version = options[:revert_to_version]
|
57
61
|
Fx.database.drop_function(name)
|
58
62
|
end
|
59
63
|
|
@@ -64,7 +68,7 @@ module Fx
|
|
64
68
|
# find the definition file in `db/functions`. This defaults to `1` if
|
65
69
|
# not provided.
|
66
70
|
# @param sql_definition [String] The SQL query for the function schema.
|
67
|
-
# If both `
|
71
|
+
# If both `sql_definition` and `version` are provided,
|
68
72
|
# `sql_definition` takes prescedence.
|
69
73
|
# @return The database response from executing the create statement.
|
70
74
|
#
|
@@ -86,7 +90,11 @@ module Fx
|
|
86
90
|
# $$ LANGUAGE plpgsql;
|
87
91
|
# SQL
|
88
92
|
#
|
89
|
-
def update_function(name,
|
93
|
+
def update_function(name, options = {})
|
94
|
+
version = options[:version]
|
95
|
+
sql_definition = options[:sql_definition]
|
96
|
+
revert_to_version = options[:revert_to_version]
|
97
|
+
|
90
98
|
if version.nil? && sql_definition.nil?
|
91
99
|
raise(
|
92
100
|
ArgumentError,
|
@@ -3,7 +3,7 @@ module Fx
|
|
3
3
|
# Methods that are made available in migrations for managing Fx triggers.
|
4
4
|
module Trigger
|
5
5
|
# @api private
|
6
|
-
|
6
|
+
DEFINITION_TYPE = "trigger".freeze
|
7
7
|
|
8
8
|
# Create a new database trigger.
|
9
9
|
#
|
@@ -27,7 +27,11 @@ module Fx
|
|
27
27
|
# EXECUTE PROCEDURE uppercase_users_name();
|
28
28
|
# SQL
|
29
29
|
#
|
30
|
-
def create_trigger(name,
|
30
|
+
def create_trigger(name, options = {})
|
31
|
+
version = options[:version]
|
32
|
+
_on = options[:on]
|
33
|
+
sql_definition = options[:sql_definition]
|
34
|
+
|
31
35
|
if version.present? && sql_definition.present?
|
32
36
|
raise(
|
33
37
|
ArgumentError,
|
@@ -43,7 +47,7 @@ module Fx
|
|
43
47
|
sql_definition ||= Fx::Definition.new(
|
44
48
|
name: name,
|
45
49
|
version: version,
|
46
|
-
type:
|
50
|
+
type: DEFINITION_TYPE,
|
47
51
|
).to_sql
|
48
52
|
|
49
53
|
Fx.database.create_trigger(sql_definition)
|
@@ -62,7 +66,9 @@ module Fx
|
|
62
66
|
# @example Drop a trigger, rolling back to version 3 on rollback
|
63
67
|
# drop_trigger(:log_inserts, on: :users, revert_to_version: 3)
|
64
68
|
#
|
65
|
-
def drop_trigger(name,
|
69
|
+
def drop_trigger(name, options = {})
|
70
|
+
on = options.fetch(:on)
|
71
|
+
revert_to_version = options[:revert_to_version]
|
66
72
|
Fx.database.drop_trigger(name, on: on)
|
67
73
|
end
|
68
74
|
|
@@ -98,7 +104,12 @@ module Fx
|
|
98
104
|
# EXECUTE PROCEDURE uppercase_users_name();
|
99
105
|
# SQL
|
100
106
|
#
|
101
|
-
def update_trigger(name,
|
107
|
+
def update_trigger(name, options = {})
|
108
|
+
version = options[:version]
|
109
|
+
on = options[:on]
|
110
|
+
sql_definition = options[:sql_definition]
|
111
|
+
revert_to_version = options[:revert_to_version]
|
112
|
+
|
102
113
|
if version.nil? && sql_definition.nil?
|
103
114
|
raise(
|
104
115
|
ArgumentError,
|
@@ -121,7 +132,7 @@ module Fx
|
|
121
132
|
sql_definition ||= Fx::Definition.new(
|
122
133
|
name: name,
|
123
134
|
version: version,
|
124
|
-
type:
|
135
|
+
type: DEFINITION_TYPE,
|
125
136
|
).to_sql
|
126
137
|
|
127
138
|
Fx.database.update_trigger(
|
data/lib/fx/version.rb
CHANGED
data/spec/fx/function_spec.rb
CHANGED
@@ -7,15 +7,15 @@ module Fx
|
|
7
7
|
it "delegates to `name`" do
|
8
8
|
function_a = Function.new(
|
9
9
|
"name" => "name_a",
|
10
|
-
"definition" => "some
|
10
|
+
"definition" => "some definition",
|
11
11
|
)
|
12
12
|
function_b = Function.new(
|
13
13
|
"name" => "name_b",
|
14
|
-
"definition" => "some
|
14
|
+
"definition" => "some definition",
|
15
15
|
)
|
16
16
|
function_c = Function.new(
|
17
17
|
"name" => "name_c",
|
18
|
-
"definition" => "some
|
18
|
+
"definition" => "some definition",
|
19
19
|
)
|
20
20
|
|
21
21
|
expect(function_b).to be_between(function_a, function_c)
|
@@ -26,11 +26,11 @@ module Fx
|
|
26
26
|
it "compares `name` and `definition`" do
|
27
27
|
function_a = Function.new(
|
28
28
|
"name" => "name_a",
|
29
|
-
"definition" => "some
|
29
|
+
"definition" => "some definition",
|
30
30
|
)
|
31
31
|
function_b = Function.new(
|
32
32
|
"name" => "name_b",
|
33
|
-
"definition" => "some other
|
33
|
+
"definition" => "some other definition",
|
34
34
|
)
|
35
35
|
|
36
36
|
expect(function_a).not_to eq(function_b)
|
@@ -44,9 +44,22 @@ module Fx
|
|
44
44
|
"definition" => "CREATE OR REPLACE TRIGGER uppercase_users_name ...",
|
45
45
|
)
|
46
46
|
|
47
|
-
expect(function.to_schema).to eq <<-EOS
|
48
|
-
create_function :uppercase_users_name, sql_definition:
|
47
|
+
expect(function.to_schema).to eq <<-'EOS'
|
48
|
+
create_function :uppercase_users_name, sql_definition: <<-'SQL'
|
49
49
|
CREATE OR REPLACE TRIGGER uppercase_users_name ...
|
50
|
+
SQL
|
51
|
+
EOS
|
52
|
+
end
|
53
|
+
|
54
|
+
it "maintains backslashes" do
|
55
|
+
function = Function.new(
|
56
|
+
"name" => "regex",
|
57
|
+
"definition" => "CREATE OR REPLACE FUNCTION regex \\1",
|
58
|
+
)
|
59
|
+
|
60
|
+
expect(function.to_schema).to eq <<-'EOS'
|
61
|
+
create_function :regex, sql_definition: <<-'SQL'
|
62
|
+
CREATE OR REPLACE FUNCTION regex \1
|
50
63
|
SQL
|
51
64
|
EOS
|
52
65
|
end
|
@@ -23,27 +23,29 @@ describe Fx::SchemaDumper::Function, :db do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "dumps a create_function for a function in the database" do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
begin
|
27
|
+
Fx.configuration.dump_functions_at_beginning_of_schema = true
|
28
|
+
sql_definition = <<-EOS
|
29
|
+
CREATE OR REPLACE FUNCTION my_function()
|
30
|
+
RETURNS text AS $$
|
31
|
+
BEGIN
|
32
|
+
RETURN 'test';
|
33
|
+
END;
|
34
|
+
$$ LANGUAGE plpgsql;
|
35
|
+
EOS
|
36
|
+
connection.create_function :my_function, sql_definition: sql_definition
|
37
|
+
connection.create_table :my_table
|
38
|
+
stream = StringIO.new
|
39
|
+
output = stream.string
|
39
40
|
|
40
|
-
|
41
|
+
ActiveRecord::SchemaDumper.dump(connection, stream)
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
expect(output).to(
|
44
|
+
match(/function :my_function.*RETURN 'test';.*table "my_table"/m),
|
45
|
+
)
|
46
|
+
ensure
|
47
|
+
Fx.configuration.dump_functions_at_beginning_of_schema = false
|
48
|
+
end
|
47
49
|
end
|
48
50
|
|
49
51
|
it "does not dump a create_function for aggregates in the database" do
|
@@ -71,7 +73,7 @@ describe Fx::SchemaDumper::Function, :db do
|
|
71
73
|
ActiveRecord::SchemaDumper.dump(connection, stream)
|
72
74
|
|
73
75
|
output = stream.string
|
74
|
-
expect(output).to include "create_function :test, sql_definition: <<-SQL"
|
76
|
+
expect(output).to include "create_function :test, sql_definition: <<-'SQL'"
|
75
77
|
expect(output).to include "RETURN 'test';"
|
76
78
|
expect(output).not_to include "aggregate_test"
|
77
79
|
end
|
data/spec/fx/trigger_spec.rb
CHANGED
@@ -7,15 +7,15 @@ module Fx
|
|
7
7
|
it "delegates to `name`" do
|
8
8
|
trigger_a = Trigger.new(
|
9
9
|
"name" => "name_a",
|
10
|
-
"definition" => "some
|
10
|
+
"definition" => "some definition",
|
11
11
|
)
|
12
12
|
trigger_b = Trigger.new(
|
13
13
|
"name" => "name_b",
|
14
|
-
"definition" => "some
|
14
|
+
"definition" => "some definition",
|
15
15
|
)
|
16
16
|
trigger_c = Trigger.new(
|
17
17
|
"name" => "name_c",
|
18
|
-
"definition" => "some
|
18
|
+
"definition" => "some definition",
|
19
19
|
)
|
20
20
|
|
21
21
|
expect(trigger_b).to be_between(trigger_a, trigger_c)
|
@@ -26,11 +26,11 @@ module Fx
|
|
26
26
|
it "compares `name` and `definition`" do
|
27
27
|
trigger_a = Trigger.new(
|
28
28
|
"name" => "name_a",
|
29
|
-
"definition" => "some
|
29
|
+
"definition" => "some definition",
|
30
30
|
)
|
31
31
|
trigger_b = Trigger.new(
|
32
32
|
"name" => "name_b",
|
33
|
-
"definition" => "some other
|
33
|
+
"definition" => "some other definition",
|
34
34
|
)
|
35
35
|
|
36
36
|
expect(trigger_a).not_to eq(trigger_b)
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Teo Ljungberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.3.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- gemfiles/rails51.gemfile
|
212
212
|
- gemfiles/rails52.gemfile
|
213
213
|
- gemfiles/rails60.gemfile
|
214
|
+
- gemfiles/rails61.gemfile
|
214
215
|
- gemfiles/rails_edge.gemfile
|
215
216
|
- lib/fx.rb
|
216
217
|
- lib/fx/adapters/postgres.rb
|
@@ -298,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
298
299
|
- !ruby/object:Gem::Version
|
299
300
|
version: '0'
|
300
301
|
requirements: []
|
301
|
-
rubygems_version: 3.2.
|
302
|
+
rubygems_version: 3.2.26
|
302
303
|
signing_key:
|
303
304
|
specification_version: 4
|
304
305
|
summary: Support for database functions and triggers in Rails migrations
|