{"action":"created","issue":{"url":"https://api.github.com/repos/jeremyevans/sequel/issues/1181","repository_url":"https://api.github.com/repos/jeremyevans/sequel","labels_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1181/labels{/name}","comments_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1181/comments","events_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1181/events","html_url":"https://github.com/jeremyevans/sequel/issues/1181","id":153601265,"number":1181,"title":"unexpected undefined instance method inside DB.alter_table block ","user":{"login":"okliv","id":884634,"avatar_url":"https://avatars.githubusercontent.com/u/884634?v=3","gravatar_id":"","url":"https://api.github.com/users/okliv","html_url":"https://github.com/okliv","followers_url":"https://api.github.com/users/okliv/followers","following_url":"https://api.github.com/users/okliv/following{/other_user}","gists_url":"https://api.github.com/users/okliv/gists{/gist_id}","starred_url":"https://api.github.com/users/okliv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okliv/subscriptions","organizations_url":"https://api.github.com/users/okliv/orgs","repos_url":"https://api.github.com/users/okliv/repos","events_url":"https://api.github.com/users/okliv/events{/privacy}","received_events_url":"https://api.github.com/users/okliv/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-07T15:47:13Z","updated_at":"2016-05-08T02:54:35Z","closed_at":"2016-05-07T16:33:02Z","body":"### Complete Description of Issue\r\n\r\ni have this methods\r\n\r\n    ...\r\n\r\n    def table_exists\r\n      DB.table_exists? name\r\n    end\r\n\r\n    def modification_method\r\n      \"#{table_exists ? 'alter' : 'create'}_table\"\r\n    end\r\n\r\n    def sync_structure\r\n      DB.public_send modification_method, name do\r\n        primary_key :id unless table_exists\r\n        absent_columns.each { |col_name| drop_column col_name; drop_index col_name }\r\n        h_columns.each do |h_col|\r\n          column h_col[:name], h_col[:type]||:string, *h_col[:options] #, unique: true, null: false, default: 1, index: true\r\n          index h_col[:name] if h_col[:options].try(:[], :index)\r\n        end\r\n      end\r\n    end\r\n\r\n    ...\r\n\r\n### Simplest Possible Self-Contained Example Showing the Bug\r\n\r\nif i try to call instance method `sync_structure` i have this error \r\n\r\n     NameError: undefined local variable or method `table_exists' for #<Sequel::Schema::AlterTableGenerator:0x007fdbd60402e0>\r\n\r\nbut i expect that instance method `table_exists` has to exist - it defined above\r\n\r\nthe same is for `absent_columns` and `h_columns` methods (and, i guess, any others)"},"comment":{"url":"https://api.github.com/repos/jeremyevans/sequel/issues/comments/217687273","html_url":"https://github.com/jeremyevans/sequel/issues/1181#issuecomment-217687273","issue_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1181","id":217687273,"user":{"login":"jeremyevans","id":3846,"avatar_url":"https://avatars.githubusercontent.com/u/3846?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremyevans","html_url":"https://github.com/jeremyevans","followers_url":"https://api.github.com/users/jeremyevans/followers","following_url":"https://api.github.com/users/jeremyevans/following{/other_user}","gists_url":"https://api.github.com/users/jeremyevans/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremyevans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremyevans/subscriptions","organizations_url":"https://api.github.com/users/jeremyevans/orgs","repos_url":"https://api.github.com/users/jeremyevans/repos","events_url":"https://api.github.com/users/jeremyevans/events{/privacy}","received_events_url":"https://api.github.com/users/jeremyevans/received_events","type":"User","site_admin":false},"created_at":"2016-05-08T02:54:35Z","updated_at":"2016-05-08T02:54:35Z","body":"If you are still in development and not in production, it may be easier to just drop the existing tables and recreate the schema instead of trying to figure out what changed.  But there may be reasons that wouldn't work for your application.  Anyway, if you have something that works for you (now that the instance_eval issue has been worked around), there's probably not a good reason to change it."}}