Content
View differences
Updated by Oliver Günther over 3 years ago
### Steps to reproduce
_Installation of OpenProject from source (in this case for the Cloudron package) with a nulldb. For example:_ `_DATABASE_URL="nulldb://foo" rails c_` for mysql or any non postgres active record adapter._
### What is the buggy behavior?
_When running \`rake assets:precompile\` it will try to load config/initializers/postgresql\_timestamp.rb which will fail with:_
```text
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz
^^^^^^^^^^^^^^^^^^^
/app/code/config/initializers/postgresql_timestamp.rb:2:in `<top (required)>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:667:in `load'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:667:in `block in load_config_initializer'
/app/code/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/notifications.rb:208:in `instrument'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:666:in `load_config_initializer'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:619:in `each'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:619:in `block in <class:Engine>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `instance_exec'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `run'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:50:in `each'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:50:in `tsort_each_child'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:60:in `run_initializers'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:372:in `initialize!'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/railtie.rb:226:in `public_send'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/railtie.rb:226:in `method_missing'
/app/code/config/environment.rb:32:in `<top (required)>'
/app/code/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/app/code/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:348:in `require_environment!'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:511:in `block in run_tasks_blocks'
/app/code/vendor/bundle/ruby/3.1.0/gems/sentry-ruby-5.4.2/lib/sentry/rake.rb:24:in `execute'
Tasks: TOP => assets:precompile => assets:compile_environment => assets:prepare_op => assets:export_locales => i18n:js:export => environment
(See full trace by running task with --trace)
```
### What is the expected behavior?
To succeed
### Environment information
_Please check and fill out the following details to help us identify in what versions and distributions of OpenProject the error occurs_
**OpenProject installation type**
* [ ] Hosted cloud edition
* [ ] Packaged installation
* What distribution?
* [ ] Docker All-in-one container
* [ ] Docker-compose installation
* [x] Other (Cloudron package building)
**OpenProject version**
v12.3.1
## Solution
After debugging this, it seems the file [https://github.com/opf/openproject/blob/dev/config/initializers/postgresql\_timestamp.rb](https://github.com/opf/openproject/blob/dev/config/initializers/postgresql_timestamp.rb) should either not be sourced at all for non postgres configs or in our case changing it to the following fixed things:
```ruby
# Use timestampz to create new timestamp columns, so that we get WITH TIME ZONE support
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz
end
```
_Installation of OpenProject from source (in this case for the Cloudron package) with a nulldb. For example:_ `_DATABASE_URL="nulldb://foo" rails c_`
### What is the buggy behavior?
_When running \`rake assets:precompile\` it will try to load config/initializers/postgresql\_timestamp.rb which will fail with:_
```text
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz
^^^^^^^^^^^^^^^^^^^
/app/code/config/initializers/postgresql_timestamp.rb:2:in `<top (required)>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:667:in `load'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:667:in `block in load_config_initializer'
/app/code/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/notifications.rb:208:in `instrument'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:666:in `load_config_initializer'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:619:in `each'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/engine.rb:619:in `block in <class:Engine>'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `instance_exec'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `run'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:50:in `each'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:50:in `tsort_each_child'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:60:in `run_initializers'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:372:in `initialize!'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/railtie.rb:226:in `public_send'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/railtie.rb:226:in `method_missing'
/app/code/config/environment.rb:32:in `<top (required)>'
/app/code/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/app/code/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:348:in `require_environment!'
/app/code/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:511:in `block in run_tasks_blocks'
/app/code/vendor/bundle/ruby/3.1.0/gems/sentry-ruby-5.4.2/lib/sentry/rake.rb:24:in `execute'
Tasks: TOP => assets:precompile => assets:compile_environment => assets:prepare_op => assets:export_locales => i18n:js:export => environment
(See full trace by running task with --trace)
```
### What is the expected behavior?
To succeed
### Environment information
_Please check and fill out the following details to help us identify in what versions and distributions of OpenProject the error occurs_
**OpenProject installation type**
* [ ] Hosted cloud edition
* [ ] Packaged installation
* What distribution?
* [ ] Docker All-in-one container
* [ ] Docker-compose installation
* [x] Other (Cloudron package building)
**OpenProject version**
v12.3.1
## Solution
After debugging this, it seems the file [https://github.com/opf/openproject/blob/dev/config/initializers/postgresql\_timestamp.rb](https://github.com/opf/openproject/blob/dev/config/initializers/postgresql_timestamp.rb) should either not be sourced at all for non postgres configs or in our case changing it to the following fixed things:
```ruby
# Use timestampz to create new timestamp columns, so that we get WITH TIME ZONE support
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz
end
```