Also fixes the :down method that would have never worked. Oops.
Also adds a Pool.default convenience method to find default pool object.
---
src/app/models/pool.rb | 6 +++++-
...amed_suggested_deployable_to_catalog_entries.rb | 18 ++++++++++++++++--
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index d29675d..412f8f5 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -1,4 +1,3 @@
-# == Schema Information
# Schema version: 20110603204130
#
# Table name: pools
@@ -97,4 +96,9 @@ class Pool < ActiveRecord::Base
:order => (order_field || 'name') +' '+ (order_dir ||
'asc'))
end
+ # Make this easier to find:
+ def self.default
+ MetadataObject.lookup("self_service_default_pool")
+ end
+
end
diff --git
a/src/db/migrate/20110816192727_renamed_suggested_deployable_to_catalog_entries.rb
b/src/db/migrate/20110816192727_renamed_suggested_deployable_to_catalog_entries.rb
index 8276e0b..aab588e 100644
--- a/src/db/migrate/20110816192727_renamed_suggested_deployable_to_catalog_entries.rb
+++ b/src/db/migrate/20110816192727_renamed_suggested_deployable_to_catalog_entries.rb
@@ -1,11 +1,25 @@
class RenamedSuggestedDeployableToCatalogEntries < ActiveRecord::Migration
+
def self.up
+ # We need a default catalog to successfully preserve existing data
+ catalog = Catalog.first || Catalog.create!(:pool => Pool.default, :name =>
'Default')
+
rename_table :suggested_deployables, :catalog_entries
- add_column :catalog_entries, :catalog_id, :integer, :null => false
+
+ # This should be :null => false, but this will fail if we had existing data,
+ # so do this in an absurdly roundabout manner instead:
+ add_column :catalog_entries, :catalog_id, :integer, :null => true
+ # Now, populate catalog_id for existing data:
+ CatalogEntry.all.each do |catalog_entry|
+ catalog_entry.catalog_id ||= catalog.id
+ catalog_entry.save!
+ end
+ # And now, with the column populated, change it to disallow nulls
+ change_column :catalog_entries, :catalog_id, :integer, :null => false
end
def self.down
rename_table :catalog_entries, :suggested_deployables
- drop_column :catalog_id
+ remove_column :suggested_deployables, :catalog_id
end
end
--
1.7.6