Skip to content

Commit

Permalink
Release SQL migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewiscowles1986 committed Feb 1, 2020
1 parent 70efcf7 commit 7a8856c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: vendor/bin/heroku-php-apache2 public/
release: php release.php
4 changes: 4 additions & 0 deletions lib/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function setupDB($host, $user, $pass, $dbname, $port='') {
define('DB_SETUP', true);
}

function installDB() {
ORM::raw_execute(file_get_contents('schema/schema.sql'));
}

function make_logger($channel) {
$log = new Logger($channel);
$log->pushHandler(new StreamHandler(dirname(__FILE__).'/../logs/app.log', Logger::DEBUG));
Expand Down
20 changes: 20 additions & 0 deletions release.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include('vendor/autoload.php');
$userlog = make_logger('release');
initdb();

if(empty(getenv('APP_NAME')) || empty(getenv('BASE_URL')) || !defined('DB_SETUP')) {
$userlog->error("Unable to release without APP_NAME, BASE_URL and valid DB_ ENV");
exit(-1);
}
try {
installDB();
} catch(\Exception $e) {
$userlog->error(
'Schema restore / migration failed'
);
exit(-1);
}
$userlog->info('Release success');
exit(0);

0 comments on commit 7a8856c

Please sign in to comment.