Sha256: 647428f243c8bbf0a4e949d3f258db309e97ec937307c6e4259e0ff3e0987e5c

Contents?: true

Size: 1.48 KB

Versions: 18

Compression:

Stored size: 1.48 KB

Contents

module Hanami
  class CLI
    module Commands
      module Destroy
        # @since 1.1.0
        # @api private
        class Migration < Command
          desc "Destroy a migration"

          argument :migration, required: true, desc: "The migration name (eg. `create_users`)"

          example [
            "create_users # Destroy `db/migrations/#{Project.migration_timestamp}_create_users.rb`"
          ]

          # @since 1.1.0
          # @api private
          def call(migration:, **options)
            migration   = Utils::String.underscore(migration)
            context     = Context.new(migration: migration, options: options)
            context     = context.with(destination: project.find_migration(context))

            assert_valid_migration!(context)

            destroy_migration(context)
            true
          end

          private

          # @since 1.1.0
          # @api private
          def assert_valid_migration!(context)
            return if !context.destination.nil? && files.exist?(context.destination)

            destination = project.migrations(context)
            warn "cannot find `#{context.migration}'. Please have a look at `#{destination}' directory to find an existing migration"
            exit(1)
          end

          # @since 1.1.0
          # @api private
          def destroy_migration(context)
            files.delete(context.destination)
            say(:remove, context.destination)
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hanami-1.3.5 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.4 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.3 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.2 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.0 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.3.0.beta1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.2.0 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.2.0.rc2 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.2.0.rc1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.2.0.beta2 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.2.0.beta1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.0 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.0.rc1 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.0.beta3 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.0.beta2 lib/hanami/cli/commands/destroy/migration.rb
hanami-1.1.0.beta1 lib/hanami/cli/commands/destroy/migration.rb