Module: ActsAsArchive::Base::Table::ClassMethods
- Defined in:
- lib/acts_as_archive/base/table.rb
Instance Method Summary collapse
- #archive_table_exists? ⇒ Boolean
- #create_archive_indexes ⇒ Object
- #create_archive_table ⇒ Object
- #migrate_from_acts_as_paranoid ⇒ Object
Instance Method Details
#archive_table_exists? ⇒ Boolean
22 23 24 |
# File 'lib/acts_as_archive/base/table.rb', line 22 def archive_table_exists? connection.table_exists?("archived_#{table_name}") end |
#create_archive_indexes ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/acts_as_archive/base/table.rb', line 41 def create_archive_indexes if archive_table_exists? indexes = archive_table_indexed_columns (archive_indexes - indexes).each do |index| connection.add_index("archived_#{table_name}", index, :name => index_name_for(table_name, index)) if table_has_columns(index) end (indexes - archive_indexes).each do |index| connection.remove_index("archived_#{table_name}", index) if table_has_columns(index) end end end |
#create_archive_table ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/acts_as_archive/base/table.rb', line 26 def create_archive_table if table_exists? && !archive_table_exists? connection.execute(%{ CREATE TABLE archived_#{table_name} #{"ENGINE=InnoDB" if connection.class.to_s.include?('Mysql')} AS SELECT * from #{table_name} WHERE false; }) columns = connection.columns("archived_#{table_name}").collect(&:name) unless columns.include?('deleted_at') connection.add_column("archived_#{table_name}", :deleted_at, :datetime) end end end |
#migrate_from_acts_as_paranoid ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/acts_as_archive/base/table.rb', line 55 def migrate_from_acts_as_paranoid if column_names.include?('deleted_at') if table_exists? && archive_table_exists? condition = "deleted_at IS NOT NULL" if self.count_by_sql("SELECT COUNT(*) FROM #{table_name} WHERE #{condition}") > 0 # Base::Destroy.copy_to_archive copy_to_archive(condition, true) end end end end |