views:

2084

answers:

6

Whell, 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?

Thanks :)

+1  A: 

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

Peter Recore
I'm using JPA. Will this delete indexes too?
Damian
The indexes need to get updated every time you delete something, otherwise queries that use indexes would be returning bad data. So when you delete entity X, all index entries pointing to X should be deleted as well. Eventually you'll have empty indexes when you've deleted all your entities.
Peter Recore
Great, thanks again Peter!
Damian
Deleting indexes using appcfg first is a good idea - it'll make the delete process faster and cause it to consume less CPU updating indexes that you're just going to delete anyway,.
Nick Johnson
A: 

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.

DanDan
Sure, but you can't delete all entities at once, right?
Damian
Nope, only 20 at a time.
RyanW
If you tweak the limit=20 in the URL you can up the limit. In my case increasing to 100 let me delete a chunk of data in a couple requests (and saved me writing a tool/page to do this).
Michael Twomey
Nice one Michael!
DanDan
A: 

You can delete all unused indexes see documentation: Deleting_Unused_Indexes

appcfg.py vacuum_indexes myapp/
jonmiddleton
A: 

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);
FredArters
A: 

Hi everybody,

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.

++

Kohistan
A: 

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

Tamas Kalman