0

Same question as Migrate table id to UUID but for tables that already have data in them

For a very simple MRE, please assume a users table with at least a couple of generic records

User.create(name: "john")
User.create(name: "Mel")
stevec
  • 41,291
  • 27
  • 223
  • 311
  • Hey uh did you actually read ALL the answers on the original question? https://stackoverflow.com/a/42504083/12672179 already covers how to do this so this question is probably going to be closed as a duplicate. – The Grand J Nov 18 '20 at 02:03
  • @TheGrandJ I saw it but reasoned there'd probably be a cleaner, more universal way. But I happen to be using postgresql so I'll give the [uuid_generate_v4()](https://www.postgresqltutorial.com/postgresql-uuid/) approach a try. I had thought this would be a common thing in rails apps, so figured there'd be some more established/standardised convention (e.g. something in rails), but perhaps not – stevec Nov 18 '20 at 03:30
  • There could be but I just have a hunch this post will be close. I'm not going to flag or downvote it but I just thought I'd warn you so it didn't just happen out of nowhere without any explanation. But I think if you reword this question to specify you want a solution that is universal/does not use postgresql then I think there is no issue with the question. It will be unique and a worthy reason to not close as duplicate. – The Grand J Nov 18 '20 at 03:32
  • If by universal you mean a polyglot solution where you type a simple command in a migration and rails creates the SQL to add the UUID column and assign UUIDs then thats not something thats built into ActiveRecord and it probally never will be as its both a pretty niche requirement and the implementations are so different across databases so that it would be hell to implement. – max Nov 19 '20 at 15:42

0 Answers0