简体   繁体   English

是否可以将oracle数据库软件包转储到db模式(ruby on rails)?

[英]It is possible to dump oracle database packages into db schema (ruby on rails)?

I try to test my rails application. 我尝试测试我的Rails应用程序。 In production it works on an existing readonly oracle database. 在生产中,它可以在现有的只读oracle数据库上运行。 My problem is that in the origin database there is an oracle package with some functions which is refered in a complex generated sql-statement. 我的问题是,在原始数据库中有一个带有某些功能的oracle包,这些包在复杂的生成的sql语句中被引用。 I Use the sql-statement to get some special data from the database. 我使用sql语句从数据库中获取一些特殊数据。

The package pa contains the definitions of some functions like A and is referenced in sql statement for example by pa包含某些函数(如A的定义,并在sql语句中引用,例如,

 SELECT pa.A(SUM(W1),'F',SUM(W2),'F') AS F1, W3 AS F2
 FROM  table1;

Is there any possibility to include the package in the schema file or some other file so that it is loaded when building the database with rake:test? 有没有可能将包包含在模式文件或其他文件中,以便在使用rake:test构建数据库时加载该包?

The short answer is No. Not in the Schema.rb file at least. 简短的答案是“否”。至少不在Schema.rb文件中。 You can however do it in Structure.rb by using your database's specific dump utility and putting the output of that into the Structure.rb file 但是,您可以通过使用数据库的特定转储实用程序并将其输出放入Structure.rb文件中,在Structure.rb中进行操作

Taken from http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you : 取自http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you

There is however a trade-off: db/schema.rb cannot express database specific items such as foreign key constraints, triggers, or stored procedures. 但是,需要进行权衡:db / schema.rb无法表示数据库特定的项目,例如外键约束,触发器或存储过程。 While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. 在迁移过程中,您可以执行自定义SQL语句,而架构转储程序则无法从数据库中重构这些语句。 If you are using features like this, then you should set the schema format to :sql. 如果使用的是这样的功能,则应将架构格式设置为:sql。

Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the db:structure:dump Rake task) into db/structure.sql. 将使用特定于数据库的工具(通过db:structure:dump Rake任务)将数据库的结构转储到db / structure.sql中,而不是使用Active Record的架构转储器。 For example, for PostgreSQL, the pg_dump utility is used. 例如,对于PostgreSQL,使用pg_dump实用程序。 For MySQL, this file will contain the output of SHOW CREATE TABLE for the various tables. 对于MySQL,此文件将包含各个表的SHOW CREATE TABLE的输出。

Loading these schemas is simply a question of executing the SQL statements they contain. 加载这些模式只是执行它们所包含的SQL语句的问题。 By definition, this will create a perfect copy of the database's structure. 根据定义,这将创建数据库结构的完美副本。 Using the :sql schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it. 但是,使用:sql模式格式将阻止将模式加载到RDBMS中,而不是用于创建模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM