Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to keep database content between consecutive runs of a Google App Engine app?

I have a Java / Spring app running on the standard environment. Every time I deploy it to App Engine, the postgres database I’m using is reset. How to prevent that?

My application.properties:

spring.datasource.url=jdbc:postgresql:///***

spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.format_sql=true

spring.jpa.hibernate.ddl-auto=create

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

My app.yaml:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

runtime: java17
instance_class: F1

automatic_scaling:
  max_idle_instances: 1

>Solution :

You just need to chage your ddl-auto config to:

spring.jpa.hibernate.ddl-auto=validate

or

spring.jpa.hibernate.ddl-auto=update

Options for spring.jpa.hibernate.ddl-auto:

  • None: No database Schema initialization
  • Create: Drops and creates the schema at the application startup. With this option, all your data will be gone on each startup.
  • Create-drop: Creates schema at the startup and destroys the schema on context closure. Useful for unit tests.
  • Validate: Only checks if the Schema matches the Entities. If the schema doesn’t match, then the application startup will fail. Makes no changes to the database.
  • Update: Updates the schema only if necessary. For example, If a new field was added in an entity, then it will simply alter the table for a new column without destroying the data

However, hibernate.ddl-auto should usually not be used in production (check this discussion).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading