Added a database upgrade that adds a tag_id,image_id index to image_tags, and lengthens the filename field to 255 characters. 64 was ridiculous.
Also added a substr to the filename for the merge code so it won't error when it's a long name
This commit is contained in:
parent
80e614b53e
commit
dfeb3bf5df
2 changed files with 21 additions and 2 deletions
|
@ -224,7 +224,7 @@ class ImageIO extends Extension
|
|||
:hash, :ext, :width, :height, now(), :source
|
||||
)",
|
||||
[
|
||||
"owner_id"=>$user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'], "filename"=>substr($image->filename, 0, 60), "filesize"=>$image->filesize,
|
||||
"owner_id" => $user->id, "owner_ip" => $_SERVER['REMOTE_ADDR'], "filename" => substr($image->filename, 0, 255), "filesize" => $image->filesize,
|
||||
"hash"=>$image->hash, "ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source
|
||||
]
|
||||
);
|
||||
|
@ -342,7 +342,7 @@ class ImageIO extends Extension
|
|||
id = :id
|
||||
",
|
||||
[
|
||||
"filename"=>$image->filename, "filesize"=>$image->filesize, "hash"=>$image->hash,
|
||||
"filename" => substr($image->filename, 0, 255), "filesize"=>$image->filesize, "hash"=>$image->hash,
|
||||
"ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source,
|
||||
"id"=>$id
|
||||
]
|
||||
|
|
|
@ -143,6 +143,25 @@ class Upgrade extends Extension
|
|||
log_info("upgrade", "Database at version 15");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
|
||||
if ($config->get_int("db_version") < 16) {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 16);
|
||||
|
||||
log_info("upgrade", "Adding tag_id, image_id index to image_tags");
|
||||
$database->execute('CREATE UNIQUE INDEX image_tags_tag_id_image_id_idx ON image_tags(tag_id,image_id) ');
|
||||
|
||||
log_info("upgrade", "Changing filename column to VARCHAR(255)");
|
||||
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
|
||||
$database->execute('ALTER TABLE images ALTER COLUMN filename SET DATA TYPE VARCHAR(255)');
|
||||
} elseif ($database->get_driver_name() == DatabaseDriver::MYSQL) {
|
||||
$database->execute('ALTER TABLE images MODIFY COLUMN filename VARCHAR(255) NOT NULL');
|
||||
}
|
||||
// SQLite doesn't support altering existing columns? This seems like a problem?
|
||||
|
||||
log_info("upgrade", "Database at version 16");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_priority(): int
|
||||
|
|
Reference in a new issue