Purge all data in Bubble's database

For testing purposes, there should be a purge button in the Database. As a workaround, I have to create a button on my app to delete all of the data, but sometimes that can take some time if I’m working with a lot of test data.

3 Likes

I think that would be really useful, although maybe at table level, as I often have static data in tables, and would not always want the User table purged.

Wonder if it is possible to do this externally, via the data API.

It is possible, but firstly you have to call

GET https://appname.bubbleapps.io/api/1.1/obj/type_name

for each table, which gives you an array of ids, and then you have to run

DELETE https://appname.bubbleapps.io/api/1.1/obj/type_name/unique_id

for each thing/row

(for development version the URL is https://appname.bubbleapps.io/version-test/api/1.1/ …)

1 Like

Getting the list of tables is the interesting part.

Indeed …

Actually, you can access the app object in plugin code, the user types are described in app.user_types property. But this is heavy hacking, I’d say …

You can get it from the Meta API call, but it is hard to parse the table names out of it.

I see. There’s no such thing as a ‘list of types’ in the response, and it’s hard to work on assumptions …

Yeah, it is a list, so they are hard to parse in Bubble. Think may be possible to get them, it is on my list of things to do :slight_smile:

@NigelG, I created a very rudimentary plugin which gives a list of types (as a list of texts); if it’s helpful I can share it to your dev application.

If its alot of test data I just copy the app without the copy database checked then delete the old one. You can repeat that step and name the copy the old apps name if it needs to be on the same bubble domain afterwards.

That would be really useful. If I can get the name, then I can pull out the fields using a little function (in this case the type is conversation, but I was having trouble making that dynamic).

image

With this you can get an array of type names:

var appObj = app["user_types"];
var usrTypes = [];
      
for (var uType in appObj) {
  usrTypes.push(uType.toString());
}

and you can put it into HTML element (within script tags), javascript or plugin code.

As I understand, the app object is a way for the web client to get basic info for rendering, but since it is undocumented, it’s use might be problematic, since the structure might change.

Another thought is to use elegant ‘swagger-client.js’ as described here: https://www.diycode.cc/projects/swagger-api/swagger-js, that would be really powerful and officially supported, but I haven’t succeed with making a reference to ‘swagger-client.js’ / ‘swagger-client.min.js’ libraries from my Bubble app.