Module: Que::Migrations
- Defined in:
- lib/que/migrations.rb
Constant Summary collapse
- CURRENT_VERSION =
In order to ship a schema change, add the relevant up and down sql files to the migrations directory, and bump the version both here and in the add_que generator template.
3
Class Method Summary collapse
- .db_version ⇒ Object
- .migrate!(options = {:version => CURRENT_VERSION}) ⇒ Object
- .set_db_version(version) ⇒ Object
Class Method Details
.db_version ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/que/migrations.rb', line 34 def db_version result = Que.execute <<-SQL SELECT relname, description FROM pg_class LEFT JOIN pg_description ON pg_description.objoid = pg_class.oid WHERE relname = 'que_jobs' SQL if result.none? # No table in the database at all. 0 elsif (d = result.first[:description]).nil? # There's a table, it was just created before the migration system existed. 1 else d.to_i end end |
.migrate!(options = {:version => CURRENT_VERSION}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/que/migrations.rb', line 11 def migrate!( = {:version => CURRENT_VERSION}) Que.transaction do version = [:version] if (current = db_version) == version return elsif current < version direction = 'up' steps = ((current + 1)..version).to_a elsif current > version direction = 'down' steps = ((version + 1)..current).to_a.reverse end steps.each do |step| sql = File.read("#{File.dirname(__FILE__)}/migrations/#{step}/#{direction}.sql") Que.execute(sql) end set_db_version(version) end end |