为什么在Rails中rake db:migrate不会将功能添加到架构文件? [英] Why does rake db:migrate in Rails not add functions to the schema file?

查看:66
本文介绍了为什么在Rails中rake db:migrate不会将功能添加到架构文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近通过迁移向数据库中添加了一些SQL函数,它们运行良好.代码有效,数据库有效,测试无效. schema.rb文件告诉我它是最新版本(正确),但是它仅包含表和索引的定义,而不包含我添加的功能.

I recently added some SQL functions to my database via a migrate, and they work perfectly fine. Code works, database works, tests don't. The schema.rb file is telling me that it's at the latest version (and it's correct), but it only contains definitions for tables and indexes, not the functions I added.

我在迁移过程中通过"execute()"方法添加了这些功能,并且需要它们在测试数据库中通过RSpec测试(公司政策规定,在解决此问题之前,我无法提交此更改).

I added the functions via the "execute()" method in my migration, and need them in the test database for the RSpec tests to pass (company policy dictates that I can't commit this changes until this is fixed).

有人知道为什么会发生这种情况或如何解决吗?我可以手动进入MySQL命令行并添加功能,但是下次有人执行db:test:prepare时,这些功能将被删除.我需要一个可以自动化的解决方案.

Does anyone know why this is happening, or how to fix it? I can manually go into the MySQL command line and add the functions, but then they're erased the next time someone does a db:test:prepare. I need a solution that can be automated.

感谢您的帮助和答复,

-Mike Trpcic

-Mike Trpcic

推荐答案

schema.rb是Ruby模式格式,它不支持函数或许多其他更高级的功能.将格式更改为纯SQL(在environment.rb中),您应该会很好.

schema.rb is the Ruby schema format and it doesn't support functions or many other more advanced features. Change the format to plain SQL (in environment.rb) and you should be good to go.

config.active_record.schema_format = :sql

编辑:在Mike发表评论后,我做了一些深入研究.将架构调用转储到MySQL和Oracle的ActiveRecord连接适配器的Rake任务. MySQL并不是很聪明,只能转储表结构,而忽略其他所有内容. PostgreSQL,SQLite,SQL Server和Firebird调用供应商提供的可执行文件.

After Mike's comment, I did a bit of digging. The Rake task to dump the schema calls into the ActiveRecord connection adapter for MySQL and Oracle. MySQL's isn't very smart and only dumps the table structure, ignoring everything else. PostgreSQL, SQLite, SQL Server and Firebird call out to a vendor-provided executable.

mysqldump 版本5.0之前不支持转储存储过程. 13.

我环顾了Rails灯塔,但是要寻找开放票证要困难得多.如果没有其他人对此提交过错误,则可以考虑这样做,尽管没有补丁,也不太可能有人对此进行处理.

I looked around the Rails Lighthouse, but searching for open tickets there is far harder than it should be. If no one else has filed a bug on this, you might consider doing so, though without a patch, it's not likely anyone is going to work on it.

这篇关于为什么在Rails中rake db:migrate不会将功能添加到架构文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