Add misc fields

This commit is contained in:
kpcyrd
2019-08-11 10:17:38 +02:00
parent d877c4346c
commit 64b3be68a0
7 changed files with 117 additions and 8 deletions

View File

@@ -145,6 +145,8 @@ connected to.
Latitude of the networks location.
``longitude``
Longitude of the networks location.
``description``
A human readable description in case the value is a technical identifier.
Accounts
--------
@@ -166,6 +168,12 @@ A users account or profile on a webservice, like github or instagram.
The url of the public profile if available.
``last_seen``
The last time this account has been active/online.
``birthday``
The users birthday set on the account.
``phonenumber``
The phonenumber associated with the account.
``profile_pic``
The blob identifier of the users current profile picture.
Breaches
--------

View File

@@ -0,0 +1,41 @@
PRAGMA foreign_keys=off;
-- accounts
CREATE TABLE _accounts_new (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
service VARCHAR NOT NULL,
username VARCHAR NOT NULL,
displayname VARCHAR,
email VARCHAR,
url VARCHAR,
last_seen DATETIME,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
CONSTRAINT account_unique UNIQUE (value)
);
INSERT INTO _accounts_new (id, value, service, username, displayname, email, url, last_seen, unscoped)
SELECT id, value, service, username, displayname, email, url, last_seen, unscoped
FROM accounts;
DROP TABLE accounts;
ALTER TABLE _accounts_new RENAME TO accounts;
-- networks
CREATE TABLE _networks_new (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
latitude FLOAT,
longitude FLOAT,
CONSTRAINT network_unique UNIQUE (value)
);
INSERT INTO _networks_new (id, value, unscoped, latitude, longitude)
SELECT id, value, unscoped, latitude, longitude
FROM networks;
DROP TABLE networks;
ALTER TABLE _networks_new RENAME TO networks;
PRAGMA foreign_keys=on;

View File

@@ -0,0 +1,4 @@
ALTER TABLE accounts ADD COLUMN phonenumber VARCHAR;
ALTER TABLE accounts ADD COLUMN profile_pic VARCHAR;
ALTER TABLE accounts ADD COLUMN birthday VARCHAR;
ALTER TABLE networks ADD COLUMN description VARCHAR;

View File

@@ -304,6 +304,7 @@ impl IntoInsert for AddNetwork {
value: network,
latitude,
longitude,
description: None,
unscoped: false,
}))
}
@@ -342,6 +343,9 @@ impl IntoInsert for AddAccount {
email: None,
url: None,
last_seen: None,
birthday: None,
phonenumber: None,
profile_pic: None,
unscoped: false,
}))
}

View File

