Search code examples
javadatabasegoogle-app-enginepopulate

How to pre-populate the GAE local database


I'm creating a Google Application Engine using java. For this application I want to pre-populate some information on the database (ex: roles, permissions, etc..) How can I do that on my local datastore? And how do I do that when I upload the application? It seems there are some python tools to work with the server datastore, but not the local database.


Solution

  • Add a servlet to your application that persists the data you need to the datastore. Then, just visit the servlet's URL before you first run your application.

    That's the simplest way. If you want to use this approach after you upload your application to GAE, make sure you add a security constraint so that only you can invoke the servlet:

        <security-constraint>
        <web-resource-collection>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>
    

    https://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication