Allow 0 file_id in third_party_trackrefs

The previous constraint of NOT NULL made it impossible to create a placeholder entry for later downloading. This uses a 0 default instead of the constraint and downloading as well as the green checkbox work again.
This commit is contained in:
Lucas Bickel 2017-03-18 11:37:45 +01:00
parent e3879b42a3
commit 7f00182913
5 changed files with 33 additions and 4 deletions

View file

@ -1 +1,3 @@
ALTER TABLE imported_podcast DROP COLUMN IF EXISTS album_override; 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;

View file

@ -42,7 +42,7 @@ class ThirdPartyTrackReferencesTableMap extends TableMap
$this->addPrimaryKey('id', 'DbId', 'INTEGER', true, null, null); $this->addPrimaryKey('id', 'DbId', 'INTEGER', true, null, null);
$this->addColumn('service', 'DbService', 'VARCHAR', true, 256, null); $this->addColumn('service', 'DbService', 'VARCHAR', true, 256, null);
$this->addColumn('foreign_id', 'DbForeignId', 'VARCHAR', false, 256, null); $this->addColumn('foreign_id', 'DbForeignId', 'VARCHAR', false, 256, null);
$this->addForeignKey('file_id', 'DbFileId', 'INTEGER', 'cc_files', 'id', true, null, null); $this->addForeignKey('file_id', 'DbFileId', 'INTEGER', 'cc_files', 'id', true, null, 0);
$this->addColumn('upload_time', 'DbUploadTime', 'TIMESTAMP', false, null, null); $this->addColumn('upload_time', 'DbUploadTime', 'TIMESTAMP', false, null, null);
$this->addColumn('status', 'DbStatus', 'VARCHAR', false, 256, null); $this->addColumn('status', 'DbStatus', 'VARCHAR', false, 256, null);
// validators // validators

View file

@ -49,6 +49,7 @@ abstract class BaseThirdPartyTrackReferences extends BaseObject implements Persi
/** /**
* The value for the file_id field. * The value for the file_id field.
* Note: this column has a database default value of: 0
* @var int * @var int
*/ */
protected $file_id; protected $file_id;
@ -102,6 +103,27 @@ abstract class BaseThirdPartyTrackReferences extends BaseObject implements Persi
*/ */
protected $celeryTaskssScheduledForDeletion = null; protected $celeryTaskssScheduledForDeletion = null;
/**
* Applies default values to this object.
* This method should be called from the object's constructor (or
* equivalent initialization method).
* @see __construct()
*/
public function applyDefaultValues()
{
$this->file_id = 0;
}
/**
* Initializes internal state of BaseThirdPartyTrackReferences object.
* @see applyDefaults()
*/
public function __construct()
{
parent::__construct();
$this->applyDefaultValues();
}
/** /**
* Get the [id] column value. * Get the [id] column value.
* *
@ -334,6 +356,10 @@ abstract class BaseThirdPartyTrackReferences extends BaseObject implements Persi
*/ */
public function hasOnlyDefaultValues() public function hasOnlyDefaultValues()
{ {
if ($this->file_id !== 0) {
return false;
}
// otherwise, everything was equal, so return true // otherwise, everything was equal, so return true
return true; return true;
} // hasOnlyDefaultValues() } // hasOnlyDefaultValues()
@ -1129,7 +1155,7 @@ abstract class BaseThirdPartyTrackReferences extends BaseObject implements Persi
public function setCcFiles(CcFiles $v = null) public function setCcFiles(CcFiles $v = null)
{ {
if ($v === null) { if ($v === null) {
$this->setDbFileId(NULL); $this->setDbFileId(0);
} else { } else {
$this->setDbFileId($v->getDbId()); $this->setDbFileId($v->getDbId());
} }
@ -1427,6 +1453,7 @@ abstract class BaseThirdPartyTrackReferences extends BaseObject implements Persi
$this->alreadyInValidation = false; $this->alreadyInValidation = false;
$this->alreadyInClearAllReferencesDeep = false; $this->alreadyInClearAllReferencesDeep = false;
$this->clearAllReferences(); $this->clearAllReferences();
$this->applyDefaultValues();
$this->resetModified(); $this->resetModified();
$this->setNew(true); $this->setNew(true);
$this->setDeleted(false); $this->setDeleted(false);

View file

@ -543,7 +543,7 @@
<column name="service" phpName="DbService" type="VARCHAR" size="256" required="true" /> <column name="service" phpName="DbService" type="VARCHAR" size="256" required="true" />
<!-- Make foreign ID a VARCHAR field in case a service uses hashes or other non-integer identifiers --> <!-- Make foreign ID a VARCHAR field in case a service uses hashes or other non-integer identifiers -->
<column name="foreign_id" phpName="DbForeignId" type="VARCHAR" size="256" /> <column name="foreign_id" phpName="DbForeignId" type="VARCHAR" size="256" />
<column name="file_id" phpName="DbFileId" type="INTEGER" required="true" /> <column name="file_id" phpName="DbFileId" type="INTEGER" required="true" default="0" />
<column name="upload_time" phpName="DbUploadTime" type="TIMESTAMP" /> <column name="upload_time" phpName="DbUploadTime" type="TIMESTAMP" />
<column name="status" phpName="DbStatus" type="VARCHAR" size="256" /> <column name="status" phpName="DbStatus" type="VARCHAR" size="256" />
<unique name="foreign_id_unique"> <unique name="foreign_id_unique">

View file

@ -685,7 +685,7 @@ CREATE TABLE "third_party_track_references"
"id" serial NOT NULL, "id" serial NOT NULL,
"service" VARCHAR(256) NOT NULL, "service" VARCHAR(256) NOT NULL,
"foreign_id" VARCHAR(256), "foreign_id" VARCHAR(256),
"file_id" INTEGER NOT NULL, "file_id" INTEGER DEFAULT 0 NOT NULL,
"upload_time" TIMESTAMP, "upload_time" TIMESTAMP,
"status" VARCHAR(256), "status" VARCHAR(256),
PRIMARY KEY ("id"), PRIMARY KEY ("id"),