Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Last active May 17, 2018 12:32
Show Gist options
  • Save thisismydesign/c5c188b0094dfd0088115d6cbd81ae97 to your computer and use it in GitHub Desktop.
Save thisismydesign/c5c188b0094dfd0088115d6cbd81ae97 to your computer and use it in GitHub Desktop.
Rails#32914 db:drop drops not created DB with postgresql and sqlite3 adapters (but not with mysql2)
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
a = gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "5.1.6"
gem "sqlite3", "1.3.13"
gem "rake", "~> 10.0"
gem "rspec", "~> 3.0"
gem "pg", "1.0.0"
gem "mysql2", "0.5.1"
end
require "active_record"
require "rspec"
require "rake"
require "fileutils"
def load_active_record_tasks(database_configuration:, root:, db_dir: root, migrations_paths: [root], env: "development", seed_loader: nil)
include ActiveRecord::Tasks
DatabaseTasks.database_configuration = database_configuration
DatabaseTasks.root = root
DatabaseTasks.db_dir = db_dir
DatabaseTasks.migrations_paths = migrations_paths
DatabaseTasks.env = env
DatabaseTasks.seed_loader = seed_loader
task :environment do
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
end
load 'active_record/railties/databases.rake'
end
root = Pathname.new(".")
db_dir = root.join("db")
mysql2_config = {
"development" => {
"adapter" => "mysql2",
"database" => "development",
"username" => "root"
}
}
pg_config = {
"development" => {
"adapter" => "postgresql",
"database" => "development"
}
}
sqlite3_config = {
"development" => {
"adapter" => "sqlite3",
"database" => "development"
}
}
load_active_record_tasks(database_configuration: sqlite3_config, root: root, db_dir: root)
Rake::Task["db:drop"].invoke
$ ruby _rails#32914.rb
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using rake 10.5.0
Using concurrent-ruby 1.0.5
Using i18n 1.0.1
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.6
Using activemodel 5.1.6
Using arel 8.0.0
Using activerecord 5.1.6
Using bundler 1.16.0
Using diff-lcs 1.3
Using mysql2 0.5.1
Using pg 1.0.0
Using rspec-support 3.7.1
Using rspec-core 3.7.1
Using rspec-expectations 3.7.0
Using rspec-mocks 3.7.0
Using rspec 3.7.0
Using sqlite3 1.3.13
Database 'development' does not exist
$ ruby _rails#32914.rb
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using rake 10.5.0
Using concurrent-ruby 1.0.5
Using i18n 1.0.1
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.6
Using activemodel 5.1.6
Using arel 8.0.0
Using activerecord 5.1.6
Using bundler 1.16.0
Using diff-lcs 1.3
Using mysql2 0.5.1
Using pg 1.0.0
Using rspec-support 3.7.1
Using rspec-core 3.7.1
Using rspec-expectations 3.7.0
Using rspec-mocks 3.7.0
Using rspec 3.7.0
Using sqlite3 1.3.13
Dropped database 'development'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment