|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#names of views I'd like created
views = %W(VIEW1 VIEW2 VIEW2)
dev_schema = Rails.configuration.database_configuration["development"]["username"].upcase
test_schema = Rails.configuration.database_configuration["test"]["username"].upcase
views.each do |view|
#for each of the views I need created
# establish a connection first to development database
ActiveRecord::Base.establish_connection(:development)
# grant select on the view to the test user
ActiveRecord::Base.connection.execute "GRANT SELECT ON #{dev_schema}.#{view} TO #{test_schema}"
# establish a connection to the test database
ActiveRecord::Base.establish_connection(:test)
# create the view as a table in the test database - 'where 1=0' discards importing data
ActiveRecord::Base.connection.execute "CREATE TABLE #{test_schema}.#{view} AS SELECT * FROM #{dev_schema}.#{view} where 1=0"
end |
The Past
- April 2013 (1)
- March 2013 (2)
- November 2012 (3)
- October 2012 (2)
- December 2011 (1)
- November 2011 (2)
- October 2011 (2)
- January 2011 (2)
- October 2010 (2)
- September 2010 (5)
- June 2010 (1)
- June 2009 (2)
- April 2009 (1)
- March 2009 (2)
- December 2008 (1)
- November 2008 (1)
- October 2008 (3)
- June 2008 (2)
- May 2008 (1)
- April 2008 (3)
- March 2008 (1)
- February 2008 (4)
- January 2008 (5)
- December 2007 (1)
- November 2007 (1)
- October 2007 (2)
- September 2007 (4)
- June 2007 (2)
- May 2007 (1)
- April 2007 (3)
- March 2007 (3)
- February 2007 (4)
- January 2007 (3)
- November 2006 (1)
- October 2006 (1)
- September 2006 (3)
- August 2006 (3)
- June 2006 (1)
- May 2006 (2)
- April 2006 (3)
- March 2006 (2)
- February 2006 (9)
- January 2006 (2)
- December 2005 (5)
- November 2005 (8)
- October 2005 (5)
- September 2005 (7)
- August 2005 (4)
- July 2005 (3)
- June 2005 (5)
- May 2005 (6)
- March 2005 (10)
- February 2005 (3)
- January 2005 (4)
- December 2004 (7)
- November 2004 (8)
- October 2004 (6)
- September 2004 (5)
- August 2004 (7)
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.