arfi 0.2.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/.rubocop.yml +4 -1
- data/README.md +61 -15
- data/lib/arfi/commands/f_idx.rb +40 -0
- data/lib/arfi/version.rb +1 -1
- data/sig/lib/arfi/version.rbs +1 -1
- metadata +104 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 072f0f4098aec38e2d25e6d3350502930f9be8b0c5b6396545239662c2651570
|
4
|
+
data.tar.gz: 8be6c8f4e5f8a38b381289c8fe127d07c9a23313aa87b24022ddb5457eb9429f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab81783efb65e023578c70e578248ea267ba3bac815726d9911ced210c139424da8e777160f75c903cdbc45e718d137772109581fe120ef886f73d31cd524f01
|
7
|
+
data.tar.gz: ce0c50d27cce3dedd894106ef50111d13b0424e00e690c2acd731c213863fcbd988d8e2a3fa7265962c58b874a320b3d04c6ab36b815524550c39472eca4b26e
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -4,10 +4,14 @@
|
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
|
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
|
-
|
10
|
-
|
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.
|
129
|
+
gem install arfi-0.3.1.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
|
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).
|
data/lib/arfi/commands/f_idx.rb
CHANGED
@@ -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
data/sig/lib/arfi/version.rbs
CHANGED
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.
|
4
|
+
version: 0.3.1
|
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
|
-
|
13
|
-
|
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: '7.0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '7.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: '12.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '12.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: '1.3'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: irb
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.15'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.15'
|
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.1.11
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.1.11
|
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:
|