Module: Archivist::Base::DB::ClassMethods

Defined in:
lib/archivist/base/db.rb

Instance Method Summary collapse

Instance Method Details

#archive_table_exists?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/archivist/base/db.rb', line 20

def archive_table_exists?
  connection.table_exists?("archived_#{table_name}")
end

#create_archive_indexesObject



38
39
40
# File 'lib/archivist/base/db.rb', line 38

def create_archive_indexes
  # TODO?
end

#create_archive_tableObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/archivist/base/db.rb', line 24

def create_archive_table
  if table_exists? && !archive_table_exists?
    cols = self.columns.reject { |column| column.name == primary_key }
    connection.create_table("archived_#{table_name}")
    cols.each do |c|
      connection.add_column("archived_#{table_name}",c.name,c.type)
    end
    connection.add_column("archived_#{table_name}",:deleted_at,:datetime)
    if archive_options[:associate_with_original]
      connection.add_column("archived_#{table_name}","#{self.new.class.to_s.underscore}_id",:integer)
    end
  end
end