arfi 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 331aff2d0db8aae05dd27918368edd128c8a30f49617026967817b32faf95bfc
4
- data.tar.gz: b3d68c00606ba1607640b458da75b094cb8a40c88aaf0dbf33758a7902172e07
3
+ metadata.gz: a95843bc4c7c39fb07723d33c94b4468193d483caea79c65b44f3cfa6736dbb1
4
+ data.tar.gz: 9d3241e16d63b05472909634885b33e0fc5dad764684826cbfff4f9f126b8312
5
5
  SHA512:
6
- metadata.gz: c2db125c26d24967ec3874ac2d210a9c1b35a9c72e929ffbc7b3b7e5c08fdc4e67acacd0f53dfb34ed208051428a785eb5c21c52ae3cc4b578016a45e4c090d2
7
- data.tar.gz: d8dc170dd81542d52979542dc03c59b041f78b6df62b219c7e5dacbc36c5927e8136a74c3f4e60cc4c108198def13e0ff0879f01c044e3561ff9455c8c088dc3
6
+ metadata.gz: e429573863462c5e717b010ad6d648d3080154e73f42addbb19eb064c3db3fdd62661fbc96cc93b14d2b8709f056c8a4c0a771b7f2f7fb9a990b034b18ae6bed
7
+ data.tar.gz: 2f0a157842ae64ea64163fce588df3c8c44a153f8629c7dc9f8287ccde8a0ad405fbed40e33658dea17a05bbe93b3e7f55e6f180039f58cc42998babdf2f4ad3
data/.rubocop.yml CHANGED
@@ -3,4 +3,7 @@ AllCops:
3
3
  NewCops: enable
4
4
  Exclude:
5
5
  - lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb
6
- - 'vendor/**/*'
6
+ - 'vendor/**/*'
7
+
8
+ Gemspec/DevelopmentDependencies:
9
+ EnforcedStyle: gemspec
data/README.md CHANGED
@@ -4,10 +4,14 @@
4
4
 
5
5
  ---
6
6
 
7
- **! WARNING !**
7
+ > [!WARNING]
8
+ > This project only supports PostgreSQL databases, however, MySQL usage will also be available in upcoming updates.
9
+ > Since SQLite3 does not support functional indexes with custom functions, support for this database will not be
10
+ > available for a while, however, you can help the project by contributing to the open source.
8
11
 
9
- This project supports only PostgreSQL databases. In near future, ARFI will support MySQL databases. Since SQLite3 does
10
- not support functional indexes with custom functions, this project won't support SQLite3 databases in near future.
12
+ > [!NOTE]
13
+ > This project requires Ruby 3.1.0+, it has not yet been tested on other versions, however, at the time of writing,
14
+ > backward compatibility was maintained wherever possible.
11
15
 
12
16
  ---
13
17
 
