feat: replace php migration with django migration
- keep latest legacy version in initial migration file - move propel schema to api legacy app - remove legacy upgrade tool
This commit is contained in:
parent
ee98387264
commit
0e4bc4cacd
85 changed files with 1005 additions and 1000 deletions
|
@ -180,32 +180,6 @@ interface AirtimeTask
|
|||
public function run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class UpgradeTask.
|
||||
*
|
||||
* Checks the current Airtime version and runs any outstanding upgrades
|
||||
*/
|
||||
class UpgradeTask implements AirtimeTask
|
||||
{
|
||||
/**
|
||||
* Check the current Airtime schema version to see if an upgrade should be run.
|
||||
*
|
||||
* @return bool true if an upgrade is needed
|
||||
*/
|
||||
public function shouldBeRun()
|
||||
{
|
||||
return UpgradeManager::checkIfUpgradeIsNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all upgrades above the current schema version.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
UpgradeManager::doUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class CeleryTask.
|
||||
*
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
class UpgradeController extends Zend_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
if (!RestAuth::verifyAuth(true, false, $this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$didWePerformAnUpgrade = UpgradeManager::doUpgrade();
|
||||
|
||||
if (!$didWePerformAnUpgrade) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody('No upgrade was performed. The current schema version is ' . Application_Model_Preference::GetSchemaVersion() . '.<br>');
|
||||
} else {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody('Upgrade to Airtime schema version ' . Application_Model_Preference::GetSchemaVersion() . ' OK<br>');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(400)
|
||||
->appendBody($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function downgradeAction()
|
||||
{
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
if (!RestAuth::verifyAuth(true, false, $this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
$toVersion = $request->getParam('version');
|
||||
|
||||
try {
|
||||
$downgradePerformed = UpgradeManager::doDowngrade($toVersion);
|
||||
|
||||
if (!$downgradePerformed) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody('No downgrade was performed. The current schema version is ' . Application_Model_Preference::GetSchemaVersion() . '.<br>');
|
||||
} else {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody('Downgrade to Airtime schema version ' . Application_Model_Preference::GetSchemaVersion() . ' OK<br>');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(400)
|
||||
->appendBody($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
-----------------------------------------------------------------------
|
||||
-- third_party_track_references
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS "third_party_track_references" CASCADE;
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- celery_tasks
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS "celery_tasks" CASCADE;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE third_party_track_references ALTER COLUMN file_id SET NOT NULL;
|
|
@ -1,11 +0,0 @@
|
|||
ALTER TABLE cc_files DROP COLUMN description;
|
||||
|
||||
DELETE FROM cc_pref WHERE keystr = 'station_podcast_id';
|
||||
|
||||
DROP TABLE IF EXISTS "podcast" CASCADE;
|
||||
|
||||
DROP TABLE IF EXISTS "imported_podcast" CASCADE;
|
||||
|
||||
DROP TABLE IF EXISTS "station_podcast" CASCADE;
|
||||
|
||||
DROP TABLE IF EXISTS "podcast_episodes" CASCADE;
|
|
@ -1,4 +0,0 @@
|
|||
ALTER TABLE imported_podcast DROP COLUMN IF EXISTS album_override;
|
||||
ALTER TABLE third_party_track_references ALTER COLUMN file_id DROP DEFAULT;
|
||||
ALTER TABLE third_party_track_references ALTER COLUMN file_id SET NOT NULL;
|
||||
ALTER TABLE cc_show DROP COLUMN IF EXISTS autoplaylist_repeat;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_service_register ALTER COLUMN ip TYPE character varying(18);
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE podcast_episodes DROP COLUMN IF EXISTS episode_title;
|
||||
ALTER TABLE podcast_episodes DROP COLUMN IF EXISTS episode_description;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_blockcriteria DROP COLUMN IF EXISTS criteriagroup;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE podcast_episodes ALTER COLUMN episode_description TYPE VARCHAR(4096);
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_block ALTER COLUMN type SET DEFAULT 'static';
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_files DROP COLUMN IF EXISTS artwork;
|
|
@ -1,3 +0,0 @@
|
|||
ALTER TABLE cc_files DROP COLUMN IF EXISTS track_type;
|
||||
|
||||
DROP TABLE IF EXISTS "cc_track_types" CASCADE;
|
|
@ -1,10 +0,0 @@
|
|||
CREATE TABLE "cc_smemb"
|
||||
(
|
||||
"id" INTEGER NOT NULL,
|
||||
"uid" INTEGER DEFAULT 0 NOT NULL,
|
||||
"gid" INTEGER DEFAULT 0 NOT NULL,
|
||||
"level" INTEGER DEFAULT 0 NOT NULL,
|
||||
"mid" INTEGER,
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "cc_smemb_id_idx" UNIQUE ("id")
|
||||
);
|
|
@ -1,6 +0,0 @@
|
|||
-- we can restore the schema here but you'll need to restore data from a backup
|
||||
ALTER TABLE cc_files ADD COLUMN soundcloud_id INTEGER;
|
||||
ALTER TABLE cc_files ADD COLUMN soundcloud_error_code INTEGER;
|
||||
ALTER TABLE cc_files ADD COLUMN soundcloud_error_msg VARCHAR(512);
|
||||
ALTER TABLE cc_files ADD COLUMN soundcloud_link_to_file VARCHAR(4096);
|
||||
ALTER TABLE cc_files ADD COLUMN soundcloud_upload_time TIMESTAMP(6);
|
|
@ -1,3 +0,0 @@
|
|||
ALTER TABLE cc_show_instances DROP COLUMN IF EXISTS autoplaylist_built;
|
||||
ALTER TABLE cc_show DROP COLUMN IF EXISTS has_autoplaylist;
|
||||
ALTER TABLE cc_show DROP COLUMN IF EXISTS autoplaylist_id;
|
|
@ -54,16 +54,10 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
|
|||
$this->_initViewHelpers();
|
||||
}
|
||||
|
||||
// Skip upgrades and task management when running unit tests
|
||||
// Skip task management when running unit tests
|
||||
if (getenv('AIRTIME_UNIT_TEST') != 1) {
|
||||
$taskManager = TaskManager::getInstance();
|
||||
|
||||
// Run the upgrade on each request (if it needs to be run)
|
||||
// We can't afford to wait 7 minutes to run an upgrade: users could
|
||||
// have several minutes of database errors while waiting for a
|
||||
// schema change upgrade to happen after a deployment
|
||||
$taskManager->runTask('UpgradeTask');
|
||||
|
||||
// Piggyback the TaskManager onto API calls. This provides guaranteed consistency
|
||||
// (there is at least one API call made from pypo to Airtime every 7 minutes) and
|
||||
// greatly reduces the chances of lock contention on cc_pref while the TaskManager runs
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE cc_files ADD COLUMN filesize integer NOT NULL
|
||||
CONSTRAINT filesize_default DEFAULT 0
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE cc_show ALTER COLUMN description TYPE varchar(8192);
|
||||
ALTER TABLE cc_show_instances ALTER COLUMN description TYPE varchar(8192);
|
|
@ -1,42 +0,0 @@
|
|||
-----------------------------------------------------------------------
|
||||
-- third_party_track_references
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "third_party_track_references"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"service" VARCHAR(256) NOT NULL,
|
||||
"foreign_id" VARCHAR(256),
|
||||
"file_id" INTEGER NOT NULL,
|
||||
"upload_time" TIMESTAMP,
|
||||
"status" VARCHAR(256),
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "foreign_id_unique" UNIQUE ("foreign_id")
|
||||
);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- celery_tasks
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "celery_tasks"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"task_id" VARCHAR(256) NOT NULL,
|
||||
"track_reference" INTEGER NOT NULL,
|
||||
"name" VARCHAR(256),
|
||||
"dispatch_time" TIMESTAMP,
|
||||
"status" VARCHAR(256) NOT NULL,
|
||||
PRIMARY KEY ("id"),
|
||||
CONSTRAINT "id_unique" UNIQUE ("id")
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "third_party_track_references" ADD CONSTRAINT "track_reference_fkey"
|
||||
FOREIGN KEY ("file_id")
|
||||
REFERENCES "cc_files" ("id")
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE "celery_tasks" ADD CONSTRAINT "celery_service_fkey"
|
||||
FOREIGN KEY ("track_reference")
|
||||
REFERENCES "third_party_track_references" ("id")
|
||||
ON DELETE CASCADE;
|
|
@ -1,3 +0,0 @@
|
|||
ALTER TABLE cc_pref ALTER COLUMN subjid SET DEFAULT NULL;
|
||||
CREATE UNIQUE INDEX cc_pref_key_idx ON cc_pref (keystr) WHERE subjid IS NULL;
|
||||
ANALYZE cc_pref;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE third_party_track_references ALTER COLUMN file_id DROP NOT NULL;
|
|
@ -1,90 +0,0 @@
|
|||
ALTER TABLE cc_files ADD COLUMN description VARCHAR(512);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- podcast
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "podcast"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"url" VARCHAR(4096) NOT NULL,
|
||||
"title" VARCHAR(4096) NOT NULL,
|
||||
"creator" VARCHAR(4096),
|
||||
"description" VARCHAR(4096),
|
||||
"language" VARCHAR(4096),
|
||||
"copyright" VARCHAR(4096),
|
||||
"link" VARCHAR(4096),
|
||||
"itunes_author" VARCHAR(4096),
|
||||
"itunes_keywords" VARCHAR(4096),
|
||||
"itunes_summary" VARCHAR(4096),
|
||||
"itunes_subtitle" VARCHAR(4096),
|
||||
"itunes_category" VARCHAR(4096),
|
||||
"itunes_explicit" VARCHAR(4096),
|
||||
"owner" INTEGER,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- station_podcast
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "station_podcast"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"podcast_id" INTEGER NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- imported_podcast
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "imported_podcast"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"auto_ingest" BOOLEAN DEFAULT 'f' NOT NULL,
|
||||
"auto_ingest_timestamp" TIMESTAMP,
|
||||
"podcast_id" INTEGER NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- podcast_episodes
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "podcast_episodes"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"file_id" INTEGER,
|
||||
"podcast_id" INTEGER NOT NULL,
|
||||
"publication_date" TIMESTAMP NOT NULL,
|
||||
"download_url" VARCHAR(4096) NOT NULL,
|
||||
"episode_guid" VARCHAR(4096) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "podcast" ADD CONSTRAINT "podcast_owner_fkey"
|
||||
FOREIGN KEY ("owner")
|
||||
REFERENCES "cc_subjs" ("id")
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE "station_podcast" ADD CONSTRAINT "podcast_id_fkey"
|
||||
FOREIGN KEY ("podcast_id")
|
||||
REFERENCES "podcast" ("id")
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE "imported_podcast" ADD CONSTRAINT "podcast_id_fkey"
|
||||
FOREIGN KEY ("podcast_id")
|
||||
REFERENCES "podcast" ("id")
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE "podcast_episodes" ADD CONSTRAINT "podcast_episodes_cc_files_fkey"
|
||||
FOREIGN KEY ("file_id")
|
||||
REFERENCES "cc_files" ("id")
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE "podcast_episodes" ADD CONSTRAINT "podcast_episodes_podcast_id_fkey"
|
||||
FOREIGN KEY ("podcast_id")
|
||||
REFERENCES "podcast" ("id")
|
||||
ON DELETE CASCADE;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_files ADD COLUMN artwork TYPE character varying(255);
|
|
@ -1,6 +0,0 @@
|
|||
-- Replacing system_version with schema_version
|
||||
DELETE FROM cc_pref WHERE keystr = 'system_version';
|
||||
INSERT INTO cc_pref (keystr, valstr) VALUES ('schema_version', '2.5.2');
|
||||
|
||||
ALTER TABLE cc_show ADD COLUMN image_path varchar(255) DEFAULT '';
|
||||
ALTER TABLE cc_show_instances ADD COLUMN description varchar(255) DEFAULT '';
|
|
@ -1,6 +0,0 @@
|
|||
DELETE FROM cc_pref WHERE keystr = 'system_version';
|
||||
INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '2.5.3');
|
||||
|
||||
ALTER TABLE cc_files DROP COLUMN state;
|
||||
ALTER TABLE cc_files ADD import_status integer default 1; -- Default is "pending"
|
||||
UPDATE cc_files SET import_status=0; -- Existing files are already "imported"
|
|
@ -1,5 +0,0 @@
|
|||
DELETE FROM cc_pref WHERE keystr = 'system_version';
|
||||
INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '2.5.5');
|
||||
|
||||
ALTER TABLE cc_show ADD COLUMN image_path varchar(255) DEFAULT '';
|
||||
ALTER TABLE cc_show_instances ADD COLUMN description varchar(255) DEFAULT '';
|
|
@ -1,11 +0,0 @@
|
|||
CREATE TABLE cloud_file
|
||||
(
|
||||
id serial NOT NULL,
|
||||
resource_id text NOT NULL,
|
||||
storage_backend text NOT NULL,
|
||||
cc_file_id integer NOT NULL,
|
||||
CONSTRAINT cloud_file_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT "cloud_file_FK_1" FOREIGN KEY (cc_file_id)
|
||||
REFERENCES cc_files (id) MATCH SIMPLE
|
||||
ON UPDATE NO ACTION ON DELETE CASCADE
|
||||
)
|
|
@ -1,4 +0,0 @@
|
|||
ALTER TABLE imported_podcast ADD COLUMN album_override boolean default 'f' NOT NULL;
|
||||
ALTER TABLE third_party_track_references ALTER COLUMN file_id SET DEFAULT 0;
|
||||
ALTER TABLE third_party_track_references ALTER COLUMN file_id DROP NOT NULL;
|
||||
ALTER TABLE cc_show ADD COLUMN autoplaylist_repeat boolean default 'f' NOT NULL;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_service_register ALTER COLUMN ip TYPE character varying(45);
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE podcast_episodes ADD COLUMN episode_title VARCHAR(4096);
|
||||
ALTER TABLE podcast_episodes ADD COLUMN episode_description VARCHAR(4096);
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_blockcriteria ADD COLUMN criteriagroup integer;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE podcast_episodes ALTER COLUMN episode_description TYPE text;
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_block ALTER COLUMN type SET DEFAULT 'dynamic';
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE cc_files ADD COLUMN artwork VARCHAR(4096);
|
|
@ -1,25 +0,0 @@
|
|||
ALTER TABLE cc_files ADD COLUMN track_type VARCHAR(16);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "cc_track_types"
|
||||
(
|
||||
"id" serial NOT NULL,
|
||||
"code" VARCHAR(16) NOT NULL,
|
||||
"type_name" VARCHAR(64),
|
||||
"description" VARCHAR(255),
|
||||
"visibility" boolean DEFAULT true NOT NULL,
|
||||
CONSTRAINT "cc_track_types_pkey" PRIMARY KEY ("id"),
|
||||
CONSTRAINT "cc_track_types_code_key" UNIQUE ("code")
|
||||
);
|
||||
|
||||
INSERT INTO cc_track_types VALUES (1, 'MUS', 'Music', 'This is used for tracks containing music.', true);
|
||||
INSERT INTO cc_track_types VALUES (2, 'SID', 'Station ID', 'This is used for Station IDs', true);
|
||||
INSERT INTO cc_track_types VALUES (3, 'INT', 'Show Intro', 'This can be used for organizing all the show introductions.', true);
|
||||
INSERT INTO cc_track_types VALUES (4, 'OUT', 'Show Outro', 'This can be used for organizing all the show outroductions.', true);
|
||||
INSERT INTO cc_track_types VALUES (5, 'SWP', 'Sweeper', 'This is used for segues between songs.', true);
|
||||
INSERT INTO cc_track_types VALUES (6, 'JIN', 'Jingle', 'A short song or tune, normally played during commercial breaks. Contains one or more hooks.', true);
|
||||
INSERT INTO cc_track_types VALUES (7, 'PRO', 'Promo', 'For promotional use.', true);
|
||||
INSERT INTO cc_track_types VALUES (8, 'SHO', 'Shout Out', 'A message of congratulation, greeting. support, or appreciation. ', true);
|
||||
INSERT INTO cc_track_types VALUES (9, 'NWS', 'News', 'This is used for noteworthy information, announcements.', true);
|
||||
INSERT INTO cc_track_types VALUES (10, 'COM', 'Commercial', 'This is used for commerical advertising.', true);
|
||||
INSERT INTO cc_track_types VALUES (11, 'ITV', 'Interview', 'This is used for radio interviews', true);
|
||||
INSERT INTO cc_track_types VALUES (12, 'VTR', 'Voice Tracking', 'Also referred as robojock or taped. Make announcements without actually being in the station.', true);
|
|
@ -1 +0,0 @@
|
|||
DROP TABLE IF EXISTS "cc_smemb" CASCADE;
|
|
@ -1,5 +0,0 @@
|
|||
ALTER TABLE cc_files DROP COLUMN soundcloud_id;
|
||||
ALTER TABLE cc_files DROP COLUMN soundcloud_error_code;
|
||||
ALTER TABLE cc_files DROP COLUMN soundcloud_error_msg;
|
||||
ALTER TABLE cc_files DROP COLUMN soundcloud_link_to_file;
|
||||
ALTER TABLE cc_files DROP COLUMN soundcloud_upload_time;
|
|
@ -1,3 +0,0 @@
|
|||
ALTER TABLE cc_show ADD COLUMN has_autoplaylist boolean default 'f' NOT NULL;
|
||||
ALTER TABLE cc_show ADD COLUMN autoplaylist_id integer DEFAULT NULL;
|
||||
ALTER TABLE cc_show_instances ADD COLUMN autoplaylist_built boolean default 'f' NOT NULL;
|
|
@ -1,726 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Check if a given classname belongs to a subclass of AirtimeUpgrader.
|
||||
*
|
||||
* @param $c string class name
|
||||
*
|
||||
* @return bool true if the $c is a subclass of AirtimeUpgrader
|
||||
*/
|
||||
function isUpgrade($c)
|
||||
{
|
||||
return is_subclass_of($c, 'AirtimeUpgrader');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter all declared classes to get all upgrade classes dynamically.
|
||||
*
|
||||
* @return array all upgrade classes
|
||||
*/
|
||||
function getUpgrades()
|
||||
{
|
||||
return array_filter(get_declared_classes(), 'isUpgrade');
|
||||
}
|
||||
|
||||
class UpgradeManager
|
||||
{
|
||||
/**
|
||||
* Used to determine if the database schema needs an upgrade in order for this version of the Airtime codebase to work correctly.
|
||||
*
|
||||
* @return array a list of schema versions that this version of the codebase supports
|
||||
*/
|
||||
public static function getSupportedSchemaVersions()
|
||||
{
|
||||
$config = Config::getConfig();
|
||||
// What versions of the schema does the code support today:
|
||||
return [$config['airtime_version']];
|
||||
}
|
||||
|
||||
public static function checkIfUpgradeIsNeeded()
|
||||
{
|
||||
$schemaVersion = Application_Model_Preference::GetSchemaVersion();
|
||||
$supportedSchemaVersions = self::getSupportedSchemaVersions();
|
||||
|
||||
return !in_array($schemaVersion, $supportedSchemaVersions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade the Airtime schema version to match the highest supported version.
|
||||
*
|
||||
* @return bool whether or not an upgrade was performed
|
||||
*/
|
||||
public static function doUpgrade()
|
||||
{
|
||||
// Get all upgrades dynamically (in declaration order!) so we don't have to add them explicitly each time
|
||||
// TODO: explicitly sort classnames by ascending version suffix for safety
|
||||
$upgraders = getUpgrades();
|
||||
$dir = (dirname(__DIR__) . '/controllers');
|
||||
$upgradePerformed = false;
|
||||
|
||||
foreach ($upgraders as $upgrader) {
|
||||
$upgradePerformed = self::_runUpgrade(new $upgrader($dir)) ? true : $upgradePerformed;
|
||||
}
|
||||
|
||||
return $upgradePerformed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downgrade the Airtime schema version to match the given version.
|
||||
*
|
||||
* @param string $toVersion the version we want to downgrade to
|
||||
*
|
||||
* @return bool whether or not an upgrade was performed
|
||||
*/
|
||||
public static function doDowngrade($toVersion)
|
||||
{
|
||||
$downgraders = array_reverse(getUpgrades()); // Reverse the array because we're downgrading
|
||||
$dir = (dirname(__DIR__) . '/controllers');
|
||||
$downgradePerformed = false;
|
||||
|
||||
foreach ($downgraders as $downgrader) {
|
||||
/** @var AirtimeUpgrader $downgrader */
|
||||
$downgrader = new $downgrader($dir);
|
||||
if ($downgrader->getNewVersion() == $toVersion) {
|
||||
break; // We've reached the version we wanted to downgrade to, so break
|
||||
}
|
||||
$downgradePerformed = self::_runDowngrade($downgrader) ? true : $downgradePerformed;
|
||||
}
|
||||
|
||||
return $downgradePerformed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given upgrade.
|
||||
*
|
||||
* @param $upgrader AirtimeUpgrader the upgrader class to be executed
|
||||
*
|
||||
* @return bool true if the upgrade was successful, otherwise false
|
||||
*/
|
||||
private static function _runUpgrade(AirtimeUpgrader $upgrader)
|
||||
{
|
||||
return $upgrader->checkIfUpgradeSupported() && $upgrader->upgrade();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given downgrade.
|
||||
*
|
||||
* @param $downgrader AirtimeUpgrader the upgrader class to be executed
|
||||
* @param $supportedVersions array array of supported versions
|
||||
*
|
||||
* @return bool true if the downgrade was successful, otherwise false
|
||||
*/
|
||||
private static function _runDowngrade(AirtimeUpgrader $downgrader)
|
||||
{
|
||||
return $downgrader->checkIfDowngradeSupported() && $downgrader->downgrade();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AirtimeUpgrader
|
||||
{
|
||||
protected $_dir;
|
||||
|
||||
protected $host;
|
||||
protected $port;
|
||||
protected $database;
|
||||
protected $username;
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @param $dir string directory housing upgrade files
|
||||
*/
|
||||
public function __construct($dir)
|
||||
{
|
||||
$this->_dir = $dir;
|
||||
}
|
||||
|
||||
/** Schema versions that this upgrader class can upgrade from (an array of version strings). */
|
||||
abstract protected function getSupportedSchemaVersions();
|
||||
|
||||
/** The schema version that this upgrader class will upgrade to. (returns a version string) */
|
||||
abstract public function getNewVersion();
|
||||
|
||||
public static function getCurrentSchemaVersion()
|
||||
{
|
||||
return Application_Model_Preference::GetSchemaVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks to see if this class can perform an upgrade of your version of Airtime.
|
||||
*
|
||||
* @return bool true if we can upgrade your version of Airtime
|
||||
*/
|
||||
public function checkIfUpgradeSupported()
|
||||
{
|
||||
return in_array(static::getCurrentSchemaVersion(), $this->getSupportedSchemaVersions());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks to see if this class can perform a downgrade of your version of Airtime.
|
||||
*
|
||||
* @return bool true if we can downgrade your version of Airtime
|
||||
*/
|
||||
public function checkIfDowngradeSupported()
|
||||
{
|
||||
return static::getCurrentSchemaVersion() == $this->getNewVersion();
|
||||
}
|
||||
|
||||
protected function toggleMaintenanceScreen($toggle)
|
||||
{
|
||||
if ($toggle) {
|
||||
// Disable Airtime UI
|
||||
// create a temporary maintenance notification file
|
||||
// when this file is on the server, zend framework redirects all
|
||||
// requests to the maintenance page and sets a 503 response code
|
||||
/* DISABLED because this does not work correctly
|
||||
$this->maintenanceFile = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."maintenance.txt" : "/tmp/maintenance.txt";
|
||||
$file = fopen($this->maintenanceFile, 'w');
|
||||
fclose($file);
|
||||
*/
|
||||
}
|
||||
// delete maintenance.txt to give users access back to Airtime
|
||||
/* DISABLED because this does not work correctly
|
||||
if ($this->maintenanceFile) {
|
||||
unlink($this->maintenanceFile);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this for each new version of Airtime
|
||||
* This function abstracts out the core upgrade functionality,
|
||||
* allowing child classes to overwrite _runUpgrade to reduce duplication.
|
||||
*/
|
||||
public function upgrade()
|
||||
{
|
||||
try {
|
||||
// $this->toggleMaintenanceScreen(true);
|
||||
|
||||
$this->_getDbValues();
|
||||
$this->_runUpgrade();
|
||||
|
||||
Application_Model_Preference::SetSchemaVersion($this->getNewVersion());
|
||||
|
||||
// $this->toggleMaintenanceScreen(false);
|
||||
} catch (Exception $e) {
|
||||
// $this->toggleMaintenanceScreen(false);
|
||||
Logging::error('Error in upgrade: ' . $e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement this for each new version of Airtime
|
||||
* This function abstracts out the core downgrade functionality,
|
||||
* allowing child classes to overwrite _runDowngrade to reduce duplication.
|
||||
*/
|
||||
public function downgrade()
|
||||
{
|
||||
try {
|
||||
$this->_getDbValues();
|
||||
$this->_runDowngrade();
|
||||
|
||||
$highestSupportedVersion = null;
|
||||
foreach ($this->getSupportedSchemaVersions() as $v) {
|
||||
// version_compare returns 1 (true) if the second parameter is lower
|
||||
if (!$highestSupportedVersion || version_compare($v, $highestSupportedVersion)) {
|
||||
$highestSupportedVersion = $v;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the schema version to the highest supported version so we don't skip versions when downgrading
|
||||
Application_Model_Preference::SetSchemaVersion($highestSupportedVersion);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function _getDbValues()
|
||||
{
|
||||
$config = Config::getConfig();
|
||||
|
||||
$this->host = $config['dsn']['host'];
|
||||
$this->port = $config['dsn']['port'];
|
||||
$this->username = $config['dsn']['username'];
|
||||
$this->password = $config['dsn']['password'];
|
||||
$this->database = $config['dsn']['database'];
|
||||
}
|
||||
|
||||
protected function _runPsql($args)
|
||||
{
|
||||
$command = <<<"END"
|
||||
PGPASSWORD={$this->password} \\
|
||||
/usr/bin/psql --quiet \\
|
||||
--host={$this->host} \\
|
||||
--port={$this->port} \\
|
||||
--dbname={$this->database} \\
|
||||
--username={$this->username} \\
|
||||
{$args}
|
||||
END;
|
||||
passthru($command);
|
||||
}
|
||||
|
||||
protected function _runUpgrade()
|
||||
{
|
||||
$sqlFile = "{$this->_dir}/upgrade_sql/airtime_{$this->getNewVersion()}/upgrade.sql";
|
||||
$args = <<<"END"
|
||||
--file={$sqlFile} 2>&1 \\
|
||||
| grep -v -E "will create implicit sequence|will create implicit index"
|
||||
END;
|
||||
$this->_runPsql($args);
|
||||
}
|
||||
|
||||
protected function _runDowngrade()
|
||||
{
|
||||
$sqlFile = "{$this->_dir}/downgrade_sql/airtime_{$this->getNewVersion()}/downgrade.sql";
|
||||
$args = <<<"END"
|
||||
--file={$sqlFile} 2>&1 \\
|
||||
| grep -v -E "will create implicit sequence|will create implicit index"
|
||||
END;
|
||||
$this->_runPsql($args);
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader253 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return ['2.5.1', '2.5.2'];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.3';
|
||||
}
|
||||
|
||||
protected function _runUpgrade()
|
||||
{
|
||||
// Update disk_usage value in cc_pref
|
||||
$storDir = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE'] . 'srv/airtime/stor' : '/srv/airtime/stor';
|
||||
$diskUsage = shell_exec("du -sb {$storDir} | awk '{print $1}'");
|
||||
|
||||
Application_Model_Preference::setDiskUsage($diskUsage);
|
||||
|
||||
parent::_runUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader254 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return ['2.5.3'];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.4';
|
||||
}
|
||||
|
||||
protected function _runUpgrade()
|
||||
{
|
||||
// First, ensure there are no superadmins already.
|
||||
$numberOfSuperAdmins = CcSubjsQuery::create()
|
||||
->filterByDbType(UTYPE_SUPERADMIN)
|
||||
->filterByDbLogin('sourcefabric_admin', Criteria::NOT_EQUAL) // Ignore sourcefabric_admin users
|
||||
->count();
|
||||
|
||||
// Only create a super admin if there isn't one already.
|
||||
if ($numberOfSuperAdmins == 0) {
|
||||
// Find the "admin" user and promote them to superadmin.
|
||||
$adminUser = CcSubjsQuery::create()
|
||||
->filterByDbLogin('admin')
|
||||
->findOne();
|
||||
if (!$adminUser) {
|
||||
// Otherwise get the user with the lowest ID that is of type administrator:
|
||||
$adminUser = CcSubjsQuery::create()
|
||||
->filterByDbType(UTYPE_ADMIN)
|
||||
->orderByDbId(Criteria::ASC)
|
||||
->findOne();
|
||||
|
||||
if (!$adminUser) {
|
||||
throw new Exception("Failed to find any users of type 'admin' ('A').");
|
||||
}
|
||||
}
|
||||
|
||||
$adminUser = new Application_Model_User($adminUser->getDbId());
|
||||
$adminUser->setType(UTYPE_SUPERADMIN);
|
||||
$adminUser->save();
|
||||
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . ' Upgrade: Promoted user ' . $adminUser->getLogin() . ' to be a Super Admin.');
|
||||
|
||||
// Also try to promote the sourcefabric_admin user
|
||||
$sofabAdminUser = CcSubjsQuery::create()
|
||||
->filterByDbLogin('sourcefabric_admin')
|
||||
->findOne();
|
||||
if ($sofabAdminUser) {
|
||||
$sofabAdminUser = new Application_Model_User($sofabAdminUser->getDbId());
|
||||
$sofabAdminUser->setType(UTYPE_SUPERADMIN);
|
||||
$sofabAdminUser->save();
|
||||
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . ' Upgrade: Promoted user ' . $sofabAdminUser->getLogin() . ' to be a Super Admin.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader255 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.4',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.5';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader259 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.5',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.9';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader2510 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.9',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.10';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader2511 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.10',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.11';
|
||||
}
|
||||
|
||||
protected function _runUpgrade()
|
||||
{
|
||||
$queryResult = CcFilesQuery::create()
|
||||
->select(['disk_usage'])
|
||||
->withColumn('SUM(CcFiles.filesize)', 'disk_usage')
|
||||
->find();
|
||||
$disk_usage = $queryResult[0];
|
||||
Application_Model_Preference::setDiskUsage($disk_usage);
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader2512 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.10',
|
||||
'2.5.11',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.12';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader2513 - Celery and SoundCloud upgrade.
|
||||
*
|
||||
* Adds third_party_track_references and celery_tasks tables for third party service
|
||||
* authentication and task architecture.
|
||||
*
|
||||
* <br/><b>third_party_track_references</b> schema:
|
||||
*
|
||||
* id -> int PK
|
||||
* service -> string internal service name
|
||||
* foreign_id -> int external unique service id
|
||||
* file_id -> int internal FK->cc_files track id
|
||||
* upload_time -> timestamp internal upload timestamp
|
||||
* status -> string external service status
|
||||
*
|
||||
* <br/><b>celery_tasks</b> schema:
|
||||
*
|
||||
* id -> int PK
|
||||
* task_id -> string external unique amqp results identifier
|
||||
* track_reference -> int internal FK->third_party_track_references id
|
||||
* name -> string external Celery task name
|
||||
* dispatch_time -> timestamp internal message dispatch time
|
||||
* status -> string external Celery task status
|
||||
*/
|
||||
class AirtimeUpgrader2513 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.12',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.13';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader2514.
|
||||
*
|
||||
* SAAS-923 - Add a partial constraint to cc_pref so that keystrings must be unique
|
||||
*/
|
||||
class AirtimeUpgrader2514 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.13',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.14';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader2515.
|
||||
*
|
||||
* SAAS-1071 - Remove not null constraint from file_id fk in third_party_track_references
|
||||
* so that we can create track references for downloads (which won't have a file
|
||||
* ID until the task is run and the file is POSTed back to Airtime)
|
||||
*/
|
||||
class AirtimeUpgrader2515 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.14',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.15';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader2516 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.15',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '2.5.16';
|
||||
}
|
||||
}
|
||||
class AirtimeUpgrader300alpha extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'2.5.16',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader300alpha1 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.1';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader300alpha6 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.1',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.6';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader300alpha7.
|
||||
*
|
||||
* GH-#636 - https://github.com/libretime/libretime/pull/636 - Change dynamic smartblock to be default smartblock type
|
||||
*/
|
||||
class AirtimeUpgrader300alpha7 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.6',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.7';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader300alpha7-1.
|
||||
*
|
||||
* GH-#659 - https://github.com/libretime/libretime/pull/659/ - Add description and title to podcast episodes database table
|
||||
*/
|
||||
class AirtimeUpgrader300alpha7_1 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.7',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.7.1';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AirtimeUpgrader300alpha7-2.
|
||||
*
|
||||
* GH-#704 - https://github.com/libretime/libretime/pull/704/ - Add criteria group to smartblock table to enable database to store separately
|
||||
*/
|
||||
class AirtimeUpgrader300alpha7_2 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.7.1',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.7.2';
|
||||
}
|
||||
}
|
||||
class AirtimeUpgrader300alpha7_3 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.7.2',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.7.3';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader300alpha9_1 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.7.3',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.9.1';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader300alpha9_2 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.9.1',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.9.2';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader200alpha9_3 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.9.2',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.9.3';
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeUpgrader200alpha9_4 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return [
|
||||
'3.0.0-alpha.9.3',
|
||||
];
|
||||
}
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return '3.0.0-alpha.9.4';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue