Working with databases

The Haplo Platform provides a relational database for plugins, with the tables defined in JavaScript.

Currently automatic migration of database schemas will only add columns which are defined as nullable:true. If you make other changes, you will need to reset the plugin’s database and recreate the contents.

Resetting a database

When you’ve made changes to the table definitions in your plugin, save the file and let the Plugin Tool upload the new definitions to the server.

To apply the changes, reset the database:

    haplo-plugin -p test_plugin reset-db

This will delete the old tables for your plugin, and recreate them with the current definitions. All the data in the tables will be deleted.

You don’t have to stop another instance of the Plugin Tool waiting to upload changes when you run this command.

Test data

If you need some test data, the best way is to create a temporary request handler which creates it. After you’ve reset the database, request the URL in your web browser to populate the new database tables.

Alternatively, you can define an onInstall() function in your Plugin definition. This will be called when you reset the database, and every time the Plugin Tool uploads a new file to the server.

Remember to remove this test data when you submit the plugin.