Welcome Guest, Not a member yet? Register   Sign In
Automatic insertion of UUID into legacy database
#1

I inherited a codebase using CodeIgniter version 3 of about 50 tables to perform a task. However I have a need to add a uuid column to all the tables automatically with the uuid values prefilled. On insertion of new data, uuid should automatically be generated for the data.
I would have inherited the CI_Model and overriden the insert method, but the CI_Model in this codebase is strangely empty and there is no insert method to override and call the parent method implementation. It seems the insert method was added through dependency injection and it can't really be overriden for each model.

How do I achieve automatic creation of the uuid fields for already existing tables and records and for new records being inserted into the database. I have more than 50 tables and doing it manually would be painfully difficult.
Reply
#2

Did you get the complete application or just the tables and model? It is strange that the model is empty.

Look at the application/config/database.php file and controllers to see what they are using for the database code.

You would need to create a method to do the UUID field, On a new record call the UUID method for the data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Yes i have the complete application, the models are not empty though.
How and where do i place the method that will add the uuid after every insert?

Thanks.
Reply
#4

You could add it as a helper or place it into your base model.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

So i have been battling with how to place it in my base model as the base model only have two methods. Do i create a new method or is there a way to chain the my uuid function to the model methods so as to generate the value in my database uuid column after every insertion to table with uuid column? Thank you. Code example will be very much helpful aswell thanks again.
Reply
#6

(This post was last modified: 12-13-2021, 02:13 AM by InsiteFX. Edit Reason: Speeling Error )

You can chain it by returning $this instead of returning a value you return the object.

PHP Code:
public function getUUID()
{
    // your code here.


    // return $this for method chaining.
    return $this;


Let us know how you make out on this.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

Thank you very much, will try the method chain of $this now and let you know.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB