为什么 rake db:migrate 在 Rails 中不向模式文件添加函数? [英] Why does rake db:migrate in Rails not add functions to the schema file?

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

问题描述

我最近通过迁移向我的数据库添加了一些 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.

感谢您的帮助和回复,

-迈克·特雷西奇

推荐答案

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 之前的版本.

mysqldump doesn't support dumping stored procedures before version 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.

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

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