From 555a0bc1d14335ef6b0c7d7701663ff29554d587 Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 8 Mar 2023 20:43:56 +0000 Subject: [PATCH] db: add tagged_media_view --- .../Schema/Result/TaggedMediaView.pm | 84 +++++++++++++++++++ migrations/1_down.sql | 2 +- migrations/1_up.sql | 17 ++-- 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 lib/PoorBooru/Schema/Result/TaggedMediaView.pm diff --git a/lib/PoorBooru/Schema/Result/TaggedMediaView.pm b/lib/PoorBooru/Schema/Result/TaggedMediaView.pm new file mode 100644 index 0000000..e82cca5 --- /dev/null +++ b/lib/PoorBooru/Schema/Result/TaggedMediaView.pm @@ -0,0 +1,84 @@ +use utf8; +package PoorBooru::Schema::Result::TaggedMediaView; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +PoorBooru::Schema::Result::TaggedMediaView + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->table_class("DBIx::Class::ResultSource::View"); + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("tagged_media_view"); + +=head1 ACCESSORS + +=head2 media_id + + data_type: 'integer' + is_nullable: 1 + +=head2 media_seaweedfs_fid + + data_type: 'text' + is_nullable: 1 + size: 35 + +=head2 media_filename + + data_type: 'text' + is_nullable: 1 + size: 256 + +=head2 media_content_type + + data_type: 'text' + is_nullable: 1 + size: 256 + +=head2 tag_id + + data_type: 'integer' + is_nullable: 1 + +=head2 tag_name + + data_type: 'text' + is_nullable: 1 + size: 256 + +=cut + +__PACKAGE__->add_columns( + "media_id", + { data_type => "integer", is_nullable => 1 }, + "media_seaweedfs_fid", + { data_type => "text", is_nullable => 1, size => 35 }, + "media_filename", + { data_type => "text", is_nullable => 1, size => 256 }, + "media_content_type", + { data_type => "text", is_nullable => 1, size => 256 }, + "tag_id", + { data_type => "integer", is_nullable => 1 }, + "tag_name", + { data_type => "text", is_nullable => 1, size => 256 }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-03-06 09:09:55 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2fQvZTUxyABEgkmYYnk75w + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/migrations/1_down.sql b/migrations/1_down.sql index 811ee77..fc83577 100644 --- a/migrations/1_down.sql +++ b/migrations/1_down.sql @@ -1,4 +1,4 @@ --- DROP VIEW tagged_media_view; +DROP VIEW tagged_media_view; DROP VIEW tag_count_view; DROP TABLE media_tags; DROP TABLE tags; diff --git a/migrations/1_up.sql b/migrations/1_up.sql index 4c09780..852b2a4 100644 --- a/migrations/1_up.sql +++ b/migrations/1_up.sql @@ -26,10 +26,13 @@ FROM tags INNER JOIN media_tags USING (tag_id) GROUP BY tag_id; --- CREATE VIEW tagged_media_view AS SELECT --- tags.tag_id AS tag_id, --- tags.name AS tag_name, --- media.media_id AS media_id --- FROM media --- INNER JOIN media_tags USING (media_id) --- INNER JOIN tags USING (tag_id); +CREATE VIEW tagged_media_view AS SELECT + media.media_id AS media_id, + media.seaweedfs_fid AS media_seaweedfs_fid, + media.filename AS media_filename, + media.content_type AS media_content_type, + tags.tag_id AS tag_id, + tags.name AS tag_name +FROM media_tags + INNER JOIN media USING (media_id) + INNER JOIN tags USING (tag_id);