knex / knex-schema-inspector

Utility for extracting information about existing DB schema
MIT License
99 stars 43 forks source link

Remove duplicate relational fields for CockroachDB #104

Closed licitdev closed 2 years ago

licitdev commented 2 years ago

Closes https://github.com/directus/directus/issues/11760.

kibertoad commented 2 years ago

Can you add test for this?

licitdev commented 2 years ago

@rijkvanzanten Do you recall the reason for this join? Removing this join is able to resolve the duplicates issue too.

https://github.com/knex/knex-schema-inspector/blob/6444b4c18949dcadfc160646705a2a6e855d1651/lib/dialects/cockroachdb.ts#L295-L298

However, either adding the distinct or removing the second join causes the returns information for all columns in all tables test to fail.

Kindly refer to the following sorted JSON results. I have sorted the array and their keys within for easy diffing.

Original test data expected (extracted from cockroachdb.spec.ts#L129-L530) https://pastebin.com/raw/ZqyPuR4r

Test result after adding distinct https://pastebin.com/raw/FaRhYc5Y

Test result after removing the 2nd join https://pastebin.com/raw/mEfWVYyN

rijkvanzanten commented 2 years ago

@licitdev I didn't write that original implementation unfortunately. @nickrum and I rebuild the implementation for Postgres recently, so we could also use that as the new starting point for CockroachDB. I recall there was an issue running the new postgres implementation as is (as a particular field didn't exist in CRDBs implementation), but the fix to support postgres 10 might actually resolve that as well