Class: Spanner::Translator::Rules::Translation::ReplaceCreateTableArgs

Inherits:
BaseRule
  • Object
show all
Defined in:
lib/spanner/translator/rules/translation/replace_create_table_args.rb

Overview

Replace create_table arguments with sensible spanner options

Constant Summary

Constants inherited from BaseRule

BaseRule::RAILS_COLUMN_TYPES

Instance Attribute Summary

Attributes inherited from BaseRule

#translation_options

Instance Method Summary collapse

Methods inherited from BaseRule

#any_index?, #capture_column_nullity, #capture_primary_key_argument, #capture_table_name, #conditionally_propagate_argument, #create_range, #initialize, #unless_seen

Constructor Details

This class inherits a constructor from Spanner::Translator::Rules::BaseRule

Instance Method Details

#on_send(node) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/spanner/translator/rules/translation/replace_create_table_args.rb', line 9

def on_send(node)
  return unless node.create_table?

  # keep table name argument, replace the rest with sensible spanner options
  primary_keys = translation_options
                 .fetch(:primary_keys, Spanner::Translator.configuration.default_primary_keys)
                 .inspect
  @rewriter.replace(node.arguments[1].source_range, "primary_key: #{primary_keys}, force: :cascade")
end