refactor: auto run migrations on startup
This commit is contained in:
@@ -44,7 +44,7 @@ Average Response Time: 12.37 µs
|
||||
```bash
|
||||
docker-compose up
|
||||
|
||||
docker-compose exec -it app migrate
|
||||
# Generate an api key
|
||||
docker-compose exec -it app cli --create-user=Admin
|
||||
```
|
||||
|
||||
@@ -59,7 +59,6 @@ docker run \
|
||||
-e APP_URL="http://localhost:4000" \
|
||||
sjdonado/bit
|
||||
|
||||
docker exec -it bit migrate
|
||||
docker exec -it bit cli --create-user=Admin
|
||||
```
|
||||
|
||||
@@ -83,7 +82,6 @@ dokku config:set bit DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&s
|
||||
dokku ports:add bit http:80:4000
|
||||
dokku ports:add bit https:443:4000
|
||||
|
||||
dokku run bit migrate
|
||||
dokku run bit cli --create-user=Admin
|
||||
```
|
||||
|
||||
@@ -261,7 +259,6 @@ brew install micrate
|
||||
```
|
||||
|
||||
```bash
|
||||
shards run migrate
|
||||
shards run bit
|
||||
```
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
require "sqlite3"
|
||||
require "crecto"
|
||||
require"micrate"
|
||||
|
||||
module App::Lib
|
||||
class Database
|
||||
@@ -14,5 +15,12 @@ module App::Lib
|
||||
if ENV["ENV"] == "development"
|
||||
Crecto::DbLogger.set_handler(STDOUT)
|
||||
end
|
||||
|
||||
def self.run_migrations
|
||||
Micrate::DB.connection_url = ENV["DATABASE_URL"]
|
||||
Micrate::Cli.run_up
|
||||
end
|
||||
|
||||
run_migrations
|
||||
end
|
||||
end
|
||||
|
||||
@@ -134,12 +134,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker-compose exec -T app migrate
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to run database migrations."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a new user and capture the API key
|
||||
output=$(docker-compose exec -T app cli --create-user=Admin)
|
||||
api_key=$(echo "$output" | awk -F' ' '/X-Api-Key:/{print $NF}')
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
require "sqlite3"
|
||||
require"micrate"
|
||||
|
||||
require "../app/config/env"
|
||||
|
||||
Micrate::DB.connection_url = ENV["DATABASE_URL"]
|
||||
Micrate::Cli.run_up
|
||||
Reference in New Issue
Block a user