Sha256: 830903fa593a2af4c7c56d0b075a2eb29f7226f2b41bf9819f12d4d7976ac7f5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 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: 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

2 entries across 2 versions & 1 rubygems

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