{"action":"created","issue":{"url":"https://api.github.com/repos/calebmer/postgraphql/issues/191","repository_url":"https://api.github.com/repos/calebmer/postgraphql","labels_url":"https://api.github.com/repos/calebmer/postgraphql/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/calebmer/postgraphql/issues/191/comments","events_url":"https://api.github.com/repos/calebmer/postgraphql/issues/191/events","html_url":"https://github.com/calebmer/postgraphql/issues/191","id":185603573,"number":191,"title":"How to use postgraphql with multiple shemas with same table names","user":{"login":"langpavel","id":142462,"avatar_url":"https://avatars.githubusercontent.com/u/142462?v=3","gravatar_id":"","url":"https://api.github.com/users/langpavel","html_url":"https://github.com/langpavel","followers_url":"https://api.github.com/users/langpavel/followers","following_url":"https://api.github.com/users/langpavel/following{/other_user}","gists_url":"https://api.github.com/users/langpavel/gists{/gist_id}","starred_url":"https://api.github.com/users/langpavel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/langpavel/subscriptions","organizations_url":"https://api.github.com/users/langpavel/orgs","repos_url":"https://api.github.com/users/langpavel/repos","events_url":"https://api.github.com/users/langpavel/events{/privacy}","received_events_url":"https://api.github.com/users/langpavel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-27T08:25:00Z","updated_at":"2016-10-27T12:15:15Z","closed_at":null,"body":"## Example:\r\n\r\n```sql\r\nCREATE SCHEMA s1;\r\nCREATE SCHEMA s2;\r\nCREATE TABLE s1.test_case(ID serial, value text);\r\nCREATE TABLE s2.test_case(ID serial, value text);\r\n```\r\n\r\nAnd then start the server on the schemas s1,s2:\r\n`postgraphql --connection pg://langpavel:xxx@localhost:5434/namecollision --schema s1,s2`\r\n\r\n```\r\nError: Collection of name 'test_cases' already exists in the inventory.\r\n    at Inventory.addCollection (/home/langpavel/.nvm/versions/node/v6.9.1/lib/node_modules/postgraphql/build/interface/Inventory.js:28:19)\r\n    at Object.addPgCatalogToInventory (/home/langpavel/.nvm/versions/node/v6.9.1/lib/node_modules/postgraphql/build/postgres/inventory/addPgCatalogToInventory.js:24:23)\r\n    at Object.<anonymous> (/home/langpavel/.nvm/versions/node/v6.9.1/lib/node_modules/postgraphql/build/postgraphql/schema/createPostGraphQLSchema.js:53:20)\r\n    at next (native)\r\n    at fulfilled (/home/langpavel/.nvm/versions/node/v6.9.1/lib/node_modules/postgraphql/build/postgraphql/schema/createPostGraphQLSchema.js:4:58)\r\n    at process._tickCallback (internal/process/next_tick.js:103:7)\r\n```\r\n\r\n## In `psql`, behavior is driven by `search_path`.\r\n\r\nFor example:\r\n```sql\r\nINSERT INTO s1.test_case (value) VALUES ('Schema s1');\r\nINSERT INTO s2.test_case (value) VALUES ('Schema s2');\r\n\r\nSELECT * FROM s1.test_case; -- Schema s1\r\nSELECT * FROM s2.test_case; -- Schema s2\r\n\r\n-- SELECT * FROM test_case;\r\n-- ERROR:  42P01: relation \"test_case\" does not exist\r\n\r\nSET search_path=s1, s2;\r\nSELECT * FROM test_case; -- Schema s1\r\n\r\nSET search_path=s2, s1;\r\nSELECT * FROM test_case; -- Schema s2\r\n```\r\n\r\n## Suggested implementation\r\n\r\nWill be more convenient if `postgraphql --schema` argument behaves like `search_path`.\r\n\r\nThere should be more options, I like only the first one:\r\n - `--hide-schema-collisions` - accept only first name on search_path \r\n - `--alias-schema-collisions` - excepth first name, other object will be prefixed with schema.\r\n\r\n   For example:\r\n    - `s1.test_case` becomes `test_case` because `s1` is first in `--schema` argument, but\r\n    - `s2.test_case` becomes `_s2__test_case`.\r\n\r\nDefault behavior can be like first, except it can write handy warnings into console.\r\n\r\nAs I said I don't like second option... If access to different schema is needed it can be done through view."},"comment":{"url":"https://api.github.com/repos/calebmer/postgraphql/issues/comments/256624457","html_url":"https://github.com/calebmer/postgraphql/issues/191#issuecomment-256624457","issue_url":"https://api.github.com/repos/calebmer/postgraphql/issues/191","id":256624457,"user":{"login":"calebmer","id":8282507,"avatar_url":"https://avatars.githubusercontent.com/u/8282507?v=3","gravatar_id":"","url":"https://api.github.com/users/calebmer","html_url":"https://github.com/calebmer","followers_url":"https://api.github.com/users/calebmer/followers","following_url":"https://api.github.com/users/calebmer/following{/other_user}","gists_url":"https://api.github.com/users/calebmer/gists{/gist_id}","starred_url":"https://api.github.com/users/calebmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calebmer/subscriptions","organizations_url":"https://api.github.com/users/calebmer/orgs","repos_url":"https://api.github.com/users/calebmer/repos","events_url":"https://api.github.com/users/calebmer/events{/privacy}","received_events_url":"https://api.github.com/users/calebmer/received_events","type":"User","site_admin":false},"created_at":"2016-10-27T12:15:15Z","updated_at":"2016-10-27T12:15:15Z","body":"Yep. I like the idea of hiding collisions by default with a warning and then providing an option like `--alias-schema-collisions`. That was one of my initial ideas.\r\n\r\nI’m also going to cc @mytototo from https://github.com/calebmer/postgraphql/issues/181. This may also be used for the `node` collision."}}
{"actor":{"display_login":"calebmer"}}