Class: SqlMigrations::Database
- Inherits:
-
Object
- Object
- SqlMigrations::Database
- Defined in:
- lib/sql_migrations/database.rb
Overview
Class that represents database gem will connect to
Constant Summary collapse
- HISTORY_TABLE =
:sqlmigrations_schema
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #history ⇒ Object
-
#initialize(name, options) ⇒ Database
constructor
A new instance of Database.
- #migrate ⇒ Object
- #seed ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Database
Returns a new instance of Database.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sql_migrations/database.rb', line 10 def initialize(name, ) @name = name @adapter = [:adapter] begin @driver = self.class.connect() rescue puts "[-] Could not connect to `#{@name}` database using #{@adapter} adapter" raise else puts "[+] Connected to `#{@name}` database using #{@adapter} adapter" end install_table end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
8 9 10 |
# File 'lib/sql_migrations/database.rb', line 8 def driver @driver end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/sql_migrations/database.rb', line 8 def name @name end |
Instance Method Details
#history ⇒ Object
44 45 46 |
# File 'lib/sql_migrations/database.rb', line 44 def history @driver[HISTORY_TABLE] end |
#migrate ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/sql_migrations/database.rb', line 24 def migrate migrations = Migration.find(@name) if !migrations.empty? puts "[i] Executing migrations for `#{@name}` database" migrations.each { |migration| migration.execute(self) } else puts "[i] No migrations for `#{@name}` database" end end |
#seed ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/sql_migrations/database.rb', line 34 def seed seeds = Seed.find(@name) if !seeds.empty? puts "[i] Seeding `#{@name}` database" seeds.each { |seed| seed.execute(self) } else puts "[i] No seeds for `#{@name}` database" end end |