Reviewers: ,
Please review this at http://codereview.tryton.org/625002/
Affected files:
M trytond/backend/mysql/init.sql
M trytond/backend/postgresql/init.sql
M trytond/model/modelsql.py
Index: trytond/backend/mysql/init.sql
===================================================================
--- a/trytond/backend/mysql/init.sql
+++ b/trytond/backend/mysql/init.sql
@@ -105,9 +105,7 @@
write_uid BIGINT,
name VARCHAR(255) NOT NULL,
state VARCHAR(255),
- PRIMARY KEY(id),
- CONSTRAINT ir_module_module_create_uid_fkey FOREIGN KEY (create_uid)
REFERENCES res_user (id) ON DELETE SET NULL,
- CONSTRAINT ir_module_module_write_uid_fkey FOREIGN KEY (write_uid)
REFERENCES res_user (id) ON DELETE SET NULL
+ PRIMARY KEY(id)
) ENGINE=InnoDB;
ALTER TABLE ir_module_module ADD CONSTRAINT name_uniq UNIQUE (name);
@@ -121,7 +119,5 @@
name VARCHAR(255),
module BIGINT,
PRIMARY KEY(id),
- CONSTRAINT ir_module_module_dependency_create_uid_fkey FOREIGN KEY
(create_uid) REFERENCES res_user (id) ON DELETE SET NULL,
- CONSTRAINT ir_module_module_dependency_write_uid_fkey FOREIGN KEY
(write_uid) REFERENCES res_user (id) ON DELETE SET NULL,
CONSTRAINT ir_module_module_dependency_module_fkey FOREIGN KEY
(module) REFERENCES ir_module_module (id) ON DELETE CASCADE
) ENGINE=InnoDB;
Index: trytond/backend/postgresql/init.sql
===================================================================
--- a/trytond/backend/postgresql/init.sql
+++ b/trytond/backend/postgresql/init.sql
@@ -127,9 +127,7 @@
write_uid INTEGER,
name VARCHAR NOT NULL,
state VARCHAR,
- PRIMARY KEY(id),
- FOREIGN KEY (create_uid) REFERENCES res_user ON DELETE SET NULL,
- FOREIGN KEY (write_uid) REFERENCES res_user ON DELETE SET NULL
+ PRIMARY KEY(id)
);
ALTER TABLE ir_module_module ADD CONSTRAINT name_uniq UNIQUE (name);
@@ -145,7 +143,5 @@
name VARCHAR,
module INTEGER,
PRIMARY KEY(id),
- FOREIGN KEY (create_uid) REFERENCES res_user ON DELETE SET NULL,
- FOREIGN KEY (write_uid) REFERENCES res_user ON DELETE SET NULL,
FOREIGN KEY (module) REFERENCES ir_module_module ON DELETE CASCADE
);
Index: trytond/model/modelsql.py
===================================================================
--- a/trytond/model/modelsql.py
+++ b/trytond/model/modelsql.py
@@ -65,34 +65,34 @@
cls.create_date.string),
('write_date', timestamp_field.sql_type(None),
timestamp_field.sql_format, None, cls.write_date.string),
- ('create_uid', (integer_field.sql_type(None)[0],
- 'INTEGER REFERENCES res_user ON DELETE SET NULL',),
- integer_field.sql_format, lambda *a: 0,
cls.create_uid.string),
- ('write_uid', (integer_field.sql_type(None)[0],
- 'INTEGER REFERENCES res_user ON DELETE SET NULL'),
- integer_field.sql_format, None, cls.write_uid.string),
+ ('create_uid', integer_field.sql_type(None),
+ integer_field.sql_format, lambda *a: 0,
cls.create_uid.string),
+ ('write_uid', integer_field.sql_type(None),
+ integer_field.sql_format, None, cls.write_uid.string),
)
- for log in logs:
- table.add_raw_column(log[0], log[1], log[2],
- default_fun=log[3], migrate=False, string=log[4])
+ for name, type_, format_, default, string in logs:
+ table.add_raw_column(name, type_, format_, default_fun=default,
+ migrate=False, string=string)
if cls._history:
history_logs = (
- ('create_date', timestamp_field.sql_type(None),
- timestamp_field.sql_format,
cls.create_date.string),
- ('write_date', timestamp_field.sql_type(None),
- timestamp_field.sql_format, cls.write_date.string),
- ('create_uid', (integer_field.sql_type(None)[0],
- 'INTEGER REFERENCES res_user ON DELETE SET NULL',),
- integer_field.sql_format, cls.create_uid.string),
- ('write_uid', (integer_field.sql_type(None)[0],
- 'INTEGER REFERENCES res_user ON DELETE SET NULL'),
- integer_field.sql_format, cls.write_uid.string),
- )
- for log in history_logs:
- history_table.add_raw_column(log[0], log[1], log[2],
- migrate=False, string=log[3])
+ ('create_date', timestamp_field.sql_type(None),
+ timestamp_field.sql_format, cls.create_date.string),
+ ('write_date', timestamp_field.sql_type(None),
+ timestamp_field.sql_format, cls.write_date.string),
+ ('create_uid', integer_field.sql_type(None),
+ integer_field.sql_format, cls.create_uid.string),
+ ('write_uid', integer_field.sql_type(None),
+ integer_field.sql_format, cls.write_uid.string),
+ )
+ for name, type_, format_, string in history_logs:
+ history_table.add_raw_column(name, type_, format_,
+ default_fun=default, migrate=False, string=string)
history_table.index_action('id', action='add')
+ # Migration from 2.6
+ for user_field in ('create_uid', 'write_uid'):
+ table.drop_fk(user_field)
+
for field_name, field in cls._fields.iteritems():
default_fun = None
if field_name in (
@@ -144,11 +144,12 @@
table.db_default(field_name, False)
if isinstance(field, fields.Many2One):
- if field.model_name in ('res.user', 'res.group'):
- ref = field.model_name.replace('.', '_')
- else:
- ref = pool.get(field.model_name)._table
- table.add_fk(field_name, ref, field.ondelete)
+ if field_name not in ('create_uid', 'write_uid'):
+ if field.model_name in ('res.user', 'res.group'):
+ ref = field.model_name.replace('.', '_')
+ else:
+ ref = pool.get(field.model_name)._table
+ table.add_fk(field_name, ref, field.ondelete)
table.index_action(
field_name, action=field.select and 'add'
or 'remove')
--
--
[email protected] mailing list