iachat/lib/tasks/db_enhancements.rake
Rodribm10 fc2663be2c feat(captain): tabelas de preço corrigidas + sync automático em deploy
- Express: adiciona Singles/Família/Singles Duplo, Master qui-dom 5h, diárias preço único
- Qnn01: renomeia Master→Luxo, remove Pole Dance e 12h, Hidromassagem preço único
- PrimeAL/PrimeVL: estrutura seg-qua + qui-dom, Pernoite Especial Prime, hora excedente
- Adiciona docs/precos/ com tabelas oficiais por marca pra consulta humana
- Implementa rake task captain:sync_prompts lendo de _modelos/
- Liga a task no chatwoot_prepare → sync automático em todo deploy

Refs ROD-14 (Captain Review 2026-04-25)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 10:31:55 -03:00

34 lines
1.6 KiB
Ruby

# We are hooking config loader to run automatically everytime migration is executed
Rake::Task['db:migrate'].enhance do
if ActiveRecord::Base.connection.table_exists? 'installation_configs'
puts 'Loading Installation config'
ConfigLoader.new.process
end
end
# we are creating a custom database prepare task
# the default rake db:prepare task isn't ideal for environments like heroku
# In heroku the database is already created before the first run of db:prepare
# In this case rake db:prepare tries to run db:migrate from all the way back from the beginning
# Since the assumption is migrations are only run after schema load from a point x, this could lead to things breaking.
# ref: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/railties/databases.rake#L356
db_namespace = namespace :db do
desc 'Runs setup if database does not exist, or runs migrations if it does'
task chatwoot_prepare: :load_config do
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config.configuration_hash)
unless ActiveRecord::Base.connection.table_exists? 'ar_internal_metadata'
db_namespace['load_config'].invoke if ActiveRecord.schema_format == :ruby
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV.fetch('SCHEMA', nil))
db_namespace['seed'].invoke
end
db_namespace['migrate'].invoke
rescue ActiveRecord::NoDatabaseError
db_namespace['setup'].invoke
end
Rake::Task['captain:sync_prompts'].invoke if Rake::Task.task_defined?('captain:sync_prompts')
end
end