add local mysql

This commit is contained in:
LingandRX 2024-12-05 22:29:27 +08:00
parent b60909f240
commit c3420dd3dc
4 changed files with 52 additions and 20 deletions

3
.env
View File

@ -1,2 +1,3 @@
RUST_LOG=info
DB_MYSQL_URL=mysql://rsgl:0andrx@122.152.201.90:9912/test_server
#DB_MYSQL_URL=mysql://rsgl:0andrx@122.152.201.90:9912/test_server
DB_MYSQL_URL=mysql://rsgl:0andrx@localhost:3306/test_server

View File

@ -8,5 +8,12 @@
<jdbc-url>jdbc:mysql://122.152.201.90:9912/test_server</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="test_server@localhost" uuid="854a2824-c635-4c70-aeab-ae58ed3600a4">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/test_server</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/init.sql" dialect="MySQL" />
<file url="PROJECT" dialect="MySQL" />
</component>
</project>

View File

@ -1,4 +1,5 @@
CREATE TABLE users (
CREATE TABLE users
(
id INT AUTO_INCREMENT PRIMARY KEY,
account VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
@ -6,24 +7,46 @@ CREATE TABLE users (
email VARCHAR(255),
password VARCHAR(255) NOT NULL,
phone VARCHAR(20),
status ENUM(
status ENUM (
'active',
'inactive',
'suspended',
'deleted',
'locked',
'pending verfication'
'pending verification'
) DEFAULT 'active',
created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
INSERT INTO
test_server.users (id, account, name, birth, password)
VALUES
(0, '123', 'hyh', '2000-0-03', '1');
CREATE TABLE IF NOT EXISTS posts
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY COMMENT '文章ID',
title VARCHAR(255) NOT NULL COMMENT '标题', -- 将长度扩展为255适应更长的标题
content TEXT COMMENT '内容',
link VARCHAR(200) COMMENT 'URL地址', -- 添加唯一索引,避免重复链接
popularity VARCHAR(100) COMMENT '热度', -- 假设热度是一个数值,使用 INT 类型
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updated_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_title (title), -- 为 title 添加索引,提高查询效率
INDEX idx_link (link) -- 为 link 添加索引,避免 URL 查找慢
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='文章表';
INSERT INTO
test_server.users (account, name, password)
VALUES
('123', 'hyh', '1');
# pub id: Option<i32>,
# pub title: Option<String>,
# pub content: Option<String>,
# pub link: Option<String>,
# pub popularity: Option<String>,
# pub created_time: Option<String>,
# pub updated_time: Option<String>,
INSERT INTO test_server.users (id, account, name, birth, password)
VALUES (0, '123', 'hyh', '2000-0-03', '1');
INSERT INTO test_server.users (account, name, password)
VALUES ('123', 'hyh', '1');