simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.18k stars 223 forks source link

custom schema name is not honored #48

Closed aol-nnov closed 10 years ago

aol-nnov commented 10 years ago

Hi!

I was trying to use express-admin with postgresql database. My tables are placed in a schema with custom name. After creating initial configuration I saw all my tables from custom schema at http://localhost:3000/ but if I click on any table name or on the plus sign, it spits a small stack trace

error: relation "vendor" does not exist
    at Connection.parseE (/home/aol/develop/web/express-admin/node_modules/express-admin/node_modules/pg/lib/connection.js:558:11)
    at Connection.parseMessage (/home/aol/develop/web/express-admin/node_modules/express-admin/node_modules/pg/lib/connection.js:387:17)
    at null.<anonymous> (/home/aol/develop/web/express-admin/node_modules/express-admin/node_modules/pg/lib/connection.js:92:20)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)
GET /vendor/add 500 5ms - 820b

After some digging I've managed to enable sql queries logging and found out that schema name is not present in the query: SELECT "vendor"."id" AS __pk,"vendor"."name","vendor"."id" FROM "vendor" WHERE "id"=null ;

As a quick test I've hacked into utils/query.js and hardcoded schema name into queries, which proved the root cause of the issue - the aforementioned error disappeared.

Unfortunately, I do not have much free time now to wrap my head around the express-admin sources to contribute a fix, but I'd be glad if this issue would be resolved soon.

Thanks in advance, Andrey

simov commented 10 years ago

Thank you for the feedback @aol-nnov it will be resolved very soon :beer:

simov commented 10 years ago

Fixed in version 1.2.2

aol-nnov commented 10 years ago

@simov thanks for a quick fix! Any plans to support multiple schemas simultaneously? I have my tables organized across several schemas in postgres.

simov commented 10 years ago

In this case the schema must be defined per table in settings.json. I'll add your request to my list, and I'll give it a thought. I can't tell you exactly when this will be implemented though.

aol-nnov commented 10 years ago

okay, thanks!

simov commented 10 years ago

@aol-nnov just pushed to master (still not in npm)

You can specify schema name for table config like this

"table": {"schema": "name", ...}

In case you want to override the schema name in some of your relation definitions.

"oneToMany": {"schema": "name", ...}
"manyToMany": {"link": {"schema": "name", ...}}
"manyToMany": {"ref": {"schema": "name", ...}}

Keep in mind that specifying schema key for the whole table does not affect the relationship declarations. In other words you need to specify your desired schema name for each of your relationship declarations.