{"action":"created","issue":{"url":"https://api.github.com/repos/almighty/almighty-core/issues/278","repository_url":"https://api.github.com/repos/almighty/almighty-core","labels_url":"https://api.github.com/repos/almighty/almighty-core/issues/278/labels{/name}","comments_url":"https://api.github.com/repos/almighty/almighty-core/issues/278/comments","events_url":"https://api.github.com/repos/almighty/almighty-core/issues/278/events","html_url":"https://github.com/almighty/almighty-core/pull/278","id":179453825,"number":278,"title":"Support migration of the database schema and data","user":{"login":"kwk","id":193408,"avatar_url":"https://avatars.githubusercontent.com/u/193408?v=3","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/almighty/almighty-core/labels/database","name":"database","color":"f9d0c4"},{"url":"https://api.github.com/repos/almighty/almighty-core/labels/deploy","name":"deploy","color":"e99695"}],"state":"open","locked":false,"assignee":{"login":"kwk","id":193408,"avatar_url":"https://avatars.githubusercontent.com/u/193408?v=3","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false},"assignees":[{"login":"kwk","id":193408,"avatar_url":"https://avatars.githubusercontent.com/u/193408?v=3","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2016-09-27T10:22:48Z","updated_at":"2016-10-05T13:12:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/almighty/almighty-core/pulls/278","html_url":"https://github.com/almighty/almighty-core/pull/278","diff_url":"https://github.com/almighty/almighty-core/pull/278.diff","patch_url":"https://github.com/almighty/almighty-core/pull/278.patch"},"body":"Fixes #184 \r\n\r\nTo be able to have all `migration/sql-files/*.sql` files bundled in the alm core binary, I've used go-bindata to pack them intothe `migration/sqlbindata.go` file. The prefix `migration/sql-files` is removed from the filepaths inside of `migration/sqlbinata.go`.\r\n\r\nThe purpose of the `migration/sql-files` is to store all files that are relevant for updating the database over time.\r\n\r\nThe SQL files themselves are packaged into the alm core binary with [go-bindata](https://github.com/jteeuwen/go-bindata).\r\n\r\nThe filenames of the SQL files have no meaning but we prefix them with the version they stand for so it is easier to find out what's happening. The `migration.go` file has the control over the updates and the SQL files are *not* blindly executed just because they exist. Instead we allow the developers to run Go code as well.\r\n\r\n## Version 0\r\n\r\nThe first sql file (`./migration/sql-files/000-bootstrap.sql`) creates the basic layout of the versioning table.\r\n\r\n### Database table layout\r\n\r\nThis is how the `version` table looks like in Postgres:\r\n\r\n```\r\npostgres=# select * from version;\r\n id |          updated_at           | version \r\n----+-------------------------------+---------\r\n  1 | 2016-09-27 10:13:30.423206+00 |       0\r\n(1 row)\r\n```\r\n\r\nThe auto migration portion in migration/migration.go has been removed.\r\n\r\nLogic to get the current version and to execute all remaining version is implemented.\r\n\r\n## Migrate at startup of core\r\n\r\nThis is how the migration looks like when the core starts up\r\n```\r\n$./bin/alm\r\n2016/09/27 12:13:30 Running as user name \"kkleine\" with UID 1000.\r\n2016/09/27 12:13:30 Opening DB connection attempt 1 of 50\r\n2016/09/27 12:13:30 Attempt to update DB to version 0\r\n\r\n(/home/kkleine/go/src/github.com/almighty/almighty-core/migration/migration.go:44) \r\n[2016-09-27 12:13:30]  [13.01ms]  -- This table sets the foundation for all future database migrations.\r\ncreate table \"version\" (\r\n  \"id\" serial primary key,\r\n  \"updated_at\" timestamp with time zone not null default current_timestamp,\r\n  \"version\" int unique not null\r\n);\r\n\r\n(/home/kkleine/go/src/github.com/almighty/almighty-core/migration/migration.go:114) \r\n[2016-09-27 12:13:30]  [1.54ms]  insert into version (version) values('0')\r\n2016/09/27 12:13:30 Successfully updated DB to version 0\r\n```"},"comment":{"url":"https://api.github.com/repos/almighty/almighty-core/issues/comments/251670127","html_url":"https://github.com/almighty/almighty-core/pull/278#issuecomment-251670127","issue_url":"https://api.github.com/repos/almighty/almighty-core/issues/278","id":251670127,"user":{"login":"kwk","id":193408,"avatar_url":"https://avatars.githubusercontent.com/u/193408?v=3","gravatar_id":"","url":"https://api.github.com/users/kwk","html_url":"https://github.com/kwk","followers_url":"https://api.github.com/users/kwk/followers","following_url":"https://api.github.com/users/kwk/following{/other_user}","gists_url":"https://api.github.com/users/kwk/gists{/gist_id}","starred_url":"https://api.github.com/users/kwk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwk/subscriptions","organizations_url":"https://api.github.com/users/kwk/orgs","repos_url":"https://api.github.com/users/kwk/repos","events_url":"https://api.github.com/users/kwk/events{/privacy}","received_events_url":"https://api.github.com/users/kwk/received_events","type":"User","site_admin":false},"created_at":"2016-10-05T13:12:13Z","updated_at":"2016-10-05T13:12:13Z","body":"@aslakknutsen @tsmaeder can you please check 05bc21e for my approach to serialization? Thank you in advance."}}
{"actor":{"display_login":"kwk"}}