Nitin Borwankar
2005-Aug-05 08:18 UTC
errors using schemas in postgresql with ActiveRecord/Rails
Hello folks, Having a bit of a problem here using schemas in PostgreSQL with Rails. My database name is ''clickstream'', schema name is ''ketlmd'' Table name is report_meta (singular) Yes, I am using legacy data. I have set the table name using set_table_name in the model both to report_meta and ketlmd.report_meta but this is after the scaffold is generated. I have set the ''schema_order'' param to ''ketlmd,public'' in database.yml The scaffolding is generated via ''rails generate scaffold ReportMeta RMAdmin'' I then try to access localhost:3000/rm_admin and get the following strange error === NameError in <controller not set>#<action not set> uninitialized constant RmAdminHelper app/controllers/rm_admin_controller.rb:1 routing.rb:219:in `traverse_to_controller'' generated/routing/recognition.rb:3:in `eval'' generated/routing/recognition.rb:3:in `recognize_path'' script/server:48 Show framework trace This error occured while loading the following files: ./script/../config/../app/controllers/rm_admin_controller.rb ==== I found the following wrong looking output in logs/development.log SQL (0.001177) SET search_path TO ketlmd,public SQL (0.063459) SELECT column_name, column_default, character_maximum_length, data_type FROM information_schema.columns WHERE table_catalog = ''clickstream'' AND table_schema = ''public'' AND table_name = ''report_meta''; SQL (0.045826) SELECT column_name, column_default, character_maximum_length, data_type FROM information_schema.columns WHERE table_catalog = ''clickstream'' AND table_schema = ''public'' AND table_name = ''report_meta''; == The first SQL statement is correct, the second and third ones have ...table_schema = ''public'' which is wrong. When the search_path is set the table_schema= clause is not needed. This SQL in second and third statements will give a null result set. Is this the source of the error or is it something else ? Has anyone used schemas with Rails in PostgreSQL and/or seen this problem ? Obviously critical metadata is not initialized in Rails because of this SQL. Thanks for any help. Nitin Borwankar http://tagschema.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jon Mercer
2005-Aug-05 09:09 UTC
Re: errors using schemas in postgresql with ActiveRecord/Rails
I too have had this problem. The only work around I have been able to identify is to create the tables in the public schema directly. That said, I''m still a noob myself and if anyone else has a better solution for PostgreSQL table access from Rails, I''m sure there would be a wide audience for it. Cheers, Jon Mercer On Fri, 2005-08-05 at 01:18 -0700, Nitin Borwankar wrote:> Hello folks, > > Having a bit of a problem here using schemas in PostgreSQL with Rails. > My database name is ''clickstream'', schema name is ''ketlmd'' > Table name is report_meta (singular) > Yes, I am using legacy data. > > I have set the table name using set_table_name in the model both to > report_meta and ketlmd.report_meta but this is after the > scaffold is generated. > I have set the ''schema_order'' param to ''ketlmd,public'' in database.yml > > The scaffolding is generated via ''rails generate scaffold ReportMeta > RMAdmin'' > I then try to access localhost:3000/rm_admin and get the following > strange error > > ===> > NameError in <controller not set>#<action not set> > > uninitialized constant RmAdminHelper > > app/controllers/rm_admin_controller.rb:1 > routing.rb:219:in `traverse_to_controller'' > generated/routing/recognition.rb:3:in `eval'' > generated/routing/recognition.rb:3:in `recognize_path'' > script/server:48 > Show framework trace > This error occured while loading the following files: > ./script/../config/../app/controllers/rm_admin_controller.rb > > ====> > > I found the following wrong looking output in logs/development.log > > SQL (0.001177) SET search_path TO ketlmd,public > SQL (0.063459) SELECT column_name, column_default, > character_maximum_length, data_type FROM information_schema.columns > WHERE table_catalog = ''clickstream'' AND table_schema = ''public'' AND > table_name = ''report_meta''; > SQL (0.045826) SELECT column_name, column_default, > character_maximum_length, data_type FROM information_schema.columns > WHERE table_catalog = ''clickstream'' AND table_schema = ''public'' AND > table_name = ''report_meta''; > > ==> > The first SQL statement is correct, the second and third ones have > ...table_schema = ''public'' which is wrong. > When the search_path is set the table_schema= clause is not needed. > > This SQL in second and third statements will give a null result set. Is > this the source of the error or is it something else ? > Has anyone used schemas with Rails in PostgreSQL and/or seen this > problem ? Obviously critical metadata is not initialized in Rails > because of this SQL. > > Thanks for any help. > > Nitin Borwankar > http://tagschema.com > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- ----------------------------------------------------------------------- Achean Ltd http://www.achean.com Jon Mercer jon.mercer-PPkJ/V4kmRXQT0dZR+AlfA@public.gmane.org Director -----------------------------------------------------------------------