{"action":"closed","number":256,"pull_request":{"url":"https://api.github.com/repos/lotus/lotus/pulls/256","id":37628063,"html_url":"https://github.com/lotus/lotus/pull/256","diff_url":"https://github.com/lotus/lotus/pull/256.diff","patch_url":"https://github.com/lotus/lotus/pull/256.patch","issue_url":"https://api.github.com/repos/lotus/lotus/issues/256","number":256,"state":"closed","locked":false,"title":"Database migrations","user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"body":"Introduce new CLI facilities for database migrations.\r\n\r\n## New Applications\r\n\r\nWhen a new application is generates via `lotus new`, if the specified `--database=` option is a SQL database (postgres, sqlite, mysql), it:\r\n\r\n  * Creates empty `db/migrations` directory\r\n  * Creates empty `db/schema.sql` file\r\n  * Adds `migrations \"db/migrations\"` setting to `lib/bookshelf.rb`\r\n  * Adds `schema \"db/schema.sql\"` setting to `lib/bookshelf.rb`\r\n\r\nExample:\r\n\r\n```shell\r\nlotus new bookshelf --database=postgres\r\n```\r\n\r\n```ruby\r\n# lib/bookshelf.rb\r\n# ...\r\nLotus::Model.configure do\r\n  # ...\r\n  migrations 'db/migrations'\r\n  schema    'db/schema.sql'\r\nend\r\n```\r\n\r\n## Migration Generator\r\n\r\nNew generator for timestamp migration:\r\n\r\n```shell\r\nbundle exec lotus generate migration create_books\r\n      create  db/migrations/20150613165259_create_books.rb\r\n```\r\n\r\n### CLI commands\r\n\r\n#### Create\r\n\r\nCreates database for the current environment. For data integrity reasons it's not allowed in production.\r\n\r\n```shell\r\nbundle exec lotus db create\r\n```\r\n\r\n#### Drop\r\n\r\nDrops database for the current environment. For data integrity reasons it's not allowed in production.\r\n\r\n```shell\r\nbundle exec lotus db drop\r\n```\r\n\r\n#### Migrate\r\n\r\nMigrate database.\r\nIt accepts an optional argument for a target version\r\n\r\n```shell\r\n% tree db/migrations\r\ndb/migrations\r\n├── 20150613165259_create_books.rb\r\n└── 20150613165900_create_authors.rb\r\n\r\n% bundle exec lotus db migrate # Migrates to max migration (20150613165900)\r\n% bundle exec lotus db migrate 20150613165259 # Migrates (down) to 20150613165900\r\n```\r\n\r\n#### Apply\r\n\r\nThis is an **experimental feature**.\r\nWhen an application is developed after years, it accumulates dozens or hundreds of migrations, this slows down  database operations for development and tests (CI).\r\n\r\nBecause it does destructive changes for files under SCM, this is only allowed in development mode.\r\n\r\nWhen we run `db apply` it:\r\n\r\n  * Runs pending migrations\r\n  * Dumps a fresh schema into `db/schema.sql`\r\n  * Deletes all the migrations from `db/migrations`\r\n\r\n```shell\r\nbundle exec lotus db apply\r\n``` \r\n\r\nSee next section.\r\n\r\n#### Prepare\r\n\r\nPrepares database for the current environment. It's only allowed in development and test mode.\r\n\r\nWhen we run `db prepare` it:\r\n\r\n  * Creates database\r\n  * Load SQL dump (if any, see `db apply`)\r\n  * Run pending migrations\r\n\r\n#### Version\r\n\r\nPrints current database version.\r\n\r\n```shell\r\n% tree db/migrations\r\ndb/migrations\r\n├── 20150613165259_create_books.rb\r\n└── 20150613165900_create_authors.rb\r\n\r\n% bundle exec lotus db migrate # Migrates to max migration (20150613165900)\r\n% bundle exec lotus db version\r\n20150613165900\r\n```\r\n\r\n---\r\n\r\nRef https://github.com/lotus/model/pull/196\r\n\r\nCloses #136 \r\nCloses #137 \r\nCloses #138 ","created_at":"2015-06-13T17:11:55Z","updated_at":"2015-06-17T12:24:52Z","closed_at":"2015-06-17T12:24:52Z","merged_at":"2015-06-17T12:24:52Z","merge_commit_sha":"9f376c1f1d5db53d7a4befc3cfbd8751eec52941","assignee":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/lotus/lotus/milestones/6","html_url":"https://github.com/lotus/lotus/milestones/v0.4.0","labels_url":"https://api.github.com/repos/lotus/lotus/milestones/6/labels","id":1136551,"number":6,"title":"v0.4.0","description":"","creator":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":14,"state":"open","created_at":"2015-05-27T18:02:47Z","updated_at":"2015-06-17T12:24:52Z","due_on":"2015-06-22T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/lotus/lotus/pulls/256/commits","review_comments_url":"https://api.github.com/repos/lotus/lotus/pulls/256/comments","review_comment_url":"https://api.github.com/repos/lotus/lotus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lotus/lotus/issues/256/comments","statuses_url":"https://api.github.com/repos/lotus/lotus/statuses/6a54e9040489e67e3aa3116ae86595f86e5c2be9","head":{"label":"lotus:database-migrations","ref":"database-migrations","sha":"6a54e9040489e67e3aa3116ae86595f86e5c2be9","user":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"repo":{"id":12004006,"name":"lotus","full_name":"lotus/lotus","owner":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lotus/lotus","description":"A complete web framework for Ruby","fork":false,"url":"https://api.github.com/repos/lotus/lotus","forks_url":"https://api.github.com/repos/lotus/lotus/forks","keys_url":"https://api.github.com/repos/lotus/lotus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lotus/lotus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lotus/lotus/teams","hooks_url":"https://api.github.com/repos/lotus/lotus/hooks","issue_events_url":"https://api.github.com/repos/lotus/lotus/issues/events{/number}","events_url":"https://api.github.com/repos/lotus/lotus/events","assignees_url":"https://api.github.com/repos/lotus/lotus/assignees{/user}","branches_url":"https://api.github.com/repos/lotus/lotus/branches{/branch}","tags_url":"https://api.github.com/repos/lotus/lotus/tags","blobs_url":"https://api.github.com/repos/lotus/lotus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lotus/lotus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lotus/lotus/git/refs{/sha}","trees_url":"https://api.github.com/repos/lotus/lotus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lotus/lotus/statuses/{sha}","languages_url":"https://api.github.com/repos/lotus/lotus/languages","stargazers_url":"https://api.github.com/repos/lotus/lotus/stargazers","contributors_url":"https://api.github.com/repos/lotus/lotus/contributors","subscribers_url":"https://api.github.com/repos/lotus/lotus/subscribers","subscription_url":"https://api.github.com/repos/lotus/lotus/subscription","commits_url":"https://api.github.com/repos/lotus/lotus/commits{/sha}","git_commits_url":"https://api.github.com/repos/lotus/lotus/git/commits{/sha}","comments_url":"https://api.github.com/repos/lotus/lotus/comments{/number}","issue_comment_url":"https://api.github.com/repos/lotus/lotus/issues/comments{/number}","contents_url":"https://api.github.com/repos/lotus/lotus/contents/{+path}","compare_url":"https://api.github.com/repos/lotus/lotus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lotus/lotus/merges","archive_url":"https://api.github.com/repos/lotus/lotus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lotus/lotus/downloads","issues_url":"https://api.github.com/repos/lotus/lotus/issues{/number}","pulls_url":"https://api.github.com/repos/lotus/lotus/pulls{/number}","milestones_url":"https://api.github.com/repos/lotus/lotus/milestones{/number}","notifications_url":"https://api.github.com/repos/lotus/lotus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lotus/lotus/labels{/name}","releases_url":"https://api.github.com/repos/lotus/lotus/releases{/id}","created_at":"2013-08-09T15:24:44Z","updated_at":"2015-06-17T09:14:17Z","pushed_at":"2015-06-17T12:24:52Z","git_url":"git://github.com/lotus/lotus.git","ssh_url":"git@github.com:lotus/lotus.git","clone_url":"https://github.com/lotus/lotus.git","svn_url":"https://github.com/lotus/lotus","homepage":"http://lotusrb.org","size":2644,"stargazers_count":1863,"watchers_count":1863,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":22,"forks":172,"open_issues":22,"watchers":1863,"default_branch":"master"}},"base":{"label":"lotus:master","ref":"master","sha":"bb8d4e14e46c4ce5dbf87959b67822495bd9a43b","user":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"repo":{"id":12004006,"name":"lotus","full_name":"lotus/lotus","owner":{"login":"lotus","id":3210273,"avatar_url":"https://avatars.githubusercontent.com/u/3210273?v=3","gravatar_id":"","url":"https://api.github.com/users/lotus","html_url":"https://github.com/lotus","followers_url":"https://api.github.com/users/lotus/followers","following_url":"https://api.github.com/users/lotus/following{/other_user}","gists_url":"https://api.github.com/users/lotus/gists{/gist_id}","starred_url":"https://api.github.com/users/lotus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotus/subscriptions","organizations_url":"https://api.github.com/users/lotus/orgs","repos_url":"https://api.github.com/users/lotus/repos","events_url":"https://api.github.com/users/lotus/events{/privacy}","received_events_url":"https://api.github.com/users/lotus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lotus/lotus","description":"A complete web framework for Ruby","fork":false,"url":"https://api.github.com/repos/lotus/lotus","forks_url":"https://api.github.com/repos/lotus/lotus/forks","keys_url":"https://api.github.com/repos/lotus/lotus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lotus/lotus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lotus/lotus/teams","hooks_url":"https://api.github.com/repos/lotus/lotus/hooks","issue_events_url":"https://api.github.com/repos/lotus/lotus/issues/events{/number}","events_url":"https://api.github.com/repos/lotus/lotus/events","assignees_url":"https://api.github.com/repos/lotus/lotus/assignees{/user}","branches_url":"https://api.github.com/repos/lotus/lotus/branches{/branch}","tags_url":"https://api.github.com/repos/lotus/lotus/tags","blobs_url":"https://api.github.com/repos/lotus/lotus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lotus/lotus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lotus/lotus/git/refs{/sha}","trees_url":"https://api.github.com/repos/lotus/lotus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lotus/lotus/statuses/{sha}","languages_url":"https://api.github.com/repos/lotus/lotus/languages","stargazers_url":"https://api.github.com/repos/lotus/lotus/stargazers","contributors_url":"https://api.github.com/repos/lotus/lotus/contributors","subscribers_url":"https://api.github.com/repos/lotus/lotus/subscribers","subscription_url":"https://api.github.com/repos/lotus/lotus/subscription","commits_url":"https://api.github.com/repos/lotus/lotus/commits{/sha}","git_commits_url":"https://api.github.com/repos/lotus/lotus/git/commits{/sha}","comments_url":"https://api.github.com/repos/lotus/lotus/comments{/number}","issue_comment_url":"https://api.github.com/repos/lotus/lotus/issues/comments{/number}","contents_url":"https://api.github.com/repos/lotus/lotus/contents/{+path}","compare_url":"https://api.github.com/repos/lotus/lotus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lotus/lotus/merges","archive_url":"https://api.github.com/repos/lotus/lotus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lotus/lotus/downloads","issues_url":"https://api.github.com/repos/lotus/lotus/issues{/number}","pulls_url":"https://api.github.com/repos/lotus/lotus/pulls{/number}","milestones_url":"https://api.github.com/repos/lotus/lotus/milestones{/number}","notifications_url":"https://api.github.com/repos/lotus/lotus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lotus/lotus/labels{/name}","releases_url":"https://api.github.com/repos/lotus/lotus/releases{/id}","created_at":"2013-08-09T15:24:44Z","updated_at":"2015-06-17T09:14:17Z","pushed_at":"2015-06-17T12:24:52Z","git_url":"git://github.com/lotus/lotus.git","ssh_url":"git@github.com:lotus/lotus.git","clone_url":"https://github.com/lotus/lotus.git","svn_url":"https://github.com/lotus/lotus","homepage":"http://lotusrb.org","size":2644,"stargazers_count":1863,"watchers_count":1863,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":22,"forks":172,"open_issues":22,"watchers":1863,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lotus/lotus/pulls/256"},"html":{"href":"https://github.com/lotus/lotus/pull/256"},"issue":{"href":"https://api.github.com/repos/lotus/lotus/issues/256"},"comments":{"href":"https://api.github.com/repos/lotus/lotus/issues/256/comments"},"review_comments":{"href":"https://api.github.com/repos/lotus/lotus/pulls/256/comments"},"review_comment":{"href":"https://api.github.com/repos/lotus/lotus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lotus/lotus/pulls/256/commits"},"statuses":{"href":"https://api.github.com/repos/lotus/lotus/statuses/6a54e9040489e67e3aa3116ae86595f86e5c2be9"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"comments":0,"review_comments":2,"commits":5,"additions":758,"deletions":14,"changed_files":23}}