From e098977739f21301c16e987eca2dbf214366c36a Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Tue, 28 Jan 2020 22:12:41 +0000 Subject: [PATCH] Release SQL migration script --- Procfile | 1 + lib/helpers.php | 4 ++++ release.php | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 release.php diff --git a/Procfile b/Procfile index 48aab52..29aa7d5 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ web: vendor/bin/heroku-php-apache2 public/ +release: php release.php diff --git a/lib/helpers.php b/lib/helpers.php index 95876dd..5dfd49a 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -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)); diff --git a/release.php b/release.php new file mode 100644 index 0000000..fd96e5b --- /dev/null +++ b/release.php @@ -0,0 +1,20 @@ +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);