Module: ShopifyCLI::Migrator

Defined in:
lib/shopify_cli/migrator.rb,
lib/shopify_cli/migrator/migration.rb,
lib/shopify_cli/migrator/migrations/1631709766_noop.rb,
lib/shopify_cli/migrator/migrations/1633691650_merge_reporting_configuration.rb

Defined Under Namespace

Modules: Migrations Classes: Migration

Class Method Summary collapse

Class Method Details

.last_migration_dateObject



27
28
29
# File 'lib/shopify_cli/migrator.rb', line 27

def self.last_migration_date
  ShopifyCLI::DB.get(ShopifyCLI::Constants::StoreKeys::LAST_MIGRATION_DATE)
end

.migrate(migrations_directory: File.expand_path("migrator/migrations", __dir__)) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify_cli/migrator.rb', line 8

def self.migrate(
  migrations_directory: File.expand_path("migrator/migrations", __dir__)
)
  baseline_date = last_migration_date
  unless baseline_date.nil?
    migrations(migrations_directory: migrations_directory)
      .select do |m|
        m.date > baseline_date.to_i
      end
      .each(&:run)
  end

  store_last_migration_date
end

.migrations(migrations_directory:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shopify_cli/migrator.rb', line 31

def self.migrations(migrations_directory:)
  Dir.glob(File.join(migrations_directory, "*.rb")).map do |file_path|
    file_name = File.basename(file_path).gsub(".rb", "")
    file_name_components = file_name.split("_")
    date_timestamp = file_name_components[0].to_i
    migration_name = file_name_components.drop(1).join("_")

    Migrator::Migration.new(
      name: migration_name,
      date: Time.at(date_timestamp).to_i,
      path: file_path
    )
  end
end

.store_last_migration_dateObject



23
24
25
# File 'lib/shopify_cli/migrator.rb', line 23

def self.store_last_migration_date
  ShopifyCLI::DB.set(ShopifyCLI::Constants::StoreKeys::LAST_MIGRATION_DATE => Time.now.to_i)
end