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.

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
<<~SQL
CREATE OR REPLACE FUNCTION #{index_name}() RETURNS TEXT[]
  LANGUAGE SQL
  IMMUTABLE AS
$$
  -- Function body here
$$
SQL
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!


47
48
49
50
51
# File 'lib/arfi/commands/f_idx.rb', line 47

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

#destroy(index_name, revision = '01') ⇒ 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.

  • revision (String) (defaults to: '01')

    Revision of the index.

Raises:



64
65
66
67
68
69
70
# File 'lib/arfi/commands/f_idx.rb', line 64

def destroy(index_name, revision = '01')
  validate_schema_format!

  revision = "0#{revision}" if revision.match?(/^\d$/)
  FileUtils.rm("#{functions_dir}/#{index_name}_v#{revision}.sql")
  puts "Deleted: #{functions_dir}/#{index_name}_v#{revision}.sql"
end