{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1303","repository_url":"https://api.github.com/repos/tgriesser/knex","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1303/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1303/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1303/events","html_url":"https://github.com/tgriesser/knex/issues/1303","id":142524003,"number":1303,"title":"createTableIfNotExists generates alter table output which fails","user":{"login":"artyomtrityak","id":957406,"avatar_url":"https://avatars0.githubusercontent.com/u/957406?v=4","gravatar_id":"","url":"https://api.github.com/users/artyomtrityak","html_url":"https://github.com/artyomtrityak","followers_url":"https://api.github.com/users/artyomtrityak/followers","following_url":"https://api.github.com/users/artyomtrityak/following{/other_user}","gists_url":"https://api.github.com/users/artyomtrityak/gists{/gist_id}","starred_url":"https://api.github.com/users/artyomtrityak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artyomtrityak/subscriptions","organizations_url":"https://api.github.com/users/artyomtrityak/orgs","repos_url":"https://api.github.com/users/artyomtrityak/repos","events_url":"https://api.github.com/users/artyomtrityak/events{/privacy}","received_events_url":"https://api.github.com/users/artyomtrityak/received_events","type":"User","site_admin":false},"labels":[{"id":178778037,"url":"https://api.github.com/repos/tgriesser/knex/labels/discussion","name":"discussion","color":"bfd4f2","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-03-22T02:11:30Z","updated_at":"2018-02-13T21:02:51Z","closed_at":"2018-02-08T19:53:42Z","author_association":"NONE","body":"I'm using knex 0.10.0, Postgres.\n\ncreateTableIfNotExists does not create table but adding primary index fails (because it already exist).\n\nHow to avoid alter table request if table already exist?\n\n``` js\n  db.schema.createTableIfNotExists('users', function(t) {\n    t.uuid('id').notNullable().primary();\n    t.string('__type', 16).defaultTo('User');\n    t.string('email', 100);\n    t.string('pass_salt', 32);\n    t.string('password_salted', 32);\n    t.boolean('verified').defaultTo(false);\n    t.json('details');\n  })\n  .then(() => {});\n```\n\nGenerates\n\n``` bash\n[ { sql: 'create table if not exists \"users\" (\"id\" uuid not null, \"__type\" varchar(16) default \\'User\\', \"email\" varchar(100), \"pass_salt\" varchar(32), \"password_salted\" varchar(32), \"verified\" boolean default \\'0\\', \"details\" json)',\n    bindings: [] },\n  { sql: 'alter table \"users\" add primary key (\"id\")',\n    bindings: [] } ]\nUnhandled rejection error: alter table \"users\" add primary key (\"id\") - multiple primary keys for table \"users\" are not allowed\n    at Connection.parseE (/usr/src/letsplay/node_modules/pg/lib/connection.js:539:11)\n    at Connection.parseMessage (/usr/src/letsplay/node_modules/pg/lib/connection.js:366:17)\n    at Socket.<anonymous> (/usr/src/letsplay/node_modules/pg/lib/connection.js:105:22)\n    at emitOne (events.js:90:13)\n    at Socket.emit (events.js:182:7)\n    at readableAddChunk (_stream_readable.js:153:18)\n    at Socket.Readable.push (_stream_readable.js:111:10)\n    at TCP.onread (net.js:529:20)\n```\n"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/365403123","html_url":"https://github.com/tgriesser/knex/issues/1303#issuecomment-365403123","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1303","id":365403123,"user":{"login":"elhigu","id":696345,"avatar_url":"https://avatars3.githubusercontent.com/u/696345?v=4","gravatar_id":"","url":"https://api.github.com/users/elhigu","html_url":"https://github.com/elhigu","followers_url":"https://api.github.com/users/elhigu/followers","following_url":"https://api.github.com/users/elhigu/following{/other_user}","gists_url":"https://api.github.com/users/elhigu/gists{/gist_id}","starred_url":"https://api.github.com/users/elhigu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elhigu/subscriptions","organizations_url":"https://api.github.com/users/elhigu/orgs","repos_url":"https://api.github.com/users/elhigu/repos","events_url":"https://api.github.com/users/elhigu/events{/privacy}","received_events_url":"https://api.github.com/users/elhigu/received_events","type":"User","site_admin":false},"created_at":"2018-02-13T21:02:51Z","updated_at":"2018-02-13T21:02:51Z","author_association":"COLLABORATOR","body":"@jcampuza I have no intention of removing it any time soon lets think about it again after couple of years (I hope I have had time to rewrite the whole schema api by then)."}}
{"actor":{"display_login":"elhigu"}}