Module: Que::Scheduler::Migrations
- Defined in:
- lib/que/scheduler/migrations.rb
Constant Summary collapse
- AUDIT_TABLE_NAME =
Que::Scheduler::Audit::TABLE_NAME
- TABLE_COMMENT =
%( SELECT description FROM pg_class LEFT JOIN pg_description ON pg_description.objoid = pg_class.oid WHERE relname = '#{AUDIT_TABLE_NAME}' ).freeze
- MAX_VERSION =
Dir.glob("#{__dir__}/migrations/*").map { |d| File.basename(d) }.map(&:to_i).max
Class Method Summary collapse
- .audit_table_exists? ⇒ Boolean
- .db_version ⇒ Object
- .migrate!(version:) ⇒ Object
-
.reenqueue_scheduler_if_missing ⇒ Object
This method is only intended for use in squashed migrations.
Class Method Details
.audit_table_exists? ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/que/scheduler/migrations.rb', line 37 def audit_table_exists? result = Que::Scheduler::VersionSupport.execute(" SELECT * FROM information_schema.tables WHERE table_name = '\#{AUDIT_TABLE_NAME}';\n SQL\n result.any?\nend\n") |
.db_version ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/que/scheduler/migrations.rb', line 29 def db_version if audit_table_exists? return Que::Scheduler::VersionSupport.execute(TABLE_COMMENT).first[:description].to_i end Que::Scheduler::Db.count_schedulers.zero? ? 0 : 1 end |
.migrate!(version:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/que/scheduler/migrations.rb', line 15 def migrate!(version:) # Like que, Do not migrate test DBs. return if defined?(Que::Testing) Que::Scheduler::Db.transaction do current = db_version if current < version migrate_up(current, version) elsif current > version migrate_down(current, version) end end end |
.reenqueue_scheduler_if_missing ⇒ Object
This method is only intended for use in squashed migrations
45 46 47 48 49 |
# File 'lib/que/scheduler/migrations.rb', line 45 def reenqueue_scheduler_if_missing return unless Que::Scheduler::Db.count_schedulers.zero? Que::Scheduler::VersionSupport.enqueue_a_job(Que::Scheduler::SchedulerJob) end |