Enables schema.rb compatibility for the que job queue gem. With this gem, you can use Rails' default :ruby schema format instead of being forced to structure.sql.
Que's migrations create PostgreSQL-specific objects (PL/pgSQL functions, triggers, UNLOGGED tables, storage options) that ActiveRecord's schema dumper doesn't represent in schema.rb by default. Apps using Que have typically had to set config.active_record.schema_format = :sql and maintain structure.sql. This gem patches the schema dump/load pipeline so all of Que's constructs round-trip through schema.rb with zero changes to your existing Que migrations.
Add to your Gemfile:
gem "que-schema"No configuration required. Keep using schema.rb (the default). If you were on structure.sql only for Que, you can switch back to :ruby and run db:schema:dump; the dump will include Que's schema via custom DSL calls.
- Dump: The gem prepends into
ActiveRecord::SchemaDumper. When it sees theque_jobstable (and reads the Que schema version from the table comment), it emitsque_define_schema(version: N)after table definitions (tables must exist first because Que's functions reference thepublic.que_jobstype). Anyque_*table detected as UNLOGGED viapg_classis written asque_create_unlogged_tableinstead ofcreate_table. GIN indexes onque_*tables are detected dynamically and suppressed from the normal table dumps (they are recreated byque_define_schema). Fillfactor settings onque_*tables are also suppressed. - Load:
db:schema:loadruns yourschema.rb. The gem addsque_define_schema(version:)andque_create_unlogged_tableto the schema context.que_define_schemaruns the stored SQL for that version (functions, triggers, indexes, fillfactor, table comment).que_create_unlogged_tableis implemented ascreate_table+ALTER TABLE ... SET UNLOGGED.
No monkey-patching of Que; everything is done by extending ActiveRecord.
- Que migration version 7 is supported (current).
Support for older migration versions (e.g. 5, 6) can be added later by adding SQL assets under lib/que_schema/sql/v5, etc.
- Rails 6.0+
- PostgreSQL (Que is PostgreSQL-only)
- Ruby >= 2.7
- PostgreSQL only. The gem does nothing on SQLite/MySQL; it only runs when the adapter is PostgreSQL.
- UNLOGGED table:
que_lockersis created as UNLOGGED. If you rundb:schema:loadagainst a non-PostgreSQL database, that call would fail (expected).
Uses RSpec. Requires a running PostgreSQL. The test database (que_schema_test) is created automatically if it doesn't exist.
bundle install
bundle exec rakeYou can set DATABASE_URL to point to a different PostgreSQL instance:
export DATABASE_URL=postgresql://user:pass@host:5432/que_schema_test
bundle exec rake- Add a directory
lib/que_schema/sql/v<N>/withfunctions.sql,triggers.sql, and optionallydown.sql. - Copy the exact
CREATE FUNCTION/CREATE TRIGGERSQL from que-rb/que for that version; useCREATE OR REPLACEandDROP TRIGGER IF EXISTSfor idempotency. - Extend the schema dumper version detection if the new version uses a different table comment or detection method.
MIT.