Question

Well, I'm developing in App Engine (Java) and after a lot of tries and deployments, I need to reset the datastore. There is a lot of random data I added to test performance, and besides that the entities changed a lot, so I need to delete all: data, tables, indexes.

How can I do that?

Was it helpful?

Solution

There is no built in command equivalent to DROP TABLE or TRUNCATE TABLE in SQL. You just need to create a "delete everything" page in your app, then repeatedly call that page via a script. In that page, you want to delete as many entities as you can yet still reasonably expect to finish before the request times out. The exact code depends on whether you're using JDO/JPA or the low level API. (the low level API will be faster because you can use batch operations.)

This previous SO question is pretty much the same, only for Python

OTHER TIPS

Sorry to wake this thread up, but just in case I'd like to add a tip for noobs like me (finally found the answer in google documentation) :

If you want to reset the Local datastore (for example while developping using eclipse) all at once, shut down the server, find the file 'local_db.bin' in your project (should be in the WEB-INF/appengine-generated/ directory), and delete it.

Works fine with java, didn't try with python yet.

++

Clearing the Development Server Datastore

The development web server uses a local version of the datastore for testing your application, using temporary files. The data persists as long as the temporary files exist, and the web server does not reset these files unless you ask it to do so.

If you want the development server to erase its datastore prior to starting up, use the --clear_datastore option when starting the server:

dev_appserver.py --clear_datastore helloworld/

Using the Datastore

Just execute a query without a filter to fetch all the entities, and delete them one by one.

import javax.servlet.http.*;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;

public class MyServlet extends HttpServlet {
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        DatastoreService datastore = 
                    DatastoreServiceFactory.getDatastoreService();

    Query mydeleteq = new Query();
    PreparedQuery pq = datastore.prepare(mydeleteq);
    for (Entity result : pq.asIterable()) {
        datastore.delete(result.getKey());      
    }   
}

sorry to be so late on this, but I was just trying to do the same myself...

I logged into my account (appengine.google.com) and found the option to browse the datastore through an admin utility (datastore/dataviewer)... that allows create/update/delete.

According to GAE docs you can delete multiple objects in JDO, call the PersistenceManager's deletePersistentAll(...) method with a Collection of objects.

PersistenceManager pm = PMF.get().getPersistenceManager();

Query query = pm.newQuery("select from " + Your.class);

List<Your> objs = (List<Your>) query.execute();

pm.deletePersistentAll(objs);

Delete all (or a part) of your application’s data is now part of the Admin console

To enable this functionality, simply enable the following builtin in your app.yaml file:

builtins:
- datastore_admin: on

Adding these lines to app.yaml enables the “Datastore Admin” page in your app’s Admin Console

Out of context for java dev but since there's few documentation here's how to do it in go :

keys, _ := datastore.NewQuery("").KeysOnly().GetAll(c, nil)
datastore.DeleteMulti(c, keys)

If you use maven in your project, you can just do a "mvn clean install". That will reset the datastore locally of course.

Deleting local data can be done by opening http://localhost:8000/datastore

in my case (working with eclipse plugin and play framework) I had to stop the application, delete file /apps/crud-gae/tmp/datastore and then restart the app

it worked for me... working locally, of course...

When working locally, on Windows 7 the file is user\UserName\AppData\Local\Temp\dev_appserver.datastore

I was using app engine with Google Coursebuilder and had to use this command to clear the datastore:

python dev_appserver.py --clear_datastore /path/to/app

To add another bit of helpful info: If using Eclipse and you want to clear the local datastore, look for this console msg:

INFO: Local Datastore initialized: 
Storage: C:\Users\eric\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\appname\WEB-INF\appengine-generated\local_db.bin

It only shows up after you do something to force datastore initialization, e.g. which could be refreshing the entity list on the admin page. Then stop your server and delete the file, and when you restart you should see:

INFO: The backing store, C:\Users\eric\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\appname\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top