DB Schema: Remove episode.published_date column.

This commit is contained in:
Jordan Petridis 2017-12-30 22:23:10 +02:00
parent 963ff212ad
commit e727734443
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
6 changed files with 47 additions and 27 deletions

View File

@ -0,0 +1,24 @@
ALTER TABLE episode RENAME TO old_table;
CREATE TABLE episode (
title TEXT NOT NULL,
uri TEXT,
local_uri TEXT,
description TEXT,
published_date TEXT,
epoch INTEGER NOT NULL DEFAULT 0,
length INTEGER,
duration INTEGER,
guid TEXT,
played INTEGER,
podcast_id INTEGER NOT NULL,
favorite INTEGER DEFAULT 0,
archive INTEGER DEFAULT 0,
PRIMARY KEY (title, podcast_id)
);
INSERT INTO episode (title, uri, local_uri, description, epoch, length, duration, guid, played, favorite, archive, podcast_id)
SELECT title, uri, local_uri, description, epoch, length, duration, guid, played, favorite, archive, podcast_id
FROM old_table;
Drop table old_table;

View File

@ -0,0 +1,23 @@
ALTER TABLE episode RENAME TO old_table;
CREATE TABLE episode (
title TEXT NOT NULL,
uri TEXT,
local_uri TEXT,
description TEXT,
epoch INTEGER NOT NULL DEFAULT 0,
length INTEGER,
duration INTEGER,
guid TEXT,
played INTEGER,
podcast_id INTEGER NOT NULL,
favorite INTEGER DEFAULT 0,
archive INTEGER DEFAULT 0,
PRIMARY KEY (title, podcast_id)
);
INSERT INTO episode (title, uri, local_uri, description, epoch, length, duration, guid, played, favorite, archive, podcast_id)
SELECT title, uri, local_uri, description, epoch, length, duration, guid, played, favorite, archive, podcast_id
FROM old_table;
Drop table old_table;

View File

@ -158,7 +158,6 @@ pub(crate) struct NewEpisode {
title: String, title: String,
uri: Option<String>, uri: Option<String>,
description: Option<String>, description: Option<String>,
published_date: Option<String>,
length: Option<i32>, length: Option<i32>,
duration: Option<i32>, duration: Option<i32>,
guid: Option<String>, guid: Option<String>,
@ -234,10 +233,6 @@ impl NewEpisode {
self.description.as_ref().map(|s| s.as_str()) self.description.as_ref().map(|s| s.as_str())
} }
pub(crate) fn published_date(&self) -> Option<&str> {
self.published_date.as_ref().map(|s| s.as_str())
}
pub(crate) fn guid(&self) -> Option<&str> { pub(crate) fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str()) self.guid.as_ref().map(|s| s.as_str())
} }

View File

@ -30,7 +30,6 @@ pub struct Episode {
uri: Option<String>, uri: Option<String>,
local_uri: Option<String>, local_uri: Option<String>,
description: Option<String>, description: Option<String>,
published_date: Option<String>,
epoch: i32, epoch: i32,
length: Option<i32>, length: Option<i32>,
duration: Option<i32>, duration: Option<i32>,
@ -92,16 +91,6 @@ impl Episode {
self.description = value.map(|x| x.to_string()); self.description = value.map(|x| x.to_string());
} }
/// Get the the `published_date`.
pub fn published_date(&self) -> Option<&str> {
self.published_date.as_ref().map(|s| s.as_str())
}
/// Set the `published_date`.
pub fn set_published_date(&mut self, value: Option<&str>) {
self.published_date = value.map(|x| x.to_string().to_owned());
}
/// Get the value of the `description`. /// Get the value of the `description`.
pub fn guid(&self) -> Option<&str> { pub fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str()) self.guid.as_ref().map(|s| s.as_str())

View File

