Class: Hanami::Model::Migrator::Adapter Private
- Inherits:
-
Object
- Object
- Hanami::Model::Migrator::Adapter
- Defined in:
- lib/hanami/model/migrator/adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Migrator base adapter
Direct Known Subclasses
Constant Summary collapse
- MIGRATIONS_TABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Migrations table to store migrations metadata.
:schema_migrations
- MIGRATIONS_TABLE_VERSION_COLUMN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Migrations table version column
:filename
Class Method Summary collapse
-
.for(configuration) ⇒ Object
private
Loads and returns a specific adapter for the given connection.
Instance Method Summary collapse
-
#create ⇒ Object
private
Create database.
-
#drop ⇒ Object
private
Drop database.
-
#initialize(connection) ⇒ Adapter
constructor
private
Initialize an adapter.
-
#load ⇒ Object
private
Load database schema.
- #migrate(migrations, version) ⇒ Object private
- #rollback(migrations, steps) ⇒ Object private
-
#version ⇒ Object
private
Database version.
Constructor Details
#initialize(connection) ⇒ Adapter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize an adapter
51 52 53 |
# File 'lib/hanami/model/migrator/adapter.rb', line 51 def initialize(connection) @connection = connection end |
Class Method Details
.for(configuration) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loads and returns a specific adapter for the given connection.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hanami/model/migrator/adapter.rb', line 29 def self.for(configuration) # rubocop:disable Metrics/MethodLength connection = Connection.new(configuration) case connection.database_type when :sqlite require 'hanami/model/migrator/sqlite_adapter' SQLiteAdapter when :postgres require 'hanami/model/migrator/postgres_adapter' PostgresAdapter when :mysql require 'hanami/model/migrator/mysql_adapter' MySQLAdapter else self end.new(connection) end |
Instance Method Details
#create ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create database. It must be implemented by subclasses.
62 63 64 |
# File 'lib/hanami/model/migrator/adapter.rb', line 62 def create raise MigrationError.new("Current adapter (#{connection.database_type}) doesn't support create.") end |
#drop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Drop database. It must be implemented by subclasses.
73 74 75 |
# File 'lib/hanami/model/migrator/adapter.rb', line 73 def drop raise MigrationError.new("Current adapter (#{connection.database_type}) doesn't support drop.") end |
#load ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load database schema. It must be implemented by subclasses.
105 106 107 |
# File 'lib/hanami/model/migrator/adapter.rb', line 105 def load raise MigrationError.new("Current adapter (#{connection.database_type}) doesn't support load.") end |
#migrate(migrations, version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 82 83 84 85 |
# File 'lib/hanami/model/migrator/adapter.rb', line 79 def migrate(migrations, version) version = Integer(version) unless version.nil? Sequel::Migrator.run(connection.raw, migrations, target: version, allow_missing_migration_files: true) rescue Sequel::Migrator::Error => e raise MigrationError.new(e.) end |
#rollback(migrations, steps) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 92 93 94 95 96 |
# File 'lib/hanami/model/migrator/adapter.rb', line 89 def rollback(migrations, steps) table = migrations_table_dataset version = version_to_rollback(table, steps) Sequel::Migrator.run(connection.raw, migrations, target: version, allow_missing_migration_files: true) rescue Sequel::Migrator::Error => e raise MigrationError.new(e.) end |
#version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Database version.
113 114 115 116 117 118 119 120 121 |
# File 'lib/hanami/model/migrator/adapter.rb', line 113 def version table = migrations_table_dataset return if table.nil? record = table.order(MIGRATIONS_TABLE_VERSION_COLUMN).last return if record.nil? record.fetch(MIGRATIONS_TABLE_VERSION_COLUMN).scan(MIGRATIONS_FILE_NAME_PATTERN).first.to_s end |