Until now, running `db:dev_seed` created development data for the default tenant but it was impossible to create this data for other tenants. Now the tenant can be provided as a parameter. Note that, in order to be able to execute this task twice while running the tests, we need to use `load` instead of `require_relative`, since `require_relative` doesn't load the file again if it's already loaded. Also note that having two optional parameters in a rake task results in a cumbersome syntax to execute it. To avoid this, we're simply removing the `print_log` parameter, which was used mainly for the test environment. Now we use a different logic to get the same result. From now on it won't be possible to pass the option to avoid the log in the development environment. I don't know a developer who's ever used this option, though, and it can always be done using `> /dev/null`.
45 lines
1.5 KiB
Ruby
45 lines
1.5 KiB
Ruby
namespace :db do
|
|
desc "Resets the database and loads it from db/dev_seeds.rb"
|
|
task :dev_seed, [:tenant] => [:environment] do |_, args|
|
|
I18n.enforce_available_locales = false
|
|
Tenant.switch(args[:tenant]) { load(Rails.root.join("db", "dev_seeds.rb")) }
|
|
end
|
|
|
|
desc "Calculates the TSV column for all comments and proposal notifications"
|
|
task calculate_tsv: :environment do
|
|
logger = ApplicationLogger.new
|
|
|
|
logger.info "Calculating tsvector for comments"
|
|
Comment.with_hidden.find_each(&:calculate_tsvector)
|
|
|
|
logger.info "Calculating tsvector for proposal notifications"
|
|
ProposalNotification.with_hidden.find_each(&:calculate_tsvector)
|
|
end
|
|
|
|
desc "Adds shared extensions to the schema search path in the database.yml file"
|
|
task add_schema_search_path: :environment do
|
|
logger = ApplicationLogger.new
|
|
logger.info "Adding search path to config/database.yml"
|
|
|
|
config = Rails.application.config.paths["config/database"].first
|
|
lines = File.readlines(config)
|
|
changes_done = false
|
|
|
|
adapter_indices = lines.map.with_index do |line, index|
|
|
index if line.start_with?(" adapter: postgresql")
|
|
end.compact
|
|
|
|
adapter_indices.reverse_each do |index|
|
|
unless lines[index + 1]&.match?("schema_search_path")
|
|
lines.insert(index + 1, " schema_search_path: \"public,shared_extensions\"\n")
|
|
changes_done = true
|
|
end
|
|
end
|
|
|
|
if changes_done
|
|
File.write(config, lines.join)
|
|
logger.warn "The database search path has been updated. Restart the application to apply the changes."
|
|
end
|
|
end
|
|
end
|