Back

Migration of data | Keep createdAt and updatedAt

  • 0
  • Databases
Bouahaza
23 Jun, 2023, 12:18

Is it a simplier way to migrate data (from no appwrite project) than inject to mariaDB directly knowing that we want to keep createdAt and updatedAt

TL;DR
The user is discussing the migration of data with the goal of keeping createdAt and updatedAt fields intact. They share a pull request and an issue link for reference. They suggest injecting data into MariaDB, selecting the data, and reconstructing the "appwrite object" with the necessary fields. They mention the option of overriding the appwrite code or creating a custom document with two updatedAt fields. They also discuss the need to trigger functions on database events and suggest faking updates on each document to trigger the desired events. There is a suggestion to directly import data into MariaDB to retain the createdAt and updatedAt values. No final solution is mentioned in the
Binyamin
23 Jun, 2023, 13:24

You mean copied any other data into Appwrite directly to MariaDB? The insertion of the value of _createdAt and _updatedAt is done through the PHP which means if you will directly import your data into MariaDB you can have the same createdAt and updatedAt you had before.

Bouahaza
23 Jun, 2023, 13:24

Yes, not find other ways

Bouahaza
23 Jun, 2023, 13:25

While we need to triggers function on database events too. We need to

  1. Inject data to mariaDB
  2. Loop over 100 000+ documents via appwrite rest API
  3. For each, fake an update, to trigger event
Bouahaza
23 Jun, 2023, 13:26

But it will update updatedAt

Binyamin
23 Jun, 2023, 13:26

What is the need of step 2 and 3

Bouahaza
23 Jun, 2023, 13:27

Function don't trigger without use of appwrite api

Bouahaza
23 Jun, 2023, 13:27

Thinks it listen binlog but it's not the case :/

Binyamin
23 Jun, 2023, 13:29

Ohh, got you. Let me see something.

Bouahaza
23 Jun, 2023, 13:31

Thinks we'll need to replicate function logic on migration script, to manually call this code, to keep updatedAt intact

Binyamin
23 Jun, 2023, 13:38

If you want for this step to go you can do few things

Change Database.php file

Here https://github.com/utopia-php/database/blob/main/src/Database/Database.php#L2857C9-L2858

Appwrite's updating to the current time. You can override this file, You can look here https://discord.com/channels/564160730845151244/1121497324145868873/1121519354534711426

Custom document.

Create a document that have two updateAt fields Then trigger your function. Then run custom code in any language that will itereate over the documents and will set the _updateAt as your custom updateAt

Bouahaza
23 Jun, 2023, 13:41

If override appwrite code, thinks it's simplier to remove setAttribute here : https://github.com/utopia-php/database/blob/main/src/Database/Database.php#L2530C48-L2530C48 that let ut set createdAt and updatedAt on createDocument API call to appwrite

Binyamin
23 Jun, 2023, 13:42

This is one the creation, but yes.

Bouahaza
23 Jun, 2023, 13:43

Yes, with that not need to call updated after to trigger function, while function will be call on insertion

Binyamin
23 Jun, 2023, 13:44

Ohh, Okay.

Bouahaza
23 Jun, 2023, 13:44

But... Thinks we'll not override appwrite file. We'll inject function code on migration script

  1. Inject data to mariaDB
  2. Select * from mariaDB, & reconstruct "appwrite object" (with $documentId, etc..)
  3. Inject it on fake function code
Bouahaza
23 Jun, 2023, 13:45

Thinks it's better

Bouahaza
23 Jun, 2023, 13:45

Instead of other option

Bouahaza
23 Jun, 2023, 13:46

I'll check if feature issue exist on github, to force createdAt and updatedAt

Bouahaza
23 Jun, 2023, 13:52

Thanks for your time @Binyamin . if you or other have other idea,, don't hesitate

Binyamin
23 Jun, 2023, 13:53

Sounds good

Binyamin
23 Jun, 2023, 13:53

👍

Bouahaza
23 Jun, 2023, 13:56
Bouahaza
23 Jun, 2023, 14:17
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more