@@ -24,10 +28,14 @@ transition to `structure.sql` (SQL-based schema).
24
28
  * [Index creation](#index-creation)
25
29
  * [Index destroy](#index-destroy)
26
30
  * [Additional help](#additional-help)
31
+ * [Demo](#demo)
32
+ * [Library features](#library-features)
33
+ * [Roadmap](#roadmap)
27
34
  * [Development](#development)
28
35
  * [Build from source](#build-from-source)
29
36
  * [Requirements](#requirements)
30
37
  * [Contributing](#contributing)
38
+ * [Miscellaneous](#miscellaneous)
31
39
  * [License](#license)
32
40
  * [Code of Conduct](#code-of-conduct)
33
41
 
@@ -53,7 +61,8 @@ directory. ARFI uses `db/functions` directory to store your functional indexes.
53
61
  ### Index creation
54
62
 
55
63
  Run `bundle exec arfi f_idx create function_name` to create a new functional index. New index will be created in
56
- `db/functions` directory under `function_name_v01.sql` name. Edit you index and run `bundle exec rails db:migrate`
64
+ `db/functions` directory under `function_name_v01.sql` name. Edit you index and run `bundle exec rails db:migrate`. You
65
+ can also use custom template for index. Type `bundle exec arfi f_idx help create` for additional info.
57
66
 
58
67
  ### Index destroy
59
68
 
@@ -63,6 +72,48 @@ If you want to destroy your index, run `bundle exec arfi f_idx destroy function_
63
72
 
64
73
  Run `bundle exec arfi` for additional help.
65
74
 
75
+ ## Demo
76
+
77
+ Demo available as separate project built with Rails 7.2 and PostgreSQL 14: https://github.com/unurgunite/poc_arfi_72.
78
+ README is also available.
79
+
80
+ ## Library features
81
+
82
+ 1. ARFI supports all types of database initialization
83
+
84
+ | Task | Completed |
85
+ |----------------|--------------------|
86
+ | db:migrate | :white_check_mark: |
87
+ | db:setup | :white_check_mark: |
88
+ | db:prepare | :white_check_mark: |
89
+ | db:schema:load | :white_check_mark: |
90
+
91
+ 2. Database support
92
+
93
+ | DB adapter | Tested |
94
+ |----------------|-------------------------------------------------------|
95
+ | PostgreSQL | 9+ :white_check_mark: |
96
+ | MySQL | In progress :arrows_counterclockwise: |
97
+ | SQLite3 | In progress (not primarily) :arrows_counterclockwise: |
98
+
99
+ 3. Rails support
100
+
101
+ | Rails version | Tested |
102
+ |---------------|---------------------------------------|
103
+ | 8 | In progress :arrows_counterclockwise: |
104
+ | 7 | :white_check_mark: |
105
+ | 6 | In progress :arrows_counterclockwise: |
106
+
107
+ ## Roadmap
108
+
109
+ 1. ~~Custom template for SQL functions using `--template` flag;~~
110
+ 2. Multidb support (Rails 6+ feature);
111
+ 3. Add support for 4+ ActiveRecord;
112
+ 4. Add RSpec tests;
113
+ 5. Add separate YARD doc page;
114
+ 6. Update CI/CD;
115
+ 7. Add support for Ruby 2.6+.
116
+
66
117
  ## Development
67
118
 
68
119
  ### Build from source
@@ -75,7 +126,7 @@ git clone https://github.com/unurgunite/arfi.git
75
126
  cd arfi
76
127
  bundle install
77
128
  gem build arfi.gemspec
78
- gem install arfi-0.1.0.gem
129
+ gem install arfi-0.3.0.gem
79
130
  ```
80
131
 
81
132
  Also, you can run `bin/setup` to automatically install everything needed.
@@ -92,26 +143,21 @@ ARFI is built on top of the following gems:
92
143
  | Rubocop | For static code analysis. |
93
144
  | Rake | For patching built-in Rails Rake tasks. |
94
145
 
95
- ## Roadmap
96
-
97
- | Task | Completed |
98
- |----------------|--------------------|
99
- | db:migrate | :white_check_mark: |
100
- | db:setup | :white_check_mark: |
101
- | db:prepare | :white_check_mark: |
102
- | db:schema:load | :white_check_mark: |
103
-
104
146
  ## Contributing
105
147
 
106
148
  Bug reports and pull requests are welcome on GitHub at https://github.com/unurgunite/arfi. This project is intended to
107
149
  be a safe, welcoming space for collaboration, and contributors are expected to adhere to
108
150
  the [code of conduct](https://github.com/[USERNAME]/Arfi/blob/master/CODE_OF_CONDUCT.md).
109
151
 
152
+ ## Miscellaneous
153
+
154
+ ARFI is highly inspired by https://github.com/teoljungberg/fx project.
155
+
110
156
  ## License
111
157
 
112
158
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
113
159
 
114
160
  ## Code of Conduct
115
161
 
116
- Everyone interacting in the Arfi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow
162
+ Everyone interacting in the ARFI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow
117
163
  the [code of conduct](https://github.com/[USERNAME]/Arfi/blob/master/CODE_OF_CONDUCT.md).
@@ -9,12 +9,36 @@ module Arfi
9
9
  # +Arfi::Commands::FIdx+ module contains commands for manipulating functional index in Rails project.
10
10
  class FIdx < Thor
11
11
  desc 'create INDEX_NAME', 'Initialize the functional index'
12
+ option :template, type: :string, banner: 'template_file'
12
13
  # +Arfi::Commands::FIdx#create+ -> void
13
14
  #
14
15
  # This command is used to create the functional index.
15
16
  #
16
17
  # @example
17
18
  # bundle exec arfi f_idx create some_function
19
+ #
20
+ # ARFI also supports the use of custom templates for SQL functions, but now there are some restrictions and rules
21
+ # according to which it is necessary to describe the function. First, the function must be written in a
22
+ # Ruby-compatible syntax: the file name is not so important, but the name for the function name must be
23
+ # interpolated with the +index_name+ variable name, and the function itself must be placed in the HEREDOC
24
+ # statement. Below is an example file.
25
+ #
26
+ # @example
27
+ # # ./template/my_custom_template
28
+ # <<~SQL
29
+ # CREATE OR REPLACE FUNCTION #{index_name}() RETURNS TEXT[]
30
+ # LANGUAGE SQL
31
+ # IMMUTABLE AS
32
+ # $$
33
+ # -- Function body here
34
+ # $$
35
+ # SQL
36
+ #
37
+ # To use a custom template, add the --template flag.
38
+ #
39
+ # @example
40
+ # bundle exec arfi f_idx create some_function --template ./template/my_custom_template
41
+ #
18
42
  # @param index_name [String] Name of the index.
19
43
  # @return [void]
20
44
  # @raise [Arfi::Errors::InvalidSchemaFormat] if ActiveRecord.schema_format is not :ruby
@@ -79,6 +103,8 @@ module Arfi
79
103
  # @param index_name [String] Name of the index.
80
104
  # @return [String] SQL function body.
81
105
  def build_sql_function(index_name)
106
+ return build_from_file(index_name) if options[:template]
107
+
82
108
  <<~SQL
83
109
  CREATE OR REPLACE FUNCTION #{index_name}() RETURNS TEXT[]
84
110
  LANGUAGE SQL
@@ -89,6 +115,20 @@ module Arfi
89
115
  SQL
90
116
  end
91
117
 
118
+ # +Arfi::Commands::FIdx#build_from_file+ -> String
119
+ #
120
+ # Helper method to build the SQL function. Used with flag `--template`.
121
+ #
122
+ # @!visibility private
123
+ # @private
124
+ # @param index_name [String] Name of the index.
125
+ # @return [String] SQL function body.
126
+ # @see Arfi::Commands::FIdx#create
127
+ # @see Arfi::Commands::FIdx#build_sql_function
128
+ def build_from_file(index_name)
129
+ RubyVM::InstructionSequence.compile("index_name = '#{index_name}'; #{File.read(options[:template])}").eval
130
+ end
131
+
92
132
  # +Arfi::Commands::FIdx#create_index_file+ -> void
93
133
  #
94
134
  # Helper method to create the index file.
data/lib/arfi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arfi
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Arfi
2
- VERSION: "0.2.0"
2
+ VERSION: "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,116 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arfi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - unurgunite
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
12
- description: Bring the ability to create and maintain functional indexes without transition
13
- to structure.sql.
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: thor
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: irb
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: repl_type_completor
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.21'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.21'
110
+ description: 'ARFI — ActiveRecord Functional Indexes. Bring the ability to create
111
+ and maintain functional indexes without transition to structure.sql.
112
+
113
+ '
14
114
  email:
15
115
  - senpaiguru1488@gmail.com
16
116
  executables: