Skip to content

Commit

Permalink
[FIX] For Sqlite3 db:drop command output
Browse files Browse the repository at this point in the history
  • Loading branch information
manishElitmus committed Dec 19, 2023
1 parent d88f108 commit 25347af
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def schema_creation # :nodoc
SQLite3::SchemaCreation.new(self)
end

def create_database
mode = ::SQLite3::Constants::Open::READWRITE | ::SQLite3::Constants::Open::CREATE
config = @connection_parameters.merge(flags: mode)
::SQLite3::Database.new(config[:database].to_s, config)
end

private
def valid_table_definition_options
super + [:rename]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ class SQLite3Adapter < AbstractAdapter
class << self
def new_client(config)
::SQLite3::Database.new(config[:database].to_s, config)
rescue Errno::ENOENT => error
if error.message.include?("No such file or directory")
raise ActiveRecord::NoDatabaseError
else
raise
end
rescue ::SQLite3::CantOpenException => _error
raise ActiveRecord::NoDatabaseError
end

def dbconsole(config, options = {})
Expand Down Expand Up @@ -114,6 +110,7 @@ def initialize(...)
end
end

@config[:flags] = ::SQLite3::Constants::Open::READWRITE if @config[:flags].nil? && !@config[:readonly]
@config[:strict] = ConnectionAdapters::SQLite3Adapter.strict_strings_by_default unless @config.key?(:strict)
@connection_parameters = @config.merge(database: @config[:database].to_s, results_as_hash: true)
@use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def create
raise DatabaseAlreadyExists if File.exist?(db_config.database)

establish_connection
connection.create_database
connection
end

Expand Down Expand Up @@ -71,7 +72,6 @@ def connection

def establish_connection(config = db_config)
ActiveRecord::Base.establish_connection(config)
connection.connect!
end

def run_cmd(cmd, args, out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_sqlite_creates_directory
adapter: "sqlite3",
timeout: 100,
)
@conn.create_database
@conn.connect!

assert Dir.exist? dir.join("db")
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/cases/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,7 @@ def setup
handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
ActiveRecord::Base.connection_handler = handler
handler.establish_connection(db_config)
ActiveRecord::Base.connection.create_database

ActiveRecord::Base.connects_to(database: { writing: :default, reading: :readonly })

Expand Down
5 changes: 4 additions & 1 deletion activerecord/test/cases/migration/pending_migrations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class PendingMigrationsTest < ActiveRecord::TestCase

@original_configurations = ActiveRecord::Base.configurations
ActiveRecord::Base.configurations = base_config
ActiveRecord::Base.establish_connection(:primary)
conn_secondary = ActiveRecord::Base.establish_connection(:secondary)
conn_secondary.connection.create_database
conn_primary = ActiveRecord::Base.establish_connection(:primary)
conn_primary.connection.create_database
end

teardown do
Expand Down

0 comments on commit 25347af

Please sign in to comment.