]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/pgsqlschema.php
Filter table definitions to scrub out unsupported features before trying to alter...
[quix0rs-gnu-social.git] / lib / pgsqlschema.php
index a8ce21b3845346ba5c2b6c4dc30b064c79cbefe1..e8711a6f856ea536ebaa98c7d320a9a0113918b2 100644 (file)
@@ -406,4 +406,29 @@ class PgsqlSchema extends Schema
         }
     }
 
+    /**
+     * Filter the given table definition array to match features available
+     * in this database.
+     *
+     * This lets us strip out unsupported things like comments, foreign keys,
+     * or type variants that we wouldn't get back from getTableDef().
+     *
+     * @param array $tableDef
+     */
+    function filterDef(array $tableDef)
+    {
+        foreach (array_keys($tableDef['fields']) as $name => &$col) {
+            // No convenient support for field descriptions
+            unset($col['description']);
+
+            if (isset($col['size'])) {
+                // Don't distinguish between tinyint and int.
+                if ($col['size'] == 'tiny' && $col['type'] == 'int') {
+                    unset($col['size']);
+                }
+            }
+        }
+        return $tableDef;
+    }
+
 }