Class: Arfi::Commands::FIdx

Inherits:
Thor
  • Object
show all
Defined in:
lib/arfi/commands/f_idx.rb

Overview

Arfi::Commands::FIdx module contains commands for manipulating functional index in Rails project.

Constant Summary collapse

ADAPTERS =
i[postgresql mysql].freeze

Instance Method Summary collapse

Instance Method Details

#create(index_name) ⇒ void

This method returns an undefined value.

Arfi::Commands::FIdx#create -> void

This command is used to create the functional index.

ARFI also supports the use of custom templates for SQL functions, but now there are some restrictions and rules according to which it is necessary to describe the function. First, the function must be written in a Ruby-compatible syntax: the file name is not so important, but the name for the function name must be interpolated with the index_name variable name, and the function itself must be placed in the HEREDOC statement. Below is an example file.

To use a custom template, add the –template flag.

Examples:

bundle exec arfi f_idx create some_function
# ./template/my_custom_template
"CREATE OR REPLACE FUNCTION \#{index_name}() RETURNS TEXT[]\n  LANGUAGE SQL\n  IMMUTABLE AS\n$$\n  -- Function body here\n$$\n"
bundle exec arfi f_idx create some_function --template ./template/my_custom_template

Parameters:

  • index_name (String)

    Name of the index.

Raises:

See Also:

  • #validate_schema_format!


57
58
59
60
61
# File 'lib/arfi/commands/f_idx.rb', line 57

def create(index_name)
  validate_schema_format!
  content = build_sql_function(index_name)
  create_function_file(index_name, content)
end

#destroy(index_name) ⇒ void

This method returns an undefined value.

Arfi::Commands::FIdx#destroy -> void

This command is used to delete the functional index.

Examples:

bundle exec arfi f_idx destroy some_function [revision index (just an integer, 1 is by default)]

Parameters:

  • index_name (String)

    Name of the index.

Raises:



81
82
83
84
85
86
87
88
# File 'lib/arfi/commands/f_idx.rb', line 81

def destroy(index_name)
  validate_schema_format!

  revision = Integer(options[:revision] || '01') # steep:ignore NoMethod
  revision = "0#{revision}"
  FileUtils.rm("#{functions_dir}/#{index_name}_v#{revision}.sql")
  puts "Deleted: #{functions_dir}/#{index_name}_v#{revision}.sql"
end