@ -71,7 +71,6 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
// Should treat information from the rss feeds as invalid by default. // Should treat information from the rss feeds as invalid by default.
// Case: Thu, 05 Aug 2016 06:00:00 -0400 <-- Actually that was friday. // Case: Thu, 05 Aug 2016 06:00:00 -0400 <-- Actually that was friday.
let pub_date = date.map(|x| x.to_rfc2822()).ok();
let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0); let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0);
let length = || -> Option<i32> { item.enclosure().map(|x| x.length().parse().ok())? }(); let length = || -> Option<i32> { item.enclosure().map(|x| x.length().parse().ok())? }();
@ -83,7 +82,6 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
.description(description) .description(description)
.length(length) .length(length)
.duration(duration) .duration(duration)
.published_date(pub_date)
.epoch(epoch) .epoch(epoch)
.guid(guid) .guid(guid)
.podcast_id(parent_id) .podcast_id(parent_id)
@ -241,7 +239,6 @@ mod tests {
))) )))
.description(Some(String::from(descr))) .description(Some(String::from(descr)))
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24"))) .guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
.published_date(Some(String::from("Wed, 13 Sep 2017 10:00:00 +0000")))
.length(Some(66738886)) .length(Some(66738886))
.epoch(1505296800) .epoch(1505296800)
.duration(Some(4171)) .duration(Some(4171))
@ -269,7 +266,6 @@ mod tests {
))) )))
.description(Some(String::from(descr))) .description(Some(String::from(descr)))
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d"))) .guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
.published_date(Some(String::from("Wed, 9 Aug 2017 10:00:00 +0000")))
.length(Some(67527575)) .length(Some(67527575))
.epoch(1502272800) .epoch(1502272800)
.duration(Some(4220)) .duration(Some(4220))
@ -296,7 +292,6 @@ mod tests {
.description(Some(String::from(descr))) .description(Some(String::from(descr)))
.guid(Some(String::from("https://www.propublica.org/podcast/\ .guid(Some(String::from("https://www.propublica.org/podcast/\
the-breakthrough-hopelessness-exploitation-homes-for-mentally-ill#134472"))) the-breakthrough-hopelessness-exploitation-homes-for-mentally-ill#134472")))
.published_date(Some(String::from("Fri, 8 Sep 2017 12:00:00 +0000")))
.length(Some(33396551)) .length(Some(33396551))
.epoch(1504872000) .epoch(1504872000)
.duration(Some(1670)) .duration(Some(1670))
@ -326,7 +321,6 @@ mod tests {
"https://www.propublica.\ "https://www.propublica.\
org/podcast/the-breakthrough-hillary-clinton-failed-presidential-bid#133721", org/podcast/the-breakthrough-hillary-clinton-failed-presidential-bid#133721",
))) )))
.published_date(Some(String::from("Fri, 25 Aug 2017 12:00:00 +0000")))
.length(Some(17964071)) .length(Some(17964071))
.epoch(1503662400) .epoch(1503662400)
.duration(Some(1125)) .duration(Some(1125))
@ -355,7 +349,6 @@ mod tests {
))) )))
.description(Some(String::from(descr))) .description(Some(String::from(descr)))
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D"))) .guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
.published_date(Some(String::from("Tue, 12 Sep 2017 22:24:42 -0700")))
.length(Some(46479789)) .length(Some(46479789))
.epoch(1505280282) .epoch(1505280282)
.duration(Some(5733)) .duration(Some(5733))
@ -381,7 +374,6 @@ mod tests {
))) )))
.description(Some(String::from(descr))) .description(Some(String::from(descr)))
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B"))) .guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
.published_date(Some(String::from("Tue, 5 Sep 2017 20:57:27 -0700")))
.length(Some(36544272)) .length(Some(36544272))
.epoch(1504670247) .epoch(1504670247)
.duration(Some(4491)) .duration(Some(4491))
@ -411,7 +403,6 @@ mod tests {
.guid(Some(String::from( .guid(Some(String::from(
"https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/", "https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/",
))) )))
.published_date(Some(String::from("Mon, 28 Aug 2017 15:00:00 -0700")))
.length(Some(15077388)) .length(Some(15077388))
.epoch(1503957600) .epoch(1503957600)
.duration(Some(2533)) .duration(Some(2533))
@ -437,7 +428,6 @@ mod tests {
.guid(Some(String::from( .guid(Some(String::from(
"https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/", "https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/",
))) )))
.published_date(Some(String::from("Tue, 15 Aug 2017 17:00:00 -0700")))
.length(Some(13713219)) .length(Some(13713219))
.epoch(1502841600) .epoch(1502841600)
.duration(Some(2313)) .duration(Some(2313))

View File

@ -5,7 +5,6 @@ table! {
uri -> Nullable<Text>, uri -> Nullable<Text>,
local_uri -> Nullable<Text>, local_uri -> Nullable<Text>,
description -> Nullable<Text>, description -> Nullable<Text>,
published_date -> Nullable<Text>,
epoch -> Integer, epoch -> Integer,
length -> Nullable<Integer>, length -> Nullable<Integer>,
duration -> Nullable<Integer>, duration -> Nullable<Integer>,