Skip to content

Commit

Permalink
Extract migration folder global var
Browse files Browse the repository at this point in the history
  • Loading branch information
ciremoussadia committed Mar 2, 2021
1 parent 50b1ccf commit 3f32fc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/db_agent/db_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class DbHandler

def initialize(options)
@config = options[:config]
@superconfig = options[:superconfig]
@backup_folder = options[:backup]
@schema_folder = options[:schema]
@superconfig = options[:superconfig]
@migrations_folder = options[:migrations]
end
attr_reader :config, :superconfig, :backup_folder; :schema_folder
attr_reader :config, :superconfig, :backup_folder, :schema_folder, :migrations_folder

def ping
puts "Using #{config}"
Expand Down Expand Up @@ -61,10 +62,10 @@ def restore(t, args)

def migrate
Sequel.extension :migration
if (sf = MIGRATIONS_FOLDER/'superuser').exists?
Sequel::Migrator.run(SUPERUSER_DATABASE, MIGRATIONS_FOLDER/'superuser', table: 'superuser_migrations')
if (sf = migrations_folder/'superuser').exists?
Sequel::Migrator.run(sequel_superdb, migrations_folder/'superuser', table: 'superuser_migrations')
end
Sequel::Migrator.run(SEQUEL_DATABASE, MIGRATIONS_FOLDER)
Sequel::Migrator.run(sequel_db, migrations_folder)
end

def repl
Expand Down
9 changes: 7 additions & 2 deletions tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace :db do
end

def db_handler
options = { config: DATABASE_CONFIG, backup: BACKUP_FOLDER, schema: SCHEMA_FOLDER, superconfig: SUPERUSER_CONFIG}
@db_handler ||= DbHandler.factor(options)
@db_handler ||= DbHandler.factor({
config: DATABASE_CONFIG,
superconfig: SUPERUSER_CONFIG,
backup: BACKUP_FOLDER,
schema: SCHEMA_FOLDER,
migrations: MIGRATIONS_FOLDER
})
end

desc "Pings the database, making sure everything's ready for migration"
Expand Down

0 comments on commit 3f32fc6

Please sign in to comment.