Migrate default intervalstyle in database
By switching the `intervalstyle`, we assume to fix CODEOCEAN-FT. It is caused by by PgBouncer providing different database connections to Rails that might behave differently.
This commit is contained in:
@ -50,6 +50,7 @@ In order to execute code submissions using the [DockerContainerPool](https://git
|
|||||||
|
|
||||||
- We recommend using [Capistrano](https://capistranorb.com/) for deployment.
|
- We recommend using [Capistrano](https://capistranorb.com/) for deployment.
|
||||||
- Once deployed, CodeOcean assumes to run exclusively under a (sub)domain. If you want to use it under a custom subpath, you can specify the desired path using an environment variable: `RAILS_RELATIVE_URL_ROOT=/codeocean`. Please ensure to rebuild all assets and restart the server to apply the new path.
|
- Once deployed, CodeOcean assumes to run exclusively under a (sub)domain. If you want to use it under a custom subpath, you can specify the desired path using an environment variable: `RAILS_RELATIVE_URL_ROOT=/codeocean`. Please ensure to rebuild all assets and restart the server to apply the new path.
|
||||||
|
- When using [PgBouncer](https://www.pgbouncer.org), please make sure to correctly set the `intervalstyle` to `iso_8601` for the database. Otherwise, the application will not be able to parse timestamps correctly. See [a similar issue here](https://gitlab.com/gitlab-org/gitlab/-/issues/349912) and [our migration](./db/migrate/20221206221333_set_database_interval_style.rb) for more details.
|
||||||
|
|
||||||
## Monitoring
|
## Monitoring
|
||||||
- We use a [Prometheus Exporter](https://github.com/discourse/prometheus_exporter) and a [Telegraf Client](https://github.com/jgraichen/telegraf-ruby)
|
- We use a [Prometheus Exporter](https://github.com/discourse/prometheus_exporter) and a [Telegraf Client](https://github.com/jgraichen/telegraf-ruby)
|
||||||
|
27
db/migrate/20221206221333_set_database_interval_style.rb
Normal file
27
db/migrate/20221206221333_set_database_interval_style.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SetDatabaseIntervalStyle < ActiveRecord::Migration[7.0]
|
||||||
|
# We set the intervalstyle to ISO 8601 for the current database.
|
||||||
|
# Without this change, a transaction-based PgBouncer might cause
|
||||||
|
# issues with when switching between different sessions (e.g., by
|
||||||
|
# returning intervals in the default intervalstyle).
|
||||||
|
|
||||||
|
def change
|
||||||
|
connection = ActiveRecord::Base.connection
|
||||||
|
dbname = connection.current_database
|
||||||
|
|
||||||
|
reversible do |dir|
|
||||||
|
dir.up do
|
||||||
|
execute <<~SQL.squish
|
||||||
|
ALTER DATABASE "#{dbname}" SET intervalstyle = 'iso_8601';
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
dir.down do
|
||||||
|
execute <<~SQL.squish
|
||||||
|
ALTER DATABASE "#{dbname}" SET intervalstyle = 'postgres';
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2022_12_04_120508) do
|
ActiveRecord::Schema[7.0].define(version: 2022_12_06_221333) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
|
@ -22,6 +22,10 @@ end
|
|||||||
Rails.application.eager_load!
|
Rails.application.eager_load!
|
||||||
(ApplicationRecord.descendants - [ActiveRecord::SchemaMigration, User]).each(&:delete_all)
|
(ApplicationRecord.descendants - [ActiveRecord::SchemaMigration, User]).each(&:delete_all)
|
||||||
|
|
||||||
|
# Set the default intervalstyle to iso_8601
|
||||||
|
dbname = ApplicationRecord.connection.current_database
|
||||||
|
ApplicationRecord.connection.exec_query("ALTER DATABASE \"#{dbname}\" SET intervalstyle = 'iso_8601';")
|
||||||
|
|
||||||
# delete file uploads
|
# delete file uploads
|
||||||
FileUtils.rm_rf(Rails.public_path.join('uploads'))
|
FileUtils.rm_rf(Rails.public_path.join('uploads'))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user