system_update_7016
- Versions
- 7
system_update_7016()
Remove custom datatype *_unsigned in PostgreSQL.
Related topics
Code
modules/system/system.install, line 2020
<?php
function system_update_7016() {
// Only run these queries if the driver used is pgsql.
if (db_driver() == 'pgsql') {
$result = db_query("SELECT c.relname AS table, a.attname AS field,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
FROM pg_catalog.pg_attribute a
LEFT JOIN pg_class c ON (c.oid = a.attrelid)
WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r'
AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'");
foreach ($result as $row) {
switch ($row->type) {
case 'smallint_unsigned':
$datatype = 'int';
break;
case 'int_unsigned':
case 'bigint_unsigned':
default:
$datatype = 'bigint';
break;
}
db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype);
db_query('ALTER TABLE ' . $row->table . ' ADD CHECK (' . $row->field . ' >= 0)');
}
db_query('DROP DOMAIN smallint_unsigned');
db_query('DROP DOMAIN int_unsigned');
db_query('DROP DOMAIN bigint_unsigned');
}
}
?>Login or register to post comments 