Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master

- Fix test suite compatibility with Rails main (pglite shims). ([@MattyMc](https://github.com/MattyMc))

## 2.1.1 (2026-01-13)

- Fix defining store attributes after schema loading. ([@palkan][])
Expand Down
35 changes: 35 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,41 @@
ActiveRecord::Base.yaml_column_permitted_classes << Date
end

# pglite 0.1.1 is missing the connection methods that the latest Rails
# calls (close, finished?, status), and it answers nil when Rails asks
# parameter_status for the time zone. Getting no answer, Rails sets the
# session time zone itself, and the wasm build cannot survive that
# statement. It looks like it ships without time zone data, so any time
# zone SET kills the instance for good. Answering "UTC" here means Rails
# never sends it.
#
# The patch is pinned to this exact gem version so it retires itself on
# the next pglite release. It also has to run before the first database
# access. The support files connect at load time further down this file.
if Gem::Version.new(PGlite::VERSION) <= Gem::Version.new("0.1.1")
# Rails main compares status to PG::CONNECTION_OK, a constant the pglite
# PG stub does not define. The real libpq value is 0.
PG.const_set(:CONNECTION_OK, 0) unless defined?(PG::CONNECTION_OK)

module PGliteRailsMainCompat
def close = nil

def finished? = false

def status = PG::CONNECTION_OK

def parameter_status(name)
# We cannot ask the embedded server for its time zone because that
# query also crashes it. Assume the wasm default of GMT, same as UTC.
return "UTC" if name.to_s.casecmp?("timezone")

super
end
end

PGlite::Connection.prepend(PGliteRailsMainCompat)
end

PGlite.install!(File.expand_path(File.join(__dir__, "../tmp/pglite")))

ActiveRecord::Base.establish_connection(
Expand Down