rails sqlserver views - ruby-on-rails

how is it possible to work from rails and use sqlserver views?
rake db:schema:dump
doesn't generate schema for views
I've used rails_sql_views gem but something is buggy. probably because of sqlserver

Yes, it possible, and sometimes convenient. I'm using views to fetch some data from legacy database. But views are read-only.

Related

initially populate data in rails if database is empty from application

I have created database migration, and migrated data both on development and production servers. I would like to populate database from the application, if it is empty and avoid rake db:seed and other similar methods. I know that it could be done through rake db:seed, but since application is already deployed I would not like to pollute deploy.rb for capistrano, or do it manually on both development and production.
Is there any hook on database open or initialization of Active Record where I can do something like
if !Pages.first
Pages.populate
end
I am aware of all recommended methods to populate database, but I would still prefer to do it from app.
Thanks
As you eluded to, this is not the best idea in the world, but maybe you could try using on of these approaches:
An initializer that will get called each time the rails environment is loaded.
Something in the config.after_initialize block. See http://guides.rubyonrails.org/configuring.html

How to disable sqlite3 while using neoid?

I am using neoid with rails and want to disable sqlite in my rails application. How can I do this (after that I want to use only neoid and neo4j to store the data)?
Remove
gem 'sqlite3'
from your Gemfile and make sure that your config/database.yml file doesn't contain lines like
adapter: sqlite
From my testing with it today I don't think you can do this with this gem. Neoid adds neo4j storage as an addition to, not replacement for, your traditional RDBMS.
To have a full replacement for RDBMS-backed ActiveRecord you may need to consider the neo4j.rb gem, which requires JRuby.

Rails - disable db connections

There's a Rails 3.2.3 web application which doesn't use any database. But in spite of that if I use the gem 'sqllite3' in GemFile I works perfect. But if I use gem 'pg' in that file it throws an error
ActiveRecord::ConnectionNotEstablished
Of course, I use different versions of database.yml when I use postgreSql or SqlLite3.
But I definitely don't use any database.
Why is it happening? What should I do to solve it? And how to disable using databases?
See the SO question here for how to bypass using a database. It's a little more work than just setting a flag.

Ruby On Rails ActiveRecord SQL view into schema

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql.
The problem with this is that the view is not entered into the schema. So when I need to create my test database to run my tests against the view is not created. I then need to create it by running the sql statement. Is there a way to implement SQL views elegantly in ruby on rails?
My environment:
Ruby on Rails 3.0.3
PostgreSQL 8.3
The rails_sql_views gem is intended to solve this problem. It adds support to the schema dumper to include views, which means you can use them in your test database. I'm not sure how well it works in Rails 3, but the github issues list has a pull request that appears to add Rails 3 support.
Possibly. using config.active_record.schema_format = :sql may help.

Ruby on Rails and db:fixtures:load - can it ignore some models?

I have two databases in use in a Ruby on Rails application; one is the database for the application while the second is an independent database over which Rails is not given control.
Problem is when loading fixtures into the dev, it tries to run DELETE statements on the tables in the independent database from the connection to the dev database, which obviously errors out.
I don't want Rails to try to do ANYTHING but read the independent database - I especially don't want it trying to delete tables.
Is there a simple way to tell Rails to ignore the models for the second database when loading fixtures?
UPDATE: To clarify, Rails seems to think the tables from the independent database are part of the development connection, though I have specified the correct connection in the model class using establish_connection. As another note, all model classes work precisely as desired from script/console.
rake db:fixtures:load RAILS_ENV=testing
will do the job for database configured as testing in your database.yml
I think you might also be able to accomplish this by adding all the tables in the independent database to ActiveRecord::SchemaDumper.ignore_tables in environment.rb, like so:
ActiveRecord::SchemaDumper.ignore_tables = ['independent_db_table1', 'independent_db_table2']
Okay...my issue was that I used the script/generate to create the models from the secondary database, which also created fixture, schema, test, and migrations files. I had removed the schema, test, and migrations files, but did not remove the generated fixtures (they were empty files) as I did not think it had created any.
After removing all files (including the models) from the secondary database and re-running the migrations for the dev db, I added back only the model files and the database in databases.yml from the secondary db, which solved the issue.
I still can't explain why Rails' rake tasks were looking in the wrong database and I am a little disappointed with rails' addition of the schema_migrations table in the secondary database, which it obviously does not need.
However, it works now.
Delete the model_name.yml file in your test/fixtures directory and Rails will not try to delete these tables.
Better yet, delete all your *.yml files and stop using fixtures entirely.

Resources