Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/util/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,13 +1287,14 @@ def rename_table(cr, old_table, new_table, remove_constraints=True):
FROM information_schema.table_constraints
WHERE table_name = %s
AND constraint_name !~ '^[0-9_]+_not_null$'
AND constraint_name != %s
AND ( constraint_type NOT IN ('PRIMARY KEY', 'FOREIGN KEY')
-- For long table names the constraint name is shortened by PG to fit 63 chars, in such cases
-- it's better to drop the constraint, even if it's a foreign key, and let the ORM re-create it.
OR (constraint_type = 'FOREIGN KEY' AND constraint_name NOT LIKE %s)
)
""",
[new_table, old_table.replace("_", r"\_") + r"\_%"],
[new_table, '%s_id_not_null' % old_table, old_table.replace("_", r"\_") + r"\_%"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could check cr._cnx.server_version >= 180000 and ignore only in that case.

Nit: old_table + '_id_not_null'

)
for (const,) in cr.fetchall():
_logger.info("Dropping constraint %s on table %s", const, new_table)
Expand Down