{"action":"created","comment":{"url":"https://api.github.com/repos/amberframework/granite/pulls/comments/179960609","pull_request_review_id":110299524,"id":179960609,"diff_hunk":"@@ -451,6 +451,24 @@ You can register callbacks for the following events:\n - **destroy**\n - after_destroy\n \n+### Migration\n+\n+- `migrator` provides `drop`, `create` and `drop_and_create` methods\n+\n+```crystal\n+class User < Granite::ORM::Base\n+  adapter mysql\n+  field name : String\n+end\n+\n+User.migrator.drop_and_create\n+# => \"DROP TABLE IF EXISTS `users`;\"\n+# => \"CREATE TABLE `users` (id BIGSERIAL PRIMARY KEY, name VARCHAR(255));\"","path":"README.md","position":16,"original_position":16,"commit_id":"86f65fa5e9416c1b2f7dbfc6c5dca158012c1124","original_commit_id":"86f65fa5e9416c1b2f7dbfc6c5dca158012c1124","user":{"login":"Blacksmoke16","id":12136995,"avatar_url":"https://avatars1.githubusercontent.com/u/12136995?v=4","gravatar_id":"","url":"https://api.github.com/users/Blacksmoke16","html_url":"https://github.com/Blacksmoke16","followers_url":"https://api.github.com/users/Blacksmoke16/followers","following_url":"https://api.github.com/users/Blacksmoke16/following{/other_user}","gists_url":"https://api.github.com/users/Blacksmoke16/gists{/gist_id}","starred_url":"https://api.github.com/users/Blacksmoke16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blacksmoke16/subscriptions","organizations_url":"https://api.github.com/users/Blacksmoke16/orgs","repos_url":"https://api.github.com/users/Blacksmoke16/repos","events_url":"https://api.github.com/users/Blacksmoke16/events{/privacy}","received_events_url":"https://api.github.com/users/Blacksmoke16/received_events","type":"User","site_admin":false},"body":"That should probably be `id BIGINT` or `id INT` since `BIGSERIAL` is PostgreSQL specific.","created_at":"2018-04-08T20:41:00Z","updated_at":"2018-04-08T20:41:00Z","html_url":"https://github.com/amberframework/granite/pull/172#discussion_r179960609","pull_request_url":"https://api.github.com/repos/amberframework/granite/pulls/172","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/amberframework/granite/pulls/comments/179960609"},"html":{"href":"https://github.com/amberframework/granite/pull/172#discussion_r179960609"},"pull_request":{"href":"https://api.github.com/repos/amberframework/granite/pulls/172"}}},"pull_request":{"url":"https://api.github.com/repos/amberframework/granite/pulls/172","id":178697159,"html_url":"https://github.com/amberframework/granite/pull/172","diff_url":"https://github.com/amberframework/granite/pull/172.diff","patch_url":"https://github.com/amberframework/granite/pull/172.patch","issue_url":"https://api.github.com/repos/amberframework/granite/issues/172","number":172,"state":"open","locked":false,"title":"add `Granite::ORM.migrator` to production codes","user":{"login":"maiha","id":12258,"avatar_url":"https://avatars3.githubusercontent.com/u/12258?v=4","gravatar_id":"","url":"https://api.github.com/users/maiha","html_url":"https://github.com/maiha","followers_url":"https://api.github.com/users/maiha/followers","following_url":"https://api.github.com/users/maiha/following{/other_user}","gists_url":"https://api.github.com/users/maiha/gists{/gist_id}","starred_url":"https://api.github.com/users/maiha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maiha/subscriptions","organizations_url":"https://api.github.com/users/maiha/orgs","repos_url":"https://api.github.com/users/maiha/repos","events_url":"https://api.github.com/users/maiha/events{/privacy}","received_events_url":"https://api.github.com/users/maiha/received_events","type":"User","site_admin":false},"body":"Dry up codes about creating tables in specs, and put it production code as `Granite::ORM.migrator`.\r\nThis helps users\r\n- to add tables in specs easily\r\n- to create tables in experiment and deployment\r\n\r\n```crystal\r\nclass User < Granite::ORM::Base\r\n  adapter mysql\r\n  field name : String\r\nend\r\n\r\nUser.migrator.create\r\n```\r\n\r\n```\r\nmysql> describe users;\r\n+-------+--------------+------+-----+---------+----------------+\r\n| Field | Type         | Null | Key | Default | Extra          |\r\n+-------+--------------+------+-----+---------+----------------+\r\n| id    | bigint(20)   | NO   | PRI | NULL    | auto_increment |\r\n| name  | varchar(255) | YES  |     | NULL    |                |\r\n+-------+--------------+------+-----+---------+----------------+\r\n```\r\n\r\n#### implementation\r\n- mapping rules from **crystal class** to **database type** is defined in adapters.\r\n  - `Granite::Adapter::Base::Schema::Types`\r\n  - `Granite::Adapter::Mysql::Schema::Types`\r\n  - ...\r\n\r\nI just defined rules about basic classes used in current specs.\r\n- `Bool`, `Float32`, `Float64`, `Int32`, `Int64`, `String`, `Time`\r\n\r\nIf `migrator` is exected with undefined types, it raises a runtime error as below.\r\n\r\n```\r\nMigrator(Granite::Adapter::Mysql) doesn't support 'Time::Span' yet. (Exception)\r\n```\r\n\r\nBest regards,","created_at":"2018-03-31T19:36:12Z","updated_at":"2018-04-08T20:41:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"47c9ef37380841932012a5cf872ed72433ccab2e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":870698503,"url":"https://api.github.com/repos/amberframework/granite/labels/pr:needs-review","name":"pr:needs-review","color":"f9d0c4","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/amberframework/granite/pulls/172/commits","review_comments_url":"https://api.github.com/repos/amberframework/granite/pulls/172/comments","review_comment_url":"https://api.github.com/repos/amberframework/granite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amberframework/granite/issues/172/comments","statuses_url":"https://api.github.com/repos/amberframework/granite/statuses/86f65fa5e9416c1b2f7dbfc6c5dca158012c1124","head":{"label":"maiha:migrator","ref":"migrator","sha":"86f65fa5e9416c1b2f7dbfc6c5dca158012c1124","user":{"login":"maiha","id":12258,"avatar_url":"https://avatars3.githubusercontent.com/u/12258?v=4","gravatar_id":"","url":"https://api.github.com/users/maiha","html_url":"https://github.com/maiha","followers_url":"https://api.github.com/users/maiha/followers","following_url":"https://api.github.com/users/maiha/following{/other_user}","gists_url":"https://api.github.com/users/maiha/gists{/gist_id}","starred_url":"https://api.github.com/users/maiha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maiha/subscriptions","organizations_url":"https://api.github.com/users/maiha/orgs","repos_url":"https://api.github.com/users/maiha/repos","events_url":"https://api.github.com/users/maiha/events{/privacy}","received_events_url":"https://api.github.com/users/maiha/received_events","type":"User","site_admin":false},"repo":{"id":112625345,"name":"granite-orm","full_name":"maiha/granite-orm","owner":{"login":"maiha","id":12258,"avatar_url":"https://avatars3.githubusercontent.com/u/12258?v=4","gravatar_id":"","url":"https://api.github.com/users/maiha","html_url":"https://github.com/maiha","followers_url":"https://api.github.com/users/maiha/followers","following_url":"https://api.github.com/users/maiha/following{/other_user}","gists_url":"https://api.github.com/users/maiha/gists{/gist_id}","starred_url":"https://api.github.com/users/maiha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maiha/subscriptions","organizations_url":"https://api.github.com/users/maiha/orgs","repos_url":"https://api.github.com/users/maiha/repos","events_url":"https://api.github.com/users/maiha/events{/privacy}","received_events_url":"https://api.github.com/users/maiha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maiha/granite-orm","description":"Now same as original repository (v0.9.0 supports natural-keys)","fork":true,"url":"https://api.github.com/repos/maiha/granite-orm","forks_url":"https://api.github.com/repos/maiha/granite-orm/forks","keys_url":"https://api.github.com/repos/maiha/granite-orm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maiha/granite-orm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maiha/granite-orm/teams","hooks_url":"https://api.github.com/repos/maiha/granite-orm/hooks","issue_events_url":"https://api.github.com/repos/maiha/granite-orm/issues/events{/number}","events_url":"https://api.github.com/repos/maiha/granite-orm/events","assignees_url":"https://api.github.com/repos/maiha/granite-orm/assignees{/user}","branches_url":"https://api.github.com/repos/maiha/granite-orm/branches{/branch}","tags_url":"https://api.github.com/repos/maiha/granite-orm/tags","blobs_url":"https://api.github.com/repos/maiha/granite-orm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maiha/granite-orm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maiha/granite-orm/git/refs{/sha}","trees_url":"https://api.github.com/repos/maiha/granite-orm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maiha/granite-orm/statuses/{sha}","languages_url":"https://api.github.com/repos/maiha/granite-orm/languages","stargazers_url":"https://api.github.com/repos/maiha/granite-orm/stargazers","contributors_url":"https://api.github.com/repos/maiha/granite-orm/contributors","subscribers_url":"https://api.github.com/repos/maiha/granite-orm/subscribers","subscription_url":"https://api.github.com/repos/maiha/granite-orm/subscription","commits_url":"https://api.github.com/repos/maiha/granite-orm/commits{/sha}","git_commits_url":"https://api.github.com/repos/maiha/granite-orm/git/commits{/sha}","comments_url":"https://api.github.com/repos/maiha/granite-orm/comments{/number}","issue_comment_url":"https://api.github.com/repos/maiha/granite-orm/issues/comments{/number}","contents_url":"https://api.github.com/repos/maiha/granite-orm/contents/{+path}","compare_url":"https://api.github.com/repos/maiha/granite-orm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maiha/granite-orm/merges","archive_url":"https://api.github.com/repos/maiha/granite-orm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maiha/granite-orm/downloads","issues_url":"https://api.github.com/repos/maiha/granite-orm/issues{/number}","pulls_url":"https://api.github.com/repos/maiha/granite-orm/pulls{/number}","milestones_url":"https://api.github.com/repos/maiha/granite-orm/milestones{/number}","notifications_url":"https://api.github.com/repos/maiha/granite-orm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maiha/granite-orm/labels{/name}","releases_url":"https://api.github.com/repos/maiha/granite-orm/releases{/id}","deployments_url":"https://api.github.com/repos/maiha/granite-orm/deployments","created_at":"2017-11-30T15:08:05Z","updated_at":"2018-03-29T05:22:01Z","pushed_at":"2018-04-02T16:53:14Z","git_url":"git://github.com/maiha/granite-orm.git","ssh_url":"git@github.com:maiha/granite-orm.git","clone_url":"https://github.com/maiha/granite-orm.git","svn_url":"https://github.com/maiha/granite-orm","homepage":"","size":616,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"amberframework:master","ref":"master","sha":"dc37f7fae042de6e0f477243128afa867e12fe3f","user":{"login":"amberframework","id":27691024,"avatar_url":"https://avatars1.githubusercontent.com/u/27691024?v=4","gravatar_id":"","url":"https://api.github.com/users/amberframework","html_url":"https://github.com/amberframework","followers_url":"https://api.github.com/users/amberframework/followers","following_url":"https://api.github.com/users/amberframework/following{/other_user}","gists_url":"https://api.github.com/users/amberframework/gists{/gist_id}","starred_url":"https://api.github.com/users/amberframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amberframework/subscriptions","organizations_url":"https://api.github.com/users/amberframework/orgs","repos_url":"https://api.github.com/users/amberframework/repos","events_url":"https://api.github.com/users/amberframework/events{/privacy}","received_events_url":"https://api.github.com/users/amberframework/received_events","type":"Organization","site_admin":false},"repo":{"id":41196214,"name":"granite","full_name":"amberframework/granite","owner":{"login":"amberframework","id":27691024,"avatar_url":"https://avatars1.githubusercontent.com/u/27691024?v=4","gravatar_id":"","url":"https://api.github.com/users/amberframework","html_url":"https://github.com/amberframework","followers_url":"https://api.github.com/users/amberframework/followers","following_url":"https://api.github.com/users/amberframework/following{/other_user}","gists_url":"https://api.github.com/users/amberframework/gists{/gist_id}","starred_url":"https://api.github.com/users/amberframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amberframework/subscriptions","organizations_url":"https://api.github.com/users/amberframework/orgs","repos_url":"https://api.github.com/users/amberframework/repos","events_url":"https://api.github.com/users/amberframework/events{/privacy}","received_events_url":"https://api.github.com/users/amberframework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amberframework/granite","description":"ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.","fork":false,"url":"https://api.github.com/repos/amberframework/granite","forks_url":"https://api.github.com/repos/amberframework/granite/forks","keys_url":"https://api.github.com/repos/amberframework/granite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amberframework/granite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amberframework/granite/teams","hooks_url":"https://api.github.com/repos/amberframework/granite/hooks","issue_events_url":"https://api.github.com/repos/amberframework/granite/issues/events{/number}","events_url":"https://api.github.com/repos/amberframework/granite/events","assignees_url":"https://api.github.com/repos/amberframework/granite/assignees{/user}","branches_url":"https://api.github.com/repos/amberframework/granite/branches{/branch}","tags_url":"https://api.github.com/repos/amberframework/granite/tags","blobs_url":"https://api.github.com/repos/amberframework/granite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amberframework/granite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amberframework/granite/git/refs{/sha}","trees_url":"https://api.github.com/repos/amberframework/granite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amberframework/granite/statuses/{sha}","languages_url":"https://api.github.com/repos/amberframework/granite/languages","stargazers_url":"https://api.github.com/repos/amberframework/granite/stargazers","contributors_url":"https://api.github.com/repos/amberframework/granite/contributors","subscribers_url":"https://api.github.com/repos/amberframework/granite/subscribers","subscription_url":"https://api.github.com/repos/amberframework/granite/subscription","commits_url":"https://api.github.com/repos/amberframework/granite/commits{/sha}","git_commits_url":"https://api.github.com/repos/amberframework/granite/git/commits{/sha}","comments_url":"https://api.github.com/repos/amberframework/granite/comments{/number}","issue_comment_url":"https://api.github.com/repos/amberframework/granite/issues/comments{/number}","contents_url":"https://api.github.com/repos/amberframework/granite/contents/{+path}","compare_url":"https://api.github.com/repos/amberframework/granite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amberframework/granite/merges","archive_url":"https://api.github.com/repos/amberframework/granite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amberframework/granite/downloads","issues_url":"https://api.github.com/repos/amberframework/granite/issues{/number}","pulls_url":"https://api.github.com/repos/amberframework/granite/pulls{/number}","milestones_url":"https://api.github.com/repos/amberframework/granite/milestones{/number}","notifications_url":"https://api.github.com/repos/amberframework/granite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amberframework/granite/labels{/name}","releases_url":"https://api.github.com/repos/amberframework/granite/releases{/id}","deployments_url":"https://api.github.com/repos/amberframework/granite/deployments","created_at":"2015-08-22T07:28:16Z","updated_at":"2018-04-08T17:16:19Z","pushed_at":"2018-04-08T01:36:05Z","git_url":"git://github.com/amberframework/granite.git","ssh_url":"git@github.com:amberframework/granite.git","clone_url":"https://github.com/amberframework/granite.git","svn_url":"https://github.com/amberframework/granite","homepage":"","size":592,"stargazers_count":106,"watchers_count":106,"language":"Crystal","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":35,"mirror_url":null,"archived":false,"open_issues_count":28,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":35,"open_issues":28,"watchers":106,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amberframework/granite/pulls/172"},"html":{"href":"https://github.com/amberframework/granite/pull/172"},"issue":{"href":"https://api.github.com/repos/amberframework/granite/issues/172"},"comments":{"href":"https://api.github.com/repos/amberframework/granite/issues/172/comments"},"review_comments":{"href":"https://api.github.com/repos/amberframework/granite/pulls/172/comments"},"review_comment":{"href":"https://api.github.com/repos/amberframework/granite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amberframework/granite/pulls/172/commits"},"statuses":{"href":"https://api.github.com/repos/amberframework/granite/statuses/86f65fa5e9416c1b2f7dbfc6c5dca158012c1124"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Blacksmoke16"}}