From 0ae9c9afb2d2575cf4b50742e19f3bce39bfa3fa Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Wed, 15 Feb 2023 20:47:21 -0800 Subject: [PATCH] added the database project and migrated models and migrations --- .../Migrations/20220522083756_init.sql | 72 +++++++++++++++++++ .../Migrations/20220529082459_seed.sql | 50 +++++++++++++ .../20220619085634_subscriptions.sql | 21 ++++++ .../20221207213427_source_delete.sql | 11 +++ .../Newsbot.Collector.Database.csproj | 13 ++++ Newsbot.Collector.sln | 6 ++ 6 files changed, 173 insertions(+) create mode 100644 Newsbot.Collector.Database/Migrations/20220522083756_init.sql create mode 100644 Newsbot.Collector.Database/Migrations/20220529082459_seed.sql create mode 100644 Newsbot.Collector.Database/Migrations/20220619085634_subscriptions.sql create mode 100644 Newsbot.Collector.Database/Migrations/20221207213427_source_delete.sql create mode 100644 Newsbot.Collector.Database/Newsbot.Collector.Database.csproj diff --git a/Newsbot.Collector.Database/Migrations/20220522083756_init.sql b/Newsbot.Collector.Database/Migrations/20220522083756_init.sql new file mode 100644 index 0000000..e0bb875 --- /dev/null +++ b/Newsbot.Collector.Database/Migrations/20220522083756_init.sql @@ -0,0 +1,72 @@ +-- +goose Up +-- +goose StatementBegin +SELECT 'up SQL query'; +CREATE TABLE Articles ( + ID uuid PRIMARY KEY, + SourceId uuid NOT null, + Tags TEXT NOT NULL, + Title TEXT NOT NULL, + Url TEXT NOT NULL, + PubDate timestamp NOT NULL, + Video TEXT, + VideoHeight int NOT NULL, + VideoWidth int NOT NULL, + Thumbnail TEXT NOT NULL, + Description TEXT NOT NULL, + AuthorName TEXT, + AuthorImage TEXT +); + +CREATE Table DiscordQueue ( + ID uuid PRIMARY KEY, + ArticleId uuid NOT NULL +); + +CREATE Table DiscordWebHooks ( + ID uuid PRIMARY KEY, + Name TEXT NOT NULL, -- Defines webhook purpose + Key TEXT, + Url TEXT NOT NULL, -- Webhook Url + Server TEXT NOT NULL, -- Defines the server its bound it. Used for refrence + Channel TEXT NOT NULL, -- Defines the channel its bound to. Used for refrence + Enabled BOOLEAN NOT NULL +); + +CREATE Table Icons ( + ID uuid PRIMARY Key, + FileName TEXT NOT NULL, + Site TEXT NOT NULL +); + +Create Table Settings ( + ID uuid PRIMARY Key, + Key TEXT NOT NULL, -- How you search for a entry + Value TEXT NOT NULL, -- The value for one + Options TEXT -- any notes about the entry +); + +Create Table Sources ( + ID uuid PRIMARY Key, + Site TEXT NOT NULL, -- Vanity name + Name TEXT NOT NULL, -- Defines the name of the source. IE: dadjokes + Source TEXT NOT NULL, -- Defines the service that will use this reocrd. IE reddit or youtube + Type TEXT NOT NULL, -- Defines what kind of feed this is. feed, user, tag + Value TEXT, + Enabled BOOLEAN NOT NULL, + Url TEXT NOT NULL, + Tags TEXT NOT NULL +); + + + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +Drop Table Articles; +Drop Table DiscordQueue; +Drop Table DiscordWebHooks; +Drop Table Icons; +Drop Table Settings; +Drop Table Sources; +-- +goose StatementEnd diff --git a/Newsbot.Collector.Database/Migrations/20220529082459_seed.sql b/Newsbot.Collector.Database/Migrations/20220529082459_seed.sql new file mode 100644 index 0000000..29da683 --- /dev/null +++ b/Newsbot.Collector.Database/Migrations/20220529082459_seed.sql @@ -0,0 +1,50 @@ +-- +goose Up +-- +goose StatementBegin +SELECT 'up SQL query'; + +-- Enable UUID's +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- Final Fantasy XIV Entries +INSERT INTO sources VALUES +(uuid_generate_v4(), 'ffxiv', 'Final Fantasy XIV - NA', 'ffxiv', 'scrape', 'a', TRUE, 'https://na.finalfantasyxiv.com/lodestone/', 'ffxiv, final, fantasy, xiv, na, lodestone'); +INSERT INTO sources VALUES +(uuid_generate_v4(), 'ffxiv', 'Final Fantasy XIV - JP', 'ffxiv', 'scrape', 'a', FALSE, 'https://jp.finalfantasyxiv.com/lodestone/', 'ffxiv, final, fantasy, xiv, jp, lodestone'); +INSERT INTO sources VALUES +(uuid_generate_v4(), 'ffxiv', 'Final Fantasy XIV - EU', 'ffxiv', 'scrape', 'a', FALSE, 'https://eu.finalfantasyxiv.com/lodestone/', 'ffxiv, final, fantasy, xiv, eu, lodestone'); +INSERT INTO sources VALUES +(uuid_generate_v4(), 'ffxiv', 'Final Fantasy XIV - FR', 'ffxiv', 'scrape', 'a', FALSE, 'https://fr.finalfantasyxiv.com/lodestone/', 'ffxiv, final, fantasy, xiv, fr, lodestone'); +INSERT INTO sources VALUES +(uuid_generate_v4(), 'ffxiv', 'Final Fantasy XIV - DE', 'ffxiv', 'scrape', 'a', FALSE, 'https://de.finalfantasyxiv.com/lodestone/', 'ffxiv, final, fantasy, xiv, de, lodestone'); + +-- Reddit Entries +INSERT INTO sources VALUES +(uuid_generate_v4(), 'reddit', 'dadjokes', 'reddit', 'feed', 'a', TRUE, 'https://reddit.com/r/dadjokes', 'reddit, dadjokes'); +INSERT INTO sources VALUES +(uuid_generate_v4(), 'reddit', 'steamdeck', 'reddit', 'feed', 'a', TRUE, 'https://reddit.com/r/steamdeck', 'reddit, steam deck, steam, deck'); + +-- Youtube Entries +INSERT INTO sources VALUES +(uuid_generate_v4(), 'youtube', 'Game Grumps', 'youtube', 'feed', 'a', TRUE, 'https://www.youtube.com/user/GameGrumps', 'youtube, game grumps, game, grumps'); + +-- RSS Entries +INSERT INTO sources VALUES +(uuid_generate_v4(), 'steampowered', 'steam deck', 'rss', 'feed', 'a', TRUE, 'https://store.steampowered.com/feeds/news/app/1675200/?cc=US&l=english&snr=1_2108_9__2107', 'rss, steampowered, steam, deck, steam deck'); + +-- Twitch Entries +INSERT INTO sources VALUES +(uuid_generate_v4(), 'twitch', 'Nintendo', 'twitch', 'api', 'a', TRUE, 'https://twitch.tv/nintendo', 'twitch, nintendo'); + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +--SELECT 'down SQL query'; + +DELETE FROM sources where source = 'reddit' and name = 'dadjokes'; +DELETE FROM sources where source = 'reddit' and name = 'steamdeck'; +DELETE FROM sources where source = 'ffxiv'; +DELETE FROM sources WHERE source = 'twitch' and name = 'Nintendo'; +DELETE FROM sources WHERE source = 'youtube' and name = 'Game Grumps'; +DELETE FROM SOURCES WHERE source = 'rss' and name = 'steam deck'; +-- +goose StatementEnd diff --git a/Newsbot.Collector.Database/Migrations/20220619085634_subscriptions.sql b/Newsbot.Collector.Database/Migrations/20220619085634_subscriptions.sql new file mode 100644 index 0000000..16bf429 --- /dev/null +++ b/Newsbot.Collector.Database/Migrations/20220619085634_subscriptions.sql @@ -0,0 +1,21 @@ +-- +goose Up +-- +goose StatementBegin +SELECT 'up SQL query'; +Create TABLE Subscriptions ( + ID uuid Primary Key, + DiscordWebHookID uuid Not Null, + SourceID uuid Not Null +); + +ALTER TABLE discordwebhooks drop COLUMN Name; +ALTER TABLE discordwebhooks drop COLUMN Key; + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +SELECT 'down SQL query'; +Drop Table Subscriptions; +ALTER TABLE discordwebhooks Add COLUMN Name TEXT; +--ALTER TABLE discordwebhooks Add COLUMN Key TEXT; +-- +goose StatementEnd diff --git a/Newsbot.Collector.Database/Migrations/20221207213427_source_delete.sql b/Newsbot.Collector.Database/Migrations/20221207213427_source_delete.sql new file mode 100644 index 0000000..3130bda --- /dev/null +++ b/Newsbot.Collector.Database/Migrations/20221207213427_source_delete.sql @@ -0,0 +1,11 @@ +-- +goose Up +-- +goose StatementBegin +SELECT 'up SQL query'; +ALTER TABLE sources Add COLUMN Deleted BOOLEAN; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +SELECT 'down SQL query'; +ALTER TABLE sources Drop Deleted Deleted BOOLEAN; +-- +goose StatementEnd diff --git a/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj new file mode 100644 index 0000000..a58561a --- /dev/null +++ b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj @@ -0,0 +1,13 @@ + + + + + + + + net7.0 + enable + enable + + + diff --git a/Newsbot.Collector.sln b/Newsbot.Collector.sln index 1f368a9..7b2335e 100644 --- a/Newsbot.Collector.sln +++ b/Newsbot.Collector.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Services" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Tests", "Newsbot.Collector.Tests\Newsbot.Collector.Tests.csproj", "{B677151F-5E71-4AA9-968A-D2AAB6375DE4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newsbot.Collector.Database", "Newsbot.Collector.Database\Newsbot.Collector.Database.csproj", "{EC10CB2C-EA71-4D0C-95AB-AC9A2A15415C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,5 +38,9 @@ Global {B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Debug|Any CPU.Build.0 = Debug|Any CPU {B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Release|Any CPU.ActiveCfg = Release|Any CPU {B677151F-5E71-4AA9-968A-D2AAB6375DE4}.Release|Any CPU.Build.0 = Release|Any CPU + {EC10CB2C-EA71-4D0C-95AB-AC9A2A15415C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC10CB2C-EA71-4D0C-95AB-AC9A2A15415C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC10CB2C-EA71-4D0C-95AB-AC9A2A15415C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC10CB2C-EA71-4D0C-95AB-AC9A2A15415C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal