mhe*_*xon 27 postgresql ruby-on-rails
在我们的一些开发人员机器上rake db:migrate添加尾部空格structure.sql非常烦人,因为每次对数据库进行更改时,我们必须首先从文件中删除所有尾随空格.
任何人都知道这可能是什么?空白从哪里来?它与PostgreSQL有关还是别的什么?
这是一个可以提交版本控制的解决方案:将尾随空格修剪为db:migrate钩子.
在lib/tasks/db.rake:
namespace :db do
def remove_whitespace_in_structure
if Rails.env.development?
`sed -i '' -e's/[[:space:]]*$//' db/structure.sql`
end
end
task :migrate do
remove_whitespace_in_structure
end
end
Run Code Online (Sandbox Code Playgroud)
上面的代码可能看起来像是覆盖db:migrate,但它是一个在正常db:migrate任务之后运行的钩子.
我只是为此设置了一个git过滤器.不幸的是,这不是你可以添加到回购的东西; 每个团队成员都必须进行设置.
.gitconfig(或.git/config)[filter "remove-trailing-whitespace"]
clean = sed -E 's/[[:space:]]*$//'
smudge = cat
Run Code Online (Sandbox Code Playgroud)
.gitattributes或.git/info/attributesdb/structure.sql filter=remove-trailing-whitespace
Run Code Online (Sandbox Code Playgroud)
有关git的更多信息,请参阅gitattributes上的文档filters.
| 归档时间: |
|
| 查看次数: |
1720 次 |
| 最近记录: |