Sha256: f4f8f45de5424b7c3bc47f441dc5c70e80336d6162fc3601d8e980112c2d5bf3

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require "snowpack/cli/application/command"
require_relative "structure/dump"
require_relative "utils/database"

module Snowpack
  module CLI
    module Application
      module Commands
        module DB
          class Migrate < Command
            desc "Migrates database"

            option :target, desc: "Target migration number", aliases: ["-t"]

            def call(target: nil, **)
              measure "database #{database.name} migrated" do
                if target
                  run_migrations(target: target)
                else
                  run_migrations
                end
              end

              run_command Structure::Dump
            end

            private

            def run_migrations(**options  )
              ROM::SQL.with_gateway(database.gateway) do
                database.migrator.run(options)
              end
            end

            def database
              @database ||= Utils::Database.for_application(application)
            end
          end
        end

        register "db migrate", DB::Migrate
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
snowpack-1.0.0.alpha4 lib/snowpack/cli/application/commands/db/migrate.rb
snowpack-1.0.0.alpha3 lib/snowpack/cli/application/commands/db/migrate.rb
snowpack-1.0.0.alpha2 lib/snowpack/cli/application/commands/db/migrate.rb