diff options
| author | Francis Sullivan <francis@garlic.local> | 2008-09-30 13:52:27 -0500 |
|---|---|---|
| committer | Francis Sullivan <francis@garlic.local> | 2008-09-30 13:52:27 -0500 |
| commit | 41c26cd1035cb11bf298710792baa0571be7e00c (patch) | |
| tree | 0ca728fe83156fda025c2f37086fc42ffa29f0a3 | |
| parent | df4e0f94164944dc36d0bef263d1a9291c8147d4 (diff) | |
create version table on the fly if missing, use proper version column name when checking for existence, and add index automatically
| -rw-r--r-- | lib/acts_as_versioned.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/acts_as_versioned.rb b/lib/acts_as_versioned.rb index 9fd968f36..efc44b795 100644 --- a/lib/acts_as_versioned.rb +++ b/lib/acts_as_versioned.rb @@ -257,6 +257,8 @@ module ActiveRecord #:nodoc: :foreign_key => versioned_foreign_key versioned_class.send :include, options[:extend] if options[:extend].is_a?(Module) versioned_class.set_sequence_name version_sequence_name if version_sequence_name + + create_versioned_table end end @@ -404,10 +406,13 @@ module ActiveRecord #:nodoc: # Rake migration task to create the versioned table using options passed to acts_as_versioned def create_versioned_table(create_table_options = {}) # create version column in main table if it does not exist - if !self.content_columns.find { |c| %w(version lock_version).include? c.name } + if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name } self.connection.add_column table_name, version_column, :integer + self.reset_column_information end + return if connection.tables.include?(versioned_table_name) + self.connection.create_table(versioned_table_name, create_table_options) do |t| t.column versioned_foreign_key, :integer t.column version_column, :integer @@ -434,6 +439,8 @@ module ActiveRecord #:nodoc: if updated_col.nil? self.connection.add_column versioned_table_name, :updated_at, :timestamp end + + self.connection.create_index versioned_table_name, versioned_foreign_key end # Rake migration task to drop the versioned table |
