• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
custom record ID
#1
Is there a way for me to modify the record Id
I already have a database and they have their records Id already. It's a UUID similar to the ones you are using but slightly different.
If I create new records that are not a problem (as these ids are alpha so it does not matter as long as they are unique).
But if I want to use existing records it's another problem.

I can definitively ignore your ids but I think it's a bit of waste.

However, if I can change an id or provide the id when I create a new record it will be OK.

Please let me know...

Best,
  Reply
#2
(09-10-2021, 02:14 PM)philippecoenen Wrote: Is there a way for me to modify the record Id
I already have a database and they have their records Id already. It's a UUID similar to the ones you are using but slightly different.
If I create new records that are not a problem (as these ids are alpha so it does not matter as long as they are unique).
But if I want to use existing records it's another problem.

I can definitively ignore your ids but I think it's a bit of waste.

However, if I can change an id or provide the id when I create a new record it will be OK.

Please let me know...

Best,
Hi Philippe,

You can not change the existing record ID, but you can use your own ID in new records. They must meet the UUID format or the create command will generate an error.

You can export your existing database to either CSV or JSON. Read the data in and massage into an array.
Walk through each record and take your existing ID and place it in a cdbRecordID key. 

While making your array, use the batchCreate API's format.

You can also upload your database one record at a time if that works for you. You would still use your existing ID in the cdbRecordID key to preserve your current ID value.

Let me know if you have any problems.

-Mark
  Reply
#3
(09-10-2021, 04:52 PM)mark_talluto Wrote:
(09-10-2021, 02:14 PM)philippecoenen Wrote: Is there a way for me to modify the record Id
I already have a database and they have their records Id already. It's a UUID similar to the ones you are using but slightly different.
If I create new records that are not a problem (as these ids are alpha so it does not matter as long as they are unique).
But if I want to use existing records it's another problem.

I can definitively ignore your ids but I think it's a bit of waste.

However, if I can change an id or provide the id when I create a new record it will be OK.

Please let me know...

Best,
Hi Philippe,

You can not change the existing record ID, but you can use your own ID in new records. They must meet the UUID format or the create command will generate an error.

You can export your existing database to either CSV or JSON. Read the data in and massage into an array.
Walk through each record and take your existing ID and place it in a cdbRecordID key. 

While making your array, use the batchCreate API's format.

You can also upload your database one record at a time if that works for you. You would still use your existing ID in the cdbRecordID key to preserve your current ID value.

Let me know if you have any problems.

-Mark
Hi Mark,

Thanks for your prompt answer and it's clear.
I'll have to deal with the format of my IDs but that's OK.

So far no problems... However, I'm sure they will come... ;(

But you are there so I feel safe Wink

-Phil
  Reply
#4
Hi Phil,

You are most welcome. Thank you for taking the time to learn CanelaDB and LiveCloud. I am sure you will become a master in no time. You are well on your way. I try to be in the forums every day to answer questions.
  Reply
#5
(09-10-2021, 04:52 PM)mark_talluto Wrote:
(09-10-2021, 02:14 PM)philippecoenen Wrote: Is there a way for me to modify the record Id
I already have a database and they have their records Id already. It's a UUID similar to the ones you are using but slightly different.
If I create new records that are not a problem (as these ids are alpha so it does not matter as long as they are unique).
But if I want to use existing records it's another problem.

I can definitively ignore your ids but I think it's a bit of waste.

However, if I can change an id or provide the id when I create a new record it will be OK.

Please let me know...

Best,
Hi Philippe,

You can not change the existing record ID, but you can use your own ID in new records. They must meet the UUID format or the create command will generate an error.

You can export your existing database to either CSV or JSON. Read the data in and massage into an array.
Walk through each record and take your existing ID and place it in a cdbRecordID key. 

While making your array, use the batchCreate API's format.

You can also upload your database one record at a time if that works for you. You would still use your existing ID in the cdbRecordID key to preserve your current ID value.

Let me know if you have any problems.

-Mark

Thanks for your answer,

I don't have a problem per se but before I try:

Can you tell me if uuid("random") in livecode would work for livecloud?

this is a version 4 (random) UUID

Best,

Phil
  Reply
#6
Hi Phil,

We generate our UUIDs using put uuid() into tRecordID.

Thus, no need to supply any arguments for the uuid() function. CanelaDB validates custom recordIDs for every API call. Thus, using this model will keep you compatible.

-Mark
  Reply
#7
Hey Mark,

Thank you so much for all your answers.

Ok so I have created an array to create a record using: put uuid() into aObject["cdbRecordID"]
But when I attempt to create the record on the could database I get this error: Illegal key name starting with either 'cdb' or 'csi'
as you confirm that you are using uuid() and I do the same I guess it's not the uuid itself that is the problem.

I know I can get the id when the record is created but it will make my life a little more complicated for some operations.

What can I do?

-Phil
  Reply
#8
I don't think you can generate a cdbRecordID at will - although Mark will confirm.

I've had a similar scenario where i had existing primary/foreign keys in UUID format. I solved it by creating new foreign key for each record that corresponds to the correct cdbRecordID.
1. create columns for primary/foreign keys in all tables affected; these store your existing keys (while of course each record has the liveCloud derived cdbRecordID)
2. for each foreign key, i set up a function to return the cdbRecordID of the record that contains the correct primaryKey in the new primary key column
3. I then replace or store in a new column a new foreign key that corresponds
4. The final result is that all foreign keys now point to the correct cdbRecordID as primary key, and i no longer need the old primary/foreign keys.

hope that helps (or even makes sense!)
Stam
  Reply
#9
Hey Stamatis,

Mark says it's possible to force the uuid. (Check his answers upper)
He may argue that only the batch "batchCreate" can do that as he proposes in his answer.
I was trying to do the trick using the "create" instead.

So I will try with the batch create it might be the problem.

Thanks for your answer anyway.

-Phil
  Reply
#10
(02-25-2022, 10:21 AM)philippecoenen Wrote: Hey Stamatis,

Mark says it's possible to force the uuid. (Check his answers upper)
He may argue that only the batch "batchCreate" can do that as he proposes in his answer.
I was trying to do the trick using the "create" instead.

So I will try with the batch create it might be the problem.

Thanks for your answer anyway.

-Phil

Hi Phil, sorry i missed the answer above - do post something to update on success (or not!) if batchCreate works for you.
I didn't spend too much time on this as the process describe above was a 1-time process and fixed my issue. But always good to know if there is a way to make this work properly for future cases!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)