add account model

This commit is contained in:
anna 2022-12-05 20:22:46 +01:00
parent e69cfa1f14
commit e0358c2c67
Signed by: fef
GPG key ID: EC22E476DC2D3D84
5 changed files with 32 additions and 8 deletions

View file

@ -1,8 +0,0 @@
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
domain VARCHAR NOT NULL,
display_name VARCHAR DEFAULT NULL
);
CREATE UNIQUE INDEX index_users_on_name_and_domain ON users (name, domain);

View file

@ -0,0 +1,10 @@
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
domain VARCHAR NOT NULL,
display_name VARCHAR DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE UNIQUE INDEX index_accounts_on_name_and_domain ON accounts (name, domain);

View file

@ -5,6 +5,7 @@ use sqlx::{migrate, query, PgPool, Pool};
mod conf;
mod core;
mod model;
mod route;
mod state;
use conf::Config;

20
src/model/account.rs Normal file
View file

@ -0,0 +1,20 @@
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use crate::core::Id;
#[derive(Deserialize, Serialize, FromRow)]
pub struct Account {
pub id: Id,
pub name: String,
pub display_name: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Into<Id> for Account {
fn into(self) -> Id {
self.id
}
}

1
src/model/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod account;