@@ -20,6 +20,9 @@ pub struct Account {
pub url: Option<String>,
pub last_seen: Option<NaiveDateTime>,
pub unscoped: bool,
pub birthday: Option<String>,
pub phonenumber: Option<String>,
pub profile_pic: Option<String>,
}
impl Model for Account {
@@ -84,29 +87,29 @@ impl Model for Account {
fn by_id(db: &Database, my_id: i32) -> Result<Self> {
use crate::schema::accounts::dsl::*;
let domain = accounts.filter(id.eq(my_id))
let account = accounts.filter(id.eq(my_id))
.first::<Self>(db.db())?;
Ok(domain)
Ok(account)
}
fn get(db: &Database, query: &Self::ID) -> Result<Self> {
use crate::schema::accounts::dsl::*;
let domain = accounts.filter(value.eq(query))
let account = accounts.filter(value.eq(query))
.first::<Self>(db.db())?;
Ok(domain)
Ok(account)
}
fn get_opt(db: &Database, query: &Self::ID) -> Result<Option<Self>> {
use crate::schema::accounts::dsl::*;
let domain = accounts.filter(value.eq(query))
let account = accounts.filter(value.eq(query))
.first::<Self>(db.db())
.optional()?;
Ok(domain)
Ok(account)
}
}
@@ -160,6 +163,9 @@ pub struct DetailedAccount {
url: Option<String>,
last_seen: Option<NaiveDateTime>,
unscoped: bool,
birthday: Option<String>,
phonenumber: Option<String>,
profile_pic: Option<String>,
}
impl DisplayableDetailed for DetailedAccount {
@@ -178,6 +184,9 @@ impl DisplayableDetailed for DetailedAccount {
w.opt_debug::<Yellow, _>(&self.email)?;
w.opt_debug::<Yellow, _>(&self.url)?;
w.opt_debug::<Yellow, _>(&self.last_seen)?;
w.opt_debug::<Yellow, _>(&self.birthday)?;
w.opt_debug::<Yellow, _>(&self.phonenumber)?;
w.opt_debug::<Yellow, _>(&self.profile_pic)?;
w.end_group()?;
Ok(())
@@ -203,6 +212,9 @@ impl Detailed for Account {
url: self.url.clone(),
last_seen: self.last_seen.clone(),
unscoped: self.unscoped,
birthday: self.birthday.clone(),
phonenumber: self.phonenumber.clone(),
profile_pic: self.profile_pic.clone(),
})
}
}
@@ -218,6 +230,9 @@ pub struct NewAccount {
pub url: Option<String>,
pub last_seen: Option<NaiveDateTime>,
pub unscoped: bool,
pub birthday: Option<String>,
pub phonenumber: Option<String>,
pub profile_pic: Option<String>,
}
impl InsertableStruct<Account> for NewAccount {
@@ -247,6 +262,9 @@ impl Upsertable<Account> for NewAccount {
email: Self::upsert_opt(self.email, &existing.email),
url: Self::upsert_opt(self.url, &existing.url),
last_seen: Self::upsert_opt(self.last_seen, &existing.last_seen),
birthday: Self::upsert_opt(self.birthday, &existing.birthday),
phonenumber: Self::upsert_opt(self.phonenumber, &existing.phonenumber),
profile_pic: Self::upsert_opt(self.profile_pic, &existing.profile_pic),
}
}
}
@@ -267,6 +285,9 @@ pub struct InsertAccount {
pub email: Option<String>,
pub url: Option<String>,
pub last_seen: Option<NaiveDateTime>,
pub birthday: Option<String>,
pub phonenumber: Option<String>,
pub profile_pic: Option<String>,
}
impl LuaInsertToNew for InsertAccount {
@@ -285,6 +306,9 @@ impl LuaInsertToNew for InsertAccount {
email: self.email,
url: self.url,
last_seen: self.last_seen,
birthday: self.birthday,
phonenumber: self.phonenumber,
profile_pic: self.profile_pic,
unscoped: false,
})
}
@@ -298,6 +322,9 @@ pub struct AccountUpdate {
pub email: Option<String>,
pub url: Option<String>,
pub last_seen: Option<NaiveDateTime>,
pub birthday: Option<String>,
pub phonenumber: Option<String>,
pub profile_pic: Option<String>,
}
impl Upsert for AccountUpdate {
@@ -305,7 +332,10 @@ impl Upsert for AccountUpdate {
self.displayname.is_some() ||
self.email.is_some() ||
self.url.is_some() ||
self.last_seen.is_some()
self.last_seen.is_some() ||
self.birthday.is_some() ||
self.phonenumber.is_some() ||
self.profile_pic.is_some()
}
fn generic(self) -> Update {
@@ -323,6 +353,9 @@ impl Updateable<Account> for AccountUpdate {
Self::clear_if_equal(&mut self.email, &existing.email);
Self::clear_if_equal(&mut self.url, &existing.url);
Self::clear_if_equal(&mut self.last_seen, &existing.last_seen);
Self::clear_if_equal(&mut self.birthday, &existing.birthday);
Self::clear_if_equal(&mut self.phonenumber, &existing.phonenumber);
Self::clear_if_equal(&mut self.profile_pic, &existing.profile_pic);
}
fn fmt(&self, updates: &mut Vec<String>) {
@@ -330,5 +363,8 @@ impl Updateable<Account> for AccountUpdate {
Self::push_value(updates, "email", &self.email);
Self::push_value(updates, "url", &self.url);
Self::push_value(updates, "last_seen", &self.last_seen);
Self::push_value(updates, "birthday", &self.birthday);
Self::push_value(updates, "phonenumber", &self.phonenumber);
Self::push_value(updates, "profile_pic", &self.profile_pic);
}
}

View File

@@ -15,6 +15,7 @@ pub struct Network {
pub unscoped: bool,
pub latitude: Option<f32>,
pub longitude: Option<f32>,
pub description: Option<String>,
}
impl Model for Network {
@@ -153,6 +154,7 @@ pub struct DetailedNetwork {
unscoped: bool,
latitude: Option<f32>,
longitude: Option<f32>,
description: Option<String>,
devices: Vec<PrintableDevice>,
}
@@ -170,6 +172,7 @@ impl DisplayableDetailed for DetailedNetwork {
w.start_group();
w.opt_debug::<Yellow, _>(&self.latitude)?;
w.opt_debug::<Yellow, _>(&self.longitude)?;
w.opt_debug::<Yellow, _>(&self.description)?;
w.end_group()?;
Ok(())
@@ -200,6 +203,7 @@ impl Detailed for Network {
unscoped: self.unscoped,
latitude: self.latitude.clone(),
longitude: self.longitude.clone(),
description: self.description.clone(),
devices,
})
}
@@ -211,6 +215,7 @@ pub struct NewNetwork {
pub value: String,
pub latitude: Option<f32>,
pub longitude: Option<f32>,
pub description: Option<String>,
pub unscoped: bool,
}
@@ -239,6 +244,7 @@ impl Upsertable<Network> for NewNetwork {
id: existing.id,
latitude: Self::upsert_opt(self.latitude, &existing.latitude),
longitude: Self::upsert_opt(self.longitude, &existing.longitude),
description: Self::upsert_opt(self.description, &existing.description),
}
}
}
@@ -256,6 +262,7 @@ pub struct InsertNetwork {
pub value: String,
pub latitude: Option<f32>,
pub longitude: Option<f32>,
pub description: Option<String>,
}
impl LuaInsertToNew for InsertNetwork {
@@ -266,6 +273,7 @@ impl LuaInsertToNew for InsertNetwork {
value: self.value,
latitude: self.latitude,
longitude: self.longitude,
description: self.description,
unscoped: false,
})
@@ -278,12 +286,14 @@ pub struct NetworkUpdate {
pub id: i32,
pub latitude: Option<f32>,
pub longitude: Option<f32>,
pub description: Option<String>,
}
impl Upsert for NetworkUpdate {
fn is_dirty(&self) -> bool {
self.latitude.is_some() ||
self.longitude.is_some()
self.longitude.is_some() ||
self.description.is_some()
}
fn generic(self) -> Update {
@@ -299,10 +309,12 @@ impl Updateable<Network> for NetworkUpdate {
fn changeset(&mut self, existing: &Network) {
Self::clear_if_equal(&mut self.latitude, &existing.latitude);
Self::clear_if_equal(&mut self.longitude, &existing.longitude);
Self::clear_if_equal(&mut self.description, &existing.description);
}
fn fmt(&self, updates: &mut Vec<String>) {
Self::push_value(updates, "latitude", &self.latitude);
Self::push_value(updates, "longitude", &self.longitude);
Self::push_value(updates, "description", &self.description);
}
}

View File

@@ -9,6 +9,9 @@ table! {
url -> Nullable<Text>,
last_seen -> Nullable<Timestamp>,
unscoped -> Bool,
phonenumber -> Nullable<Text>,
profile_pic -> Nullable<Text>,
birthday -> Nullable<Text>,
}
}
@@ -136,6 +139,7 @@ table! {
unscoped -> Bool,
latitude -> Nullable<Float>,
longitude -> Nullable<Float>,
description -> Nullable<Text>,
}
}