Use storage/ instead of db/ for sqlite3 db files (#46699)
* Use storage/ instead of db/ for sqlite3 db files db/ should be for configuration only, not data. This will make it easier to mount a single volume into a container for testing, development, and even sqlite3 in production.
This commit is contained in:
parent
16eaf44b5a
commit
d18fc32999
@ -11,15 +11,15 @@ default: &default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
|
@ -11,15 +11,15 @@ default: &default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
|
@ -697,7 +697,7 @@
|
||||
```yaml
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
foreign_keys: false
|
||||
```
|
||||
|
||||
|
@ -272,7 +272,7 @@ def primary_class? # :nodoc:
|
||||
#
|
||||
# ActiveRecord::Base.connection_db_config
|
||||
# #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
||||
# @name="primary", @config={pool: 5, timeout: 5000, database: "db/development.sqlite3", adapter: "sqlite3"}>
|
||||
# @name="primary", @config={pool: 5, timeout: 5000, database: "storage/development.sqlite3", adapter: "sqlite3"}>
|
||||
#
|
||||
# Use only for reading.
|
||||
def connection_db_config
|
||||
|
@ -53,19 +53,19 @@ def self.destroy_association_async_job
|
||||
#
|
||||
# development:
|
||||
# adapter: sqlite3
|
||||
# database: db/development.sqlite3
|
||||
# database: storage/development.sqlite3
|
||||
#
|
||||
# production:
|
||||
# adapter: sqlite3
|
||||
# database: db/production.sqlite3
|
||||
# database: storage/production.sqlite3
|
||||
#
|
||||
# ...would result in ActiveRecord::Base.configurations to look like this:
|
||||
#
|
||||
# #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
||||
# #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
||||
# @name="primary", @config={adapter: "sqlite3", database: "db/development.sqlite3"}>,
|
||||
# @name="primary", @config={adapter: "sqlite3", database: "storage/development.sqlite3"}>,
|
||||
# #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90 @env_name="production",
|
||||
# @name="primary", @config={adapter: "sqlite3", database: "db/production.sqlite3"}>
|
||||
# @name="primary", @config={adapter: "sqlite3", database: "storage/production.sqlite3"}>
|
||||
# ]>
|
||||
def self.configurations=(config)
|
||||
@@configurations = ActiveRecord::DatabaseConfigurations.new(config)
|
||||
|
@ -204,13 +204,13 @@ def test_symbolized_configurations_assignment
|
||||
development: {
|
||||
primary: {
|
||||
adapter: "sqlite3",
|
||||
database: "test/db/development.sqlite3",
|
||||
database: "test/storage/development.sqlite3",
|
||||
},
|
||||
},
|
||||
test: {
|
||||
primary: {
|
||||
adapter: "sqlite3",
|
||||
database: "test/db/test.sqlite3",
|
||||
database: "test/storage/test.sqlite3",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ def test_do_not_dump_foreign_keys_when_bypassed_by_config
|
||||
ActiveRecord::Base.establish_connection(
|
||||
{
|
||||
adapter: "sqlite3",
|
||||
database: "test/db/test.sqlite3",
|
||||
database: "test/storage/test.sqlite3",
|
||||
foreign_keys: false,
|
||||
}
|
||||
)
|
||||
|
@ -2772,7 +2772,7 @@ Here's the section of the default configuration file (`config/database.yml`) wit
|
||||
```yaml
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
```
|
||||
@ -2844,7 +2844,7 @@ If you choose to use SQLite3 and are using JRuby, your `config/database.yml` wil
|
||||
```yaml
|
||||
development:
|
||||
adapter: jdbcsqlite3
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
```
|
||||
|
||||
#### Configuring a MySQL or MariaDB Database for JRuby Platform
|
||||
@ -3198,7 +3198,7 @@ Active Record database connections are managed by `ActiveRecord::ConnectionAdapt
|
||||
```ruby
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
```
|
||||
|
@ -1,3 +1,9 @@
|
||||
* Always generate the storage/ directory with rails new to ensure there's a stable place to
|
||||
put permanent files, and a single mount point for containers to map. Then default sqlite3 databases
|
||||
to live there instead of db/, which is only meant for configuration, not data.
|
||||
|
||||
*DHH*
|
||||
|
||||
* Rails console now disables `IRB`'s autocompletion feature in production by default.
|
||||
|
||||
Setting `IRB_USE_AUTOCOMPLETE=true` can override this default.
|
||||
|
@ -406,7 +406,7 @@ def create_system_test_files
|
||||
end
|
||||
|
||||
def create_storage_files
|
||||
build(:storage) unless skip_active_storage?
|
||||
build(:storage)
|
||||
end
|
||||
|
||||
def delete_app_assets_if_api_option
|
||||
|
@ -10,15 +10,15 @@ default: &default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
|
@ -11,15 +11,15 @@ default: &default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
|
@ -7,12 +7,6 @@
|
||||
# Ignore bundler config.
|
||||
/.bundle
|
||||
|
||||
<% if sqlite3? -%>
|
||||
# Ignore the default SQLite database.
|
||||
/db/*.sqlite3
|
||||
/db/*.sqlite3-*
|
||||
|
||||
<% end -%>
|
||||
# Ignore all logfiles and tempfiles.
|
||||
/log/*
|
||||
/tmp/*
|
||||
@ -26,8 +20,7 @@
|
||||
!/tmp/pids/.keep
|
||||
<% end -%>
|
||||
|
||||
<% unless skip_active_storage? -%>
|
||||
# Ignore uploaded files in development.
|
||||
# Ignore storage (uploaded files in development and any SQLite databases).
|
||||
/storage/*
|
||||
<% if keeps? -%>
|
||||
!/storage/.keep
|
||||
@ -35,7 +28,6 @@
|
||||
!/tmp/storage/
|
||||
!/tmp/storage/.keep
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% unless options.api? -%>
|
||||
|
||||
/public/assets
|
||||
|
@ -9,8 +9,6 @@
|
||||
/<%= dummy_path %>/db/*.sqlite3-*
|
||||
<% end -%>
|
||||
/<%= dummy_path %>/log/*.log
|
||||
<% unless skip_active_storage? -%>
|
||||
/<%= dummy_path %>/storage/
|
||||
<% end -%>
|
||||
/<%= dummy_path %>/tmp/
|
||||
<% end -%>
|
||||
|
@ -29,7 +29,7 @@ def test_use_value_defined_in_environment_file_in_database_yml
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
@ -49,11 +49,11 @@ def test_respect_environment_option
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
YAML
|
||||
|
||||
primary, replica = PTY.open
|
||||
|
@ -43,10 +43,10 @@ def test_migrations_paths_takes_first
|
||||
development:
|
||||
primary:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
animals:
|
||||
<<: *default
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
migrations_paths:
|
||||
- db/animals_migrate
|
||||
- db/common
|
||||
|
@ -59,17 +59,17 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
File.write("#{app_path}/config/database.yml", <<~YAML)
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
YAML
|
||||
|
||||
with_rails_env "development" do
|
||||
db_create_and_drop database_url_db_name do
|
||||
assert_not File.exist?("#{app_path}/db/test.sqlite3")
|
||||
assert_not File.exist?("#{app_path}/db/development.sqlite3")
|
||||
assert_not File.exist?("#{app_path}/storage/test.sqlite3")
|
||||
assert_not File.exist?("#{app_path}/storage/development.sqlite3")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -84,18 +84,18 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML with alias ERB" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
sqlite: &sqlite
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
|
||||
development:
|
||||
<<: *<%= ENV["DB"] || "sqlite" %>
|
||||
@ -103,11 +103,11 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML with multiline ERB" do
|
||||
@ -121,17 +121,17 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading ERB accessing nested configurations" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
adapter: sqlite3
|
||||
other: <%= Rails.application.config.other.value %>
|
||||
YAML
|
||||
@ -142,7 +142,7 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML containing conditional statements in ERB" do
|
||||
@ -158,11 +158,11 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML containing multiple ERB statements on the same line" do
|
||||
@ -174,44 +174,44 @@ def db_create_and_drop(expected_database, environment_loaded: true)
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML with single-line ERB" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
<%= Rails.application.config.database ? 'database: db/development.sqlite3' : 'database: db/development.sqlite3' %>
|
||||
<%= Rails.application.config.database ? 'database: storage/development.sqlite3' : 'database: storage/development.sqlite3' %>
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML which contains a key's value as an ERB statement" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
database: <%= Rails.application.config.database ? 'db/development.sqlite3' : 'db/development.sqlite3' %>
|
||||
database: <%= Rails.application.config.database ? 'storage/development.sqlite3' : 'storage/development.sqlite3' %>
|
||||
custom_option: <%= ENV['CUSTOM_OPTION'] %>
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
|
||||
db_create_and_drop("storage/development.sqlite3", environment_loaded: false)
|
||||
end
|
||||
|
||||
def with_database_existing
|
||||
@ -430,7 +430,7 @@ def db_schema_cache_dump
|
||||
statement_timeout: 1000
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
schema_cache_path: db/special_schema_cache.yml
|
||||
YAML
|
||||
end
|
||||
@ -464,7 +464,7 @@ def db_schema_cache_dump
|
||||
development:
|
||||
some_entry:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
another_entry:
|
||||
<<: *default
|
||||
database: db/another_entry_development.sqlite3
|
||||
|
@ -834,8 +834,8 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
rails("db:migrate")
|
||||
output = rails("db:version")
|
||||
|
||||
assert_match(/database: db\/development.sqlite3\nCurrent version: #{primary_version}/, output)
|
||||
assert_match(/database: db\/development_animals.sqlite3\nCurrent version: #{animals_version}/, output)
|
||||
assert_match(/database: storage\/development.sqlite3\nCurrent version: #{primary_version}/, output)
|
||||
assert_match(/database: storage\/development_animals.sqlite3\nCurrent version: #{animals_version}/, output)
|
||||
end
|
||||
end
|
||||
|
||||
@ -940,7 +940,7 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
RUBY
|
||||
|
||||
output = rails("db:seed")
|
||||
assert_equal output, "db/development.sqlite3"
|
||||
assert_equal output, "storage/development.sqlite3"
|
||||
ensure
|
||||
ENV["RAILS_ENV"] = @old_rails_env
|
||||
ENV["RACK_ENV"] = @old_rack_env
|
||||
@ -955,17 +955,17 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
%>
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop_namespace("primary", "db/development.sqlite3")
|
||||
db_create_and_drop_namespace("primary", "storage/development.sqlite3")
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML containing conditional statements in ERB" do
|
||||
@ -975,22 +975,22 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
<% if Rails.application.config.database %>
|
||||
database: <%= Rails.application.config.database %>
|
||||
<% else %>
|
||||
database: db/default.sqlite3
|
||||
database: storage/default.sqlite3
|
||||
<% end %>
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop_namespace("primary", "db/development.sqlite3")
|
||||
db_create_and_drop_namespace("primary", "storage/development.sqlite3")
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML containing ERB in database keys" do
|
||||
@ -998,12 +998,12 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
development:
|
||||
<% 5.times do |i| %>
|
||||
shard_<%= i %>:
|
||||
database: db/development_shard_<%= i %>.sqlite3
|
||||
database: storage/development_shard_<%= i %>.sqlite3
|
||||
adapter: sqlite3
|
||||
<% end %>
|
||||
YAML
|
||||
|
||||
db_create_and_drop_namespace("shard_3", "db/development_shard_3.sqlite3")
|
||||
db_create_and_drop_namespace("shard_3", "storage/development_shard_3.sqlite3")
|
||||
end
|
||||
|
||||
test "schema generation when dump_schema_after_migration is true schema_dump is false" do
|
||||
@ -1137,71 +1137,71 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
primary:
|
||||
database: <% if Rails.application.config.database %><%= Rails.application.config.database %><% else %>db/default.sqlite3<% end %>
|
||||
database: <% if Rails.application.config.database %><%= Rails.application.config.database %><% else %>storage/default.sqlite3<% end %>
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop_namespace("primary", "db/development.sqlite3")
|
||||
db_create_and_drop_namespace("primary", "storage/development.sqlite3")
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML with single-line ERB" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
primary:
|
||||
<%= Rails.application.config.database ? 'database: db/development.sqlite3' : 'database: db/development.sqlite3' %>
|
||||
<%= Rails.application.config.database ? 'database: storage/development.sqlite3' : 'database: storage/development.sqlite3' %>
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop_namespace("primary", "db/development.sqlite3")
|
||||
db_create_and_drop_namespace("primary", "storage/development.sqlite3")
|
||||
end
|
||||
|
||||
test "db:create and db:drop don't raise errors when loading YAML which contains a key's value as an ERB statement" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
primary:
|
||||
database: <%= Rails.application.config.database ? 'db/development.sqlite3' : 'db/development.sqlite3' %>
|
||||
database: <%= Rails.application.config.database ? 'storage/development.sqlite3' : 'storage/development.sqlite3' %>
|
||||
custom_option: <%= ENV['CUSTOM_OPTION'] %>
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
YAML
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
config.database = "db/development.sqlite3"
|
||||
config.database = "storage/development.sqlite3"
|
||||
end
|
||||
RUBY
|
||||
|
||||
db_create_and_drop_namespace("primary", "db/development.sqlite3")
|
||||
db_create_and_drop_namespace("primary", "storage/development.sqlite3")
|
||||
end
|
||||
|
||||
test "when there is no primary config, the first is chosen as the default" do
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
default:
|
||||
database: db/default.sqlite3
|
||||
database: storage/default.sqlite3
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
YAML
|
||||
@ -1214,10 +1214,10 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
primary:
|
||||
database: db/default.sqlite3
|
||||
database: storage/default.sqlite3
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
database_tasks: false
|
||||
schema_dump: true ### database_tasks should override all sub-settings
|
||||
@ -1268,18 +1268,18 @@ class TwoMigration < ActiveRecord::Migration::Current
|
||||
app_file "config/database.yml", <<-YAML
|
||||
development:
|
||||
primary:
|
||||
database: db/default.sqlite3
|
||||
database: storage/default.sqlite3
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
test:
|
||||
primary:
|
||||
database: db/default_test.sqlite3
|
||||
database: storage/default_test.sqlite3
|
||||
adapter: sqlite3
|
||||
animals:
|
||||
database: db/test_animals.sqlite3
|
||||
database: storage/test_animals.sqlite3
|
||||
adapter: sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
YAML
|
||||
|
@ -64,7 +64,7 @@ class ChangeGeneratorTest < Rails::Generators::TestCase
|
||||
|
||||
assert_file("config/database.yml") do |content|
|
||||
assert_match "adapter: sqlite3", content
|
||||
assert_match "db/development.sqlite3", content
|
||||
assert_match "storage/development.sqlite3", content
|
||||
end
|
||||
|
||||
assert_file("Gemfile") do |content|
|
||||
|
@ -174,22 +174,6 @@ def test_generator_without_skips
|
||||
end
|
||||
end
|
||||
|
||||
def test_gitignore_when_sqlite3
|
||||
run_generator
|
||||
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_match(/sqlite3/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_gitignore_when_non_sqlite3_db
|
||||
run_generator([destination_root, "-d", "mysql"])
|
||||
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_no_match(/sqlite/i, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_if_skip_active_record_is_given
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_no_directory "#{application_path}/db/"
|
||||
@ -202,9 +186,6 @@ def test_generator_if_skip_active_record_is_given
|
||||
assert_file "#{application_path}/bin/setup" do |setup_content|
|
||||
assert_no_match(/db:prepare/, setup_content)
|
||||
end
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_no_match(/sqlite/i, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_for_active_storage
|
||||
@ -225,10 +206,6 @@ def test_generator_for_active_storage
|
||||
assert_file "#{application_path}/config/storage.yml"
|
||||
assert_directory "#{application_path}/storage"
|
||||
assert_directory "#{application_path}/tmp/storage"
|
||||
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_match(/\/storage\//, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_if_skip_active_storage_is_given
|
||||
@ -249,12 +226,6 @@ def test_generator_if_skip_active_storage_is_given
|
||||
end
|
||||
|
||||
assert_no_file "#{application_path}/config/storage.yml"
|
||||
assert_no_directory "#{application_path}/storage"
|
||||
assert_no_directory "#{application_path}/tmp/storage"
|
||||
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_no_match(/\/storage\//, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_does_not_generate_active_storage_contents_if_skip_active_record_is_given
|
||||
@ -275,12 +246,6 @@ def test_generator_does_not_generate_active_storage_contents_if_skip_active_reco
|
||||
end
|
||||
|
||||
assert_no_file "#{application_path}/config/storage.yml"
|
||||
assert_no_directory "#{application_path}/storage"
|
||||
assert_no_directory "#{application_path}/tmp/storage"
|
||||
|
||||
assert_file ".gitignore" do |content|
|
||||
assert_no_match(/\/storage\//, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generator_if_skip_action_mailer_is_given
|
||||
|
@ -155,13 +155,13 @@ def default_database_configs
|
||||
timeout: 5000
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
YAML
|
||||
end
|
||||
|
||||
@ -176,52 +176,52 @@ def multi_db_database_configs
|
||||
development:
|
||||
primary:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
primary_readonly:
|
||||
<<: *default
|
||||
database: db/development.sqlite3
|
||||
database: storage/development.sqlite3
|
||||
replica: true
|
||||
animals:
|
||||
<<: *default
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
animals_readonly:
|
||||
<<: *default
|
||||
database: db/development_animals.sqlite3
|
||||
database: storage/development_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
replica: true
|
||||
test:
|
||||
primary:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
primary_readonly:
|
||||
<<: *default
|
||||
database: db/test.sqlite3
|
||||
database: storage/test.sqlite3
|
||||
replica: true
|
||||
animals:
|
||||
<<: *default
|
||||
database: db/test_animals.sqlite3
|
||||
database: storage/test_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
animals_readonly:
|
||||
<<: *default
|
||||
database: db/test_animals.sqlite3
|
||||
database: storage/test_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
replica: true
|
||||
production:
|
||||
primary:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
primary_readonly:
|
||||
<<: *default
|
||||
database: db/production.sqlite3
|
||||
database: storage/production.sqlite3
|
||||
replica: true
|
||||
animals:
|
||||
<<: *default
|
||||
database: db/production_animals.sqlite3
|
||||
database: storage/production_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
animals_readonly:
|
||||
<<: *default
|
||||
database: db/production_animals.sqlite3
|
||||
database: storage/production_animals.sqlite3
|
||||
migrations_paths: db/animals_migrate
|
||||
replica: true
|
||||
YAML
|
||||
|
Loading…
Reference in New Issue
Block a user