Class: SqlMigrations::Database
- Inherits:
-
Object
- Object
- SqlMigrations::Database
- Defined in:
- lib/sql_migrations/database.rb
Constant Summary collapse
- SCHEMA_TABLE =
:sqlmigrations_schema
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #execute_migrations ⇒ Object
-
#initialize(options) ⇒ Database
constructor
A new instance of Database.
- #schema_dataset ⇒ Object
- #seed_database ⇒ Object
- #seed_with_fixtures ⇒ Object
Constructor Details
#initialize(options) ⇒ Database
Returns a new instance of Database.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sql_migrations/database.rb', line 7 def initialize() @name = [:name] || :default begin @db = Sequel.connect(adapter: ['adapter'], host: ['host'], database: ['database'], user: ['username'], password: ['password'], test: true) rescue puts "[-] Could not connect to database using #{options['adapter']} adapter" raise else puts "[+] Connected to database using #{options['adapter']} adapter" end install_table end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/sql_migrations/database.rb', line 5 def db @db end |
Instance Method Details
#execute_migrations ⇒ Object
25 26 27 28 |
# File 'lib/sql_migrations/database.rb', line 25 def execute_migrations puts "[i] Executing migrations" Migration.find(@name).each { |migration| migration.execute(self) } end |
#schema_dataset ⇒ Object
40 41 42 |
# File 'lib/sql_migrations/database.rb', line 40 def schema_dataset @db[SCHEMA_TABLE] end |
#seed_database ⇒ Object
30 31 32 33 |
# File 'lib/sql_migrations/database.rb', line 30 def seed_database puts "[i] Seeding database" Seed.find(@name).each { |seed| seed.execute(self) } end |
#seed_with_fixtures ⇒ Object
35 36 37 38 |
# File 'lib/sql_migrations/database.rb', line 35 def seed_with_fixtures puts "[i] Seeding test database with fixtures" Fixture.find(@name).each { |fixture| fixture.execute(self) } end |