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:
jo 2022-05-28 16:27:57 +02:00 committed by Kyle Robbertze
parent ee98387264
commit 0e4bc4cacd
85 changed files with 1005 additions and 1000 deletions

View file

@ -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());
}
}
}

View file

@ -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;

View file

@ -1 +0,0 @@
ALTER TABLE third_party_track_references ALTER COLUMN file_id SET NOT NULL;

View file

@ -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;

View file

@ -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;

View file

@ -1 +0,0 @@
ALTER TABLE cc_service_register ALTER COLUMN ip TYPE character varying(18);

View file

@ -1,2 +0,0 @@
ALTER TABLE podcast_episodes DROP COLUMN IF EXISTS episode_title;
ALTER TABLE podcast_episodes DROP COLUMN IF EXISTS episode_description;

View file

@ -1 +0,0 @@
ALTER TABLE cc_blockcriteria DROP COLUMN IF EXISTS criteriagroup;

View file

@ -1 +0,0 @@
ALTER TABLE podcast_episodes ALTER COLUMN episode_description TYPE VARCHAR(4096);

View file

@ -1 +0,0 @@
ALTER TABLE cc_block ALTER COLUMN type SET DEFAULT 'static';

View file

@ -1 +0,0 @@
ALTER TABLE cc_files DROP COLUMN IF EXISTS artwork;

View file

@ -1,3 +0,0 @@
ALTER TABLE cc_files DROP COLUMN IF EXISTS track_type;
DROP TABLE IF EXISTS "cc_track_types" CASCADE;

View file

@ -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")
);

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -1,2 +0,0 @@
ALTER TABLE cc_files ADD COLUMN filesize integer NOT NULL
CONSTRAINT filesize_default DEFAULT 0

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -1 +0,0 @@
ALTER TABLE third_party_track_references ALTER COLUMN file_id DROP NOT NULL;

View file

@ -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;

View file

@ -1 +0,0 @@
ALTER TABLE cc_files ADD COLUMN artwork TYPE character varying(255);

View file

@ -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 '';

View file

@ -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"

View file

@ -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 '';

View file

@ -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
)

View file

@ -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;

View file

@ -1 +0,0 @@
ALTER TABLE cc_service_register ALTER COLUMN ip TYPE character varying(45);

View file

@ -1,2 +0,0 @@
ALTER TABLE podcast_episodes ADD COLUMN episode_title VARCHAR(4096);
ALTER TABLE podcast_episodes ADD COLUMN episode_description VARCHAR(4096);

View file

@ -1 +0,0 @@
ALTER TABLE cc_blockcriteria ADD COLUMN criteriagroup integer;

View file

@ -1 +0,0 @@
ALTER TABLE podcast_episodes ALTER COLUMN episode_description TYPE text;

View file

@ -1 +0,0 @@
ALTER TABLE cc_block ALTER COLUMN type SET DEFAULT 'dynamic';

View file

@ -1 +0,0 @@
ALTER TABLE cc_files ADD COLUMN artwork VARCHAR(4096);

View file

@ -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);

View file

@ -1 +0,0 @@
DROP TABLE IF EXISTS "cc_smemb" CASCADE;

View file

@ -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;

View file

@ -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;