简体   繁体   中英

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

I try to test my rails application. In production it works on an existing readonly oracle database. 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. I Use the sql-statement to get some special data from the database.

The package pa contains the definitions of some functions like A and is referenced in sql statement for example by

 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?

The short answer is No. Not in the Schema.rb file at least. 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

Taken from 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. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to :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. For example, for PostgreSQL, the pg_dump utility is used. For MySQL, this file will contain the output of SHOW CREATE TABLE for the various tables.

Loading these schemas is simply a question of executing the SQL statements they contain. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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