From a2c91a7733c40402f5c228bea50b909f3b02004c Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Wed, 16 Dec 2009 16:57:50 +0100 Subject: [PATCH 1/2] [IMP] Add comment on table base on description [IMP] Add comment on column base on field name [IMP] Add comment on relation table (many2many) bzr revid: christophe.chauvet@syleam.fr-20091216155750-mpujuc3v3zojwhw6 --- bin/osv/orm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 280b5020704..08d8bfc2664 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1843,6 +1843,7 @@ class orm(orm_template): cr.execute("SELECT relname FROM pg_class WHERE relkind in ('r','v') AND relname='%s'" % self._table) if not cr.rowcount: cr.execute("CREATE TABLE \"%s\" (id SERIAL NOT NULL, PRIMARY KEY(id)) WITH OIDS" % self._table) + cr.execute("COMMENT ON TABLE \"%s\" IS '%s'" % (self._table, self._description.replace("'","''"))) create = True cr.commit() if self._parent_store: @@ -1907,6 +1908,7 @@ class orm(orm_template): cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE, "%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE) WITH OIDS' % (f._rel, f._id1, self._table, f._id2, ref)) cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id1, f._rel, f._id1)) cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id2, f._rel, f._id2)) + cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (f._rel, self._table, ref)) cr.commit() else: cr.execute("SELECT c.relname,a.attname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,t.typname,CASE WHEN a.attlen=-1 THEN a.atttypmod-4 ELSE a.attlen END as size " \ @@ -1935,6 +1937,7 @@ class orm(orm_template): # add the missing field cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, get_pg_type(f)[1])) + cr.execute("COMMENT ON COLUMN %s.%s IS '%s'" % (self._table, k, f.string.replace("'","''"))) # initialize it if not create and k in self._defaults: From 17a627ced93809fc50b002b5785c4e7003a58f05 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Wed, 16 Dec 2009 17:40:44 +0100 Subject: [PATCH 2/2] [IMP] Don't use OIDS when create database, because - There is a primary key on all tables - OIDS are disable since 8.0 bzr revid: christophe.chauvet@syleam.fr-20091216164044-stzqgdxsbl019x41 --- bin/osv/orm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 08d8bfc2664..f9e216ec5a8 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1842,7 +1842,7 @@ class orm(orm_template): if not hasattr(self, "_auto") or self._auto: cr.execute("SELECT relname FROM pg_class WHERE relkind in ('r','v') AND relname='%s'" % self._table) if not cr.rowcount: - cr.execute("CREATE TABLE \"%s\" (id SERIAL NOT NULL, PRIMARY KEY(id)) WITH OIDS" % self._table) + cr.execute("CREATE TABLE \"%s\" (id SERIAL NOT NULL, PRIMARY KEY(id)) WITHOUT OIDS" % self._table) cr.execute("COMMENT ON TABLE \"%s\" IS '%s'" % (self._table, self._description.replace("'","''"))) create = True cr.commit() @@ -1905,7 +1905,7 @@ class orm(orm_template): ref = self.pool.get(f._obj)._table except AttributeError: ref = f._obj.replace('.', '_') - cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE, "%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE) WITH OIDS' % (f._rel, f._id1, self._table, f._id2, ref)) + cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE, "%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE) WITHOUT OIDS' % (f._rel, f._id1, self._table, f._id2, ref)) cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id1, f._rel, f._id1)) cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id2, f._rel, f._id2)) cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (f._rel, self._table, ref))