fx 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +2 -0
- data/.rubocop.yml +648 -0
- data/.travis.yml +3 -0
- data/Appraisals +5 -0
- data/README.md +3 -0
- data/bin/setup +1 -0
- data/gemfiles/rails40.gemfile.lock +7 -7
- data/gemfiles/rails41.gemfile.lock +10 -10
- data/gemfiles/rails42.gemfile.lock +14 -14
- data/gemfiles/rails50.gemfile.lock +27 -27
- data/gemfiles/rails_edge.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile.lock +179 -0
- data/lib/fx/adapters/postgres.rb +13 -0
- data/lib/fx/function.rb +2 -0
- data/lib/fx/statements/function.rb +4 -2
- data/lib/fx/statements/trigger.rb +2 -0
- data/lib/fx/trigger.rb +2 -0
- data/lib/fx/version.rb +1 -1
- data/spec/acceptance_helper.rb +2 -1
- data/spec/dummy/Rakefile +7 -0
- data/spec/fx/adapters/postgres/functions_spec.rb +37 -0
- data/spec/fx/adapters/postgres/triggers_spec.rb +44 -0
- data/spec/fx/function_spec.rb +55 -0
- data/spec/fx/trigger_spec.rb +55 -0
- metadata +15 -3
data/lib/fx/adapters/postgres.rb
CHANGED
|
@@ -23,6 +23,19 @@ module Fx
|
|
|
23
23
|
# config.adapter = Fx::Adapters::Postgres.new
|
|
24
24
|
# end
|
|
25
25
|
class Postgres
|
|
26
|
+
# Creates an instance of the F(x) Postgres adapter.
|
|
27
|
+
#
|
|
28
|
+
# This is the default adapter for F(x). Configuring it via
|
|
29
|
+
# {Fx.configure} is not required, but the example below shows how one
|
|
30
|
+
# would explicitly set it.
|
|
31
|
+
#
|
|
32
|
+
# @param [#connection] connectable An object that returns the connection
|
|
33
|
+
# for F(x) to use. Defaults to `ActiveRecord::Base`.
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# Fx.configure do |config|
|
|
37
|
+
# config.adapter = Fx::Adapters::Postgres.new
|
|
38
|
+
# end
|
|
26
39
|
def initialize(connectable = ActiveRecord::Base)
|
|
27
40
|
@connectable = connectable
|
|
28
41
|
end
|
data/lib/fx/function.rb
CHANGED
|
@@ -36,6 +36,7 @@ module Fx
|
|
|
36
36
|
"version or sql_definition must be specified",
|
|
37
37
|
)
|
|
38
38
|
end
|
|
39
|
+
sql_definition = sql_definition.strip_heredoc if sql_definition
|
|
39
40
|
sql_definition ||= Fx::Definition.new(name: name, version: version).to_sql
|
|
40
41
|
|
|
41
42
|
Fx.database.create_function(sql_definition)
|
|
@@ -49,8 +50,8 @@ module Fx
|
|
|
49
50
|
# the `version` argument to {#create_function}.
|
|
50
51
|
# @return The database response from executing the drop statement.
|
|
51
52
|
#
|
|
52
|
-
# @example Drop a function, rolling back to version
|
|
53
|
-
# drop_function(:uppercase_users_name,
|
|
53
|
+
# @example Drop a function, rolling back to version 2 on rollback
|
|
54
|
+
# drop_function(:uppercase_users_name, revert_to_version: 2)
|
|
54
55
|
#
|
|
55
56
|
def drop_function(name, revert_to_version: nil)
|
|
56
57
|
Fx.database.drop_function(name)
|
|
@@ -93,6 +94,7 @@ module Fx
|
|
|
93
94
|
)
|
|
94
95
|
end
|
|
95
96
|
|
|
97
|
+
sql_definition = sql_definition.strip_heredoc if sql_definition
|
|
96
98
|
sql_definition ||= Fx::Definition.new(
|
|
97
99
|
name: name,
|
|
98
100
|
version: version,
|
|
@@ -39,6 +39,7 @@ module Fx
|
|
|
39
39
|
version = 1
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
sql_definition = sql_definition.strip_heredoc if sql_definition
|
|
42
43
|
sql_definition ||= Fx::Definition.new(
|
|
43
44
|
name: name,
|
|
44
45
|
version: version,
|
|
@@ -116,6 +117,7 @@ module Fx
|
|
|
116
117
|
raise ArgumentError, "on is required"
|
|
117
118
|
end
|
|
118
119
|
|
|
120
|
+
sql_definition = sql_definition.strip_heredoc if sql_definition
|
|
119
121
|
sql_definition ||= Fx::Definition.new(
|
|
120
122
|
name: name,
|
|
121
123
|
version: version,
|
data/lib/fx/trigger.rb
CHANGED
data/lib/fx/version.rb
CHANGED
data/spec/acceptance_helper.rb
CHANGED
|
@@ -23,7 +23,8 @@ RSpec.configure do |config|
|
|
|
23
23
|
Dir.chdir("spec/dummy") do
|
|
24
24
|
ActiveRecord::Base.connection.disconnect!
|
|
25
25
|
system <<-CMD
|
|
26
|
-
|
|
26
|
+
echo &&
|
|
27
|
+
rake db:environment:set db:drop db:create &&
|
|
27
28
|
git add -A &&
|
|
28
29
|
git reset --hard HEAD 1>/dev/null &&
|
|
29
30
|
rm -rf .git/ 1>/dev/null
|
data/spec/dummy/Rakefile
CHANGED
|
@@ -4,3 +4,10 @@
|
|
|
4
4
|
require File.expand_path('../config/application', __FILE__)
|
|
5
5
|
|
|
6
6
|
Rails.application.load_tasks
|
|
7
|
+
|
|
8
|
+
unless Rake::Task.task_defined?('db:environment:set')
|
|
9
|
+
desc 'dummy task for rails versions where this task does not exist'
|
|
10
|
+
task 'db:environment:set' do
|
|
11
|
+
# no-op
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Fx
|
|
4
|
+
module Adapters
|
|
5
|
+
describe Postgres::Functions, :db do
|
|
6
|
+
describe ".all" do
|
|
7
|
+
it "returns `Function` objects" do
|
|
8
|
+
connection = ActiveRecord::Base.connection
|
|
9
|
+
connection.execute <<-EOS.strip_heredoc
|
|
10
|
+
CREATE OR REPLACE FUNCTION test()
|
|
11
|
+
RETURNS text AS $$
|
|
12
|
+
BEGIN
|
|
13
|
+
RETURN 'test';
|
|
14
|
+
END;
|
|
15
|
+
$$ LANGUAGE plpgsql;
|
|
16
|
+
EOS
|
|
17
|
+
|
|
18
|
+
functions = Postgres::Functions.new(connection).all
|
|
19
|
+
|
|
20
|
+
first = functions.first
|
|
21
|
+
expect(functions.size).to eq 1
|
|
22
|
+
expect(first.name).to eq "test"
|
|
23
|
+
expect(first.definition).to eq <<-EOS.strip_heredoc
|
|
24
|
+
CREATE OR REPLACE FUNCTION public.test()
|
|
25
|
+
RETURNS text
|
|
26
|
+
LANGUAGE plpgsql
|
|
27
|
+
AS $function$
|
|
28
|
+
BEGIN
|
|
29
|
+
RETURN 'test';
|
|
30
|
+
END;
|
|
31
|
+
$function$
|
|
32
|
+
EOS
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Fx
|
|
4
|
+
module Adapters
|
|
5
|
+
describe Postgres::Triggers, :db do
|
|
6
|
+
describe ".all" do
|
|
7
|
+
it "returns `Trigger` objects" do
|
|
8
|
+
connection = ActiveRecord::Base.connection
|
|
9
|
+
connection.execute <<-EOS.strip_heredoc
|
|
10
|
+
CREATE TABLE users (
|
|
11
|
+
id int PRIMARY KEY,
|
|
12
|
+
name varchar(256),
|
|
13
|
+
upper_name varchar(256)
|
|
14
|
+
);
|
|
15
|
+
EOS
|
|
16
|
+
connection.execute <<-EOS.strip_heredoc
|
|
17
|
+
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
18
|
+
RETURNS trigger AS $$
|
|
19
|
+
BEGIN
|
|
20
|
+
NEW.upper_name = UPPER(NEW.name);
|
|
21
|
+
RETURN NEW;
|
|
22
|
+
END;
|
|
23
|
+
$$ LANGUAGE plpgsql;
|
|
24
|
+
EOS
|
|
25
|
+
connection.execute <<-EOS.strip_heredoc
|
|
26
|
+
CREATE TRIGGER uppercase_users_name
|
|
27
|
+
BEFORE INSERT ON users
|
|
28
|
+
FOR EACH ROW
|
|
29
|
+
EXECUTE PROCEDURE uppercase_users_name();
|
|
30
|
+
EOS
|
|
31
|
+
|
|
32
|
+
triggers = Postgres::Triggers.new(connection).all
|
|
33
|
+
|
|
34
|
+
first = triggers.first
|
|
35
|
+
expect(triggers.size).to eq 1
|
|
36
|
+
expect(first.name).to eq "uppercase_users_name"
|
|
37
|
+
expect(first.definition).to eq <<-EOS.strip_heredoc.strip
|
|
38
|
+
CREATE TRIGGER uppercase_users_name BEFORE INSERT ON users FOR EACH ROW EXECUTE PROCEDURE uppercase_users_name()
|
|
39
|
+
EOS
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "fx/function"
|
|
3
|
+
|
|
4
|
+
module Fx
|
|
5
|
+
describe Function do
|
|
6
|
+
describe "#<=>" do
|
|
7
|
+
it "delegates to `name`" do
|
|
8
|
+
function_a = Function.new(
|
|
9
|
+
"name" => "name_a",
|
|
10
|
+
"definition" => "some defintion",
|
|
11
|
+
)
|
|
12
|
+
function_b = Function.new(
|
|
13
|
+
"name" => "name_b",
|
|
14
|
+
"definition" => "some defintion",
|
|
15
|
+
)
|
|
16
|
+
function_c = Function.new(
|
|
17
|
+
"name" => "name_c",
|
|
18
|
+
"definition" => "some defintion",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
expect(function_b).to be_between(function_a, function_c)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#==" do
|
|
26
|
+
it "compares `name` and `definition`" do
|
|
27
|
+
function_a = Function.new(
|
|
28
|
+
"name" => "name_a",
|
|
29
|
+
"definition" => "some defintion",
|
|
30
|
+
)
|
|
31
|
+
function_b = Function.new(
|
|
32
|
+
"name" => "name_b",
|
|
33
|
+
"definition" => "some other defintion",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
expect(function_a).not_to eq(function_b)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "#to_schema" do
|
|
41
|
+
it "returns a schema compatible version of the function" do
|
|
42
|
+
function = Function.new(
|
|
43
|
+
"name" => "uppercase_users_name",
|
|
44
|
+
"definition" => "CREATE OR REPLACE TRIGGER uppercase_users_name ...",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
expect(function.to_schema).to eq <<-EOS
|
|
48
|
+
create_function :uppercase_users_name, sql_definition: <<-\SQL
|
|
49
|
+
CREATE OR REPLACE TRIGGER uppercase_users_name ...
|
|
50
|
+
SQL
|
|
51
|
+
EOS
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "fx/trigger"
|
|
3
|
+
|
|
4
|
+
module Fx
|
|
5
|
+
describe Trigger do
|
|
6
|
+
describe "#<=>" do
|
|
7
|
+
it "delegates to `name`" do
|
|
8
|
+
trigger_a = Trigger.new(
|
|
9
|
+
"name" => "name_a",
|
|
10
|
+
"definition" => "some defintion",
|
|
11
|
+
)
|
|
12
|
+
trigger_b = Trigger.new(
|
|
13
|
+
"name" => "name_b",
|
|
14
|
+
"definition" => "some defintion",
|
|
15
|
+
)
|
|
16
|
+
trigger_c = Trigger.new(
|
|
17
|
+
"name" => "name_c",
|
|
18
|
+
"definition" => "some defintion",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
expect(trigger_b).to be_between(trigger_a, trigger_c)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#==" do
|
|
26
|
+
it "compares `name` and `definition`" do
|
|
27
|
+
trigger_a = Trigger.new(
|
|
28
|
+
"name" => "name_a",
|
|
29
|
+
"definition" => "some defintion",
|
|
30
|
+
)
|
|
31
|
+
trigger_b = Trigger.new(
|
|
32
|
+
"name" => "name_b",
|
|
33
|
+
"definition" => "some other defintion",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
expect(trigger_a).not_to eq(trigger_b)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "#to_schema" do
|
|
41
|
+
it "returns a schema compatible version of the trigger" do
|
|
42
|
+
trigger = Trigger.new(
|
|
43
|
+
"name" => "uppercase_users_name",
|
|
44
|
+
"definition" => "CREATE TRIGGER uppercase_users_name ...",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
expect(trigger.to_schema).to eq <<-EOS
|
|
48
|
+
create_trigger :uppercase_users_name, sql_definition: <<-\SQL
|
|
49
|
+
CREATE TRIGGER uppercase_users_name ...
|
|
50
|
+
SQL
|
|
51
|
+
EOS
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
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: 2018-04-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: appraisal
|
|
@@ -188,7 +188,9 @@ extensions: []
|
|
|
188
188
|
extra_rdoc_files: []
|
|
189
189
|
files:
|
|
190
190
|
- ".gitignore"
|
|
191
|
+
- ".hound.yml"
|
|
191
192
|
- ".rspec"
|
|
193
|
+
- ".rubocop.yml"
|
|
192
194
|
- ".ruby-version"
|
|
193
195
|
- ".travis.yml"
|
|
194
196
|
- ".yardopts"
|
|
@@ -212,6 +214,8 @@ files:
|
|
|
212
214
|
- gemfiles/rails42.gemfile.lock
|
|
213
215
|
- gemfiles/rails50.gemfile
|
|
214
216
|
- gemfiles/rails50.gemfile.lock
|
|
217
|
+
- gemfiles/rails_edge.gemfile
|
|
218
|
+
- gemfiles/rails_edge.gemfile.lock
|
|
215
219
|
- lib/fx.rb
|
|
216
220
|
- lib/fx/adapters/postgres.rb
|
|
217
221
|
- lib/fx/adapters/postgres/connection.rb
|
|
@@ -259,15 +263,19 @@ files:
|
|
|
259
263
|
- spec/features/functions/revert_spec.rb
|
|
260
264
|
- spec/features/triggers/migrations_spec.rb
|
|
261
265
|
- spec/features/triggers/revert_spec.rb
|
|
266
|
+
- spec/fx/adapters/postgres/functions_spec.rb
|
|
267
|
+
- spec/fx/adapters/postgres/triggers_spec.rb
|
|
262
268
|
- spec/fx/adapters/postgres_spec.rb
|
|
263
269
|
- spec/fx/command_recorder/arguments_spec.rb
|
|
264
270
|
- spec/fx/command_recorder_spec.rb
|
|
265
271
|
- spec/fx/configuration_spec.rb
|
|
266
272
|
- spec/fx/definition_spec.rb
|
|
273
|
+
- spec/fx/function_spec.rb
|
|
267
274
|
- spec/fx/schema_dumper/function_spec.rb
|
|
268
275
|
- spec/fx/schema_dumper/trigger_spec.rb
|
|
269
276
|
- spec/fx/statements/function_spec.rb
|
|
270
277
|
- spec/fx/statements/trigger_spec.rb
|
|
278
|
+
- spec/fx/trigger_spec.rb
|
|
271
279
|
- spec/generators/fx/function/function_generator_spec.rb
|
|
272
280
|
- spec/generators/fx/trigger/trigger_generator_spec.rb
|
|
273
281
|
- spec/spec_helper.rb
|
|
@@ -294,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
294
302
|
version: '0'
|
|
295
303
|
requirements: []
|
|
296
304
|
rubyforge_project:
|
|
297
|
-
rubygems_version: 2.5.1
|
|
305
|
+
rubygems_version: 2.5.2.1
|
|
298
306
|
signing_key:
|
|
299
307
|
specification_version: 4
|
|
300
308
|
summary: Support for database functions and triggers in Rails migrations
|
|
@@ -317,15 +325,19 @@ test_files:
|
|
|
317
325
|
- spec/features/functions/revert_spec.rb
|
|
318
326
|
- spec/features/triggers/migrations_spec.rb
|
|
319
327
|
- spec/features/triggers/revert_spec.rb
|
|
328
|
+
- spec/fx/adapters/postgres/functions_spec.rb
|
|
329
|
+
- spec/fx/adapters/postgres/triggers_spec.rb
|
|
320
330
|
- spec/fx/adapters/postgres_spec.rb
|
|
321
331
|
- spec/fx/command_recorder/arguments_spec.rb
|
|
322
332
|
- spec/fx/command_recorder_spec.rb
|
|
323
333
|
- spec/fx/configuration_spec.rb
|
|
324
334
|
- spec/fx/definition_spec.rb
|
|
335
|
+
- spec/fx/function_spec.rb
|
|
325
336
|
- spec/fx/schema_dumper/function_spec.rb
|
|
326
337
|
- spec/fx/schema_dumper/trigger_spec.rb
|
|
327
338
|
- spec/fx/statements/function_spec.rb
|
|
328
339
|
- spec/fx/statements/trigger_spec.rb
|
|
340
|
+
- spec/fx/trigger_spec.rb
|
|
329
341
|
- spec/generators/fx/function/function_generator_spec.rb
|
|
330
342
|
- spec/generators/fx/trigger/trigger_generator_spec.rb
|
|
331
343
|
- spec/spec_helper.rb
|