Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update SQL Server DB Rake Tasks #1795

Merged
merged 1 commit into from

2 participants

@metaskills

These have been outdated forever and need a bump up. Details in commit message bullet points.

@metaskills metaskills Update SQL Server db related rake tasks.
  * Uses open source smoscript since scptxfr came out in 2000.
  * Uses sqlcmd which replaces osql.
  * Takes advantage of host/user/pass passed down by TinyTDS.
e5cf2ad
@metaskills

Serious question, should I add tests for this? Is there a standard rake test file too, not rhetorical, never looked?

@tenderlove
Owner

@metaskills ya, we should probably test this stuff. I think we need to extract the rake task in to some sort of plugin system or something though. Having this much code in a rake task is pretty ridiculous. I imagine we need some sort of factory method that returns the correct runner for a particular database. Then we can just test each runner independently.

I'll merge this in for now though. Thanks!

@tenderlove tenderlove merged commit 98ae482 into rails:3-1-stable
@metaskills

I 100% agreed about proposed arrangement too! Thanks for letting me punt in, already burdened down with tons of other stuff for the SQL Server stack to work on that part of rails now. Cheers!

@tenderlove
Owner

@metaskills do you mind sending another pull request for master? I'm feeling lazy about merging....

@metaskills

Sure, my first use of cherry-pick :)
#1835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 21, 2011
  1. @metaskills

    Update SQL Server db related rake tasks.

    metaskills authored
      * Uses open source smoscript since scptxfr came out in 2000.
      * Uses sqlcmd which replaces osql.
      * Takes advantage of host/user/pass passed down by TinyTDS.
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 6 deletions.
  1. +7 −6 activerecord/lib/active_record/railties/databases.rake
View
13 activerecord/lib/active_record/railties/databases.rake
@@ -377,8 +377,7 @@ db_namespace = namespace :db do
dbfile = abcs[Rails.env]['database'] || abcs[Rails.env]['dbfile']
`sqlite3 #{dbfile} .schema > db/#{Rails.env}_structure.sql`
when 'sqlserver'
- `scptxfr /s #{abcs[Rails.env]['host']} /d #{abcs[Rails.env]['database']} /I /f db\\#{Rails.env}_structure.sql /q /A /r`
- `scptxfr /s #{abcs[Rails.env]['host']} /d #{abcs[Rails.env]['database']} /I /F db\ /q /A /r`
+ `smoscript -s #{abcs[Rails.env]['host']} -d #{abcs[Rails.env]['database']} -u #{abcs[Rails.env]['username']} -p #{abcs[Rails.env]['password']} -f db\\#{Rails.env}_structure.sql -A -U`
when "firebird"
set_firebird_env(abcs[Rails.env])
db_string = firebird_db_string(abcs[Rails.env])
@@ -423,7 +422,7 @@ db_namespace = namespace :db do
dbfile = abcs['test']['database'] || abcs['test']['dbfile']
`sqlite3 #{dbfile} < #{Rails.root}/db/#{Rails.env}_structure.sql`
when 'sqlserver'
- `osql -E -S #{abcs['test']['host']} -d #{abcs['test']['database']} -i db\\#{Rails.env}_structure.sql`
+ `sqlcmd -S #{abcs['test']['host']} -d #{abcs['test']['database']} -U #{abcs['test']['username']} -P #{abcs['test']['password']} -i db\\#{Rails.env}_structure.sql`
when 'oci', 'oracle'
ActiveRecord::Base.establish_connection(:test)
IO.readlines("#{Rails.root}/db/#{Rails.env}_structure.sql").join.split(";\n\n").each do |ddl|
@@ -453,9 +452,11 @@ db_namespace = namespace :db do
dbfile = abcs['test']['database'] || abcs['test']['dbfile']
File.delete(dbfile) if File.exist?(dbfile)
when 'sqlserver'
- dropfkscript = "#{abcs['test']['host']}.#{abcs['test']['database']}.DP1".gsub(/\\/,'-')
- `osql -E -S #{abcs['test']['host']} -d #{abcs['test']['database']} -i db\\#{dropfkscript}`
- `osql -E -S #{abcs['test']['host']} -d #{abcs['test']['database']} -i db\\#{Rails.env}_structure.sql`
+ test = abcs.deep_dup['test']
+ test_database = test['database']
+ test['database'] = 'master'
+ ActiveRecord::Base.establish_connection(test)
+ ActiveRecord::Base.connection.recreate_database!(test_database)
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
Something went wrong with that request. Please try again.