管理rdb模式的诀窍
gocept.rdbmanagement的Python项目详细描述
这是一个zc.buildout配方,有助于管理关系模式更新 数据库
目前只支持PostgreSQL。
定义托管数据库
必须在此配方之外创建托管数据库(createDB)。这个 配方只负责初始化现有数据库并升级 架构随后。
零件定义如下:
[managed_db] recipe = gocept.rdbmanagement dbname = mydatabase eggs = projectegg schema = projectegg.schemadir host = localhost user = username password = apassword
其中
- dbname
- is the name of the PostgreSQL database to work with
- eggs
- is a list of egg requirements that should be activated before looking up the schema directory resource path
- schema
- is a setuptools resource path that is a managed schema directory
托管架构目录
模式目录包含一组SQL和Python文件,这些文件用于 管理数据库的架构典型的目录如下:
$ ls schemadir __init__.py init.sql precondition3.py update1.sql update2.sql update3.sql
注意:托管模式目录必须是python包。
初始sql
- Creates the schema beginning from an empty database.
- After init.sql the current generation will be set to the highest generation number as available from the update scripts. Therefore the init.sql always creates a current database schema and no updates will be run.
updatex.sql
- Update scripts MUST start with a BEGIN statement and end with a COMMIT statement.
- Update script X will be run from a database at generation X-1.
前提条件x.py
- Script must contain a function called ^{tt1}$ which takes one parameter which is an open DB-API2-connection to the database.
- Precondition script X will be run on a database at generation X-1.
- Precondition script X has to raise an exception to indicate that the database MUST not be updated to generation X.
变化
1.0(2015-07-06)
- 实现访问数据库时使用密码的能力,要求 此功能的PostgreSQL 9.0最低版本。
- 至少需要Python2.7
0.1.2
- 允许比exactly psycopg2==2.0.6更高的版本
0.1.1
- 首次公开发行