|
2 | 2 | """Utility functions for interacting with PostgreSQL."""
|
3 | 3 |
|
4 | 4 | import collections
|
| 5 | +import functools |
5 | 6 | import logging
|
6 | 7 | import os
|
7 | 8 | import re
|
|
43 | 44 |
|
44 | 45 | from .exceptions import MigrationError, SleepyDeveloperError
|
45 | 46 | from .helpers import _validate_table, model_of_table
|
46 |
| -from .misc import Sentinel, log_progress |
| 47 | +from .misc import Sentinel, log_progress, version_gte |
47 | 48 |
|
48 | 49 | _logger = logging.getLogger(__name__)
|
49 | 50 |
|
@@ -472,6 +473,29 @@ def _column_info(cr, table, column):
|
472 | 473 | return cr.fetchone()
|
473 | 474 |
|
474 | 475 |
|
| 476 | +_COLUMNS = {} |
| 477 | +if version_gte("10.0"): # before 10.0 it could be arch or arch_db, because it changed in 9.0 |
| 478 | + _COLUMNS[("ir_ui_view", "arch_db")] = True |
| 479 | +if not version_gte("8.0"): # before 8.0 we know it was arch |
| 480 | + _COLUMNS[("ir_ui_view", "arch_db")] = False |
| 481 | +if version_gte("14.0"): # new from 13.0 |
| 482 | + _COLUMNS[("ir_module_module_dependency", "auto_install_required")] = False |
| 483 | + |
| 484 | + |
| 485 | +def _forced_cache(cache): |
| 486 | + def decorator(f): |
| 487 | + @functools.wraps(f) |
| 488 | + def wrapper(cr, *args, **kwargs): |
| 489 | + if not kwargs and tuple(args) in cache: |
| 490 | + return cache[tuple(args)] |
| 491 | + return f(cr, *args, **kwargs) |
| 492 | + |
| 493 | + return wrapper |
| 494 | + |
| 495 | + return decorator |
| 496 | + |
| 497 | + |
| 498 | +@_forced_cache(_COLUMNS) |
475 | 499 | def column_exists(cr, table, column):
|
476 | 500 | """
|
477 | 501 | Return whether a column exists.
|
|
0 commit comments