Skip to content

Commit

Permalink
add migrate (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
wannanbigpig committed Jun 10, 2023
1 parent 72e5888 commit 2d2abe8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ storage
*.ini
gin-layout/
logs/
.vscode
.vscode
migrate
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@
### Gin Project Template
> 本项目使用 gin 框架为核心搭建的一个脚手架,可以基于本项目快速完成业务开发,开箱📦 即用
### 以实现接口文档
接口文档:[点击跳转至接口文档](https://apifox.com/apidoc/shared-721e0594-dea4-4d86-bad3-851b51c16e03/api-87990142)

### 运行
拉取代码后在项目根目录执行如下命令:
拉取代码:
```shell
git clone https://github.com/wannanbigpig/gin-layout.git
```
执行迁移文件:

安装migrate [查看安装文档](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)

使用migrate [更多用法](https://github.com/golang-migrate/migrate)
```shell
# 执行迁移文件创建数据表
migrate -database 'mysql://root:root@tcp(127.0.0.1:3306)/go_layout?charset=utf8mb4&parseTime=True&loc=Local' -path data/migrations up
```
启动脚手架服务:
```shell
# 建议开启GO111MODULE
# go env -w GO111MODULE=on
Expand All @@ -22,9 +38,11 @@ go mod download
go run main.go server

# 项目起来后执行下面命令访问示例路由
curl "http://127.0.0.1:9999/api/v1/hello-world"
curl "http://127.0.0.1:9001/ping"
# {"message":"pong"}
curl "http://127.0.0.1:9001/api/v1/hello-world"
# {"code":0,"message":"OK","data":{"result":"hello gin-layout"},"cost":"6.151µs"}
curl "http://127.0.0.1:9999/api/v1/hello-world?name=world"
curl "http://127.0.0.1:9001/api/v1/hello-world?name=world"
# {"code":0,"message":"OK","data":{"result":"hello world"},"cost":"6.87µs"}
```
更多用法使用以下命令查看:
Expand Down Expand Up @@ -56,7 +74,7 @@ server {
server_name api.xxx.com;
location / {
proxy_set_header Host $host;
proxy_pass http://172.0.0.1:9999;
proxy_pass http://172.0.0.1:9001;
}
}
```
Expand Down
1 change: 1 addition & 0 deletions data/migrations/000001_create_a_admin_users_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS `a_admin_user`;
19 changes: 19 additions & 0 deletions data/migrations/000001_create_a_admin_users_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE IF NOT EXISTS `a_admin_user` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`nickname` varchar(30) NOT NULL DEFAULT '' COMMENT '昵称',
`username` varchar(30) NOT NULL DEFAULT '' COMMENT '用户名',
`password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码',
`mobile` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '手机号',
`email` varchar(120) NOT NULL DEFAULT '' COMMENT '邮箱',
`avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态 0禁用,1启用',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `a_u_u_d` (`username`,`deleted_at`) USING BTREE,
UNIQUE KEY `a_u_p_d` (`mobile`,`deleted_at`) USING BTREE,
UNIQUE KEY `a_u_e_d` (`email`,`deleted_at`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='后台管理用户表';

INSERT INTO `a_admin_user` (`id`, `nickname`, `username`, `password`, `mobile`, `email`, `avatar`, `status`, `created_at`, `updated_at`, `deleted_at`) VALUES (1, '超级管理员', 'admin', '$2a$10$K52COmufcXarNTnsQw.7P.ji.uMA.wt26n3/7PqlKgiI4qNBiuQZC', '13200000000', '723164417@qq.com', 'https://avatars.githubusercontent.com/u/48752601?v=4', 1, '2022-07-10 12:01:02', '2022-07-10 12:01:02', 0);

0 comments on commit 2d2abe8

Please sign in to comment.