fx 0.3.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +648 -0
  5. data/.travis.yml +18 -8
  6. data/Appraisals +21 -10
  7. data/LICENSE +18 -0
  8. data/README.md +45 -13
  9. data/bin/setup +1 -0
  10. data/gemfiles/rails42.gemfile +2 -1
  11. data/gemfiles/rails50.gemfile +1 -1
  12. data/gemfiles/rails51.gemfile +8 -0
  13. data/gemfiles/rails52.gemfile +8 -0
  14. data/gemfiles/rails60.gemfile +8 -0
  15. data/gemfiles/rails_edge.gemfile +8 -0
  16. data/lib/fx.rb +22 -0
  17. data/lib/fx/adapters/postgres.rb +26 -1
  18. data/lib/fx/adapters/postgres/functions.rb +3 -0
  19. data/lib/fx/command_recorder.rb +0 -5
  20. data/lib/fx/configuration.rb +10 -0
  21. data/lib/fx/definition.rb +13 -3
  22. data/lib/fx/function.rb +2 -0
  23. data/lib/fx/railtie.rb +15 -0
  24. data/lib/fx/schema_dumper.rb +0 -5
  25. data/lib/fx/schema_dumper/function.rb +14 -5
  26. data/lib/fx/statements.rb +0 -5
  27. data/lib/fx/statements/function.rb +4 -2
  28. data/lib/fx/statements/trigger.rb +2 -0
  29. data/lib/fx/trigger.rb +2 -0
  30. data/lib/fx/version.rb +1 -1
  31. data/lib/generators/fx/function/USAGE +2 -0
  32. data/lib/generators/fx/function/function_generator.rb +15 -1
  33. data/lib/generators/fx/trigger/USAGE +2 -0
  34. data/lib/generators/fx/trigger/trigger_generator.rb +15 -1
  35. data/spec/acceptance/user_manages_functions_spec.rb +20 -0
  36. data/spec/acceptance_helper.rb +2 -1
  37. data/spec/dummy/Rakefile +7 -0
  38. data/spec/fx/adapters/postgres/functions_spec.rb +37 -0
  39. data/spec/fx/adapters/postgres/triggers_spec.rb +45 -0
  40. data/spec/fx/adapters/postgres_spec.rb +36 -14
  41. data/spec/fx/definition_spec.rb +23 -0
  42. data/spec/fx/function_spec.rb +55 -0
  43. data/spec/fx/schema_dumper/function_spec.rb +57 -1
  44. data/spec/fx/trigger_spec.rb +55 -0
  45. data/spec/generators/fx/function/function_generator_spec.rb +12 -0
  46. data/spec/generators/fx/trigger/trigger_generator_spec.rb +12 -0
  47. metadata +19 -11
  48. data/.ruby-version +0 -1
  49. data/gemfiles/rails40.gemfile +0 -8
  50. data/gemfiles/rails40.gemfile.lock +0 -111
  51. data/gemfiles/rails41.gemfile +0 -8
  52. data/gemfiles/rails41.gemfile.lock +0 -113
  53. data/gemfiles/rails42.gemfile.lock +0 -130
  54. data/gemfiles/rails50.gemfile.lock +0 -126
@@ -3,14 +3,69 @@ require "spec_helper"
3
3
  describe Fx::SchemaDumper::Function, :db do
4
4
  it "dumps a create_function for a function in the database" do
5
5
  sql_definition = <<-EOS
6
- CREATE OR REPLACE FUNCTION test()
6
+ CREATE OR REPLACE FUNCTION my_function()
7
7
  RETURNS text AS $$
8
8
  BEGIN
9
9
  RETURN 'test';
10
10
  END;
11
11
  $$ LANGUAGE plpgsql;
12
12
  EOS
