使用 db:schema:dump 使用 rake 在旧版 Oracle 数据库上进行架构转储

发布于 2024-07-07 23:44:02 字数 264 浏览 4 评论 0原文

有谁知道用于导入旧 Oracle 数据库模式的任何特定 DSL 实现吗? 我尝试在现有数据库上运行 db:schema:dump 我想移植到新的 ruby​​ 应用程序。 然而,耙子在中途就死掉了,没有任何错误。 它有点锁起来了。 我开始寻找解决这个问题的最佳方法,并找到了如何覆盖 SQLServer 的一些内容的示例,但对于 Oracle 来说却没有太多。

我基本上想提取模式并从中生成脚手架和模型。

有没有更简单的方法来做到这一点,或者我必须发明轮子?

Does anyone know of any specific DSL implementations used to import legacy Oracle database schemas. I have tried to just run db:schema:dump on my existing db I want to port to a new ruby app. However, the rake dies about halfway through with out any error. It kinda just locks up. I started looking for the best way to tackle this and found examples of how to override some stuff for SQLServer but not much for Oracle.

I basically want to pull in the schema and generate a scaffold and model from it.

Is there a more simple way to do this or will I have to invent the wheel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

已下线请稍等 2024-07-14 23:44:02

第一个问题 - 您使用的是原始 ActiveRecord Oracle 适配器还是 oracle_enhanced 适配器(http://github.com/rsim/甲骨文增强)? 我建议使用 oracle_enhanced 适配器,因为我对架构转储做了一些性能改进。

Rails 提供了两种模式转储方法:

rake db:schema:dump

这将使用 Rails 迁移创建 schema.rb 文件以进行模式创建。 在 Oracle 情况下,它将搜索用户本地架构中的所有表(用户在 database.yml 中指定),并尝试将 Oracle 数据类型转换为 Rails 模型属性类型。 如果 Rails 不支持某些数据类型,那么您可能会丢失它们。 但如果您想以 Rails 方式重新设计您的应用程序,那么这是首选方法。 正如我所说,在大型 Oracle 数据字典的情况下(如果所有模式中有数千个表),我对 oracle_enhanced 适配器的模式转储进行了一些性能改进。

rake db:structure:dump

这将创建 SQL 模式文件(例如 db/development_struct.sql),您可以在其他 Oracle 数据库中执行该文件(这不适用于其他数据库)。 这可能是创建模式转储的更快方法,并且不会丢失 Oracle 特定的数据类型。 但通过这种方式,当您稍后将 ActiveRecord 与此数据库一起使用时,您可能会遇到麻烦,然后会注意到某些数据类型未正确处理。 因此,我建议使用 Rails 迁移来维护架构而不是原始 SQL。

但是,如果您想将 Rails 与某些现有 Oracle 数据库一起使用,则无需重新创建此架构 - 您只需将 database.yml 指向此现有数据库架构,然后开始在现有表之上创建 ActiveRecord 模型。 请参阅 http://blog.rayapps .com/2008/09/26/openworld-unconference-presentation-about-rails-on-oracle/ 了解如何将 Rails 与旧版 Oracle 数据库结合使用的一些提示。

The firs question - are you using original ActiveRecord Oracle adapter or oracle_enhanced adapter (http://github.com/rsim/oracle-enhanced)? I recommend to use oracle_enhanced adapter as I made there some performance improvements for schema dump.

Rails provides two ways for schema dump:

rake db:schema:dump

This will create schema.rb file with Rails migrations for schema creation. In Oracle case it will search for all tables in user local schema (user is specified in database.yml) and will try to translate Oracle data types to Rails model attribute types. If you have some data types which are not supported by Rails then you might loose them. But if you want to reengineer your application in Rails way then this is preferred approach. As I said I made some performance improvement in oracle_enhanced adapter for schema dump in case of large Oracle data disctionaries (if you have thousands of tables in all schemas).

rake db:structure:dump

This will create SQL schema file (e.g. db/development_structure.sql) which you can execute in other Oracle database (this will not work on other databases). This might be faster way to create schema dump and it will not lose Oracle specific data types. But in this way you can get into trouble later when you will use ActiveRecord with this database and then will notice that some data types are not processed correctly. Therefore I recommend to use Rails migration to maintain schema and not raw SQL.

But if you want to use Rails with some existing Oracle database then you don't need to recreate this schema - you can just point database.yml to this existing database schema and start to create ActiveRecord models on top of existing tables. See http://blog.rayapps.com/2008/09/26/openworld-unconference-presentation-about-rails-on-oracle/ for some tips how to use Rails with legacy Oracle databases.

一个人的旅程 2024-07-14 23:44:02

更新:仅当您使用“, :require => false”时才会失败。 删除此参数,按预期工作。

这真的应该有效吗?

~/Projects/test (master) $ rake db:structure:dump
(in /Users/plentz/Projects/test)
rake aborted!
Task not supported by 'oracle_enhanced'

(See full trace by running task with --trace)

宝石文件

gem 'activerecord-oracle_enhanced-adapter', :require => false

Using activerecord-oracle_enhanced-adapter (1.3.2) 

update: this only fail if you use ", :require => false". Removing this param, work as expected.

This really should work?

~/Projects/test (master) $ rake db:structure:dump
(in /Users/plentz/Projects/test)
rake aborted!
Task not supported by 'oracle_enhanced'

(See full trace by running task with --trace)

Gemfile

gem 'activerecord-oracle_enhanced-adapter', :require => false

Using activerecord-oracle_enhanced-adapter (1.3.2) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文