2021-06-14 20:34:44 +05:30
# frozen_string_literal: true
def check_environment!
2023-01-09 12:10:19 +00:00
raise " Database commands are only supported in development environment " if ! Rails . env . development?
2021-06-14 20:34:44 +05:30
2023-01-09 12:10:19 +00:00
ENV [ " SKIP_TEST_DATABASE " ] = " 1 "
ENV [ " SKIP_MULTISITE " ] = " 1 "
2021-06-14 20:34:44 +05:30
end
2023-01-09 12:10:19 +00:00
desc " Run db:migrate:reset task and populate sample content for development environment "
task " dev:reset " = > [ " db:load_config " ] do | _ , args |
2021-06-14 20:34:44 +05:30
check_environment!
2023-01-09 12:10:19 +00:00
Rake :: Task [ " db:migrate:reset " ] . invoke
Rake :: Task [ " dev:config " ] . invoke
Rake :: Task [ " dev:populate " ] . invoke
2021-06-14 20:34:44 +05:30
end
2023-01-09 12:10:19 +00:00
desc " Initialize development environment "
task " dev:config " = > [ " db:load_config " ] do | _ , args |
2021-06-14 20:34:44 +05:30
DiscourseDev . config . update!
end
2023-01-09 12:10:19 +00:00
desc " Populate sample content for development environment "
task " dev:populate " = > [ " db:load_config " ] do | _ , args |
2021-06-14 20:34:44 +05:30
system ( " redis-cli flushall " )
2023-01-09 12:10:19 +00:00
Rake :: Task [ " groups:populate " ] . invoke
Rake :: Task [ " users:populate " ] . invoke
Rake :: Task [ " categories:populate " ] . invoke
Rake :: Task [ " tags:populate " ] . invoke
Rake :: Task [ " topics:populate " ] . invoke
2021-06-14 20:34:44 +05:30
end
2023-01-09 12:10:19 +00:00
desc " Repopulate sample datas in development environment "
task " dev:repopulate " = > [ " db:load_config " ] do | _ , args |
require " highline/import "
2021-06-14 20:34:44 +05:30
2023-01-09 12:10:19 +00:00
answer =
ask (
" Do you want to repopulate the database with fresh data? It will recreate DBs and run migration from scratch before generating all the samples. (Y/n) " ,
)
2021-06-14 20:34:44 +05:30
2023-01-09 12:10:19 +00:00
if ( answer == " " || answer . downcase == " y " )
Rake :: Task [ " dev:reset " ] . invoke
2021-06-14 20:34:44 +05:30
else
puts " You can run `bin/rails dev:reset` to repopulate anytime. "
end
end