server/test/data-migractions/cubes/fakecustomtype/site_cubicweb.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 09 Dec 2015 17:44:18 +0100
changeset 11006 096adb786873
parent 11005 server/test/data-migractions/cubes/fakegis/site_cubicweb.py@f8417bd135ed
permissions -rw-r--r--
[migration/test] use numeric(precision, scale) instead of geometry The latter requires the postgis extension which is overkill for this test.

from yams import register_base_type
from logilab.database import get_db_helper
from logilab.database.sqlgen import SQLExpression

_NUMERIC_PARAMETERS = {'scale': 0, 'precision': None}
register_base_type('Numeric', _NUMERIC_PARAMETERS)

# Add the datatype to the helper mapping
pghelper = get_db_helper('postgres')


def pg_numeric_sqltype(rdef):
    """Return a PostgreSQL column type corresponding to rdef
    """
    return 'numeric(%s, %s)' % (rdef.precision, rdef.scale)

pghelper.TYPE_MAPPING['Numeric'] = pg_numeric_sqltype