GitHub PullRequestReviewCommentEvent at 2014-06-12 11:17:39
Repository: rails
Actor: morgoth
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/13696433","id":13696433,"diff_hunk":"@@ -104,6 +104,98 @@ class UserTest < ActiveSupport::TestCase\n       assert !result.include?(\"create_table(:users)\")\n     end\n \n+    test \"sql structure migrations\" do\n+      output  = script('generate model user name:string')\n+      version = output.match(/(\\d+)_create_users\\.rb/)[1]\n+\n+      app_file 'test/models/user_test.rb', <<-RUBY\n+        require 'test_helper'\n+\n+        class UserTest < ActiveSupport::TestCase\n+          test \"user\" do\n+            User.create! name: \"Jon\"\n+          end\n+        end\n+      RUBY\n+\n+      app_file 'db/structure.sql', ''\n+      app_file 'config/initializers/enable_sql_schema_format.rb', <<-RUBY\n+        Rails.application.config.active_record.schema_format = :sql\n+      RUBY\n+\n+      assert_unsuccessful_run \"models/user_test.rb\", \"Migrations are pending\"\n+\n+      app_file 'db/structure.sql', <<-SQL\n+        CREATE TABLE \"schema_migrations\" (\"version\" varchar(255) NOT NULL);\n+        CREATE UNIQUE INDEX \"unique_schema_migrations\" ON \"schema_migrations\" (\"version\");\n+        CREATE TABLE \"users\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"name\" varchar(255));\n+        INSERT INTO schema_migrations (version) VALUES ('#{version}');\n+      SQL\n+\n+      app_file 'config/initializers/disable_maintain_test_schema.rb', <<-RUBY\n+        Rails.application.config.active_record.maintain_test_schema = false\n+      RUBY\n+\n+      assert_unsuccessful_run \"models/user_test.rb\", \"Could not find table 'users'\"\n+\n+      File.delete \"#{app_path}/config/initializers/disable_maintain_test_schema.rb\"\n+\n+      assert_successful_test_run('models/user_test.rb')\n+    end\n+\n+    test \"sql structure migrations when adding column to existing table\" do","path":"railties/test/application/test_test.rb","position":52,"original_position":52,"commit_id":"ad42aaed04a6098732105c12c853bc912ee5cadd","original_commit_id":"bd8ed4f8bdda74235043567fd76a4cdc627c4a57","user":{"login":"morgoth","id":10766,"avatar_url":"https://avatars.githubusercontent.com/u/10766?","gravatar_id":"8085138938c34ae1af140bfc91f2fe56","url":"https://api.github.com/users/morgoth","html_url":"https://github.com/morgoth","followers_url":"https://api.github.com/users/morgoth/followers","following_url":"https://api.github.com/users/morgoth/following{/other_user}","gists_url":"https://api.github.com/users/morgoth/gists{/gist_id}","starred_url":"https://api.github.com/users/morgoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morgoth/subscriptions","organizations_url":"https://api.github.com/users/morgoth/orgs","repos_url":"https://api.github.com/users/morgoth/repos","events_url":"https://api.github.com/users/morgoth/events{/privacy}","received_events_url":"https://api.github.com/users/morgoth/received_events","type":"User","site_admin":false},"body":"I removed 2 lines, but it doesn't help much ;-).\r\nI tried to follow user steps and I think it is minimal test case this way.\r\n\r\nIt would simplify if we create db with first version of `structure.sql` without all these steps, but I don't how to do that in this test.","created_at":"2014-06-12T11:17:39Z","updated_at":"2014-06-12T11:17:39Z","html_url":"https://github.com/rails/rails/pull/15394#discussion_r13696433","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/15394","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/13696433"},"html":{"href":"https://github.com/rails/rails/pull/15394#discussion_r13696433"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/15394"}}},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/15394","id":16576794,"html_url":"https://github.com/rails/rails/pull/15394","diff_url":"https://github.com/rails/rails/pull/15394.diff","patch_url":"https://github.com/rails/rails/pull/15394.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/15394","number":15394,"state":"open","title":"ActiveRecord::Migration.maintain_test_schema! doesn't work with structure.sql","user":{"login":"morgoth","id":10766,"avatar_url":"https://avatars.githubusercontent.com/u/10766?","gravatar_id":"8085138938c34ae1af140bfc91f2fe56","url":"https://api.github.com/users/morgoth","html_url":"https://github.com/morgoth","followers_url":"https://api.github.com/users/morgoth/followers","following_url":"https://api.github.com/users/morgoth/following{/other_user}","gists_url":"https://api.github.com/users/morgoth/gists{/gist_id}","starred_url":"https://api.github.com/users/morgoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morgoth/subscriptions","organizations_url":"https://api.github.com/users/morgoth/orgs","repos_url":"https://api.github.com/users/morgoth/repos","events_url":"https://api.github.com/users/morgoth/events{/privacy}","received_events_url":"https://api.github.com/users/morgoth/received_events","type":"User","site_admin":false},"body":"Introduced in rails 4.1.\r\nChecked using sqlite3 and postgres.\r\n\r\nAt the end of calling `ActiveRecord::Migration.maintain_test_schema!` this method is called: https://github.com/rails/rails/blob/99873ca1ea98d73c73f8be60dfce0a54224f4ea8/activerecord/lib/active_record/tasks/database_tasks.rb#L159 which later, after choosing database adapter calls method, in example on sqlite3 adapter: https://github.com/rails/rails/blob/99873ca1ea98d73c73f8be60dfce0a54224f4ea8/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb#L35\r\n\r\nSo at the very end it runs: `sqlite3 db/test.sqlite3 < db/structure.sql`\r\n\r\nThis however can result in error like:\r\n\r\n```\r\nError: near line 1: table \"schema_migrations\" already exists\r\nError: near line 2: index unique_schema_migrations already exists\r\nError: near line 3: table \"users\" already exists\r\nError: near line 4: UNIQUE constraint failed: schema_migrations.version\r\n```\r\n\r\nThis error can happen when we created migration to add column to existing table.\r\n\r\nIt looks like it's necessary to always purge database before loading sql file and adding:\r\n\r\n```\r\npurge(current_config)\r\ncreate(current_config)\r\n```\r\n\r\nbefore line https://github.com/rails/rails/blob/99873ca1ea98d73c73f8be60dfce0a54224f4ea8/activerecord/lib/active_record/tasks/database_tasks.rb#L168 fixes the issue.\r\nI'm not sure if that is the best place however.\r\n\r\nSimilar issue was noted in https://github.com/rails/rails/pull/13528#issuecomment-40718912 by @kevintyll\r\n\r\nPlease, let me know if the issue is unclear, I can submit example app then.\r\nIf you think that's the correct way of fixing it, I can prepare a PR.\r\n\r\nAddressing to @jonleighton as he is the author of this feature.","created_at":"2014-06-01T15:47:28Z","updated_at":"2014-06-12T11:17:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ccaf158901e22c6f79d19bf6282caaa176921857","assignee":{"login":"senny","id":5402,"avatar_url":"https://avatars.githubusercontent.com/u/5402?","gravatar_id":"3d698e2872c07061a455d9e250861235","url":"https://api.github.com/users/senny","html_url":"https://github.com/senny","followers_url":"https://api.github.com/users/senny/followers","following_url":"https://api.github.com/users/senny/following{/other_user}","gists_url":"https://api.github.com/users/senny/gists{/gist_id}","starred_url":"https://api.github.com/users/senny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/senny/subscriptions","organizations_url":"https://api.github.com/users/senny/orgs","repos_url":"https://api.github.com/users/senny/repos","events_url":"https://api.github.com/users/senny/events{/privacy}","received_events_url":"https://api.github.com/users/senny/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/rails/rails/milestones/33","labels_url":"https://api.github.com/repos/rails/rails/milestones/33/labels","id":665168,"number":33,"title":"4.1.3","description":"","creator":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?","gravatar_id":"0525b332aafb83307b32d9747a93de03","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"open_issues":12,"closed_issues":5,"state":"open","created_at":"2014-05-20T23:54:31Z","updated_at":"2014-06-12T10:11:18Z","due_on":"2014-06-24T07:00:00Z"},"commits_url":"https://api.github.com/repos/rails/rails/pulls/15394/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/15394/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rails/rails/issues/15394/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/ad42aaed04a6098732105c12c853bc912ee5cadd","head":{"label":"morgoth:fix-automatic-maintaining-test-schema-for-sql-format","ref":"fix-automatic-maintaining-test-schema-for-sql-format","sha":"ad42aaed04a6098732105c12c853bc912ee5cadd","user":{"login":"morgoth","id":10766,"avatar_url":"https://avatars.githubusercontent.com/u/10766?","gravatar_id":"8085138938c34ae1af140bfc91f2fe56","url":"https://api.github.com/users/morgoth","html_url":"https://github.com/morgoth","followers_url":"https://api.github.com/users/morgoth/followers","following_url":"https://api.github.com/users/morgoth/following{/other_user}","gists_url":"https://api.github.com/users/morgoth/gists{/gist_id}","starred_url":"https://api.github.com/users/morgoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morgoth/subscriptions","organizations_url":"https://api.github.com/users/morgoth/orgs","repos_url":"https://api.github.com/users/morgoth/repos","events_url":"https://api.github.com/users/morgoth/events{/privacy}","received_events_url":"https://api.github.com/users/morgoth/received_events","type":"User","site_admin":false},"repo":{"id":2748795,"name":"rails","full_name":"morgoth/rails","owner":{"login":"morgoth","id":10766,"avatar_url":"https://avatars.githubusercontent.com/u/10766?","gravatar_id":"8085138938c34ae1af140bfc91f2fe56","url":"https://api.github.com/users/morgoth","html_url":"https://github.com/morgoth","followers_url":"https://api.github.com/users/morgoth/followers","following_url":"https://api.github.com/users/morgoth/following{/other_user}","gists_url":"https://api.github.com/users/morgoth/gists{/gist_id}","starred_url":"https://api.github.com/users/morgoth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morgoth/subscriptions","organizations_url":"https://api.github.com/users/morgoth/orgs","repos_url":"https://api.github.com/users/morgoth/repos","events_url":"https://api.github.com/users/morgoth/events{/privacy}","received_events_url":"https://api.github.com/users/morgoth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/morgoth/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/morgoth/rails","forks_url":"https://api.github.com/repos/morgoth/rails/forks","keys_url":"https://api.github.com/repos/morgoth/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/morgoth/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/morgoth/rails/teams","hooks_url":"https://api.github.com/repos/morgoth/rails/hooks","issue_events_url":"https://api.github.com/repos/morgoth/rails/issues/events{/number}","events_url":"https://api.github.com/repos/morgoth/rails/events","assignees_url":"https://api.github.com/repos/morgoth/rails/assignees{/user}","branches_url":"https://api.github.com/repos/morgoth/rails/branches{/branch}","tags_url":"https://api.github.com/repos/morgoth/rails/tags","blobs_url":"https://api.github.com/repos/morgoth/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/morgoth/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/morgoth/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/morgoth/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/morgoth/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/morgoth/rails/languages","stargazers_url":"https://api.github.com/repos/morgoth/rails/stargazers","contributors_url":"https://api.github.com/repos/morgoth/rails/contributors","subscribers_url":"https://api.github.com/repos/morgoth/rails/subscribers","subscription_url":"https://api.github.com/repos/morgoth/rails/subscription","commits_url":"https://api.github.com/repos/morgoth/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/morgoth/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/morgoth/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/morgoth/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/morgoth/rails/contents/{+path}","compare_url":"https://api.github.com/repos/morgoth/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/morgoth/rails/merges","archive_url":"https://api.github.com/repos/morgoth/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/morgoth/rails/downloads","issues_url":"https://api.github.com/repos/morgoth/rails/issues{/number}","pulls_url":"https://api.github.com/repos/morgoth/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/morgoth/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/morgoth/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/morgoth/rails/labels{/name}","releases_url":"https://api.github.com/repos/morgoth/rails/releases{/id}","created_at":"2011-11-10T13:53:52Z","updated_at":"2014-06-12T11:09:12Z","pushed_at":"2014-06-12T11:09:15Z","git_url":"git://github.com/morgoth/rails.git","ssh_url":"git@github.com:morgoth/rails.git","clone_url":"https://github.com/morgoth/rails.git","svn_url":"https://github.com/morgoth/rails","homepage":"http://rubyonrails.org","size":99539,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"2a7580e63cdcc9cf1c8837578b1d18602db2b74c","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?","gravatar_id":"30f39a09e233e8369dddf6feb4be0308","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?","gravatar_id":"30f39a09e233e8369dddf6feb4be0308","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2014-06-12T09:46:17Z","pushed_at":"2014-06-12T06:56:27Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":318179,"stargazers_count":22118,"watchers_count":22118,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":8203,"mirror_url":null,"open_issues_count":618,"forks":8203,"open_issues":618,"watchers":22118,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/15394"},"html":{"href":"https://github.com/rails/rails/pull/15394"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/15394"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/15394/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/15394/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/15394/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/ad42aaed04a6098732105c12c853bc912ee5cadd"}}}}