13
+ connection.create_function :my_function, sql_definition: sql_definition
14
+ connection.create_table :my_table
15
+ stream = StringIO.new
16
+ output = stream.string
17
+
18
+ ActiveRecord::SchemaDumper.dump(connection, stream)
19
+
20
+ expect(output).to(
21
+ match(/table "my_table".*function :my_function.*RETURN 'test';/m),
22
+ )
23
+ end
24
+
25
+ it "dumps a create_function for a function in the database" do
26
+ Fx.configuration.dump_functions_at_beginning_of_schema = true
27
+ sql_definition = <<-EOS
28
+ CREATE OR REPLACE FUNCTION my_function()
29
+ RETURNS text AS $$
30
+ BEGIN
31
+ RETURN 'test';
32
+ END;
33
+ $$ LANGUAGE plpgsql;
34
+ EOS
35
+ connection.create_function :my_function, sql_definition: sql_definition
36
+ connection.create_table :my_table
37
+ stream = StringIO.new
38
+ output = stream.string
39
+
40
+ ActiveRecord::SchemaDumper.dump(connection, stream)
41
+
42
+ expect(output).to(
43
+ match(/function :my_function.*RETURN 'test';.*table "my_table"/m),
44
+ )
45
+ ensure
46
+ Fx.configuration.dump_functions_at_beginning_of_schema = false
47
+ end
48
+
49
+ it "does not dump a create_function for aggregates in the database" do
50
+ sql_definition = <<-EOS
51
+ CREATE OR REPLACE FUNCTION test(text, text)
52
+ RETURNS text AS $$
53
+ BEGIN
54
+ RETURN 'test';
55
+ END;
56
+ $$ LANGUAGE plpgsql;
57
+ EOS
58
+
59
+ aggregate_sql_definition = <<-EOS
60
+ CREATE AGGREGATE aggregate_test(text)
61
+ (
62
+ sfunc = test,
63
+ stype = text
64
+ );
65
+ EOS
66
+
13
67
  connection.create_function :test, sql_definition: sql_definition
68
+ connection.execute aggregate_sql_definition
14
69
  stream = StringIO.new
15
70
 
16
71
  ActiveRecord::SchemaDumper.dump(connection, stream)
@@ -18,5 +73,6 @@ describe Fx::SchemaDumper::Function, :db do
18
73
  output = stream.string
19
74
  expect(output).to include "create_function :test, sql_definition: <<-SQL"
20
75
  expect(output).to include "RETURN 'test';"
76
+ expect(output).not_to include "aggregate_test"
21
77
  end
22
78
  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
@@ -13,6 +13,18 @@ describe Fx::Generators::FunctionGenerator, :generator do
13
13
  expect(migration_file(migration)).to contain "CreateFunctionTest"
14
14
  end
15
15
 
16
+ context "when passed --no-migration" do
17
+ it "creates a only function definition file" do
18
+ migration = file("db/migrate/create_function_test.rb")
19
+ function_definition = file("db/functions/test_v01.sql")
20
+
21
+ run_generator ["test", "--no-migration"]
22
+
23
+ expect(function_definition).to exist
24
+ expect(migration_file(migration)).not_to exist
25
+ end
26
+ end
27
+
16
28
  it "updates an existing function" do
