From 65af40d990b6d881f927609da7b63cbcbabe9e57 Mon Sep 17 00:00:00 2001 From: Steve Linabery Date: Wed, 21 May 2008 20:16:39 -0500 Subject: [PATCH] Add lock_version attribute to all objects to enable optimistic locking. Edit migration files to use the 't.type :fieldname' syntax. Signed-off-by: Steve Linabery --- wui/src/db/migrate/001_create_pools.rb | 3 +- wui/src/db/migrate/002_create_hosts.rb | 21 ++++++------ wui/src/db/migrate/003_create_nics.rb | 15 +++++---- wui/src/db/migrate/004_create_storage_volumes.rb | 28 +++++++++-------- wui/src/db/migrate/005_create_quotas.rb | 15 +++++---- wui/src/db/migrate/006_create_vms.rb | 37 ++++++++++++---------- wui/src/db/migrate/007_create_tasks.rb | 30 ++++++++++-------- wui/src/db/migrate/008_create_permissions.rb | 7 ++-- 8 files changed, 85 insertions(+), 71 deletions(-) diff --git a/wui/src/db/migrate/001_create_pools.rb b/wui/src/db/migrate/001_create_pools.rb index 2348013..34c01d3 100644 --- a/wui/src/db/migrate/001_create_pools.rb +++ b/wui/src/db/migrate/001_create_pools.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -25,6 +25,7 @@ class CreatePools < ActiveRecord::Migration t.integer :parent_id t.integer :lft t.integer :rgt + t.integer :lock_version, :default => 0 t.timestamps end diff --git a/wui/src/db/migrate/002_create_hosts.rb b/wui/src/db/migrate/002_create_hosts.rb index 62d9edd..e8b26f2 100644 --- a/wui/src/db/migrate/002_create_hosts.rb +++ b/wui/src/db/migrate/002_create_hosts.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,15 +20,16 @@ class CreateHosts < ActiveRecord::Migration def self.up create_table :hosts do |t| - t.column :uuid, :string - t.column :hypervisor_type, :string - t.column :hostname, :string - t.column :num_cpus, :integer - t.column :cpu_speed, :integer - t.column :arch, :string - t.column :memory, :integer - t.column :is_disabled, :integer - t.column :hardware_pool_id, :integer, :null => false + t.string :uuid + t.string :hypervisor_type + t.string :hostname + t.integer :num_cpus + t.integer :cpu_speed + t.string :arch + t.integer :memory + t.integer :is_disabled + t.integer :hardware_pool_id, :null => false + t.integer :lock_version, :default => 0 end execute "alter table hosts add constraint fk_host_pools diff --git a/wui/src/db/migrate/003_create_nics.rb b/wui/src/db/migrate/003_create_nics.rb index 3d1ad0a..31bc33f 100644 --- a/wui/src/db/migrate/003_create_nics.rb +++ b/wui/src/db/migrate/003_create_nics.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,12 +20,13 @@ class CreateNics < ActiveRecord::Migration def self.up create_table :nics do |t| - t.column :mac, :string - t.column :ip_addr, :string - t.column :bridge, :string - t.column :usage_type, :string - t.column :bandwidth, :integer - t.column :host_id, :integer, :null => false + t.string :mac + t.string :ip_addr + t.string :bridge + t.string :usage_type + t.integer :bandwidth + t.integer :host_id, :null => false + t.integer :lock_version, :default => 0 end execute "alter table nics add constraint fk_nic_hosts diff --git a/wui/src/db/migrate/004_create_storage_volumes.rb b/wui/src/db/migrate/004_create_storage_volumes.rb index e2ae51d..0b52a95 100644 --- a/wui/src/db/migrate/004_create_storage_volumes.rb +++ b/wui/src/db/migrate/004_create_storage_volumes.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,29 +20,31 @@ class CreateStorageVolumes < ActiveRecord::Migration def self.up create_table :storage_pools do |t| - t.column :ip_addr, :string - t.column :type, :string - t.column :hardware_pool_id, :integer, :null => false + t.string :ip_addr + t.string :type + t.integer :hardware_pool_id, :null => false + t.integer :lock_version, :default => 0 # for IscsiStoragePool - t.column :port, :integer - t.column :target, :string + t.integer :port + t.string :target # for NfsStoragePool - t.column :export_path, :string + t.string :export_path end create_table :storage_volumes do |t| - t.column :path, :string - t.column :size, :integer - t.column :storage_pool_id, :integer, :null => false - t.column :type, :string + t.string :path + t.integer :size + t.integer :storage_pool_id, :null => false + t.string :type + t.integer :lock_version, :default => 0 # for IscsiStorageVolume - t.column :lun, :string + t.string :lun # for IscsiStorageVolume - t.column :filename, :string + t.string :filename end execute "alter table storage_pools add constraint fk_storage_pool_pools diff --git a/wui/src/db/migrate/005_create_quotas.rb b/wui/src/db/migrate/005_create_quotas.rb index f22401d..9bdada7 100644 --- a/wui/src/db/migrate/005_create_quotas.rb +++ b/wui/src/db/migrate/005_create_quotas.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,12 +20,13 @@ class CreateQuotas < ActiveRecord::Migration def self.up create_table :quotas do |t| - t.column :total_vcpus, :integer - t.column :total_vmemory, :integer - t.column :total_vnics, :integer - t.column :total_storage, :integer - t.column :total_vms, :integer - t.column :pool_id, :integer + t.integer :total_vcpus + t.integer :total_vmemory + t.integer :total_vnics + t.integer :total_storage + t.integer :total_vms + t.integer :pool_id + t.integer :lock_version, :default => 0 end execute "alter table quotas add constraint fk_quotas_pools diff --git a/wui/src/db/migrate/006_create_vms.rb b/wui/src/db/migrate/006_create_vms.rb index a85a0a9..7035a3c 100644 --- a/wui/src/db/migrate/006_create_vms.rb +++ b/wui/src/db/migrate/006_create_vms.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,18 +20,19 @@ class CreateVms < ActiveRecord::Migration def self.up create_table :vms do |t| - t.column :uuid, :string - t.column :description, :string - t.column :num_vcpus_allocated, :integer - t.column :num_vcpus_used, :integer - t.column :memory_allocated, :integer - t.column :memory_used, :integer - t.column :vnic_mac_addr, :string - t.column :state, :string - t.column :host_id, :integer - t.column :vm_resource_pool_id, :integer - t.column :needs_restart, :integer - t.column :boot_device, :string, :null => false + t.string :uuid + t.string :description + t.integer :num_vcpus_allocated + t.integer :num_vcpus_used + t.integer :memory_allocated + t.integer :memory_used + t.string :vnic_mac_addr + t.string :state + t.integer :host_id + t.integer :vm_resource_pool_id + t.integer :needs_restart + t.string :boot_device, :null => false + t.integer :lock_version, :default => 0 end execute "alter table vms add constraint fk_vms_hosts foreign key (host_id) references hosts(id)" @@ -39,12 +40,14 @@ class CreateVms < ActiveRecord::Migration foreign key (vm_resource_pool_id) references pools(id)" create_table :storage_volumes_vms, :id => false do |t| - t.column :vm_id, :integer, :null => false - t.column :storage_volume_id, :integer, :null => false + t.integer :vm_id, :null => false + t.integer :storage_volume_id, :null => false end - execute "alter table storage_volumes_vms add constraint fk_stor_vol_vms_vm_id + execute "alter table storage_volumes_vms add constraint + fk_stor_vol_vms_vm_id foreign key (vm_id) references vms(id)" - execute "alter table storage_volumes_vms add constraint fk_stor_vol_vms_stor_vol_id + execute "alter table storage_volumes_vms add constraint + fk_stor_vol_vms_stor_vol_id foreign key (storage_volume_id) references storage_volumes(id)" end diff --git a/wui/src/db/migrate/007_create_tasks.rb b/wui/src/db/migrate/007_create_tasks.rb index d8c0ad0..30b6a1d 100644 --- a/wui/src/db/migrate/007_create_tasks.rb +++ b/wui/src/db/migrate/007_create_tasks.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,21 +20,25 @@ class CreateTasks < ActiveRecord::Migration def self.up create_table :tasks do |t| - t.column :user, :string - t.column :type, :string - t.column :action, :string - t.column :state, :string - t.column :args, :string - t.column :created_at, :timestamp - t.column :time_started, :timestamp - t.column :time_ended, :timestamp - t.column :message, :text + t.string :user + t.string :type + t.string :action + t.string :state + t.string :args + t.timestamp :created_at + t.timestamp :time_started + t.timestamp :time_ended + t.text :message + t.integer :lock_version, :default => 0 + # VmTask columns - t.column :vm_id, :integer + t.integer :vm_id + # StorageTask columns - t.column :storage_pool_id, :integer + t.integer :storage_pool_id + # HostTask columns - t.column :host_id, :integer + t.integer :host_id end execute "alter table tasks add constraint fk_tasks_vms foreign key (vm_id) references vms(id)" diff --git a/wui/src/db/migrate/008_create_permissions.rb b/wui/src/db/migrate/008_create_permissions.rb index 0cc361c..69a0aa7 100644 --- a/wui/src/db/migrate/008_create_permissions.rb +++ b/wui/src/db/migrate/008_create_permissions.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago # @@ -20,9 +20,10 @@ class CreatePermissions < ActiveRecord::Migration def self.up create_table :permissions do |t| - t.string :user_role - t.string :user + t.string :user_role + t.string :user t.integer :pool_id + t.integer :lock_version, :default => 0 end end -- 1.5.4.1