fx 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c933b484808a6a2a99f4a0faf84a20ea685f17bf
4
- data.tar.gz: 6f38a705c1017b72f0930310f7a2dd9d3e273813
2
+ SHA256:
3
+ metadata.gz: 4b2ed07756db1d26e35994559994635b2e5bc1e807eda6eb4b132442a3b561ea
4
+ data.tar.gz: c5d60d5200347b5fc5cdf5b18d232b0662b2f92926cfb816f4bb4a36206c9bb3
5
5
  SHA512:
6
- metadata.gz: '018b13261d9eabe7f6e79e36bcf4cf765956d409789d6d1c37255976c883a8f9fb4f4a2c5be960ebb283d5d436f9ea0e651309e635f531c0b74b9e88041cb6cd'
7
- data.tar.gz: 12a8a67b11f91f717c75d4fe7a6a98b400501bf5f3914dc8088ecc8abf07ab2a08f45c012eba6578cd9f97cf32cf106a0add7db2fdfcc8d816e705cfcd445187
6
+ metadata.gz: ac363c781155605fc98eac9649d5e49fc3e5a0412ef50f4195e8fa37dcf7bf58d9ac89625e7dd8e482e4ebafc0fbcdc447f7a3d5c97cb2813c6d1a60727e2f1a
7
+ data.tar.gz: db5c222c9de3b758dbdd21f725cd5740b8ecfe1571ee761de7385cb4e73ec77f8f02284c95b2b115dbf62906d2fa2d6613c6f39535cdef3e62cf1d3419c36765
data/README.md CHANGED
@@ -21,18 +21,29 @@ F(x) ships with support for PostgreSQL. The adapter is configurable (see
21
21
 
22
22
  ## Great, how do I create a trigger and a function?
23
23
 
24
- You've got this great idea for a trigger you'd like to call
24
+ You've got this great idea for a function you'd like to call
25
25
  `uppercase_users_name`. You can create the migration and the corresponding
26
26
  definition file with the following command:
27
27
 
28
28
  ```sh
29
- % rails generate fx:trigger uppercase_users_name
29
+ % rails generate fx:function uppercase_users_name
30
+ create db/functions/uppercase_users_name_v01.sql
31
+ create db/migrate/[TIMESTAMP]_create_function_uppercase_users_name.rb
32
+ ```
33
+
34
+ Edit the `db/functions/uppercase_users_name_v01.sql` file with the SQL statement
35
+ that defines your function.
36
+
37
+ Next, let's add a trigger called `uppercase_users_name` to call our new
38
+ function each time we `INSERT` on the `users` table.
39
+
40
+ ```sh
41
+ % rails generate fx:trigger uppercase_users_name table_name:users
30
42
  create db/triggers/uppercase_users_name_v01.sql
31
43
  create db/migrate/[TIMESTAMP]_create_trigger_uppercase_users_name.rb
32
44
  ```
33
45
 
34
- Edit the `db/triggers/uppercase_users_name_v01.sql` file with the SQL statement
35
- that defines your trigger. In our example, this might look something like this:
46
+ In our example, this might look something like this:
36
47
 
37
48
  ```sql
38
49
  CREATE TRIGGER uppercase_users_name
@@ -41,15 +52,6 @@ CREATE TRIGGER uppercase_users_name
41
52
  EXECUTE PROCEDURE uppercase_users_name();
42
53
  ```
43
54
 
44
- As you see, we execute a function called `uppercase_users_name` before each
45
- `INSERT` on the `users` table, which is a function we don't have yet.
46
-
47
- ```sh
48
- % rails generate fx:function uppercase_users_name
49
- create db/functions/uppercase_users_name_v01.sql
50
- create db/migrate/[TIMESTAMP]_create_function_uppercase_users_name.rb
51
- ```
52
-
53
55
  The generated migrations contains `create_function` and `create_trigger`
54
56
  statements. The migration is reversible and the schema will be dumped into your
55
57
  `schema.rb` file.
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 4.0.0"
6
6
  gem "railties", "~> 4.0.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- fx (0.3.0)
4
+ fx (0.4.0)
5
5
  activerecord (>= 4.0.0)
6
6
  railties (>= 4.0.0)
7
7
 
@@ -108,4 +108,4 @@ DEPENDENCIES
108
108
  yard
109
109
 
110
110
  BUNDLED WITH
111
- 1.14.2
111
+ 1.17.3
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 4.1.0"
6
6
  gem "railties", "~> 4.1.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- fx (0.3.0)
4
+ fx (0.4.0)
5
5
  activerecord (>= 4.0.0)
6
6
  railties (>= 4.0.0)
7
7
 
@@ -110,4 +110,4 @@ DEPENDENCIES
110
110
  yard
111
111
 
112
112
  BUNDLED WITH
113
- 1.14.2
113
+ 1.17.3
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 4.2.0"
6
6
  gem "railties", "~> 4.2.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- fx (0.3.0)
4
+ fx (0.4.0)
5
5
  activerecord (>= 4.0.0)
6
6
  railties (>= 4.0.0)
7
7
 
@@ -127,4 +127,4 @@ DEPENDENCIES
127
127
  yard
128
128
 
129
129
  BUNDLED WITH
130
- 1.14.2
130
+ 1.17.3
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 5.0"
6
6
  gem "railties", "~> 5.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- fx (0.3.0)
4
+ fx (0.4.0)
5
5
  activerecord (>= 4.0.0)
6
6
  railties (>= 4.0.0)
7
7
 
@@ -123,4 +123,4 @@ DEPENDENCIES
123
123
  yard
124
124
 
125
125
  BUNDLED WITH
126
- 1.14.2
126
+ 1.17.3
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", :github => "rails/rails"
6
- gem "arel", :github => "rails/arel"
5
+ gem "rails", github: "rails/rails"
6
+ gem "arel", github: "rails/arel"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -67,7 +67,7 @@ GIT
67
67
  PATH
68
68
  remote: ..
69
69
  specs:
70
- fx (0.3.0)
70
+ fx (0.4.0)
71
71
  activerecord (>= 4.0.0)
72
72
  railties (>= 4.0.0)
73
73
 
@@ -176,4 +176,4 @@ DEPENDENCIES
176
176
  yard
177
177
 
178
178
  BUNDLED WITH
179
- 1.14.2
179
+ 1.17.3
data/lib/fx/definition.rb CHANGED
@@ -8,7 +8,7 @@ module Fx
8
8
  end
9
9
 
10
10
  def to_sql
11
- File.read(full_path).tap do |content|
11
+ File.read(find_file || full_path).tap do |content|
12
12
  if content.empty?
13
13
  raise "Define #{@type} in #{path} before migrating."
14
14
  end
@@ -20,7 +20,7 @@ module Fx
20
20
  end
21
21
 
22
22
  def path
23
- File.join("db", @type.pluralize, filename)
23
+ @_path ||= File.join("db", @type.pluralize, filename)
24
24
  end
25
25
 
26
26
  def version
@@ -30,7 +30,17 @@ module Fx
30
30
  private
31
31
 
32
32
  def filename
33
- "#{@name}_v#{version}.sql"
33
+ @_filename ||= "#{@name}_v#{version}.sql"
34
+ end
35
+
36
+ def find_file
37
+ migration_paths.lazy
38
+ .map { |migration_path| File.expand_path(File.join("..", "..", path), migration_path) }
39
+ .find { |definition_path| File.exist?(definition_path) }
40
+ end
41
+
42
+ def migration_paths
43
+ Rails.application.config.paths["db/migrate"].expanded
34
44
  end
35
45
  end
36
46
  end
data/lib/fx/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Fx
2
2
  # @api private
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -34,9 +34,10 @@ module Fx
34
34
  first = triggers.first
35
35
  expect(triggers.size).to eq 1
36
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
37
+ expect(first.definition).to include("BEFORE INSERT")
38
+ expect(first.definition).to match(/ON [public\.users|users]/)
39
+ expect(first.definition).to include("FOR EACH ROW")
40
+ expect(first.definition).to include("EXECUTE PROCEDURE uppercase_users_name()")
40
41
  end
41
42
  end
42
43
  end
@@ -28,6 +28,29 @@ describe Fx::Definition do
28
28
  %r(Define function in db/functions/test_v01.sql before migrating),
29
29
  )
