From 4c8a727e9e010f1466f106ea6c2ea4838b113854 Mon Sep 17 00:00:00 2001 From: Baptiste Gelez Date: Sun, 21 Oct 2018 14:19:07 +0100 Subject: [PATCH] Add a model for external apps Stores their name, website, and credentials --- .../2018-10-19-165407_create_apps/down.sql | 2 ++ .../2018-10-19-165407_create_apps/up.sql | 10 ++++++++++ .../2018-10-19-165450_create_apps/down.sql | 2 ++ .../2018-10-19-165450_create_apps/up.sql | 10 ++++++++++ plume-models/src/apps.rs | 18 ++++++++++++++++++ plume-models/src/lib.rs | 1 + plume-models/src/schema.rs | 13 +++++++++++++ 7 files changed, 56 insertions(+) create mode 100755 migrations/postgres/2018-10-19-165407_create_apps/down.sql create mode 100755 migrations/postgres/2018-10-19-165407_create_apps/up.sql create mode 100755 migrations/sqlite/2018-10-19-165450_create_apps/down.sql create mode 100755 migrations/sqlite/2018-10-19-165450_create_apps/up.sql create mode 100755 plume-models/src/apps.rs diff --git a/migrations/postgres/2018-10-19-165407_create_apps/down.sql b/migrations/postgres/2018-10-19-165407_create_apps/down.sql new file mode 100755 index 00000000..09b3f609 --- /dev/null +++ b/migrations/postgres/2018-10-19-165407_create_apps/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE apps; diff --git a/migrations/postgres/2018-10-19-165407_create_apps/up.sql b/migrations/postgres/2018-10-19-165407_create_apps/up.sql new file mode 100755 index 00000000..48ab4dcf --- /dev/null +++ b/migrations/postgres/2018-10-19-165407_create_apps/up.sql @@ -0,0 +1,10 @@ +-- Your SQL goes here +CREATE TABLE apps ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL DEFAULT '', + client_id TEXT NOT NULL, + client_secret TEXT NOT NULL, + redirect_uri TEXT, + website TEXT, + creation_date TIMESTAMP NOT NULL DEFAULT now() +); diff --git a/migrations/sqlite/2018-10-19-165450_create_apps/down.sql b/migrations/sqlite/2018-10-19-165450_create_apps/down.sql new file mode 100755 index 00000000..09b3f609 --- /dev/null +++ b/migrations/sqlite/2018-10-19-165450_create_apps/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE apps; diff --git a/migrations/sqlite/2018-10-19-165450_create_apps/up.sql b/migrations/sqlite/2018-10-19-165450_create_apps/up.sql new file mode 100755 index 00000000..0e9408bd --- /dev/null +++ b/migrations/sqlite/2018-10-19-165450_create_apps/up.sql @@ -0,0 +1,10 @@ +-- Your SQL goes here +CREATE TABLE apps ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL DEFAULT '', + client_id TEXT NOT NULL, + client_secret TEXT NOT NULL, + redirect_uri TEXT, + website TEXT, + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/plume-models/src/apps.rs b/plume-models/src/apps.rs new file mode 100755 index 00000000..ff398c41 --- /dev/null +++ b/plume-models/src/apps.rs @@ -0,0 +1,18 @@ +use chrono::NaiveDateTime; + +use schema::apps; + +pub struct App { + pub id: i32, + pub name: String, + pub client_id: String, + pub client_secret: String, + pub redirect_uri: Option, + pub website: Option, + pub creation_date: NaiveDateTime, +} + +impl App { + get!(apps, App); + insert!(apps, NewApp); +} diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index f80b7bd8..deab3cd5 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -214,6 +214,7 @@ pub fn ap_url(url: String) -> String { } pub mod admin; +pub mod apps; pub mod blog_authors; pub mod blogs; pub mod comments; diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index b2a01083..582fb464 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -1,3 +1,15 @@ +table! { + apps (id) { + id -> Int4, + name -> Text, + client_id -> Text, + client_secret -> Text, + redirect_uri -> Nullable, + website -> Nullable, + creation_date -> Timestamp, + } +} + table! { blog_authors (id) { id -> Int4, @@ -192,6 +204,7 @@ joinable!(tags -> posts (post_id)); joinable!(users -> instances (instance_id)); allow_tables_to_appear_in_same_query!( + apps, blog_authors, blogs, comments,