ARFI

Alt


[!WARNING] This project only supports PostgreSQL databases, however, MySQL usage will also be available in upcoming updates. Since SQLite3 does not support functional indexes with custom functions, support for this database will not be available for a while, however, you can help the project by contributing to the open source.

[!NOTE] This project requires Ruby 3.1.0+, it has not yet been tested on other versions, however, at the time of writing, backward compatibility was maintained wherever possible.


ARFI – ActiveRecord Functional Indexes

ARFI gem brings you the ability to create and maintain functional indexes for your ActiveRecord models without transition to structure.sql (SQL-based schema).

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add arfi

Usage

CLI

ARFI uses Thor as a command line interface (CLI) instead of Rake, so it has a specific DSL.

Project creation

Firstly, run bundle exec arfi project create to create a new project. This command will create db/functions directory. ARFI uses db/functions directory to store your functional indexes.

Index creation

Run bundle exec arfi f_idx create function_name to create a new functional index. New index will be created in db/functions directory under function_name_v01.sql name. Edit you index and run bundle exec rails db:migrate. You can also use custom template for index. Type bundle exec arfi f_idx help create for additional info.

Index destroy

If you want to destroy your index, run bundle exec arfi f_idx destroy function_name [revision (1 by default)]

Additional help

Run bundle exec arfi for additional help.

Demo

Demo available as separate project built with Rails 7.2 and PostgreSQL 14: https://github.com/unurgunite/poc_arfi_72. README is also available.

Library features

  1. ARFI supports all types of database initialization

    Task Completed
    db:migrate :white_check_mark:
    db:setup :white_check_mark:
    db:prepare :white_check_mark:
    db:schema:load :white_check_mark:
  2. Database support

    DB adapter Tested
    PostgreSQL 9+ :white_check_mark:
    MySQL In progress :arrows_counterclockwise:
    SQLite3 In progress (not primarily) :arrows_counterclockwise:
  3. Rails support

| Rails version | Tested | |---------------|---------------------------------------| | 8 | In progress :arrows_counterclockwise: | | 7 | :white_check_mark: | | 6 | In progress :arrows_counterclockwise: |

Roadmap

  1. ~~Custom template for SQL functions using --template flag;~~
  2. Multidb support (Rails 6+ feature);
  3. Add support for 4+ ActiveRecord;
  4. Add RSpec tests;
  5. Add separate YARD doc page;
  6. Update CI/CD;
  7. Add support for Ruby 2.6+.

Development

Build from source

The manual installation includes installation via command line interface. it is practically no different from what happens during the automatic build of the project:

git clone https://github.com/unurgunite/arfi.git
cd arfi
bundle install
gem build arfi.gemspec
gem install arfi-0.3.0.gem

Also, you can run bin/setup to automatically install everything needed.

Requirements

ARFI is built on top of the following gems:

Dependencies Description
ActiveRecord Used to patch ActiveRecord::Base module with new methods.
Rails Used for fetching project settings (database connection settings, Rails environment, etc.)
Thor For CLI development.
Rubocop For static code analysis.
Rake For patching built-in Rails Rake tasks.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/unurgunite/arfi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Miscellaneous

ARFI is highly inspired by https://github.com/teoljungberg/fx project.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ARFI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.