How to preserve a SQLite database from being reverted after deploying to OpenShift?

无人久伴 提交于 2019-12-12 20:27:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!