Monday, November 19, 2018

[google-cloud-sql-discuss] Re: Migrating from Cloud SQL to Datastore

Thanks Omair for your guidance.

So I tried to first see if my PHP can talk to Datastore and retrieve data.
I created two entities nuder the kind "keypad_research".

This is how my PHP looks like:

<?php
require __DIR__ . '/../../vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Entity;
$projectId = "__my projectID__";
$datasetId = $projectId;
$datastore = new DatastoreClient(['projectId' => $projectId]);
function llist($datastore){
$query = $datastore->query()
        ->kind('keypad_research')
->start($cursor);

    $results = $datastore->runQuery($query);
$entries = [];
$count = 0;
foreach ($results as $entity) {
$count++;
}

echo $count; // this shows me '0' results even when I have 2 entities.
}
llist($datastore);
?>

Do I need to do any addition configuration or edit my PHP to be able to read from datastore?

I am thinking of writing a PHP script that will first read from SQL database and insert entities in datastore.
But my very basic attempt at reading data from datastore using PHP is failing.

Any advice is appreciated.


On Monday, November 19, 2018 at 9:28:34 AM UTC-8, Omair (Cloud Platform Support) wrote:

Hi Sajid,


Unfortunately there is no automatic way to migrate a Cloud SQL database to Datastore.  The general process for migrating is as follows:


  1. Map your relational model to datastore kinds and entities

  2. [Optional] Download your relational database as csv

  3. Write a script using one of our Cloud Datastore Client Libraries that would transfer your data from Cloud SQL or the csv in step 2 to Datastore

  4. If you have a large database, it would speed up the migration process by hosting your script on App Engine.



If you require assistance in writing your script for migrating relational database to Datastore it is recommended to post your complete question to Stack Overflow using one of our supported tags, as your question will receive a lot more attention there.


I have found a useful post on Stack Overflow for you that I think might help you.



On Sunday, November 18, 2018 at 4:22:23 PM UTC-5, sajid saiyed wrote:
Hi,
I am currently using Cloud SQL but its an over kill for the small application that I moved from another host to Google Cloud.
I wanted to know how can I move my data from SQL to Datastore?

Is there an automatic way to do that?
It would be impossible to manually re-create the existing database in Datastore (100's of rows of sql data).

Any tips are appreciated.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/9d54e616-355f-4249-8eda-735f4c7152bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment