Class: Lotus::Model::Migrator::Adapter Private
- Inherits:
-
Object
- Object
- Lotus::Model::Migrator::Adapter
- Defined in:
- lib/lotus/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(connection) ⇒ 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.
-
#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
48 49 50 |
# File 'lib/lotus/model/migrator/adapter.rb', line 48 def initialize(connection) @connection = Connection.new(connection) end |
Class Method Details
.for(connection) ⇒ 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lotus/model/migrator/adapter.rb', line 28 def self.for(connection) case connection.database_type when :sqlite require 'lotus/model/migrator/sqlite_adapter' SQLiteAdapter when :postgres require 'lotus/model/migrator/postgres_adapter' PostgresAdapter when :mysql require 'lotus/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.
59 60 61 |
# File 'lib/lotus/model/migrator/adapter.rb', line 59 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.
70 71 72 |
# File 'lib/lotus/model/migrator/adapter.rb', line 70 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.
81 82 83 |
# File 'lib/lotus/model/migrator/adapter.rb', line 81 def load raise MigrationError.new("Current adapter (#{ connection.database_type }) doesn't support load.") 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.
89 90 91 92 93 94 95 |
# File 'lib/lotus/model/migrator/adapter.rb', line 89 def version return unless connection.adapter_connection.tables.include?(MIGRATIONS_TABLE) if record = connection.adapter_connection[MIGRATIONS_TABLE].order(MIGRATIONS_TABLE_VERSION_COLUMN).last record.fetch(MIGRATIONS_TABLE_VERSION_COLUMN).scan(/\A[\d]{14}/).first.to_s end end |