Skip to content Skip to sidebar Skip to footer

Openshift App With Flask, Sqlalchemy And Sqlite - Problems With Database Reverting

I have a problem pretty much exactly like this: How to preserve a SQLite database from being reverted after deploying to OpenShift? I don't understand his answer fully and clearly

Solution 1:

Via the note at the top of the OpenShift Cartridge Guide:

"Cartridges and Persistent Storage: Every time you push, everything in your remote repo directory is recreated. Store long term items (like an sqlite database) in the OpenShift data directory, which will persist between pushes of your repo. The OpenShift data directory can be found via the environment variable $OPENSHIFT_DATA_DIR."

You can keep your existing project structure as-is and just use a deploy hook to move your database to persistent storage.

Create a deploy action hook (executable file) .openshift/action_hooks/deploy:

#!/bin/bash# This deploy hook gets executed after dependencies are resolved and the# build hook has been run but before the application has been started back# up again.# if this is the initial install, copy DB from repo to persistent storage directoryif [ ! -f ${OPENSHIFT_DATA_DIR}database.db ]; thencp -rf ${OPENSHIFT_REPO_DIR}database.db ${OPENSHIFT_DATA_DIR}/database.db 2>/dev/null
fi# remove the database from the repo during all deploysif [ -d ${OPENSHIFT_REPO_DIR}database.db ]; thenrm -rf ${OPENSHIFT_REPO_DIR}database.db
fi# create symlink from repo directory to new database location in persistent storageln -sf ${OPENSHIFT_DATA_DIR}database.db ${OPENSHIFT_REPO_DIR}database.db

As another person pointed out, also make sure you are actually committing/pushing your database (make sure your database isn't included in your .gitignore).

Post a Comment for "Openshift App With Flask, Sqlalchemy And Sqlite - Problems With Database Reverting"