[DB][MEDIA] Small database structure changes

This commit is contained in:
Hugo Sales 2020-08-20 00:43:33 +00:00 committed by Hugo Sales
parent 9204213dbc
commit 57297aba56
2 changed files with 40 additions and 40 deletions

View File

@ -43,14 +43,14 @@ class File extends Entity
private int $id;
private ?string $url;
private ?bool $is_url_protected;
private ?string $url_hash;
private ?string $file_hash;
private ?int $actor_id;
private ?string $mimetype;
private ?int $size;
private ?string $title;
private ?bool $is_local;
private ?bool $is_nsfw;
private ?bool $is_url_protected;
private DateTimeInterface $modified;
public function setId(int $id): self
@ -75,17 +75,6 @@ class File extends Entity
return $this->url;
}
public function setIsUrlProtected(?bool $is_url_protected): self
{
$this->is_url_protected = $is_url_protected;
return $this;
}
public function getIsUrlProtected(): ?bool
{
return $this->is_url_protected;
}
public function setUrlHash(?string $url_hash): self
{
$this->url_hash = $url_hash;
@ -130,17 +119,6 @@ class File extends Entity
return $this->mimetype;
}
public function setSize(?int $size): self
{
$this->size = $size;
return $this;
}
public function getSize(): ?int
{
return $this->size;
}
public function setTitle(?string $title): self
{
$this->title = $title;
@ -163,6 +141,28 @@ class File extends Entity
return $this->is_local;
}
public function setIsNsfw(?bool $is_nsfw): self
{
$this->is_nsfw = $is_nsfw;
return $this;
}
public function getIsNsfw(): ?bool
{
return $this->is_nsfw;
}
public function setIsUrlProtected(?bool $is_url_protected): self
{
$this->is_url_protected = $is_url_protected;
return $this;
}
public function getIsUrlProtected(): ?bool
{
return $this->is_url_protected;
}
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
@ -226,14 +226,14 @@ class File extends Entity
'fields' => [
'id' => ['type' => 'serial', 'not null' => true],
'url' => ['type' => 'text', 'description' => 'URL after following possible redirections'],
'is_url_protected' => ['type' => 'bool', 'default' => false, 'description' => 'true when URL is private (needs login)'],
'url_hash' => ['type' => 'varchar', 'length' => 64, 'description' => 'sha256 of destination URL (url field)'],
'file_hash' => ['type' => 'varchar', 'length' => 64, 'description' => 'sha256 of the file contents, if the file is stored locally'],
'actor_id' => ['type' => 'int', 'description' => 'If set, used so each actor can have a version of this file (for avatars, for instance)'],
'mimetype' => ['type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'],
'size' => ['type' => 'int', 'description' => 'size of resource when available'],
'title' => ['type' => 'text', 'description' => 'title of resource when available'],
'is_local' => ['type' => 'bool', 'description' => 'whether the file is stored locally'],
'is_nsfw' => ['type' => 'bool', 'default' => false, 'description' => 'whether the file is NSFW'],
'is_url_protected' => ['type' => 'bool', 'default' => false, 'description' => 'true when URL is private (needs login)'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['id'],

View File

@ -41,7 +41,7 @@ class FileToNote extends Entity
// {{{ Autocode
private int $file_id;
private int $activity_id;
private int $note_id;
private DateTimeInterface $modified;
public function setFileId(int $file_id): self
@ -55,15 +55,15 @@ class FileToNote extends Entity
return $this->file_id;
}
public function setActivityId(int $activity_id): self
public function setNoteId(int $note_id): self
{
$this->activity_id = $activity_id;
$this->note_id = $note_id;
return $this;
}
public function getActivityId(): int
public function getNoteId(): int
{
return $this->activity_id;
return $this->note_id;
}
public function setModified(DateTimeInterface $modified): self
@ -82,20 +82,20 @@ class FileToNote extends Entity
public static function schemaDef(): array
{
return [
'name' => 'file_to_activity',
'name' => 'file_to_note',
'fields' => [
'file_id' => ['type' => 'int', 'not null' => true, 'description' => 'id of file'],
'activity_id' => ['type' => 'int', 'not null' => true, 'description' => 'id of the activity it belongs to'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
'file_id' => ['type' => 'int', 'not null' => true, 'description' => 'id of file'],
'note_id' => ['type' => 'int', 'not null' => true, 'description' => 'id of the note it belongs to'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['file_id', 'activity_id'],
'primary key' => ['file_id', 'note_id'],
'foreign keys' => [
'file_to_activity_file_id_fkey' => ['file', ['file_id' => 'id']],
'file_to_activity_activity_id_fkey' => ['notice', ['activity_id' => 'id']],
'file_to_note_file_id_fkey' => ['file', ['file_id' => 'id']],
'file_to_note_note_id_fkey' => ['note', ['note_id' => 'id']],
],
'indexes' => [
'file_id_idx' => ['file_id'],
'activity_id_idx' => ['activity_id'],
'file_id_idx' => ['file_id'],
'note_id_idx' => ['note_id'],
],
];
}