Module: Hanami::Model

Defined in:
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/error.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/types.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/mapping.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/plugins.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/version.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migration.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/types.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/association.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/entity_name.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/console.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/configurator.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/relation_name.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/plugins/schema.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/mapped_relation.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/logger.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/plugins/mapping.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/associations/dsl.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/adapter.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/entity/schema.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/plugins/timestamps.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/consoles/mysql.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/connection.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/consoles/sqlite.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/associations/has_one.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/associations/has_many.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/consoles/abstract.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/mysql_adapter.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/associations/belongs_to.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/sqlite_adapter.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/consoles/postgresql.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/associations/many_to_many.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/migrator/postgres_adapter.rb,
gems/gems/hanami-model-1.3.0/lib/hanami/model/sql/types/schema/coercions.rb

Overview

Hanami::Model migrations

Since:

  • 0.1.0

Defined Under Namespace

Modules: Associations, Sql, Types Classes: CheckConstraintViolationError, ConstraintViolationError, DatabaseError, Error, ForeignKeyConstraintViolationError, InvalidCommandError, MigrationError, Migrator, MissingPrimaryKeyError, NotNullConstraintViolationError, UniqueConstraintViolationError, UnknownAttributeError, UnknownDatabaseAdapterError, UnknownDatabaseTypeError

Constant Summary

VERSION =

Defines the version

Since:

  • 0.1.0

'1.3.0'.freeze

Class Method Summary collapse

Class Method Details

.migration(&blk) ⇒ Object

Define a migration

It must define an up/down strategy to write schema changes (up) and to rollback them (down).

We can use up and down blocks for custom strategies, or only one change block that automatically implements “down” strategy.

Examples:

Use up/down blocks

Hanami::Model.migration do
  up do
    create_table :books do
      primary_key :id
      column :book, String
    end
  end

  down do
    drop_table :books
  end
end

Use change block

Hanami::Model.migration do
  change do
    create_table :books do
      primary_key :id
      column :book, String
    end
  end

  # DOWN strategy is automatically generated
end

Parameters:

  • blk (Proc)

    a block that defines up/down or change database migration

Since:

  • 0.4.0

def self.migration(&blk)
  Migration.new(configuration.gateways[:default], &blk)
end