X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fpgsqlschema.php;h=d50e35f660f65587c89809be2f85198d0c80b04f;hb=b53e1439969bfa2c0b551d8cc2fc8fe15652c62a;hp=aa7f6733b09ad6fa66dddb64b5a770dd27d5565f;hpb=b865ded7ffca54534dac858f20eada3882af9d04;p=quix0rs-gnu-social.git diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index aa7f6733b0..d50e35f660 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -334,6 +334,20 @@ class PgsqlSchema extends Schema } } + /** + * Append an SQL statement to drop an index from a table. + * Note that in PostgreSQL, index names are DB-unique. + * + * @param array $statements + * @param string $table + * @param string $name + * @param array $def + */ + function appendDropIndex(array &$statements, $table, $name) + { + $statements[] = "DROP INDEX $name"; + } + /** * Quote a db/table/column identifier if necessary. * @@ -409,7 +423,33 @@ class PgsqlSchema extends Schema $col['type'] = $this->mapType($col); unset($col['size']); } + if (!empty($tableDef['primary key'])) { + $tableDef['primary key'] = $this->filterKeyDef($tableDef['primary key']); + } + if (!empty($tableDef['unique keys'])) { + foreach ($tableDef['unique keys'] as $i => $def) { + $tableDef['unique keys'][$i] = $this->filterKeyDef($def); + } + } return $tableDef; } + /** + * Filter the given key/index definition to match features available + * in this database. + * + * @param array $def + * @return array + */ + function filterKeyDef(array $def) + { + // PostgreSQL doesn't like prefix lengths specified on keys...? + foreach ($def as $i => $item) + { + if (is_array($item)) { + $def[$i] = $item[0]; + } + } + return $def; + } }