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 here.
7
Class Method Summary collapse
-
._raise_db_version_comment_missing_error ⇒ Object
The que_jobs table could be missing the schema version comment either due to: - Being created before the migration system existed; or - A bug in Rails schema dump in some versions of Rails The former is the case on Que versions prior to v0.5.0 (2014-01-14).
- .db_version ⇒ Object
- .migrate!(version:) ⇒ Object
- .set_db_version(version) ⇒ Object
Class Method Details
._raise_db_version_comment_missing_error ⇒ Object
The que_jobs table could be missing the schema version comment either due to:
-
Being created before the migration system existed; or
-
A bug in Rails schema dump in some versions of Rails
The former is the case on Que versions prior to v0.5.0 (2014-01-14). Upgrading directly from there is unsupported, so we just raise in all cases of the comment being missing
62 63 64 65 66 67 68 69 70 |
# File 'lib/que/migrations.rb', line 62 def _raise_db_version_comment_missing_error raise Error, " Cannot determine Que DB schema version.\n\n The que_jobs table is missing its comment recording the Que DB schema version. This is likely due to a bug in Rails schema dump in Rails 7 versions prior to 7.0.3, omitting comments - see https://github.com/que-rb/que/issues/363. Please determine the appropriate schema version from your migrations and record it manually by running the following SQL (replacing version as appropriate):\n\n COMMENT ON TABLE que_jobs IS 'version';\n ERROR\nend\n" |
.db_version ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/que/migrations.rb', line 38 def db_version result = Que.execute " SELECT relname, description\n FROM pg_class\n LEFT JOIN pg_description ON pg_description.objoid = pg_class.oid\n WHERE relname = 'que_jobs'\n SQL\n\n if result.none?\n # No table in the database at all.\n 0\n elsif (d = result.first[:description]).nil?\n # The table exists but the version comment is missing\n _raise_db_version_comment_missing_error\n else\n d.to_i\n end\nend\n" |
.migrate!(version:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/que/migrations.rb', line 10 def migrate!(version:) Que.transaction do current = db_version if current == 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| filename = [ File.dirname(__FILE__), 'migrations', step, direction, ].join('/') << '.sql' Que.execute(File.read(filename)) end set_db_version(version) end end |
.set_db_version(version) ⇒ Object
72 73 74 75 |
# File 'lib/que/migrations.rb', line 72 def set_db_version(version) i = version.to_i Que.execute "COMMENT ON TABLE que_jobs IS '#{i}'" unless i.zero? end |