{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/1005","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1005/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1005/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1005/events","html_url":"https://github.com/elixir-lang/ecto/issues/1005","id":110706313,"number":1005,"title":"Support prefixes in migration runner","user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2015-10-09T17:47:31Z","updated_at":"2015-10-15T05:43:34Z","closed_at":null,"body":"See #978."},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/148287233","html_url":"https://github.com/elixir-lang/ecto/issues/1005#issuecomment-148287233","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1005","id":148287233,"user":{"login":"Tica2","id":817517,"avatar_url":"https://avatars.githubusercontent.com/u/817517?v=3","gravatar_id":"","url":"https://api.github.com/users/Tica2","html_url":"https://github.com/Tica2","followers_url":"https://api.github.com/users/Tica2/followers","following_url":"https://api.github.com/users/Tica2/following{/other_user}","gists_url":"https://api.github.com/users/Tica2/gists{/gist_id}","starred_url":"https://api.github.com/users/Tica2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tica2/subscriptions","organizations_url":"https://api.github.com/users/Tica2/orgs","repos_url":"https://api.github.com/users/Tica2/repos","events_url":"https://api.github.com/users/Tica2/events{/privacy}","received_events_url":"https://api.github.com/users/Tica2/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T05:43:34Z","updated_at":"2015-10-15T05:43:34Z","body":"> @Tica2 what is the issue with the references? If I do \"create table PREFIX.FOO ... references BAR\" in postgres, shouldn't bar automatically belong to that prefix?\r\n\r\nFor Postgresql is working in schema.\r\nFor MySql is working perfect see example [1].\r\nIf is removed then we make logic restriction that make sens. \r\n\r\nI think the best is to have also prefix for Reference. \r\nFirst version from @Dania02525. Is up to @josevalim to decide. \r\n**AND Adapter** to decide what to do. If is not supported Adapter can show warning message and ignore. Is exact what do databases until implemented. (See sqlite) \r\n\r\nIn one DB instance I can have:\r\n\r\nshare.<public tables here> like countries, cities\r\nshare.countries\r\nshare.cities\r\n\r\n```sql\r\ntenant_001.company  field county_id **reference** share.countries \r\n```\r\n\r\n```sql\r\ntenant_091.company  field county_id **reference** share.countries \r\n```\r\n\r\nWith @Dania02525 version I can do that:\r\n\r\nShareRepo (all objects has share prefix)\r\nTenantRepo (all objects do not have prefix, will be provided by --prefix on migration)\r\n\r\nmix ecto.migrate --prefix tenant_001\r\nmix ecto.migrate --prefix tenant_091\r\n  \r\n\r\nTable, Index are stored objects, \r\nReference is like Logical object and belongs to table.\r\n \r\n### MySql example, cross reference is woring   \r\n\r\n```sql\r\nmysql> show databases;\r\n+--------------------+\r\n| Database           |\r\n+--------------------+\r\n| information_schema |\r\n| a_db               |\r\n| b_db               |\r\n| ecto_test          |\r\n| mysql              |\r\n| performance_schema |\r\n| tenant_001         |\r\n| test               |\r\n+--------------------+\r\n8 rows in set (0.00 sec)\r\n\r\nmysql> create table a_db.parent (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;\r\nQuery OK, 0 rows affected (0.01 sec)\r\n\r\nmysql> CREATE TABLE b_db.child (id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id)  REFERENCES a_db.parent (id)) ENGINE=INNODB;\r\nQuery OK, 0 rows affected (0.01 sec)\r\n\r\nmysql> insert into a_db.parent values (1);\r\nQuery OK, 1 row affected (0.00 sec)\r\n\r\nmysql> insert into a_db.parent values (1);\r\nERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'\r\nmysql> insert into a_db.parent values (2);\r\nQuery OK, 1 row affected (0.00 sec)\r\n\r\nmysql> select * from a_db.parent;\r\n+----+\r\n| id |\r\n+----+\r\n|  1 |\r\n|  2 |\r\n+----+\r\n2 rows in set (0.00 sec)\r\n\r\nmysql> insert into b_db.child values (1, 1);\r\nQuery OK, 1 row affected (0.00 sec)\r\n\r\nmysql> insert into b_db.child values (1, 10);\r\nERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`b_db`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `a_db`.`parent` (`id`))\r\nmysql>\r\n\r\npetrica@mac ~ >\r\n\r\n```"}}