Skip to content

Commit

Permalink
Remove support for oracle, sqlserver and JRuby specific database adap…
Browse files Browse the repository at this point in the history
…ters from the new and db:system:change commands. The supported options are sqlite3, mysql, postgresql and trilogy.
  • Loading branch information
andrewn617 committed May 13, 2024
1 parent 3e08223 commit 5b91084
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 126 deletions.
3 changes: 1 addition & 2 deletions actionview/test/active_record_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def reconnect
def setup_connection
if Object.const_defined?(:ActiveRecord)
defaults = { database: ":memory:" }
adapter = defined?(JRUBY_VERSION) ? "jdbcsqlite3" : "sqlite3"
options = defaults.merge adapter: adapter, timeout: 500
options = defaults.merge adapter: "sqlite3", timeout: 500
ActiveRecord::Base.establish_connection(options)
ActiveRecord::Base.configurations = { "sqlite3_ar_integration" => options }
ActiveRecord::Base.lease_connection
Expand Down
38 changes: 0 additions & 38 deletions activerecord/test/schema/oracle_specific_schema.rb

This file was deleted.

5 changes: 5 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
* Remove support for `oracle`, `sqlserver` and JRuby specific database adapters from the
`rails new` and `rails db:system:change` commands. The supported options are `sqlite3`,
`mysql`, `postgresql` and `trilogy`.

*Andrew Novoselac*

Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/railties/CHANGELOG.md) for previous changes.
26 changes: 1 addition & 25 deletions railties/lib/rails/generators/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
module Rails
module Generators
module Database # :nodoc:
JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
DATABASES = %w( mysql trilogy postgresql sqlite3 oracle sqlserver ) + JDBC_DATABASES

def initialize(*)
super
convert_database_option_for_jruby
end
DATABASES = %w( mysql trilogy postgresql sqlite3 )

def gem_for_database(database = options[:database])
case database
when "mysql" then ["mysql2", ["~> 0.5"]]
when "trilogy" then ["trilogy", ["~> 2.7"]]
when "postgresql" then ["pg", ["~> 1.1"]]
when "sqlite3" then ["sqlite3", [">= 1.4"]]
when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
when "jdbc" then ["activerecord-jdbc-adapter", nil]
else [database, nil]
end
end
Expand All @@ -47,18 +35,6 @@ def docker_for_database_build(database = options[:database])
end
end

def convert_database_option_for_jruby
if defined?(JRUBY_VERSION)
opt = options.dup
case opt[:database]
when "postgresql" then opt[:database] = "jdbcpostgresql"
when "mysql" then opt[:database] = "jdbcmysql"
when "sqlite3" then opt[:database] = "jdbcsqlite3"
end
self.options = opt.freeze
end
end

def base_package_for_database(database = options[:database])
case database
when "mysql" then "default-mysql-client"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def all_database_gems
end

def all_docker_bases
DATABASES.map { |database| docker_for_database_base(database).nil? ? nil : docker_for_database_base(database) }.compact!
DATABASES.filter_map { |database| docker_for_database_base(database) }
end

def all_docker_builds
DATABASES.map { |database| docker_for_database_build(database).nil? ? nil : docker_for_database_build(database) }.compact!
DATABASES.filter_map { |database| docker_for_database_build(database) }
end

def all_database_gems_regex
Expand Down
4 changes: 1 addition & 3 deletions railties/test/commands/db_system_change_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class Rails::Command::DbSystemChangeTest < ActiveSupport::TestCase
assert_match <<~MSG.squish, output
Invalid value for --to option.
Supported preconfigurations are:
mysql, trilogy, postgresql, sqlite3,
oracle, sqlserver, jdbcmysql,
jdbcsqlite3, jdbcpostgresql, jdbc.
mysql, trilogy, postgresql, sqlite3.
MSG
end

Expand Down
51 changes: 3 additions & 48 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,21 +477,13 @@ def test_gemfile_has_no_whitespace_errors
def test_config_database_is_added_by_default
run_generator
assert_file "config/database.yml", /sqlite3/
if defined?(JRUBY_VERSION)
assert_gem "activerecord-jdbcsqlite3-adapter"
else
assert_gem "sqlite3", '">= 1.4"'
end
assert_gem "sqlite3", '">= 1.4"'
end

def test_config_mysql_database
run_generator([destination_root, "-d", "mysql"])
assert_file "config/database.yml", /mysql/
if defined?(JRUBY_VERSION)
assert_gem "activerecord-jdbcmysql-adapter"
else
assert_gem "mysql2", '"~> 0.5"'
end
assert_gem "mysql2", '"~> 0.5"'
end

def test_config_database_app_name_with_period
Expand All @@ -502,44 +494,7 @@ def test_config_database_app_name_with_period
def test_config_postgresql_database
run_generator([destination_root, "-d", "postgresql"])
assert_file "config/database.yml", /postgresql/
if defined?(JRUBY_VERSION)
assert_gem "activerecord-jdbcpostgresql-adapter"
else
assert_gem "pg", '"~> 1.1"'
end
end

def test_config_jdbcmysql_database
run_generator([destination_root, "-d", "jdbcmysql"])
assert_file "config/database.yml", /mysql/
assert_gem "activerecord-jdbcmysql-adapter"
end

def test_config_jdbcsqlite3_database
run_generator([destination_root, "-d", "jdbcsqlite3"])
assert_file "config/database.yml", /sqlite3/
assert_gem "activerecord-jdbcsqlite3-adapter"
end

def test_config_jdbcpostgresql_database
run_generator([destination_root, "-d", "jdbcpostgresql"])
assert_file "config/database.yml", /postgresql/
assert_gem "activerecord-jdbcpostgresql-adapter"
end

def test_config_jdbc_database
run_generator([destination_root, "-d", "jdbc"])
assert_file "config/database.yml", /jdbc/
assert_file "config/database.yml", /mssql/
assert_gem "activerecord-jdbc-adapter"
end

if defined?(JRUBY_VERSION)
def test_config_jdbc_database_when_no_option_given
run_generator
assert_file "config/database.yml", /sqlite3/
assert_gem "activerecord-jdbcsqlite3-adapter"
end
assert_gem "pg", '"~> 1.1"'
end

def test_generator_defaults_to_puma_version
Expand Down
4 changes: 1 addition & 3 deletions railties/test/generators/db_system_change_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class ChangeGeneratorTest < Rails::Generators::TestCase
assert_match <<~MSG.squish, output
Invalid value for --to option.
Supported preconfigurations are:
mysql, trilogy, postgresql, sqlite3,
oracle, sqlserver, jdbcmysql,
jdbcsqlite3, jdbcpostgresql, jdbc.
mysql, trilogy, postgresql, sqlite3.
MSG
end

Expand Down
6 changes: 1 addition & 5 deletions railties/test/generators/plugin_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,7 @@ def test_no_development_dependencies_in_gemspec
def test_default_database_dependency_is_sqlite
run_generator
assert_file "test/dummy/config/database.yml", /sqlite/
if defined?(JRUBY_VERSION)
assert_gem "activerecord-jdbcsqlite3-adapter"
else
assert_gem "sqlite3"
end
assert_gem "sqlite3"
end

def test_custom_database_dependency
Expand Down

0 comments on commit 5b91084

Please sign in to comment.