class Clear::Migration::Manager

Overview

The migration manager is a singleton, it load all the migrations, check which one are #up and #down, and can trigger one or multiple downgrade / upgrade of the database.

The migration system needs the creation of a table named __clear_metadatas in your database. This table will be created automatically on the first initialization of the Migration Manager.

Included Modules

Defined in:

clear/migration/manager.cr

Constant Summary

METADATA_VERSION = "1"

Used to migrate between metadata version, in case we need it in the future.

Class Method Summary

Instance Method Summary

Instance methods inherited from module Clear::ErrorMessages

build_error_message(message : String, ways_to_resolve : Tuple | Array = Tuple.new, manual_pages : Tuple | Array = Tuple.new) build_error_message, converter_error(from, to) converter_error, format_width(x, w = 80) format_width, illegal_setter_access_to_undefined_column(name) illegal_setter_access_to_undefined_column, lack_of_primary_key(model_name) lack_of_primary_key, migration_already_down(number) migration_already_down, migration_already_up(number) migration_already_up, migration_drop_irreversible(name) migration_drop_irreversible, migration_irreversible(name = nil, operation = nil) migration_irreversible, migration_not_found(number) migration_not_found, migration_not_unique(numbers) migration_not_unique, no_migration_yet(version) no_migration_yet, null_column_mapping_error(name, type) null_column_mapping_error, order_by_error_invalid_order(current_order) order_by_error_invalid_order, polymorphic_nil(through) polymorphic_nil, polymorphic_unknown_class(class_name) polymorphic_unknown_class, query_building_error(message) query_building_error, uid_not_found(class_name) uid_not_found, uninitialized_db_connection(connection) uninitialized_db_connection

Class Method Detail

def self.instance #

To access to the manager

Clear::Migration::Manager.instance

[View source]

Instance Method Detail

def apply_all #

Apply all the migrations not yet applied.


[View source]
def apply_to(version, direction = :both) #

[View source]
def commited?(m : Clear::Migration) #

Return true if the migration has been commited (already applied into the database) or false otherwise


[View source]
def current_version #

[View source]
def down(number : Int64) : Nil #

Force down a migration; throw error if the mgiration is already down


[View source]
def ensure_ready #

Create if needed the metadata table to save the migrations.


[View source]
def find(number) #

Fetch the migration instance with the selected number


[View source]
def load_existing_migrations #

Fetch all the migrations already activated on the database.


[View source]
def max_version #

[View source]
def migrations_up #

[View source]
def print_status : String #

Print out the status ( up | down ) of all migrations found by the manager.


[View source]
def refresh #

[View source]
def reinit! #

Force reloading the migration system Recheck all the current up migrations and the metadata table. This is useful if you access to the migration process through another program, or during specs


[View source]
def up(number : Int64) : Nil #

Force up a migration; throw error if the migration is already up


[View source]