fortunejs / fortune-postgres

Postgres adapter for Fortune.
MIT License
23 stars 21 forks source link

Query to information_schema.columns selects columns from all schemas #32

Open rwest202 opened 5 years ago

rwest202 commented 5 years ago

https://github.com/fortunejs/fortune-postgres/blob/7d158ec79334584049fc2f8de404527eb24ae598/lib/index.js#L141-L142

Let's say I have a schema named schema-v1 and another named schema-v2 that both have a table called users. If schema-v1 has a column in users like users.email then the below if statement will wrongly think that the column exists in schema-v2. This is because information_schema.columns returns a list of columns in all schemas.

https://github.com/fortunejs/fortune-postgres/blob/7d158ec79334584049fc2f8de404527eb24ae598/lib/index.js#L188

Solution should be to specify the exact schema to search in.

gr0uch commented 5 years ago

Hmm I see, but does this cause any errors?

rwest202 commented 5 years ago

It doesn't add the columns to the new schema, since it thinks they already exist. I was able to resolve my issue by removing the schema-v1. But it wasn't immediately obvious what was causing the issue.

rwest202 commented 5 years ago

Looks like there is a table_schema key that you can check against, so something like

if (!tableColumns[type].some(row => row.column_name === field && row.table_schema === currentSchema)