This modifies a few of the patches in Scott's patchset so that they will work on fresh setups with a clean database.
-- Matt
--- src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser < ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'}) - pt.ssh_user = 'root' - pt.home_dir = '/root' - pt.save! + if pt + pt.ssh_user = 'root' + pt.home_dir = '/root' + pt.save! + end end
def self.down pt = ProviderType.first(:conditions => {:codename => 'ec2'}) - pt.ssh_user = 'ec2-user' - pt.home_dir = '/home/ec2-user' - pt.save! + if pt + pt.ssh_user = 'ec2-user' + pt.home_dir = '/home/ec2-user' + pt.save! + end end end diff --git a/src/db/migrate/20110513160000_rename_rhevm_target.rb b/src/db/migrate/20110513160000_rename_rhevm_target.rb index 8d4ba5b..35f1912 100644 --- a/src/db/migrate/20110513160000_rename_rhevm_target.rb +++ b/src/db/migrate/20110513160000_rename_rhevm_target.rb @@ -2,14 +2,18 @@ class RenameRhevmTarget < ActiveRecord::Migration
def self.up type = ProviderType.find_by_codename("rhevm") - type.codename = "rhev-m" - type.save + if type + type.codename = "rhev-m" + type.save + end end
def self.down type = ProviderType.find_by_codename("rhev-m") - type.codename = "rhevm" - type.save + if type + type.codename = "rhevm" + type.save + end end
end diff --git a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb index 4394253..ef32882 100644 --- a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb +++ b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb @@ -12,8 +12,10 @@ class RenameRhevmAndVmwareTargets < ActiveRecord::Migration
def self.rename_type(old, new) type = ProviderType.find_by_codename(old) - type.codename = new - type.save + if type + type.codename = new + type.save + end end
end diff --git a/src/db/migrate/20110811091500_rename_condorcloud.rb b/src/db/migrate/20110811091500_rename_condorcloud.rb index 332eef5..30c4762 100644 --- a/src/db/migrate/20110811091500_rename_condorcloud.rb +++ b/src/db/migrate/20110811091500_rename_condorcloud.rb @@ -1,5 +1,7 @@ class RenameCondorcloud < ActiveRecord::Migration def self.up + # Not sure why this is necessary, but it is: + ProviderType.reset_column_information condorcloud_type = ProviderType.find_by_deltacloud_driver('condorcloud') if condorcloud_type condorcloud_type.deltacloud_driver = "condor"
On 08/26/2011 01:55 PM, Matt Wagner wrote:
src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser< ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'root'
- pt.home_dir = '/root'
- pt.save!
if pt
pt.ssh_user = 'root'
pt.home_dir = '/root'
pt.save!
end end
def self.down pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'ec2-user'
- pt.home_dir = '/home/ec2-user'
- pt.save!
- if pt
pt.ssh_user = 'ec2-user'
pt.home_dir = '/home/ec2-user'
pt.save!
- end end end
diff --git a/src/db/migrate/20110513160000_rename_rhevm_target.rb b/src/db/migrate/20110513160000_rename_rhevm_target.rb index 8d4ba5b..35f1912 100644 --- a/src/db/migrate/20110513160000_rename_rhevm_target.rb +++ b/src/db/migrate/20110513160000_rename_rhevm_target.rb @@ -2,14 +2,18 @@ class RenameRhevmTarget< ActiveRecord::Migration
def self.up type = ProviderType.find_by_codename("rhevm")
- type.codename = "rhev-m"
- type.save
if type
type.codename = "rhev-m"
type.save
end end
def self.down type = ProviderType.find_by_codename("rhev-m")
- type.codename = "rhevm"
- type.save
if type
type.codename = "rhevm"
type.save
end end
end
diff --git a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb index 4394253..ef32882 100644 --- a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb +++ b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb @@ -12,8 +12,10 @@ class RenameRhevmAndVmwareTargets< ActiveRecord::Migration
def self.rename_type(old, new) type = ProviderType.find_by_codename(old)
- type.codename = new
- type.save
if type
type.codename = new
type.save
end end
end
diff --git a/src/db/migrate/20110811091500_rename_condorcloud.rb b/src/db/migrate/20110811091500_rename_condorcloud.rb index 332eef5..30c4762 100644 --- a/src/db/migrate/20110811091500_rename_condorcloud.rb +++ b/src/db/migrate/20110811091500_rename_condorcloud.rb @@ -1,5 +1,7 @@ class RenameCondorcloud< ActiveRecord::Migration def self.up
- # Not sure why this is necessary, but it is:
- ProviderType.reset_column_information condorcloud_type = ProviderType.find_by_deltacloud_driver('condorcloud') if condorcloud_type condorcloud_type.deltacloud_driver = "condor"
Ack.
On 09/08/2011 03:33 PM, Richard Su wrote:
On 08/26/2011 01:55 PM, Matt Wagner wrote:
src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser< ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'root'
- pt.home_dir = '/root'
- pt.save!
if pt
pt.ssh_user = 'root'
pt.home_dir = '/root'
pt.save!
end end
def self.down pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'ec2-user'
- pt.home_dir = '/home/ec2-user'
- pt.save!
- if pt
pt.ssh_user = 'ec2-user'
pt.home_dir = '/home/ec2-user'
pt.save!
- end end end
diff --git a/src/db/migrate/20110513160000_rename_rhevm_target.rb b/src/db/migrate/20110513160000_rename_rhevm_target.rb index 8d4ba5b..35f1912 100644 --- a/src/db/migrate/20110513160000_rename_rhevm_target.rb +++ b/src/db/migrate/20110513160000_rename_rhevm_target.rb @@ -2,14 +2,18 @@ class RenameRhevmTarget< ActiveRecord::Migration
def self.up type = ProviderType.find_by_codename("rhevm")
- type.codename = "rhev-m"
- type.save
if type
type.codename = "rhev-m"
type.save
end end
def self.down type = ProviderType.find_by_codename("rhev-m")
- type.codename = "rhevm"
- type.save
if type
type.codename = "rhevm"
type.save
end end
end
diff --git a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb index 4394253..ef32882 100644 --- a/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb +++ b/src/db/migrate/20110707082304_rename_rhevm_and_vmware_targets.rb @@ -12,8 +12,10 @@ class RenameRhevmAndVmwareTargets< ActiveRecord::Migration
def self.rename_type(old, new) type = ProviderType.find_by_codename(old)
- type.codename = new
- type.save
if type
type.codename = new
type.save
end end
end
diff --git a/src/db/migrate/20110811091500_rename_condorcloud.rb b/src/db/migrate/20110811091500_rename_condorcloud.rb index 332eef5..30c4762 100644 --- a/src/db/migrate/20110811091500_rename_condorcloud.rb +++ b/src/db/migrate/20110811091500_rename_condorcloud.rb @@ -1,5 +1,7 @@ class RenameCondorcloud< ActiveRecord::Migration def self.up
- # Not sure why this is necessary, but it is:
- ProviderType.reset_column_information condorcloud_type = ProviderType.find_by_deltacloud_driver('condorcloud') if condorcloud_type condorcloud_type.deltacloud_driver = "condor"
Ack. _______________________________________________ aeolus-devel mailing list aeolus-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/aeolus-devel
Pushed
I ran into these issues myself, and was going to post similar feedback before I noticed the reply. See additional comments inline
On 08/26/2011 04:55 PM, Matt Wagner wrote:
src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser< ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'root'
- pt.home_dir = '/root'
- pt.save!
- if pt
pt.ssh_user = 'root'
pt.home_dir = '/root'
pt.save!
- end end
Overall these changes work, though since the seed data has been moved to seed.rb, the migrations affected here are somewhat unnecessary (these migrations rely on the seed data, while the seed data relies on the migrations). Instead the changes in these migrations can be added to the seed data themselves and these migrations can be removed all together.
No objections to pushing these patches, but at some point we should cleanup / consolidate what belongs in the migrations and what belongs in the seed data.
diff --git a/src/db/migrate/20110811091500_rename_condorcloud.rb b/src/db/migrate/20110811091500_rename_condorcloud.rb index 332eef5..30c4762 100644 --- a/src/db/migrate/20110811091500_rename_condorcloud.rb +++ b/src/db/migrate/20110811091500_rename_condorcloud.rb @@ -1,5 +1,7 @@ class RenameCondorcloud< ActiveRecord::Migration def self.up
- # Not sure why this is necessary, but it is:
- ProviderType.reset_column_information
Yes this stumped me for a little while as well. My current theory is that since Rails inspects the tables at the very beginning of the script invocation, before the column is renamed in the migration, the change does not propogate to the model class until after we manually reset it.
-Mo
On 09/09/2011 01:11 AM, Mo Morsi wrote:
I ran into these issues myself, and was going to post similar feedback before I noticed the reply. See additional comments inline
On 08/26/2011 04:55 PM, Matt Wagner wrote:
src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser< ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'root'
- pt.home_dir = '/root'
- pt.save!
- if pt
pt.ssh_user = 'root'
pt.home_dir = '/root'
pt.save!
- end end
Overall these changes work, though since the seed data has been moved to seed.rb, the migrations affected here are somewhat unnecessary (these migrations rely on the seed data, while the seed data relies on the migrations). Instead the changes in these migrations can be added to the seed data themselves and these migrations can be removed all together.
That's exactly why this is necessary. Migrations should only touch data that's already there -- i.e. fixing existing data in a real installation. If the db is blank when the migration is run, it shouldn't add any rows. Matt added these conditions because I added a migration that changed the columns in ProviderType, so any time these old migrations are run, they'll throw an error if they touch ProviderTypes -- that's why this fix was added -- with my patchset and without this patch, things blow up on a fresh db.
No objections to pushing these patches, but at some point we should cleanup / consolidate what belongs in the migrations and what belongs in the seed data.
Actually, we did that months ago -- seed data includes all data necessary to run for a new database. What we're seeing here is that after we scrubbed the migrations of seed data some months back, a few migrations have been written that were less careful _not_ to add data to a new database.
Scott
On Fri, Sep 09, 2011 at 01:11:35AM -0400, Mo Morsi wrote:
I ran into these issues myself, and was going to post similar feedback before I noticed the reply. See additional comments inline
On 08/26/2011 04:55 PM, Matt Wagner wrote:
src/db/migrate/20110329104633_rename_ssh_user.rb | 16 ++++++++++------ .../migrate/20110513160000_rename_rhevm_target.rb | 12 ++++++++---- ...110707082304_rename_rhevm_and_vmware_targets.rb | 6 ++++-- .../migrate/20110811091500_rename_condorcloud.rb | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb index e77eae3..f13ae1f 100644 --- a/src/db/migrate/20110329104633_rename_ssh_user.rb +++ b/src/db/migrate/20110329104633_rename_ssh_user.rb @@ -1,15 +1,19 @@ class RenameSshUser< ActiveRecord::Migration def self.up pt = ProviderType.first(:conditions => {:codename => 'ec2'})
- pt.ssh_user = 'root'
- pt.home_dir = '/root'
- pt.save!
- if pt
pt.ssh_user = 'root'
pt.home_dir = '/root'
pt.save!
- end end
Overall these changes work, though since the seed data has been moved to seed.rb, the migrations affected here are somewhat unnecessary (these migrations rely on the seed data, while the seed data relies on the migrations). Instead the changes in these migrations can be added to the seed data themselves and these migrations can be removed all together.
Hmm, you're right that this is a little weird. The problem I've been running into lately is that we want to support new users (via db:seed) and existing users (via migrations). If we just did it in seeds, existing users wouldn't get them, since our db:seed can only be run once.
No objections to pushing these patches, but at some point we should cleanup / consolidate what belongs in the migrations and what belongs in the seed data.
We've kicked around the idea of dumping all our migrations and using db:schema to populate them. Both of these are worth exploring later.
diff --git a/src/db/migrate/20110811091500_rename_condorcloud.rb b/src/db/migrate/20110811091500_rename_condorcloud.rb index 332eef5..30c4762 100644 --- a/src/db/migrate/20110811091500_rename_condorcloud.rb +++ b/src/db/migrate/20110811091500_rename_condorcloud.rb @@ -1,5 +1,7 @@ class RenameCondorcloud< ActiveRecord::Migration def self.up
- # Not sure why this is necessary, but it is:
- ProviderType.reset_column_information
Yes this stumped me for a little while as well. My current theory is that since Rails inspects the tables at the very beginning of the script invocation, before the column is renamed in the migration, the change does not propogate to the model class until after we manually reset it.
Now I want to dig more into this, because this sounds like a bug to me. Why on Earth wouldn't cached information about tables be flushed after those tables were modified?
-- Matt
aeolus-devel@lists.fedorahosted.org