Class: Shikibu::Storage::Migrations
- Inherits:
-
Object
- Object
- Shikibu::Storage::Migrations
- Defined in:
- lib/shikibu/storage/migrations.rb
Overview
Handles database schema migrations from shared durax-io/schema Compatible with dbmate migration format and schema_migrations tracking
Constant Summary collapse
- SCHEMA_PATH =
File.('../../../schema/db/migrations', __dir__)
- MIGRATION_LOCK_KEY =
Advisory lock key for migration (consistent across workers)
20_251_217_000_000
Class Method Summary collapse
-
.apply(db) ⇒ Array<String>
Apply migrations to the database.
Class Method Details
.apply(db) ⇒ Array<String>
Apply migrations to the database
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shikibu/storage/migrations.rb', line 19 def apply(db) db_type = detect_db_type(db) migration_dir = File.join(SCHEMA_PATH, db_type) raise Error, "Migration directory not found: #{migration_dir}" unless File.directory?(migration_dir) # Ensure schema_migrations table exists ensure_schema_migrations_table(db) # Use advisory lock to ensure only one worker applies migrations with_migration_lock(db, db_type) do |acquired| unless acquired # Another worker is applying migrations, wait and return sleep(1) return [] end apply_pending_migrations(db, migration_dir) end end |