修复时间字段命名:createdate/modifydate 改为 snake_case

This commit is contained in:
fish
2026-04-13 21:41:15 +08:00
parent dc1056ffb0
commit 0187160401
4 changed files with 19 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ backend/
### 数据库模型 ### 数据库模型
核心表结构(见 `services/user-service/migrations/001_init.sql` 核心表结构(见 `services/user-service/migrations/001_init.sql`
- `user_main(id UUID PK, deleted BOOLEAN, createdate, modifydate)` - `user_main(id UUID PK, deleted BOOLEAN, create_date, modify_date)`
- `user_login_account(id UUID PK, user_id FK, account VARCHAR)` - `user_login_account(id UUID PK, user_id FK, account VARCHAR)`
- `user_login_email(id UUID PK, user_id FK, email VARCHAR)` - `user_login_email(id UUID PK, user_id FK, email VARCHAR)`
- `user_login_password(id UUID PK, user_id FK, password VARCHAR)` - `user_login_password(id UUID PK, user_id FK, password VARCHAR)`
@@ -164,15 +164,15 @@ OK
### 3. 时间字段约定 ### 3. 时间字段约定
所有表中的 `createdate` 和 `modifydate` **必须由业务层生成并传入**数据库Schema中**不设置** `DEFAULT CURRENT_TIMESTAMP`,也不使用触发器自动更新。 所有表中的 `create_date` 和 `modify_date` **必须由业务层生成并传入**数据库Schema中**不设置** `DEFAULT CURRENT_TIMESTAMP`,也不使用触发器自动更新。
- 建表时: - 建表时:
```sql ```sql
createdate TIMESTAMP WITH TIME ZONE NOT NULL, create_date TIMESTAMP WITH TIME ZONE NOT NULL,
modifydate TIMESTAMP WITH TIME ZONE NOT NULL modify_date TIMESTAMP WITH TIME ZONE NOT NULL
``` ```
- Rust 代码中使用 `chrono::Utc::now()` 生成时间戳,统一在事务开始前创建 `let now = Utc::now();`,确保同一笔业务中各表时间一致。 - Rust 代码中使用 `chrono::Utc::now()` 生成时间戳,统一在事务开始前创建 `let now = Utc::now();`,确保同一笔业务中各表时间一致。
- `modifydate` 更新时同样需要在业务代码中显式传入 `Utc::now()`。 - `modify_date` 更新时同样需要在业务代码中显式传入 `Utc::now()`。
### 4. 环境变量 ### 4. 环境变量

View File

@@ -2,8 +2,8 @@
CREATE TABLE IF NOT EXISTS user_main ( CREATE TABLE IF NOT EXISTS user_main (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
deleted BOOLEAN NOT NULL DEFAULT FALSE, deleted BOOLEAN NOT NULL DEFAULT FALSE,
createdate TIMESTAMP WITH TIME ZONE NOT NULL, create_date TIMESTAMP WITH TIME ZONE NOT NULL,
modifydate TIMESTAMP WITH TIME ZONE NOT NULL modify_date TIMESTAMP WITH TIME ZONE NOT NULL
); );
-- 用户登录账号表 -- 用户登录账号表
@@ -12,8 +12,8 @@ CREATE TABLE IF NOT EXISTS user_login_account (
user_id UUID NOT NULL, user_id UUID NOT NULL,
account VARCHAR(100) NOT NULL, account VARCHAR(100) NOT NULL,
deleted BOOLEAN NOT NULL DEFAULT FALSE, deleted BOOLEAN NOT NULL DEFAULT FALSE,
createdate TIMESTAMP WITH TIME ZONE NOT NULL, create_date TIMESTAMP WITH TIME ZONE NOT NULL,
modifydate TIMESTAMP WITH TIME ZONE NOT NULL, modify_date TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT fk_user_login_account_user_main FOREIGN KEY (user_id) REFERENCES user_main(id) 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, user_id UUID NOT NULL,
password VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL,
deleted BOOLEAN NOT NULL DEFAULT FALSE, deleted BOOLEAN NOT NULL DEFAULT FALSE,
createdate TIMESTAMP WITH TIME ZONE NOT NULL, create_date TIMESTAMP WITH TIME ZONE NOT NULL,
modifydate TIMESTAMP WITH TIME ZONE NOT NULL, modify_date TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT fk_user_login_password_user_main FOREIGN KEY (user_id) REFERENCES user_main(id) 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, user_id UUID NOT NULL,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
deleted BOOLEAN NOT NULL DEFAULT FALSE, deleted BOOLEAN NOT NULL DEFAULT FALSE,
createdate TIMESTAMP WITH TIME ZONE NOT NULL, create_date TIMESTAMP WITH TIME ZONE NOT NULL,
modifydate TIMESTAMP WITH TIME ZONE NOT NULL, modify_date TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT fk_user_login_email_user_main FOREIGN KEY (user_id) REFERENCES user_main(id) CONSTRAINT fk_user_login_email_user_main FOREIGN KEY (user_id) REFERENCES user_main(id)
); );

View File

@@ -154,7 +154,7 @@ async fn register_handler(
let user_id = Uuid::now_v7(); let user_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_main (id, createdate, modifydate) VALUES ($1, $2, $3)" "INSERT INTO user_main (id, create_date, modify_date) VALUES ($1, $2, $3)"
) )
.bind(user_id) .bind(user_id)
.bind(now) .bind(now)
@@ -176,7 +176,7 @@ async fn register_handler(
let account_id = Uuid::now_v7(); let account_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_login_account (id, user_id, account, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)" "INSERT INTO user_login_account (id, user_id, account, create_date, modify_date) VALUES ($1, $2, $3, $4, $5)"
) )
.bind(account_id) .bind(account_id)
.bind(user_id) .bind(user_id)
@@ -200,7 +200,7 @@ async fn register_handler(
let password_id = Uuid::now_v7(); let password_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_login_password (id, user_id, password, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)" "INSERT INTO user_login_password (id, user_id, password, create_date, modify_date) VALUES ($1, $2, $3, $4, $5)"
) )
.bind(password_id) .bind(password_id)
.bind(user_id) .bind(user_id)

View File

@@ -154,7 +154,7 @@ async fn register_handler(
let user_id = Uuid::now_v7(); let user_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_main (id, createdate, modifydate) VALUES ($1, $2, $3)" "INSERT INTO user_main (id, create_date, modify_date) VALUES ($1, $2, $3)"
) )
.bind(user_id) .bind(user_id)
.bind(now) .bind(now)
@@ -176,7 +176,7 @@ async fn register_handler(
let email_id = Uuid::now_v7(); let email_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_login_email (id, user_id, email, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)" "INSERT INTO user_login_email (id, user_id, email, create_date, modify_date) VALUES ($1, $2, $3, $4, $5)"
) )
.bind(email_id) .bind(email_id)
.bind(user_id) .bind(user_id)
@@ -200,7 +200,7 @@ async fn register_handler(
let password_id = Uuid::now_v7(); let password_id = Uuid::now_v7();
if let Err(e) = sqlx::query( if let Err(e) = sqlx::query(
"INSERT INTO user_login_password (id, user_id, password, createdate, modifydate) VALUES ($1, $2, $3, $4, $5)" "INSERT INTO user_login_password (id, user_id, password, create_date, modify_date) VALUES ($1, $2, $3, $4, $5)"
) )
.bind(password_id) .bind(password_id)
.bind(user_id) .bind(user_id)