Skip to content

Commit 7a4a2a6

Browse files
Release SQL migration script
1 parent 4d91b4a commit 7a4a2a6

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
web: vendor/bin/heroku-php-apache2 public/
2+
release: php release.php

lib/helpers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function setupDB($host, $user, $pass, $dbname, $port='') {
4040
define('DB_SETUP', true);
4141
}
4242

43+
function installDB() {
44+
ORM::raw_execute(file_get_contents('schema/schema.sql'));
45+
}
46+
4347
function make_logger($channel) {
4448
$log = new Logger($channel);
4549
$log->pushHandler(new StreamHandler(dirname(__FILE__).'/../logs/app.log', Logger::DEBUG));

release.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
include('vendor/autoload.php');
4+
$userlog = make_logger('release');
5+
initdb();
6+
7+
if(empty(getenv('APP_NAME')) || empty(getenv('BASE_URL')) || !defined('DB_SETUP')) {
8+
$userlog->error("Unable to release without APP_NAME, BASE_URL and valid DB_ ENV");
9+
exit(-1);
10+
}
11+
try {
12+
installDB();
13+
} catch(\Exception $e) {
14+
$userlog->error(
15+
'Schema restore / migration failed'
16+
);
17+
exit(-1);
18+
}
19+
$userlog->info('Release success');
20+
exit(0);

0 commit comments

Comments
 (0)