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:
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
|
Reference in New Issue
Block a user