17
29
  with_function_definition(
18
30
  name: "test",
@@ -14,6 +14,18 @@ describe Fx::Generators::TriggerGenerator, :generator do
14
14
  expect(migration_file(migration)).to contain "on: :some_table"
15
15
  end
16
16
 
17
+ context "when passed --no-migration" do
18
+ it "creates a only trigger definition file" do
19
+ migration = file("db/migrate/create_trigger_test.rb")
20
+ trigger_definition = file("db/triggers/test_v01.sql")
21
+
22
+ run_generator ["test", {"table_name" => "some_table"}, "--no-migration"]
23
+
24
+ expect(trigger_definition).to exist
25
+ expect(migration_file(migration)).not_to exist
26
+ end
27
+ end
28
+
17
29
  it "supports naming the table as `on` aswell as `table_name`" do
18
30
  migration = file("db/migrate/create_trigger_test.rb")
19
31
  trigger_definition = file("db/triggers/test_v01.sql")
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.0
4
+ version: 0.6.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: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -188,13 +188,15 @@ extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
190
190
  - ".gitignore"
191
+ - ".hound.yml"
191
192
  - ".rspec"
192
- - ".ruby-version"
193
+ - ".rubocop.yml"
193
194
  - ".travis.yml"
194
195
  - ".yardopts"
195
196
  - Appraisals
196
197
  - CONTRIBUTING.md
197
198
  - Gemfile
199
+ - LICENSE
198
200
  - README.md
199
201
  - Rakefile
200
202
  - bin/appraisal
@@ -204,14 +206,12 @@ files:
204
206
  - bin/setup
205
207
  - bin/yard
206
208
  - fx.gemspec
207
- - gemfiles/rails40.gemfile
208
- - gemfiles/rails40.gemfile.lock
209
- - gemfiles/rails41.gemfile
210
- - gemfiles/rails41.gemfile.lock
211
209
  - gemfiles/rails42.gemfile
212
- - gemfiles/rails42.gemfile.lock
213
210
  - gemfiles/rails50.gemfile
214
- - gemfiles/rails50.gemfile.lock
211
+ - gemfiles/rails51.gemfile
212
+ - gemfiles/rails52.gemfile
213
+ - gemfiles/rails60.gemfile
214
+ - gemfiles/rails_edge.gemfile
215
215
  - lib/fx.rb
216
216
  - lib/fx/adapters/postgres.rb
217
217
  - lib/fx/adapters/postgres/connection.rb
@@ -224,6 +224,7 @@ files:
224
224
  - lib/fx/configuration.rb
225
225
  - lib/fx/definition.rb
226
226
  - lib/fx/function.rb
227
+ - lib/fx/railtie.rb
227
228
  - lib/fx/schema_dumper.rb
228
229
  - lib/fx/schema_dumper/function.rb
229
230
  - lib/fx/schema_dumper/trigger.rb
@@ -259,15 +260,19 @@ files:
259
260
  - spec/features/functions/revert_spec.rb
260
261
  - spec/features/triggers/migrations_spec.rb
261
262
  - spec/features/triggers/revert_spec.rb
263
+ - spec/fx/adapters/postgres/functions_spec.rb
264
+ - spec/fx/adapters/postgres/triggers_spec.rb
262
265
  - spec/fx/adapters/postgres_spec.rb
263
266
  - spec/fx/command_recorder/arguments_spec.rb
264
267
  - spec/fx/command_recorder_spec.rb
265
268
  - spec/fx/configuration_spec.rb
266
269
  - spec/fx/definition_spec.rb
270
+ - spec/fx/function_spec.rb
267
271
  - spec/fx/schema_dumper/function_spec.rb
268
272
  - spec/fx/schema_dumper/trigger_spec.rb
269
273
  - spec/fx/statements/function_spec.rb
270
274
  - spec/fx/statements/trigger_spec.rb
275
+ - spec/fx/trigger_spec.rb
271
276
  - spec/generators/fx/function/function_generator_spec.rb
272
277
  - spec/generators/fx/trigger/trigger_generator_spec.rb
273
278
  - spec/spec_helper.rb
@@ -293,8 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
298
  - !ruby/object:Gem::Version
294
299
  version: '0'
295
300
  requirements: []
296
- rubyforge_project:
297
- rubygems_version: 2.5.1
301
+ rubygems_version: 3.1.4
298
302
  signing_key:
299
303
  specification_version: 4
300
304
  summary: Support for database functions and triggers in Rails migrations
@@ -317,15 +321,19 @@ test_files:
317
321
  - spec/features/functions/revert_spec.rb
318
322
  - spec/features/triggers/migrations_spec.rb
319
323
  - spec/features/triggers/revert_spec.rb
324
+ - spec/fx/adapters/postgres/functions_spec.rb
325
+ - spec/fx/adapters/postgres/triggers_spec.rb
320
326
  - spec/fx/adapters/postgres_spec.rb
321
327
  - spec/fx/command_recorder/arguments_spec.rb
322
328
  - spec/fx/command_recorder_spec.rb
323
329
  - spec/fx/configuration_spec.rb
324
330
  - spec/fx/definition_spec.rb
331
+ - spec/fx/function_spec.rb
325
332
  - spec/fx/schema_dumper/function_spec.rb
326
333
  - spec/fx/schema_dumper/trigger_spec.rb
327
334
  - spec/fx/statements/function_spec.rb
328
335
  - spec/fx/statements/trigger_spec.rb
336
+ - spec/fx/trigger_spec.rb
329
337
  - spec/generators/fx/function/function_generator_spec.rb
330
338
  - spec/generators/fx/trigger/trigger_generator_spec.rb
331
339
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- 2.3
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.0"
6
- gem "railties", "~> 4.0.0"
7
-
8
- gemspec :path => "../"
@@ -1,111 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- fx (0.3.0)
5
- activerecord (>= 4.0.0)
6
- railties (>= 4.0.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (4.0.13)
12
- activesupport (= 4.0.13)
13
- builder (~> 3.1.0)
14
- erubis (~> 2.7.0)
15
- rack (~> 1.5.2)
16
- rack-test (~> 0.6.2)
17
- activemodel (4.0.13)
18
- activesupport (= 4.0.13)
19
- builder (~> 3.1.0)
20
- activerecord (4.0.13)
21
- activemodel (= 4.0.13)
22
- activerecord-deprecated_finders (~> 1.0.2)
23
- activesupport (= 4.0.13)
24
- arel (~> 4.0.0)
25
- activerecord-deprecated_finders (1.0.4)
26
- activesupport (4.0.13)
27
- i18n (~> 0.6, >= 0.6.9)
28
- minitest (~> 4.2)
29
- multi_json (~> 1.3)
30
- thread_safe (~> 0.1)
31
- tzinfo (~> 0.3.37)
32
- ammeter (1.1.4)
33
- activesupport (>= 3.0)
34
- railties (>= 3.0)
35
- rspec-rails (>= 2.2)
36
- appraisal (2.1.0)
37
- bundler
38
- rake
39
- thor (>= 0.14.0)
40
- arel (4.0.2)
41
- builder (3.1.4)
42
- coderay (1.1.1)
43
- database_cleaner (1.5.3)
44
- diff-lcs (1.2.5)
45
- erubis (2.7.0)
46
- i18n (0.7.0)
47
- method_source (0.8.2)
48
- minitest (4.7.5)
49
- multi_json (1.12.1)
50
- pg (0.19.0)
51
- pry (0.10.4)
52
- coderay (~> 1.1.0)
53
- method_source (~> 0.8.1)
54
- slop (~> 3.4)
55
- rack (1.5.5)
56
- rack-test (0.6.3)
57
- rack (>= 1.0)
58
- railties (4.0.13)
59
- actionpack (= 4.0.13)
60
- activesupport (= 4.0.13)
61
- rake (>= 0.8.7)
62
- thor (>= 0.18.1, < 2.0)
63
- rake (11.3.0)
64
- redcarpet (3.3.4)
65
- rspec (3.5.0)
66
- rspec-core (~> 3.5.0)
67
- rspec-expectations (~> 3.5.0)
68
- rspec-mocks (~> 3.5.0)
69
- rspec-core (3.5.4)
70
- rspec-support (~> 3.5.0)
71
- rspec-expectations (3.5.0)
72
- diff-lcs (>= 1.2.0, < 2.0)
73
- rspec-support (~> 3.5.0)
74
- rspec-mocks (3.5.0)
75
- diff-lcs (>= 1.2.0, < 2.0)
76
- rspec-support (~> 3.5.0)
77
- rspec-rails (3.5.2)
78
- actionpack (>= 3.0)
79
- activesupport (>= 3.0)
80
- railties (>= 3.0)
81
- rspec-core (~> 3.5.0)
82
- rspec-expectations (~> 3.5.0)
83
- rspec-mocks (~> 3.5.0)
84
- rspec-support (~> 3.5.0)
85
- rspec-support (3.5.0)
86
- slop (3.6.0)
87
- thor (0.19.1)
88
- thread_safe (0.3.5)
89
- tzinfo (0.3.52)
90
- yard (0.9.5)
91
-
92
- PLATFORMS
93
- ruby
94
-
95
- DEPENDENCIES
96
- activerecord (~> 4.0.0)
97
- ammeter (>= 1.1.3)
98
- appraisal
99
- bundler (>= 1.5)
100
- database_cleaner
101
- fx!
102
- pg
103
- pry
104
- railties (~> 4.0.0)
105
- rake
106
- redcarpet
107
- rspec (>= 3.3)
108
- yard
109
-
110
- BUNDLED WITH
111
- 1.13.6
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.0"
6
- gem "railties", "~> 4.1.0"
7
-
8
- gemspec :path => "../"
@@ -1,113 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- fx (0.3.0)
5
- activerecord (>= 4.0.0)
6
- railties (>= 4.0.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (4.1.16)
12
- actionview (= 4.1.16)
13
- activesupport (= 4.1.16)
14
- rack (~> 1.5.2)
15
- rack-test (~> 0.6.2)
16
- actionview (4.1.16)
17
- activesupport (= 4.1.16)
18
- builder (~> 3.1)
19
- erubis (~> 2.7.0)
20
- activemodel (4.1.16)
21
- activesupport (= 4.1.16)
22
- builder (~> 3.1)
23
- activerecord (4.1.16)
24
- activemodel (= 4.1.16)
25
- activesupport (= 4.1.16)
26
- arel (~> 5.0.0)
27
- activesupport (4.1.16)
28
- i18n (~> 0.6, >= 0.6.9)
29
- json (~> 1.7, >= 1.7.7)
30
- minitest (~> 5.1)
31
- thread_safe (~> 0.1)
32
- tzinfo (~> 1.1)
33
- ammeter (1.1.4)
34
- activesupport (>= 3.0)
35
- railties (>= 3.0)
36
- rspec-rails (>= 2.2)
37
- appraisal (2.1.0)
38
- bundler
39
- rake
40
- thor (>= 0.14.0)
41
- arel (5.0.1.20140414130214)
42
- builder (3.2.2)
43
- coderay (1.1.1)
44
- database_cleaner (1.5.3)
45
- diff-lcs (1.2.5)
46
- erubis (2.7.0)
47
- i18n (0.7.0)
48
- json (1.8.3)
49
- method_source (0.8.2)
50
- minitest (5.9.1)
51
- pg (0.19.0)
52
- pry (0.10.4)
53
- coderay (~> 1.1.0)
54
- method_source (~> 0.8.1)
55
- slop (~> 3.4)
56
- rack (1.5.5)
57
- rack-test (0.6.3)
58
- rack (>= 1.0)
59
- railties (4.1.16)
60
- actionpack (= 4.1.16)
61
- activesupport (= 4.1.16)
62
- rake (>= 0.8.7)
63
- thor (>= 0.18.1, < 2.0)
64
- rake (11.3.0)
65
- redcarpet (3.3.4)
66
- rspec (3.5.0)
67
- rspec-core (~> 3.5.0)
68
- rspec-expectations (~> 3.5.0)
69
- rspec-mocks (~> 3.5.0)
70
- rspec-core (3.5.4)
71
- rspec-support (~> 3.5.0)
72
- rspec-expectations (3.5.0)
73
- diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.5.0)
75
- rspec-mocks (3.5.0)
76
- diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.5.0)
78
- rspec-rails (3.5.2)
79
- actionpack (>= 3.0)
80
- activesupport (>= 3.0)
81
- railties (>= 3.0)
82
- rspec-core (~> 3.5.0)
83
- rspec-expectations (~> 3.5.0)
84
- rspec-mocks (~> 3.5.0)
85
- rspec-support (~> 3.5.0)
86
- rspec-support (3.5.0)
87
- slop (3.6.0)
88
- thor (0.19.1)
89
- thread_safe (0.3.5)
90
- tzinfo (1.2.2)
91
- thread_safe (~> 0.1)
92
- yard (0.9.5)
93
-
94
- PLATFORMS
95
- ruby
96
-
97
- DEPENDENCIES
98
- activerecord (~> 4.1.0)
99
- ammeter (>= 1.1.3)
100
- appraisal
101
- bundler (>= 1.5)
102
- database_cleaner
103
- fx!
104
- pg
105
- pry
106
- railties (~> 4.1.0)
107
- rake
108
- redcarpet
109
- rspec (>= 3.3)
110
- yard
111
-
112
- BUNDLED WITH
113
- 1.13.6