add account model
This commit is contained in:
parent
e69cfa1f14
commit
e0358c2c67
5 changed files with 32 additions and 8 deletions
|
@ -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);
|
10
migrations/20221205020531_create_accounts.sql
Normal file
10
migrations/20221205020531_create_accounts.sql
Normal 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);
|
|
@ -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
20
src/model/account.rs
Normal 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
1
src/model/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod account;
|
Loading…
Reference in a new issue