标题: XML to DDL的项目关键:与数据库同步 [打印本页] 作者: tzlink 时间: 2008-5-30 15:23 标题: XML to DDL的项目关键:与数据库同步 对于xml2ddl项目,Freshmeat.org提供了一整套基于GNU或者GPL通用公共许可证下的Python程序。在一个运行的Python环境下,这套工具能够在许多操作系统上工作,包括Windows, Linux, 以及UNIX平台上,同时也能工作在以下数据库引擎:PostgreSQL, MySQL, Oracle, 以及Firebird.
<table name="students" fullname="List of Students"
desc="List of students with their full names">
<columns>
<column name="id" fullname="Primary Key" type="integer" key="1"
desc="Primary key for the table"/>
<column name="student_name" fullname="Student Name"
type="varchar" size="80"
desc="The full name of the student"/>
</columns>
</table>
</schema>
DROP TABLE students;
CREATE TABLE students (
id integer,
student_name varchar(80),
CONSTRAINT pk_students PRIMARY KEY (id));
COMMENT ON TABLE students IS 'List of students with their full names';
COMMENT ON COLUMN students.id IS 'Primary key for the table';
COMMENT ON COLUMN students.student_name IS 'The full name of the student';
<schema>
<table name="students" fullname="List of Students"
desc="List of students">
<columns>
<column name="id" fullname="Primary Key" type="integer" key="1"
desc="Primary key for the table"/>
<column name="student_name" fullname="Student Name"
type="varchar" size="100"
desc="The full name of the student"/>
<column name="email" fullname="Electronic mail address"
type="varchar" size="100"
desc="The primary email for the student"/>
</columns>
</table>
</schema>
那么PostgresSQL将产生以下的DDL输出:
ALTER TABLE students ALTER student_name TYPE varchar(80);
ALTER TABLE students DROP email;
COMMENT ON TABLE students IS 'List of students with their full names';