Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add storage of user basic info #55

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions cmd/user/dal/db/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2024 The west2-online Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package db

import (
"github.com/west2-online/fzuhelper-server/pkg/client"
"github.com/west2-online/fzuhelper-server/pkg/logger"
"github.com/west2-online/fzuhelper-server/pkg/utils"

"gorm.io/gorm"

"github.com/west2-online/fzuhelper-server/pkg/constants"
)

var (
DB *gorm.DB
SF *utils.Snowflake
err error
)

func InitMySQL() {
DB, SF, err = client.InitMySQL(constants.UserTableName)
if err != nil {
logger.Fatal(err)
}
}
25 changes: 25 additions & 0 deletions cmd/user/dal/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2024 The west2-online Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package dal

import (
"github.com/west2-online/fzuhelper-server/cmd/user/dal/db"
)

func Init() {
db.InitMySQL()
}
4 changes: 4 additions & 0 deletions cmd/user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"net"

"github.com/west2-online/fzuhelper-server/cmd/user/dal/db"
"github.com/west2-online/fzuhelper-server/pkg/eshook"

"github.com/cloudwego/kitex/pkg/limit"
Expand All @@ -45,6 +46,9 @@ func Init() {
flag.Parse()
config.Init(*path, serviceName)

// dal init
db.InitMySQL()

// log
eshook.InitLoggerWithHook(serviceName)
}
Expand Down
17 changes: 3 additions & 14 deletions config/sql/init.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
create table `fzu-helper`.`student`
(
`id` bigint not null comment '学生ID',
`number` varchar(255) not null comment '学号',
`password` varchar(255) not null comment '密码',
`sex` varchar(255) not null comment '性别',
`birthday` varchar(255) not null comment '出生日期',
`phone` varchar(255) not null comment '手机号',
`email` varchar(255) comment '邮箱',
`id` bigint not null comment 'ID',
`number` varchar(16) not null comment '学号',
`sex` varchar(8) not null comment '性别',
`college` varchar(255) not null comment '学院',
`grade` bigint not null comment '年级',
`status_change` varchar(255) comment '学籍异动与奖励',
`major` varchar(255) not null comment '专业',
`counselor` varchar(255) not null comment '辅导员',
`examinee_category` varchar(255) not null comment '考生类别',
`nationality` varchar(255) not null comment '民族',
`country` varchar(255) not null comment '国别',
`political_status` varchar(255) not null comment '政治面貌',
`source` varchar(255) not null comment '生源地',
`created_at` timestamp default current_timestamp not null,
`updated_at` timestamp default current_timestamp not null on update current_timestamp comment 'update profile time',
`deleted_at` timestamp default null null,
Expand Down
Loading