Sha256: c3e3bcda0594f66083717635cea649b0154a06620d5a3edf02df46ec745011b1

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 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, **)
              return if Dir[application.root.join("db/migrate/*.rb")].empty?

              measure "database #{database.name} migrated" do
                if target
                  run_migrations(target: Integer(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

1 entries across 1 versions & 1 rubygems

Version Path
snowpack-1.0.0.alpha7 lib/snowpack/cli/application/commands/db/migrate.rb