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 ++-
...talogs.rb => 20110816192725_create_catalogs.rb} | 4 +-
...amed_suggested_deployable_to_catalog_entries.rb | 67 +++++++++++++++++++-
3 files changed, 73 insertions(+), 4 deletions(-)
rename src/db/migrate/{20110816193604_create_catalogs.rb =>
20110816192725_create_catalogs.rb} (55%)
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/20110816193604_create_catalogs.rb
b/src/db/migrate/20110816192725_create_catalogs.rb
similarity index 55%
rename from src/db/migrate/20110816193604_create_catalogs.rb
rename to src/db/migrate/20110816192725_create_catalogs.rb
index b09deaf..89918d3 100644
--- a/src/db/migrate/20110816193604_create_catalogs.rb
+++ b/src/db/migrate/20110816192725_create_catalogs.rb
@@ -1,10 +1,12 @@
class CreateCatalogs < ActiveRecord::Migration
def self.up
+ # Conditional because this used to be shipped under another name,
+ # so some people have already run it and others haven't. Blech.
create_table :catalogs do |t|
t.integer :pool_id
t.string :name
t.timestamps
- end
+ end unless table_exists?(:catalogs)
end
def self.down
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..52692bb 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,74 @@
class RenamedSuggestedDeployableToCatalogEntries < ActiveRecord::Migration
+ VIEW = "view"
+ USE = "use"
+ MOD = "modify"
+ CRE = "create"
+ VPRM = "view_perms"
+ GPRM = "set_perms"
+
def self.up
+ # We need a default catalog to successfully preserve existing data
+ # If there are no pools, we assume a fresh setup, and thus pass.
+ catalog = Catalog.first || Catalog.create!(:pool => Pool.default, :name =>
'Default') if Pool.count > 0
+
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
+
+ # So we also need to set up permissions if they don't already exist:
+ # Copied from db/seeds and adapted, as db:seeds can't be run incrementally
:'(
+
+ roles = {
+ Catalog => {
+ "Catalog User" => [false, {Catalog => [VIEW,
USE]}],
+ "Catalog Administrator" => [true, {Catalog =>
[VIEW,USE,MOD,VPRM,GPRM]}]
+ },
+ CatalogEntry => {
+ "CatalogEntry User" => [false, {CatalogEntry =>
[VIEW,USE]}],
+ "CatalogEntry Owner" => [true, {CatalogEntry =>
[VIEW,USE,MOD,VPRM,GPRM]}]
+ },
+ BasePermissionObject => {
+ "CatalogEntry Administrator" => [false, {CatalogEntry =>
[VIEW,USE,MOD,CRE,VPRM,GPRM]}],
+ "CatalogEntry Global User" => [false, {CatalogEntry=>
[VIEW,USE]}],
+ "Administrator" => [false, {
+ Catalog =>
[VIEW,USE,MOD,CRE,VPRM,GPRM],
+ CatalogEntry =>
[VIEW,USE,MOD,CRE,VPRM,GPRM]
+ }]
+
+ }
+ }
+ Role.transaction do
+ break unless Role.find_by_name('Instance Controller').present? # Only run
if db:seeds has already run
+ roles.each do |role_scope, scoped_hash|
+ scoped_hash.each do |role_name, role_def|
+ role = Role.find_or_initialize_by_name(role_name)
+ role.update_attributes({:name => role_name, :scope => role_scope.name,
+ :assign_to_owner => role_def[0]})
+ role.save!
+ role_def[1].each do |priv_type, priv_actions|
+ priv_actions.each do |action|
+ Privilege.create!(:role => role, :target_type => priv_type.name,
+ :action => action)
+ end
+ end
+ end
+ end
+ end
+
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