{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/scenic/issues/150","repository_url":"https://api.github.com/repos/thoughtbot/scenic","labels_url":"https://api.github.com/repos/thoughtbot/scenic/issues/150/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/scenic/issues/150/comments","events_url":"https://api.github.com/repos/thoughtbot/scenic/issues/150/events","html_url":"https://github.com/thoughtbot/scenic/pull/150","id":146508997,"number":150,"title":"Interpret embedded ERB in sql files","user":{"login":"adzap","id":6318,"avatar_url":"https://avatars.githubusercontent.com/u/6318?v=3","gravatar_id":"","url":"https://api.github.com/users/adzap","html_url":"https://github.com/adzap","followers_url":"https://api.github.com/users/adzap/followers","following_url":"https://api.github.com/users/adzap/following{/other_user}","gists_url":"https://api.github.com/users/adzap/gists{/gist_id}","starred_url":"https://api.github.com/users/adzap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adzap/subscriptions","organizations_url":"https://api.github.com/users/adzap/orgs","repos_url":"https://api.github.com/users/adzap/repos","events_url":"https://api.github.com/users/adzap/events{/privacy}","received_events_url":"https://api.github.com/users/adzap/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-07T04:49:27Z","updated_at":"2016-05-08T08:41:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/thoughtbot/scenic/pulls/150","html_url":"https://github.com/thoughtbot/scenic/pull/150","diff_url":"https://github.com/thoughtbot/scenic/pull/150.diff","patch_url":"https://github.com/thoughtbot/scenic/pull/150.patch"},"body":"I needed to use some logic for generating a complex view. So using the Rails-ish way of interpreting ERB in these kinds of text files seemed like a reasonable solution.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/thoughtbot/scenic/issues/comments/217703864","html_url":"https://github.com/thoughtbot/scenic/pull/150#issuecomment-217703864","issue_url":"https://api.github.com/repos/thoughtbot/scenic/issues/150","id":217703864,"user":{"login":"adzap","id":6318,"avatar_url":"https://avatars.githubusercontent.com/u/6318?v=3","gravatar_id":"","url":"https://api.github.com/users/adzap","html_url":"https://github.com/adzap","followers_url":"https://api.github.com/users/adzap/followers","following_url":"https://api.github.com/users/adzap/following{/other_user}","gists_url":"https://api.github.com/users/adzap/gists{/gist_id}","starred_url":"https://api.github.com/users/adzap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adzap/subscriptions","organizations_url":"https://api.github.com/users/adzap/orgs","repos_url":"https://api.github.com/users/adzap/repos","events_url":"https://api.github.com/users/adzap/events{/privacy}","received_events_url":"https://api.github.com/users/adzap/received_events","type":"User","site_admin":false},"created_at":"2016-05-08T08:41:23Z","updated_at":"2016-05-08T08:41:23Z","body":"My use case is to create a lengthy view from existing knowledge in the app, table names, column names and other metadata, then use some loops to generate the final columns which are pg functions. To avoid transcription errors I wanted to use Ruby. Initially I was going to generate it outside of scenic and dump it in the view, but it was very verbose. But I wondered why it needed to much different from anything I could do in a regular migration which contains Ruby to generate SQL behinds the scenes.\r\n\r\nThe concern about value drift in the migration SQL is valid in the context of it being able to be affected from distant code in the app. Which is a problem in any app design; a change in one location having unintended consequences in another. Though a general concern about value changes doesn't seem valid. Such changes always occur and a remigration to use the new value may be the exact intention, nevertheless, the code change would/should be source controlled. Your example of fragile information in such a migration such as model data is rather fraught and to be avoided, and again an issue with developer common sense.\r\n\r\nIn general not seeing the final SQL before migrating is a nothing new to Rails. That is how the migrations already work. Though the difference here is that no formal DSL is present to attempt represent the output SQL.\r\n\r\nAdding the `.erb` is a good idea given your example."}}