问题
I ported a Python Twisted application to OpenShift, which stores its data to a SQLite database. After putting database file to the git repo data/ directory (during the first deploy) I had no issues, but the database was simply resetted at the second deploy.
I searched for a proper solution to this weird behavior (considering that the database was under versioning) and then I found the answer in the OpenShift Knowledge Base:
The short solution to this issue is to store your SQLite database one level up from your git repository in the ‘data’ directory.
Now my question is what happens when I move the database to this directory? Have I to move or copy the data directory's content? And this data will be preserver from deploy to deploy?
I tried to move the database from repo/data to data/ directory but the application cannot access this upper level directory. I'm looking for the best solution to this problem.
回答1:
I've found a solution by dividing my application data into two categories:
- stateful data
- dynamic data
I left the stateful information in the repo/data directory and I moved permanently the changing data to the upper level data/ directory. Making this change I am able to maintain the stateful_data under version control in my git repo accessing them through:
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
static_data_folder = __location__ + '/data/'
The dynamically generated data is then moved to $OPENSHIFT_DATA_DIR which is NOT under version control and corresponds to the upper level directory of my app-root. I changed my getter in my singleton Configuration module to return this mutable data folder:
self.mutable_data_path = os.environ['OPENSHIFT_DATA_DIR'] + "mutable_data_subdir/"
I'm testing this configuration right now but it seems to work like a charm.
来源:https://stackoverflow.com/questions/21658920/how-to-preserve-a-sqlite-database-from-being-reverted-after-deploying-to-openshi