Class: Hanami::Model::Migrator
- Inherits:
-
Object
- Object
- Hanami::Model::Migrator
- Defined in:
- gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/logger.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/adapter.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/connection.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/mysql_adapter.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/sqlite_adapter.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/model/migrator/postgres_adapter.rb
Overview
Database schema migrator
Class Method Summary collapse
-
.apply ⇒ Object
Migrate, dump schema, delete migrations.
-
.create ⇒ Object
Create database defined by current configuration.
-
.drop ⇒ Object
Drop database defined by current configuration.
-
.migrate(version: nil) ⇒ Object
Migrate database schema.
-
.prepare ⇒ Object
Prepare database: drop, create, load schema (if any), migrate.
-
.rollback(steps: 1) ⇒ Object
Rollback database schema.
-
.version ⇒ String, NilClass
Return current database version timestamp.
Class Method Details
.apply ⇒ Object
Migrate, dump schema, delete migrations.
This is an experimental feature. It may change or be removed in the future.
Actively developed applications accumulate tons of migrations. In the long term they are hard to maintain and slow to execute.
“Apply” feature solves this problem.
It keeps an updated SQL file with the structure of the database. This file can be used to create fresh databases for developer machines or during testing. This is faster than to run dozen or hundred migrations.
When we use “apply”, it eliminates all the migrations that are no longer necessary.
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.apply new.apply end |
.create ⇒ Object
Create database defined by current configuration.
It’s only implemented for the following databases:
-
SQLite3
-
PostgreSQL
-
MySQL
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.create new.create end |
.drop ⇒ Object
Drop database defined by current configuration.
It’s only implemented for the following databases:
-
SQLite3
-
PostgreSQL
-
MySQL
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.drop new.drop end |
.migrate(version: nil) ⇒ Object
Migrate database schema
It’s possible to migrate “down” by specifying a version (eg. "20150610133853"
)
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.migrate(version: nil) new.migrate(version: version) end |
.prepare ⇒ Object
Prepare database: drop, create, load schema (if any), migrate.
This is designed for development machines and testing mode. It works faster if used with apply
.
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.prepare new.prepare end |
.rollback(steps: 1) ⇒ Object
Rollback database schema
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.rollback(steps: 1) new.rollback(steps: steps) end |
.version ⇒ String, NilClass
Return current database version timestamp
If no migrations were ran, it returns nil
.
NOTE: Class level interface SHOULD be removed in Hanami 2.0
Source: | on GitHub
def self.version new.version end |