时间字段改由业务层生成并传入
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
CREATE TABLE IF NOT EXISTS user_main (
|
||||
id UUID PRIMARY KEY,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
-- 用户登录账号表
|
||||
@@ -12,8 +12,8 @@ CREATE TABLE IF NOT EXISTS user_login_account (
|
||||
user_id UUID NOT NULL,
|
||||
account VARCHAR(100) NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
CONSTRAINT fk_user_login_account_user_main FOREIGN KEY (user_id) REFERENCES user_main(id)
|
||||
);
|
||||
|
||||
@@ -27,8 +27,8 @@ CREATE TABLE IF NOT EXISTS user_login_password (
|
||||
user_id UUID NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
CONSTRAINT fk_user_login_password_user_main FOREIGN KEY (user_id) REFERENCES user_main(id)
|
||||
);
|
||||
|
||||
@@ -41,8 +41,8 @@ CREATE TABLE IF NOT EXISTS user_login_email (
|
||||
user_id UUID NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
createdate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
modifydate TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
CONSTRAINT fk_user_login_email_user_main FOREIGN KEY (user_id) REFERENCES user_main(id)
|
||||
);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use chrono::Utc;
|
||||
use tracing::{info, warn};
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
@@ -149,12 +150,15 @@ async fn register_handler(
|
||||
}
|
||||
};
|
||||
|
||||
let now = Utc::now();
|
||||
let user_id = Uuid::now_v7();
|
||||
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_main (id) VALUES ($1)"
|
||||
"INSERT INTO user_main (id, createdate, modifydate) VALUES ($1, $2, $3)"
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
@@ -172,11 +176,13 @@ async fn register_handler(
|
||||
|
||||
let account_id = Uuid::now_v7();
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_login_account (id, user_id, account) VALUES ($1, $2, $3)"
|
||||
"INSERT INTO user_login_account (id, user_id, account, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)"
|
||||
)
|
||||
.bind(account_id)
|
||||
.bind(user_id)
|
||||
.bind(&req.data.username)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
@@ -194,11 +200,13 @@ async fn register_handler(
|
||||
|
||||
let password_id = Uuid::now_v7();
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_login_password (id, user_id, password) VALUES ($1, $2, $3)"
|
||||
"INSERT INTO user_login_password (id, user_id, password, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)"
|
||||
)
|
||||
.bind(password_id)
|
||||
.bind(user_id)
|
||||
.bind(&password_hash)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use chrono::Utc;
|
||||
use tracing::{info, warn};
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
@@ -149,12 +150,15 @@ async fn register_handler(
|
||||
}
|
||||
};
|
||||
|
||||
let now = Utc::now();
|
||||
let user_id = Uuid::now_v7();
|
||||
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_main (id) VALUES ($1)"
|
||||
"INSERT INTO user_main (id, createdate, modifydate) VALUES ($1, $2, $3)"
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
@@ -172,11 +176,13 @@ async fn register_handler(
|
||||
|
||||
let email_id = Uuid::now_v7();
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_login_email (id, user_id, email) VALUES ($1, $2, $3)"
|
||||
"INSERT INTO user_login_email (id, user_id, email, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)"
|
||||
)
|
||||
.bind(email_id)
|
||||
.bind(user_id)
|
||||
.bind(&req.data.email)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
@@ -194,11 +200,13 @@ async fn register_handler(
|
||||
|
||||
let password_id = Uuid::now_v7();
|
||||
if let Err(e) = sqlx::query(
|
||||
"INSERT INTO user_login_password (id, user_id, password) VALUES ($1, $2, $3)"
|
||||
"INSERT INTO user_login_password (id, user_id, password, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)"
|
||||
)
|
||||
.bind(password_id)
|
||||
.bind(user_id)
|
||||
.bind(&password_hash)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user