Wednesday, November 21, 2018

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

Hi,
Thanks for looking into this.
Actually I solved this and it seems that the documentation is not clear about the importance of custom namespaces.

All I had to do was change:
$datastore = new DatastoreClient(['projectId' => $projectId]);
to 
$datastore = new DatastoreClient(['projectId' => $projectId, 'namespaceId' => 'ssd']);

I was not using 'default' namespace. That was causing all the problem.
Hope someone will add this to the documentation.


On Wednesday, November 21, 2018 at 8:26:48 AM UTC-8, Mohammad I (Cloud Platform Support) wrote:

Hello Sajid,


I have reproduced your code as below with some modification after executing the commands and PHP code outlined here.


$datasetId = $projectId;

$datastore = new DatastoreClient(['projectId' => $projectId]);

function llist($datastore){

$query = $datastore->query()

       ->kind('Task');

   $results = $datastore->runQuery($query);

$entries = [];

$count = 0;

foreach ($results as $entity) {

$count++;

}


echo $count; // this shows me '1' results when I have used Kind('Task') and shows me '0' for Kind('Task1') .

}

llist($datastore);


The kind, 'Task' was defined in the PHP code of the above mentioned link as a result when the modified version of your code was executed it has shown the result 1. When the kind, 'Task' was modified with 'Task1' it has shown the result 0.


From the above observation, it is appearing the kind, 'keypad_research' that you used may not exist or your typed it wrong. In addition the variable $cursor is not defined in your code which I removed during reproduction as it was showing the following error:


PHP Notice:  Undefined variable: cursor in /home/.../php/index.php on line 17


As it was mentioned earlier, If your issue is not a platform issue but rather a problem with how you've configured your code, although you're not sure what it may be specifically, you should post to StackOverflow and community of developers will assist you.



On Tuesday, November 20, 2018 at 12:50:02 AM UTC-6, sajid saiyed wrote:
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/0e445e0f-33bd-458b-8e8d-4d3859e25de0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment