Class: ActiveVersion::Migrators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_version/migrators/base.rb

Overview

Base migrator for converting from other versioning libraries

Direct Known Subclasses

Audited

Constant Summary collapse

AUDIT_STORAGES =
%i[json_column yaml_column mirror_columns].freeze

Class Method Summary collapse

Class Method Details

.create_audit_table(table_name, options = {}) ⇒ Object

Migration helper for creating audit tables



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_version/migrators/base.rb', line 17

def create_audit_table(table_name, options = {})
  table_options = options.dup
  storage = normalize_audit_storage(table_options.delete(:storage))
  mirror_columns = normalize_mirror_columns(table_options.delete(:mirror_columns))
  changes_column = (table_options.delete(:changes_column) || :audited_changes).to_sym
  context_column = (table_options.delete(:context_column) || :audited_context).to_sym

  create_table_with_plan(
    table_name,
    table_options,
    audit_table_plan(
      table_name: table_name,
      storage: storage,
      mirror_columns: mirror_columns,
      changes_column: changes_column,
      context_column: context_column
    )
  )
end

.create_revision_table(table_name, options = {}) ⇒ Object

Migration helper for creating revision tables



38
39
40
# File 'lib/active_version/migrators/base.rb', line 38

def create_revision_table(table_name, options = {})
  create_table_with_plan(table_name, options.dup, revision_table_plan(table_name))
end

.create_translation_table(table_name, options = {}) ⇒ Object

Migration helper for creating translation tables



43
44
45
# File 'lib/active_version/migrators/base.rb', line 43

def create_translation_table(table_name, options = {})
  create_table_with_plan(table_name, options.dup, translation_table_plan(table_name))
end

.migrate(model_class, options = {}) ⇒ Integer

Migrate data from another library

Parameters:

  • model_class (Class)

    ActiveRecord model class

  • options (Hash) (defaults to: {})

    Migration options

Returns:

  • (Integer)

    Number of records migrated

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/active_version/migrators/base.rb', line 12

def migrate(model_class, options = {})
  raise NotImplementedError, "Subclasses must implement migrate"
end