30
30
  end
31
+
32
+ context "when definition is at Rails engine" do
33
+ it "returns the content of a function definition" do
34
+ sql_definition = <<-EOS
35
+ CREATE OR REPLACE FUNCTION test()
36
+ RETURNS text AS $$
37
+ BEGIN
38
+ RETURN 'test';
39
+ END;
40
+ $$ LANGUAGE plpgsql;
41
+ EOS
42
+ engine_path = Rails.root.join("tmp", "engine")
43
+ FileUtils.mkdir_p(engine_path.join("db", "functions"))
44
+ File.write(engine_path.join("db", "functions", "custom_test_v01.sql"), sql_definition)
45
+ Rails.application.config.paths["db/migrate"].push(engine_path.join("db", "migrate"))
46
+
47
+ definition = Fx::Definition.new(name: "custom_test", version: 1)
48
+
49
+ expect(definition.to_sql).to eq sql_definition
50
+
51
+ FileUtils.rm_rf(engine_path)
52
+ end
53
+ end
31
54
  end
32
55
 
33
56
  context "representing a trigger definition" do
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.1
4
+ version: 0.4.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: 2018-04-08 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -191,7 +191,6 @@ files:
191
191
  - ".hound.yml"
192
192
  - ".rspec"
193
193
  - ".rubocop.yml"
194
- - ".ruby-version"
195
194
  - ".travis.yml"
196
195
  - ".yardopts"
197
196
  - Appraisals
@@ -301,8 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
300
  - !ruby/object:Gem::Version
302
301
  version: '0'
303
302
  requirements: []
304
- rubyforge_project:
305
- rubygems_version: 2.5.2.1
303
+ rubygems_version: 3.0.3
306
304
  signing_key:
307
305
  specification_version: 4
308
306
  summary: Support for database functions and triggers in Rails migrations
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.3