Skip to content

Commit

Permalink
Adding in new db.setup task to run db.create and db.migrate together (#…
Browse files Browse the repository at this point in the history
…361)

* Adding in new db.setup task to run db.create and db.migrate together. Fixes #359

* Adding db.setup to integration specs
  • Loading branch information
jwoertink authored May 20, 2020
1 parent 7f5c311 commit 42ce5b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ then
$COMPOSE lucky db.migrate
$COMPOSE lucky db.migrations.status
$COMPOSE lucky db.reset
$COMPOSE lucky db.drop
$COMPOSE lucky db.setup
fi

printf "\nRunning specs\n\n"
Expand Down
30 changes: 30 additions & 0 deletions src/avram/tasks/db/setup.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Db::Setup < LuckyCli::Task
summary "Runs a few tasks for setting up your database"

def initialize(@quiet : Bool = false)
end

def help_message
<<-TEXT
#{summary}
This task will run the following:
* db.create - Create the database from config/database.cr
* db.migrate - Migrate all pending migrations from db/migrations/
Examples:
lucky db.setup
LUCKY_ENV=test lucky db.setup # Setup test database
TEXT
end

def call
Avram::Migrator.run do
Avram::Migrator::Runner.create_db(@quiet)
Avram::Migrator::Runner.new(@quiet).run_pending_migrations
end
end
end

0 comments on commit 42ce5b5

Please sign in to comment.