| 76 | | if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql" |
|---|
| 77 | | ActiveRecord::Base.establish_connection(:test) |
|---|
| 78 | | ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') |
|---|
| 79 | | IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| |
|---|
| 80 | | ActiveRecord::Base.connection.execute(table) |
|---|
| 81 | | end |
|---|
| 82 | | elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql" |
|---|
| 83 | | `psql -U #{ActiveRecord::Base.configurations["test"]["username"]} -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations["test"]["database"]}` |
|---|
| 84 | | elsif ActiveRecord::Base.configurations["test"]["adapter"] == "sqlite" |
|---|
| 85 | | `sqlite #{ActiveRecord::Base.configurations["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql` |
|---|
| | 76 | abcs = ActiveRecord::Base.configurations |
|---|
| | 77 | case abcs["test"]["adapter"] |
|---|
| | 78 | when "mysql" |
|---|
| | 79 | ActiveRecord::Base.establish_connection(:test) |
|---|
| | 80 | ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') |
|---|
| | 81 | IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| |
|---|
| | 82 | ActiveRecord::Base.connection.execute(table) |
|---|
| | 83 | end |
|---|
| | 84 | when "postgresql" |
|---|
| | 85 | `psql -U #{abcs["test"]["username"]} -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` |
|---|
| | 86 | when "sqlite", "sqlite3" |
|---|
| | 87 | `#{abcs[RAILS_ENV]["adapter"]} #{abcs["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql` |
|---|
| | 88 | else |
|---|
| | 89 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
|---|
| 91 | | if ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "mysql" |
|---|
| 92 | | ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV]) |
|---|
| 93 | | File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } |
|---|
| 94 | | elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "postgresql" |
|---|
| 95 | | `pg_dump -U #{ActiveRecord::Base.configurations[RAILS_ENV]["username"]} -s -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations[RAILS_ENV]["database"]}` |
|---|
| 96 | | elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "sqlite" |
|---|
| 97 | | `sqlite #{ActiveRecord::Base.configurations[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql` |
|---|
| | 95 | abcs = ActiveRecord::Base.configurations |
|---|
| | 96 | case abcs[RAILS_ENV]["adapter"] |
|---|
| | 97 | when "mysql" |
|---|
| | 98 | ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) |
|---|
| | 99 | File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } |
|---|
| | 100 | when "postgresql" |
|---|
| | 101 | `pg_dump -U #{abcs[RAILS_ENV]["username"]} -s -f db/#{RAILS_ENV}_structure.sql #{abcs[RAILS_ENV]["database"]}` |
|---|
| | 102 | when "sqlite", "sqlite3" |
|---|
| | 103 | `#{abcs[RAILS_ENV]["adapter"]} #{abcs[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql` |
|---|
| | 104 | else |
|---|
| | 105 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
|---|
| 103 | | if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql" |
|---|
| 104 | | ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV]) |
|---|
| 105 | | ActiveRecord::Base.connection.recreate_database(ActiveRecord::Base.configurations["test"]["database"]) |
|---|
| 106 | | elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql" |
|---|
| 107 | | `dropdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}` |
|---|
| 108 | | `createdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}` |
|---|
| 109 | | elsif ActiveRecord::Base.configurations["test"]["adapter"] == "sqlite" |
|---|
| 110 | | File.delete(ActiveRecord::Base.configurations["test"]["dbfile"]) if File.exist?(ActiveRecord::Base.configurations["test"]["dbfile"]) |
|---|
| | 111 | abcs = ActiveRecord::Base.configurations |
|---|
| | 112 | case abcs["test"]["adapter"] |
|---|
| | 113 | when "mysql" |
|---|
| | 114 | ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) |
|---|
| | 115 | ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) |
|---|
| | 116 | when "postgresql" |
|---|
| | 117 | `dropdb -U #{abcs["test"]["username"]} #{abcs["test"]["database"]}` |
|---|
| | 118 | `createdb -U #{abcs["test"]["username"]} #{abcs["test"]["database"]}` |
|---|
| | 119 | when "sqlite","sqlite3" |
|---|
| | 120 | File.delete(abcs["test"]["dbfile"]) if File.exist?(abcs["test"]["dbfile"]) |
|---|
| | 121 | else |
|---|
| | 122 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
|---|