top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Migrate postgresql database to uuid in Ruby On Rails

+3 votes
175 views

I am using rails 3.1 and ruby 1.9.3,Now i want to use uuid concept in rails 3 for existing data

so I did like :-

create_table :posts, :id => false do |t|
 t.string :uuid, :limit => 36, :primary => true
end

ActiveRecord::Base.class_eval do

# old rails versions
set_primary_key 'uuid'

before_create :generate_uuid
def generate_uuid
self.id = UUIDTools::UUID.random_create.to_s
end
end

This is working for new data,now i want to migrate existing data with relation.for uuid they are using datatype as string,in postgresql the data type used for primary_key and foreign key is integer ,so if i am trying to change foreign key integer to string it is throwing error. Can someone please tell me some example,how to do this.

posted Oct 25, 2013 by Sumit Pokharna

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

By default, a table on PostgreSQL does not register UUID...
It might work only for new tables you create, because to Postgres use UUID you need say it when creating the table... for existing ones, it might not happen because the table on PostgreSQL may not have been created with the option to use Uuids.

answer Oct 25, 2013 by Deepankar Dubey
Similar Questions
0 votes

Hi,

I need to take the only schema from Postgresql. Can anyone suggest how to dumb or migrate the schema?

0 votes

I was reading the docs for primary key on postgresql and I saw that there was a way to add a custom stored procedure that returns a UUID. There is a test case as well that uses a custom uuid generator

https://github.com/rails/rails/blob/650ea5e5cf50d8a7242499463cf1762922d330a8/activerecord/test/cases/adapters/postgresql/uuid_test.rb#L193

But I was not sure how to to implement this myself. Like in the test case where do I place my_uuid_generator() and how to implement it in my rails application?

+1 vote

In my local machine I had input some data into database using SQLite3 . When I deployed it to heroku why I can't get data that i input?

I'm doing like this

-in Gemfile
group :development do
 gem 'sqlite3'
end
group :production do
 gem 'pg'
 gem 'rails_12factor'
end
-bundle install
-heroku login
-git init 
-git add .
-git commit -m "test"
-git create
-git push heroku master
-heroku run rake db:migrate

How can I get some data when I deployed it to heroku? Please help me.

+2 votes

I am trying to search the phrase of numbers in a html page in the
sentence below:

(253 items)

I used this piece of code, but it does not work,

limit= page.search("div[class=Results]").search("div").gsub("items","")

 begin
 Integer(limit)
 rescue
 return 0
 end

Would you give me any suggestion on this?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...