From: Tomas Sedovic <tsedovic(a)redhat.com>
---
src/app/models/view_state.rb | 12 +++++++++---
.../20110513164105_change_view_state_id_to_uuid.rb | 12 ++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
create mode 100644 src/db/migrate/20110513164105_change_view_state_id_to_uuid.rb
diff --git a/src/app/models/view_state.rb b/src/app/models/view_state.rb
index e677b81..c2109c0 100644
--- a/src/app/models/view_state.rb
+++ b/src/app/models/view_state.rb
@@ -1,9 +1,9 @@
# == Schema Information
-# Schema version: 20110504124706
+# Schema version: 20110513164105
#
# Table name: view_states
#
-# id :integer not null, primary key
+# uuid :string(36) not null, primary key
# user_id :integer
# name :string(255) not null
# controller :string(255) not null
@@ -14,6 +14,7 @@
#
class ViewState < ActiveRecord::Base
+ set_primary_key :uuid
belongs_to :user
validates_presence_of :name
@@ -23,6 +24,7 @@ class ViewState < ActiveRecord::Base
validates_presence_of :action
validates_presence_of :state
+ before_create :ensure_uuid
before_save :strip_session_only_keys
attr_reader :pending_delete
@@ -31,6 +33,10 @@ class ViewState < ActiveRecord::Base
@pending_delete = true
end
+ def ensure_uuid
+ self.uuid = UUIDTools::UUID.timestamp_create.to_s
+ end
+
# Things that make sense to remember for the session ViewState but not for
# the saved state -- such as position in the pagination.
SESSION_ONLY_KEYS = ['page']
@@ -46,6 +52,6 @@ class ViewState < ActiveRecord::Base
end
def state=(attrs)
- write_attribute :state, JSON.dump(attrs ||= {})
+ write_attribute :state, JSON.dump(attrs || {})
end
end
diff --git a/src/db/migrate/20110513164105_change_view_state_id_to_uuid.rb
b/src/db/migrate/20110513164105_change_view_state_id_to_uuid.rb
new file mode 100644
index 0000000..f547b61
--- /dev/null
+++ b/src/db/migrate/20110513164105_change_view_state_id_to_uuid.rb
@@ -0,0 +1,12 @@
+class ChangeViewStateIdToUuid < ActiveRecord::Migration
+ def self.up
+ change_table :view_states do |t|
+ t.change :id, :string, :limit => 36
+ t.rename :id, :uuid
+ end
+ end
+
+ def self.down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
--
1.7.4.4