-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: daz-3ux <[email protected]>
- Loading branch information
Showing
11 changed files
with
197 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# 为 dBlog 创建数据库 | ||
- 使用 Docker + MariaDB 创建数据库 | ||
- sqldump 数据相关详细信息查看: | ||
[sql](/internal/pkg/model/README.md) | ||
|
||
### 创建数据库 | ||
- 启动数据库实例 | ||
```shell | ||
docker run -p 3306:3306 --name dazblogDB -e MARIADB_ROOT_PASSWORD=passwd -d mariadb:lts | ||
``` | ||
- 初始化数据库 | ||
```sql | ||
CREATE DATABASE `dazblog`; | ||
USE `dazblog`; | ||
``` | ||
|
||
- 初始化用户表 | ||
```sql | ||
CREATE TABLE `user` ( | ||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | ||
`postcount` int(11) NOT NULL DEFAULT '0', | ||
`username` varchar(30) NOT NULL, | ||
`password` varchar(255) NOT NULL, | ||
`nickname` varchar(30) NOT NULL, | ||
`email` varchar(320) NOT NULL, | ||
`gender` ENUM('Male', 'Female', 'Other') DEFAULT NULL, | ||
`phone` varchar(16), | ||
`qq` varchar(16), | ||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(), | ||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(), | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `username` (`username`), | ||
UNIQUE KEY `email` (`email`) | ||
) ENGINE=InnoDB, AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; | ||
``` | ||
|
||
- 初始化博客表 | ||
```sql | ||
CREATE TABLE `post` ( | ||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | ||
`username` varchar(30) NOT NULL, | ||
`postID` varchar(100) NOT NULL, | ||
`title` varchar(150) NOT NULL, | ||
`content` longtext NOT NULL, | ||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(), | ||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(), | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `postID` (`postID`), | ||
KEY `idx_username` (`username`), | ||
CONSTRAINT fk_post_username FOREIGN KEY (`username`) REFERENCES `user` (`username`) ON DELETE CASCADE | ||
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.