From 14c5f661ea7dab169c73fd489cc2761cc8ca906e Mon Sep 17 00:00:00 2001 From: Bertrand Chenal Date: Wed, 8 Jul 2009 14:10:07 +0200 Subject: [PATCH] Fix NOT NULL handling in base tables: - Removed useless NOT NULL for sqlite in init.sql - Added missing NOT NULL for postgresql in init.sql - Take care of populating required fields when creating records in module tables --- trytond/backend/postgresql/database.py | 13 +++++++------ trytond/backend/postgresql/init.sql | 8 ++++---- trytond/backend/sqlite/database.py | 13 +++++++------ trytond/backend/sqlite/init.sql | 8 ++++---- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index 0cc4dc56e4..4254580701 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -208,17 +208,18 @@ class Database(DatabaseInterface): cursor.execute('SELECT NEXTVAL(\'ir_module_module_id_seq\')') module_id = cursor.fetchone()[0] cursor.execute('INSERT INTO ir_module_module ' \ - '(id, author, website, name, shortdesc, ' \ - 'description, state) ' \ - 'VALUES (%s, %s, %s, %s, %s, %s, %s)', - (module_id, info.get('author', ''), + '(id, create_uid, create_date, author, website, name, ' \ + 'shortdesc, description, state) ' \ + 'VALUES (%s, %s, now(), %s, %s, %s, %s, %s, %s)', + (module_id, 0, info.get('author', ''), info.get('website', ''), i, info.get('name', False), info.get('description', ''), state)) dependencies = info.get('depends', []) for dependency in dependencies: cursor.execute('INSERT INTO ir_module_module_dependency ' \ - '(module, name) VALUES (%s, %s)', - (module_id, dependency)) + '(create_uid, create_date, module, name) ' \ + 'VALUES (%s, now(), %s, %s)', + (0, module_id, dependency)) class _Cursor(cursor): diff --git a/trytond/backend/postgresql/init.sql b/trytond/backend/postgresql/init.sql index 9b65d55769..e99f96abfe 100644 --- a/trytond/backend/postgresql/init.sql +++ b/trytond/backend/postgresql/init.sql @@ -183,8 +183,8 @@ create table wkf_witm_trans CREATE TABLE ir_module_module ( id serial NOT NULL, - create_uid integer references res_user on delete set null, - create_date timestamp without time zone, + create_uid integer NOT NULL references res_user on delete set null, + create_date timestamp without time zone NOT NULL, write_date timestamp without time zone, write_uid integer references res_user on delete set null, website varchar, @@ -200,8 +200,8 @@ ALTER TABLE ir_module_module add constraint name_uniq unique (name); CREATE TABLE ir_module_module_dependency ( id serial NOT NULL, - create_uid integer references res_user on delete set null, - create_date timestamp without time zone, + create_uid integer NOT NULL references res_user on delete set null, + create_date timestamp without time zone NOT NULL, write_date timestamp without time zone, write_uid integer references res_user on delete set null, name varchar, diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index 11f75de48c..5ba466d8ae 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -176,10 +176,10 @@ class Database(DatabaseInterface): else: state = 'uninstalled' cursor.execute('INSERT INTO ir_module_module ' \ - '(author, website, name, shortdesc, ' \ - 'description, state) ' \ - 'VALUES (%s, %s, %s, %s, %s, %s)', - (info.get('author', ''), + '(create_uid, create_date, author, website, name, ' \ + 'shortdesc, description, state) ' \ + 'VALUES (%s, now(), %s, %s, %s, %s, %s, %s)', + (0, info.get('author', ''), info.get('website', ''), i, info.get('name', False), info.get('description', ''), state)) cursor.execute('SELECT last_insert_rowid()') @@ -187,8 +187,9 @@ class Database(DatabaseInterface): dependencies = info.get('depends', []) for dependency in dependencies: cursor.execute('INSERT INTO ir_module_module_dependency ' \ - '(module, name) VALUES (%s, %s)', - (module_id, dependency)) + '(create_uid, create_date, module, name) ' \ + 'VALUES (%s, now(), %s, %s) ', + (0, module_id, dependency)) class _Cursor(sqlite.Cursor): diff --git a/trytond/backend/sqlite/init.sql b/trytond/backend/sqlite/init.sql index 44cc5440b0..21828f6982 100644 --- a/trytond/backend/sqlite/init.sql +++ b/trytond/backend/sqlite/init.sql @@ -91,7 +91,7 @@ insert into res_user (id,login,password,name,action,active) values (0,'root',NUL CREATE TABLE res_group ( id INTEGER PRIMARY KEY, - name VARCHAR NOT NULL + name VARCHAR ); CREATE TABLE "res_user-res_group" ( @@ -143,9 +143,9 @@ create table wkf_instance id INTEGER PRIMARY KEY, workflow INTEGER, uid INTEGER, - res_id INTEGER not null, - res_type VARCHAR not null, - state VARCHAR not null + res_id INTEGER, + res_type VARCHAR, + state VARCHAR ); create table wkf_workitem