Class: WebpageArchivist::Migrations
- Inherits:
-
Object
- Object
- WebpageArchivist::Migrations
- Defined in:
- lib/webpage-archivist/migrations.rb
Overview
Define the sequel migrations and run them at startup, code adapted from sinatra-sequel gem
Constant Summary collapse
- @@migrations =
[]
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.migration(name, &block) ⇒ Object
26 27 28 |
# File 'lib/webpage-archivist/migrations.rb', line 26 def self.migration(name, &block) @@migrations << {:name => name, :block => block} end |
Instance Method Details
#create_migrations_table ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/webpage-archivist/migrations.rb', line 81 def create_migrations_table DATABASE.create_table? :migrations do primary_key :id String :name, :null => false, :index => true :ran_at, :null => false end end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/webpage-archivist/migrations.rb', line 13 def run create_migrations_table @@migrations.each do |migration| if DATABASE[:migrations].filter(:name => migration[:name]).count == 0 p "Running migration: #{migration[:name]}" DATABASE.transaction do migration[:block].yield DATABASE[:migrations] << {:name => migration[:name], :ran_at => Time.now} end end end end |