Class: Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/yodel/models/core/site/migration.rb

Class Method Summary collapse

Class Method Details

.copy_missing_migrations_for_all_sitesObject



2
3
4
5
6
7
# File 'lib/yodel/models/core/site/migration.rb', line 2

def self.copy_missing_migrations_for_all_sites
  Site.all.each do |site|
    next if site.name == 'yodel'
    copy_missing_migrations_for_site(site)
  end
end

.copy_missing_migrations_for_site(site) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/yodel/models/core/site/migration.rb', line 9

def self.copy_missing_migrations_for_site(site)
  # core yodel migrations
  site_yodel_migrations_dir = File.join(site.migrations_directory, Yodel::YODEL_MIGRATIONS_DIRECTORY_NAME)
  sync_migration_directories(Yodel.config.yodel_migration_directory, site_yodel_migrations_dir)

  # extension migrations
  extension_migrations_dir = File.join(site.root_directory, Yodel::MIGRATIONS_DIRECTORY_NAME, Yodel::EXTENSION_MIGRATIONS_DIRECTORY_NAME)
  Yodel.config.extensions.each do |extension|
    sync_migration_directories(extension.migrations_dir, File.join(extension_migrations_dir, extension.name))
  end
end

.inherited(child) ⇒ Object

As migration files are require’d this method will be triggered so we have a reference to the ‘current’ migration class being run



52
53
54
# File 'lib/yodel/models/core/site/migration.rb', line 52

def self.inherited(child)
  @migration = child
end

.run_migrations(site) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/yodel/models/core/site/migration.rb', line 27

def self.run_migrations(site)
  Yodel.config.logger.info "Migrating #{site.name}"
  
  each_migration_for(site) do |migration, file|
    unless migration.nil?
      next if site.migrations.include?(migration.name)
      migration.up(site)
    
      # newly created models are incomplete; reload the site
      # to force complete versions to be generated for use
      site.migrations << migration.name
      site.save
      site.reload
    
      Yodel.config.logger.info "Migrated #{migration.name}"
    else
      raise MissingMigration.new(file)
    end
  end
  
  Yodel.config.logger.info "Migrations for #{site.name} complete"
end

.run_migrations_for_all_sitesObject



21
22
23
24
25
# File 'lib/yodel/models/core/site/migration.rb', line 21

def self.run_migrations_for_all_sites
  Site.all.each do |site|
    run_migrations(site)
  end
end