Tuesday 15 March 2011

How to migrate complex Rails database to use UUID primary keys Postgresql -


I have a database that I want to use as the primary key in postgrascale form of UUID.

I have around 30 tables with deep multi-level associations, is there an 'easy' way to convert all existing IDs into UUID?

From this:, I can see that I can change the table in migration. I was thinking something like this: for the clients in the client

  get children underwriting = clients. Endwritings # Perform the primary key 'Optional table client change column ID type UUID;' Execute 'Optional Table Clients Column ID Set Default UUID_Generate_ (1);' # Get the new ID - is it already generated? Client_id = underwriting clients.id = Underwriting for underwriting in locations. Location other_record = underwriting. Other_records ... 'Ultra Table Footer Temporarily Column ID Type UUID;' Execute 'Optional Table Underwriting Optional Column ID Set Default UUIDGenerate_V 1 ();' Underwriting.client_id = client_id underwriting.saved underwriting_id = underwriting. Building = location for the location of the place. Building 'execute temporary table locations; Optionally column ID type; ' Executed 'ALTER TABLE places ALTER COLUMN id SET DEFAULT uuid_generate_v1 ();' Location.undewriting_id = underwriting_id location.save location_id = location.id for construction in buildings ... other_resounds in the end of second_record ... end ... ... and end   

questions :

  • Will this work?
  • Is there an easy way to do this?
  • Should the child record be properly received before the primary key is changed?
  • Should the new primary key be changed as already called the optical table?

    Thank you very much for any help or suggestions in doing this.

    I found this to be quite tedious.

      Optional table Optional call dot default for the students, optional column id sET data type UUID UUID UUID (UPID (UPID (UPID (UPID (UPID For additional reference:  
      Alternate table for students optional option for students using the column City_ID set data type UUD (UUID (LPAD (text (city_ID), '-', ' '), 32, 0')) )   

    Returns the integer values ​​with the left foot above the zero and converts to the UUID. This approach does not require id mapping, and if necessary, retrieve the old ID.

    Since there is no data copy, this approach works very fast.

    Use multipurpose associations to handle these more complex cases Please The mound Active migrations adds additional support for ActiveRecord :: Migration to reduce.

No comments:

Post a Comment