rename table

This commit is contained in:
yggverse 2026-01-08 00:42:26 +02:00
parent 7b9fac8d3a
commit e26236a591
3 changed files with 23 additions and 23 deletions

View file

@ -187,7 +187,7 @@ fn crawl(db: &Mysql, channel_config: &config::Channel) -> Result<()> {
}, },
}; };
assert!( assert!(
db.contents_by_channel_item_id_source_id(channel_item_id, None, Some(1))? db.contents_by_channel_item_id_provider_id(channel_item_id, None, Some(1))?
.is_empty() .is_empty()
); );
let _content_id = db.insert_content(channel_item_id, None, title, description)?; let _content_id = db.insert_content(channel_item_id, None, title, description)?;

View file

@ -1,5 +1,5 @@
-- MySQL Script generated by MySQL Workbench -- MySQL Script generated by MySQL Workbench
-- Wed 07 Jan 2026 04:18:03 PM EET -- Thu 08 Jan 2026 12:40:45 AM EET
-- Model: New Model Version: 1.0 -- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering -- MySQL Workbench Forward Engineering
@ -51,12 +51,12 @@ ENGINE = InnoDB;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `rssto`.`source` -- Table `rssto`.`provider`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rssto`.`source` ( CREATE TABLE IF NOT EXISTS `rssto`.`provider` (
`source_id` INT NOT NULL AUTO_INCREMENT, `provider_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL,
PRIMARY KEY (`source_id`), PRIMARY KEY (`provider_id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE) UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE)
ENGINE = InnoDB; ENGINE = InnoDB;
@ -67,21 +67,21 @@ ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `rssto`.`content` ( CREATE TABLE IF NOT EXISTS `rssto`.`content` (
`content_id` BIGINT NOT NULL AUTO_INCREMENT, `content_id` BIGINT NOT NULL AUTO_INCREMENT,
`channel_item_id` INT NOT NULL, `channel_item_id` INT NOT NULL,
`source_id` INT NULL, `provider_id` INT NULL,
`title` VARCHAR(255) NOT NULL, `title` VARCHAR(255) NOT NULL,
`description` LONGTEXT NOT NULL, `description` LONGTEXT NOT NULL,
PRIMARY KEY (`content_id`), PRIMARY KEY (`content_id`),
INDEX `fk_content_channel_item_idx` (`channel_item_id` ASC) VISIBLE, INDEX `fk_content_channel_item_idx` (`channel_item_id` ASC) VISIBLE,
INDEX `fk_content_source_idx` (`source_id` ASC) VISIBLE, INDEX `fk_content_provider_idx` (`provider_id` ASC) VISIBLE,
UNIQUE INDEX `UNIQUE` (`channel_item_id` ASC, `source_id` ASC) VISIBLE, UNIQUE INDEX `UNIQUE` (`channel_item_id` ASC, `provider_id` ASC) VISIBLE,
CONSTRAINT `fk_content_channel_item` CONSTRAINT `fk_content_channel_item`
FOREIGN KEY (`channel_item_id`) FOREIGN KEY (`channel_item_id`)
REFERENCES `rssto`.`channel_item` (`channel_item_id`) REFERENCES `rssto`.`channel_item` (`channel_item_id`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT `fk_content_source` CONSTRAINT `fk_content_provider`
FOREIGN KEY (`source_id`) FOREIGN KEY (`provider_id`)
REFERENCES `rssto`.`source` (`source_id`) REFERENCES `rssto`.`provider` (`provider_id`)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;

View file

@ -99,7 +99,7 @@ impl Mysql {
self.pool.get_conn()?.exec_first( self.pool.get_conn()?.exec_first(
"SELECT `content_id`, "SELECT `content_id`,
`channel_item_id`, `channel_item_id`,
`source_id`, `provider_id`,
`title`, `title`,
`description` FROM `content` WHERE `content_id` = ?", `description` FROM `content` WHERE `content_id` = ?",
(content_id,), (content_id,),
@ -118,43 +118,43 @@ impl Mysql {
self.pool.get_conn()?.query(format!( self.pool.get_conn()?.query(format!(
"SELECT `content_id`, "SELECT `content_id`,
`channel_item_id`, `channel_item_id`,
`source_id`, `provider_id`,
`title`, `title`,
`description` FROM `content` ORDER BY `content_id` {sort} LIMIT {}", `description` FROM `content` ORDER BY `content_id` {sort} LIMIT {}",
limit.unwrap_or(DEFAULT_LIMIT) limit.unwrap_or(DEFAULT_LIMIT)
)) ))
} }
pub fn contents_by_channel_item_id_source_id( pub fn contents_by_channel_item_id_provider_id(
&self, &self,
channel_item_id: u64, channel_item_id: u64,
source_id: Option<u64>, provider_id: Option<u64>,
limit: Option<usize>, limit: Option<usize>,
) -> Result<Vec<Content>, Error> { ) -> Result<Vec<Content>, Error> {
self.pool.get_conn()?.exec( self.pool.get_conn()?.exec(
format!( format!(
"SELECT `content_id`, "SELECT `content_id`,
`channel_item_id`, `channel_item_id`,
`source_id`, `provider_id`,
`title`, `title`,
`description` FROM `content` WHERE `channel_item_id` = ? AND `source_id` = ? LIMIT {}", `description` FROM `content` WHERE `channel_item_id` = ? AND `provider_id` = ? LIMIT {}",
limit.unwrap_or(DEFAULT_LIMIT) limit.unwrap_or(DEFAULT_LIMIT)
), ),
(channel_item_id, source_id), (channel_item_id, provider_id),
) )
} }
pub fn insert_content( pub fn insert_content(
&self, &self,
channel_item_id: u64, channel_item_id: u64,
source_id: Option<u64>, provider_id: Option<u64>,
title: String, title: String,
description: String, description: String,
) -> Result<u64, Error> { ) -> Result<u64, Error> {
let mut c = self.pool.get_conn()?; let mut c = self.pool.get_conn()?;
c.exec_drop( c.exec_drop(
"INSERT INTO `content` SET `channel_item_id` = ?, `source_id` = ?, `title` = ?, `description` = ?", "INSERT INTO `content` SET `channel_item_id` = ?, `provider_id` = ?, `title` = ?, `description` = ?",
(channel_item_id, source_id, title, description ), (channel_item_id, provider_id, title, description ),
)?; )?;
Ok(c.last_insert_id()) Ok(c.last_insert_id())
} }
@ -183,7 +183,7 @@ pub struct Content {
pub channel_item_id: u64, pub channel_item_id: u64,
/// None if the original `title` and `description` values /// None if the original `title` and `description` values
/// parsed from the channel item on crawl /// parsed from the channel item on crawl
pub source_id: Option<u64>, pub provider_id: Option<u64>,
pub title: String, pub title: String,
pub description: String, pub description: String,
} }