theforeman / foreman_statistics

Foreman plugin to present statistics and trends
https://theforeman.org/plugins/foreman_statistics/
GNU General Public License v3.0
0 stars 6 forks source link

DB migrations are not loaded on the initial migration #46

Open ekohl opened 1 year ago

ekohl commented 1 year ago

When I use a fresh Foreman without a DB and the following bundler.d/statistics.local.rb file:

gem 'foreman_statistics', path: '/home/ekohl/dev/foreman_statistics'

What I see when I run db:migrate -> db:seed -> db:migrate:

$ bundle exec rake db:migrate
2022-12-13T16:44:08 [I|app|] Rails cache backend: File
.... LOTS OF MIGRATION OUTPUT HERE
== 20221025151600 AddCreatorIdToHosts: migrating ==============================
-- add_reference(:hosts, :creator, {:foreign_key=>{:to_table=>:users, :on_delete=>:nullify}})
   -> 0.0127s
== 20221025151600 AddCreatorIdToHosts: migrated (0.0129s) =====================

== 20221102134032 AddBiosToHostFacets: migrating ==============================
-- add_column(:host_facets_reported_data_facets, :bios_vendor, :string, {:limit=>255})
   -> 0.0067s
-- add_column(:host_facets_reported_data_facets, :bios_release_date, :string, {:limit=>255})
   -> 0.0012s
-- add_column(:host_facets_reported_data_facets, :bios_version, :string, {:limit=>255})
   -> 0.0012s
== 20221102134032 AddBiosToHostFacets: migrated (0.0096s) =====================
$ bundle exec rake db:seed
2022-12-13T16:44:18 [I|app|] Rails cache backend: File
2022-12-13T16:44:18 [W|app|] You are trying to replace import_subnets from . Adding allowed actions from plugin permissions to the existing one.
2022-12-13T16:44:18 [W|app|] DEPRECATION WARNING: You are using a deprecated behavior, it will be removed in version 3.3, initial value of setting 'instance_id' should be created in a migration (called from block in load_definitions at /home/ekohl/dev/foreman-plugins/foreman_statistics/app/services/setting_registry.rb:131)
2022-12-13T16:44:19 [D|app|] Slow initializers:
2022-12-13T16:44:19 [D|app|]     105.89  ./config/initializers/foreman_register.rb
2022-12-13T16:44:19 [W|app|] DEPRECATION WARNING: Initialization autoloaded the constants Net::Validations, SettingRegistry, HiddenValue, SettingPresenter, Foreman::Deprecation, SettingSelectCollection, MediumProviders, MediumProviders::Provider, MediumProviders::Default, and Foreman::TelemetryHelper.
 | 
 | Being able to do this is deprecated. Autoloading during initialization is going
 | to be an error condition in future versions of Rails.
 | 
 | Reloading does not reboot the application, and therefore code executed during
 | initialization does not run again. So, if you reload Net::Validations, for example,
 | the expected changes won't be reflected in that stale Module object.
 | 
 | `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
 | 
 | In order to autoload safely at boot time, please wrap your code in a reloader
 | callback this way:
 | 
 |     Rails.application.reloader.to_prepare do
 |       # Autoload classes and modules needed at boot time here.
 |     end
 | 
 | That block runs when the application boots, and every time there is a reload.
 | For historical reasons, it may run twice, so it has to be idempotent.
 | 
 | Check the "Autoloading and Reloading Constants" guide to learn more about how
 | Rails autoloads and reloads.
 |  (called from block in run at /home/ekohl/dev/foreman-plugins/foreman_statistics/config/initializers/0_print_time_spent.rb:45)
2022-12-13T16:44:19 [W|app|] DEPRECATION WARNING: You are using a deprecated behavior, it will be removed in version 3.3, initial value of setting 'instance_id' should be created in a migration (called from block in load_definitions at /home/ekohl/dev/foreman-plugins/foreman_statistics/app/services/setting_registry.rb:131)
You have 4 pending migrations:
  20121012170851 CreateTrends
  20121012170936 CreateTrendCounters
  20150202094307 AddRangeToTrendCounters
  20181031155025 AddTrendCounterCreatedAtUniqueConstraint
$  bundle exec rake db:migrate
2022-12-13T16:46:59 [I|app|] Rails cache backend: File
2022-12-13T16:46:59 [W|app|] You are trying to replace import_subnets from . Adding allowed actions from plugin permissions to the existing one.
2022-12-13T16:46:59 [W|app|] DEPRECATION WARNING: You are using a deprecated behavior, it will be removed in version 3.3, initial value of setting 'instance_id' should be created in a migration (called from block in load_definitions at /home/ekohl/dev/foreman-plugins/foreman_statistics/app/services/setting_registry.rb:131)
2022-12-13T16:46:59 [D|app|] Slow initializers:
2022-12-13T16:46:59 [D|app|]     178.25  ./config/initializers/foreman_register.rb
2022-12-13T16:46:59 [W|app|] DEPRECATION WARNING: Initialization autoloaded the constants Net::Validations, SettingRegistry, HiddenValue, SettingPresenter, Foreman::Deprecation, SettingSelectCollection, MediumProviders, MediumProviders::Provider, MediumProviders::Default, and Foreman::TelemetryHelper.
 | 
 | Being able to do this is deprecated. Autoloading during initialization is going
 | to be an error condition in future versions of Rails.
 | 
 | Reloading does not reboot the application, and therefore code executed during
 | initialization does not run again. So, if you reload Net::Validations, for example,
 | the expected changes won't be reflected in that stale Module object.
 | 
 | `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
 | 
 | In order to autoload safely at boot time, please wrap your code in a reloader
 | callback this way:
 | 
 |     Rails.application.reloader.to_prepare do
 |       # Autoload classes and modules needed at boot time here.
 |     end
 | 
 | That block runs when the application boots, and every time there is a reload.
 | For historical reasons, it may run twice, so it has to be idempotent.
 | 
 | Check the "Autoloading and Reloading Constants" guide to learn more about how
 | Rails autoloads and reloads.
 |  (called from block in run at /home/ekohl/dev/foreman-plugins/foreman_statistics/config/initializers/0_print_time_spent.rb:45)
== 20121012170851 CreateTrends: migrating =====================================
-- create_table(:trends, {})
   -> 0.0160s
-- add_index(:trends, :type)
   -> 0.0052s
-- add_index(:trends, [:trendable_type, :trendable_id])
   -> 0.0050s
-- add_index(:trends, :fact_value)
   -> 0.0054s
== 20121012170851 CreateTrends: migrated (0.0321s) ============================

== 20121012170936 CreateTrendCounters: migrating ==============================
-- create_table(:trend_counters, {})
   -> 0.0155s
== 20121012170936 CreateTrendCounters: migrated (0.0157s) =====================

== 20150202094307 AddRangeToTrendCounters: migrating ==========================
-- add_column(:trend_counters, :interval_start, :datetime)
   -> 0.0020s
-- add_column(:trend_counters, :interval_end, :datetime)
   -> 0.0010s
== 20150202094307 AddRangeToTrendCounters: migrated (0.0033s) =================

== 20181031155025 AddTrendCounterCreatedAtUniqueConstraint: migrating =========
-- add_index(:trend_counters, [:trend_id, :created_at], {:unique=>true})
   -> 0.0064s
== 20181031155025 AddTrendCounterCreatedAtUniqueConstraint: migrated (0.0067s) 

_Originally posted by @ekohl in https://github.com/theforeman/foreman_statistics/issues/44#issuecomment-1348857207_