From 310e3fe31b996d05c55dadc329b29caca76562d5 Mon Sep 17 00:00:00 2001 From: Cairry <115769353+Cairry@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:50:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Fix=20init=20mysql=20data=20fail?= =?UTF-8?q?ed=20of=20the=20docker-compose=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 4 ++-- deploy/docker-compose/config/config.yaml | 21 --------------------- deploy/docker-compose/docker-compose.yaml | 3 ++- deploy/sql/auto_import.sh | 11 +++++------ deploy/sql/user_roles.sql | 4 ---- initialization/sql.go | 3 +-- 6 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 deploy/docker-compose/config/config.yaml delete mode 100644 deploy/sql/user_roles.sql diff --git a/config/config.yaml b/config/config.yaml index a2ba07c..c708133 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -4,7 +4,7 @@ Server: mode: "release" MySQL: - host: 127.0.0.1 + host: w8t-mysql port: 3306 user: root pass: w8t.123 @@ -12,7 +12,7 @@ MySQL: timeout: 10s Redis: - host: 127.0.0.1 + host: w8t-redis port: 6379 pass: "" diff --git a/deploy/docker-compose/config/config.yaml b/deploy/docker-compose/config/config.yaml deleted file mode 100644 index f96a539..0000000 --- a/deploy/docker-compose/config/config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -Server: - port: "9001" - # release / debug / test - mode: "release" - -MySQL: - host: w8t-mysql - port: 3306 - user: root - pass: w8t.123 - dbName: watchalert - timeout: 10s - -Redis: - host: w8t-redis - port: 6379 - pass: "" - -Jwt: - # 失效时间 - expire: 18000 diff --git a/deploy/docker-compose/docker-compose.yaml b/deploy/docker-compose/docker-compose.yaml index fc1315a..d55cd31 100644 --- a/deploy/docker-compose/docker-compose.yaml +++ b/deploy/docker-compose/docker-compose.yaml @@ -71,10 +71,11 @@ services: - ../sql:/sql environment: - TZ=Asia/Shanghai + - MYSQL_HOST=w8t-mysql - MYSQL_ROOT_PASSWORD=w8t.123 - MYSQL_DATABASE=watchalert restart: on-failure - command: ["sh", "-c", "/sql/auto_import.sh"] + command: ["sh", "-c", "chmod +x /sql/auto_import.sh; /sql/auto_import.sh"] depends_on: - w8t-mysql - w8t-service diff --git a/deploy/sql/auto_import.sh b/deploy/sql/auto_import.sh index a32af2c..54c8e9f 100644 --- a/deploy/sql/auto_import.sh +++ b/deploy/sql/auto_import.sh @@ -1,7 +1,6 @@ #!/bin/bash -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/notice_template_examples.sql -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/rule_template_groups.sql -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/rule_templates.sql -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/user_roles.sql -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/tenants.sql -mysql -h w8t-mysql -u root -pw8t.123 --default-character-set=utf8mb4 -D watchalert < /sql/tenants_linked_users.sql +mysql -h ${MYSQL_HOST} -u root -p${MYSQL_ROOT_PASSWORD} --default-character-set=utf8mb4 -D ${MYSQL_DATABASE} < /sql/notice_template_examples.sql +mysql -h ${MYSQL_HOST} -u root -p${MYSQL_ROOT_PASSWORD} --default-character-set=utf8mb4 -D ${MYSQL_DATABASE} < /sql/rule_template_groups.sql +mysql -h ${MYSQL_HOST} -u root -p${MYSQL_ROOT_PASSWORD} --default-character-set=utf8mb4 -D ${MYSQL_DATABASE} < /sql/rule_templates.sql +mysql -h ${MYSQL_HOST} -u root -p${MYSQL_ROOT_PASSWORD} --default-character-set=utf8mb4 -D ${MYSQL_DATABASE} < /sql/tenants.sql +mysql -h ${MYSQL_HOST} -u root -p${MYSQL_ROOT_PASSWORD} --default-character-set=utf8mb4 -D ${MYSQL_DATABASE} < /sql/tenants_linked_users.sql diff --git a/deploy/sql/user_roles.sql b/deploy/sql/user_roles.sql deleted file mode 100644 index cb2e8e0..0000000 --- a/deploy/sql/user_roles.sql +++ /dev/null @@ -1,4 +0,0 @@ -use watchalert; -INSERT ignore INTO `user_roles`(`id`, `name`, `description`, `permissions`, `create_at`) VALUES ('admin', 'admin', 'system', '[{"key":"创建规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupCreate"},{"key":"查看规则模版","api":"/api/w8t/ruleTmpl/ruleTmplList"},{"key":"更新告警规则","api":"/api/w8t/rule/ruleUpdate"},{"key":"更新值班表","api":"/api/w8t/dutyManage/dutyManageDelete"},{"key":"删除通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateDelete"},{"key":"更新通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateUpdate"},{"key":"查看用户列表","api":"/api/w8t/user/userList"},{"key":"删除租户成员","api":"/api/w8t/tenant/delUsersOfTenant"},{"key":"创建通知对象","api":"/api/w8t/notice/noticeCreate"},{"key":"更新值班表","api":"/api/w8t/dutyManage/dutyManageUpdate"},{"key":"查看用户权限","api":"/api/w8t/permissions/permsList"},{"key":"创建用户角色","api":"/api/w8t/role/roleCreate"},{"key":"更新用户角色","api":"/api/w8t/role/roleUpdate"},{"key":"删除用户","api":"/api/w8t/user/userDelete"},{"key":"查看数据源","api":"/api/w8t/datasource/dataSourceList"},{"key":"更新告警规则组","api":"/api/w8t/ruleGroup/ruleGroupUpdate"},{"key":"创建静默规则","api":"/api/w8t/silence/silenceCreate"},{"key":"更新仪表盘","api":"/api/w8t/dashboard/updateDashboard"},{"key":"搜索告警规则","api":"/api/w8t/rule/ruleSearch"},{"key":"用户注册","api":"/api/system/register"},{"key":"删除告警规则","api":"/api/w8t/rule/ruleDelete"},{"key":"Prometheus指标查询","api":"/api/w8t/datasource/promQuery"},{"key":"获取租户详细信息","api":"/api/w8t/tenant/getTenant"},{"key":"删除仪表盘","api":"/api/w8t/dashboard/deleteDashboard"},{"key":"查看值班表","api":"/api/w8t/dutyManage/dutyManageList"},{"key":"查看租户","api":"/api/w8t/tenant/getTenantList"},{"key":"删除通知对象","api":"/api/w8t/notice/noticeDelete"},{"key":"创建告警规则","api":"/api/w8t/rule/ruleCreate"},{"key":"更新用户信息","api":"/api/w8t/user/userUpdate"},{"key":"更新日历表","api":"/api/w8t/calendar/calendarUpdate"},{"key":"搜索数据源","api":"/api/w8t/datasource/dataSourceSearch"},{"key":"查看仪表盘","api":"/api/w8t/dashboard/listDashboard"},{"key":"查看告警规则","api":"/api/w8t/rule/ruleList"},{"key":"搜索日历表","api":"/api/w8t/calendar/calendarSearch"},{"key":"创建值班表","api":"/api/w8t/dutyManage/dutyManageCreate"},{"key":"查看静默规则","api":"/api/w8t/silence/silenceList"},{"key":"修改租户成员角色","api":"/api/w8t/tenant/changeTenantUserRole"},{"key":"发布日历表","api":"/api/w8t/calendar/calendarCreate"},{"key":"创建告警规则组","api":"/api/w8t/ruleGroup/ruleGroupCreate"},{"key":"获取Jaeger服务列表","api":"/api/w8t/c/getJaegerService"},{"key":"编辑系统配置","api":"/api/w8t/setting/saveSystemSetting"},{"key":"删除租户","api":"/api/w8t/tenant/deleteTenant"},{"key":"创建租户","api":"/api/w8t/tenant/createTenant"},{"key":"获取仪表盘","api":"/api/w8t/dashboard/getDashboard"},{"key":"创建通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateCreate"},{"key":"删除用户角色","api":"/api/w8t/role/roleDelete"},{"key":"删除规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupDelete"},{"key":"创建仪表盘","api":"/api/w8t/dashboard/createDashboard"},{"key":"搜索值班表","api":"/api/w8t/dutyManage/dutyManageSearch"},{"key":"查看通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateList"},{"key":"搜索值班用户","api":"/api/w8t/user/searchDutyUser"},{"key":"搜索用户","api":"/api/w8t/user/searchUser"},{"key":"获取租户成员列表","api":"/api/w8t/tenant/getUsersForTenant"},{"key":"创建数据源","api":"/api/w8t/datasource/dataSourceCreate"},{"key":"搜索仪表盘","api":"/api/w8t/dashboard/searchDashboard"},{"key":"删除静默规则","api":"/api/w8t/silence/silenceDelete"},{"key":"更新静默规则","api":"/api/w8t/silence/silenceUpdate"},{"key":"删除规则模版","api":"/api/w8t/ruleTmpl/ruleTmplDelete"},{"key":"创建规则模版","api":"/api/w8t/ruleTmpl/ruleTmplCreate"},{"key":"获取系统配置","api":"/api/w8t/setting/getSystemSetting"},{"key":"查看告警规则组","api":"/api/w8t/ruleGroup/ruleGroupList"},{"key":"查看通知对象","api":"/api/w8t/notice/noticeList"},{"key":"查看用户角色","api":"/api/w8t/role/roleList"},{"key":"查看规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupList"},{"key":"修改用户密码","api":"/api/w8t/user/userChangePass"},{"key":"搜索通知模版","api":"/api/w8t/noticeTemplate/searchNoticeTmpl"},{"key":"获取数据源","api":"/api/w8t/datasource/dataSourceGet"},{"key":"删除数据源","api":"/api/w8t/datasource/dataSourceDelete"},{"key":"搜索通知对象","api":"/api/w8t/notice/noticeSearch"},{"key":"更新租户信息","api":"/api/w8t/tenant/updateTenant"},{"key":"向租户添加成员","api":"/api/w8t/tenant/addUsersToTenant"},{"key":"查看当前告警事件","api":"/api/w8t/event/curEvent"},{"key":"查看历史告警","api":"/api/w8t/event/hisEvent"},{"key":"更新通知对象","api":"/api/w8t/notice/noticeUpdate"},{"key":"删除告警规则组","api":"/api/w8t/ruleGroup/ruleGroupDelete"},{"key":"更新数据源","api":"/api/w8t/datasource/dataSourceUpdate"}]', '1722331221'); -INSERT ignore INTO `user_roles`(`id`, `name`, `description`, `permissions`, `create_at`) VALUES ('ur-cq7nkj1d6gviooaigqi0', '读写', '拥有系统读写操作权限', '[{"key":"用户注册","api":"/api/system/register"},{"key":"获取Jaeger服务列表","api":"/api/w8t/c/getJaegerService"},{"key":"搜索通知对象","api":"/api/w8t/notice/noticeSearch"},{"key":"搜索用户","api":"/api/w8t/user/searchUser"},{"key":"修改用户密码","api":"/api/w8t/user/userChangePass"},{"key":"搜索值班表","api":"/api/w8t/dutyManage/dutyManageSearch"},{"key":"发布日历表","api":"/api/w8t/calendar/calendarCreate"},{"key":"搜索仪表盘","api":"/api/w8t/dashboard/searchDashboard"},{"key":"搜索通知模版","api":"/api/w8t/noticeTemplate/searchNoticeTmpl"},{"key":"编辑系统配置","api":"/api/w8t/setting/saveSystemSetting"},{"key":"搜索日历表","api":"/api/w8t/calendar/calendarSearch"},{"key":"搜索数据源","api":"/api/w8t/datasource/dataSourceSearch"},{"key":"获取仪表盘","api":"/api/w8t/dashboard/getDashboard"},{"key":"搜索告警规则","api":"/api/w8t/rule/ruleSearch"},{"key":"获取数据源","api":"/api/w8t/datasource/dataSourceGet"},{"key":"搜索值班用户","api":"/api/w8t/user/searchDutyUser"},{"key":"获取系统配置","api":"/api/w8t/setting/getSystemSetting"},{"key":"查看值班表","api":"/api/w8t/dutyManage/dutyManageList"},{"key":"查看用户角色","api":"/api/w8t/role/roleList"},{"key":"查看告警规则组","api":"/api/w8t/ruleGroup/ruleGroupList"},{"key":"查看告警规则","api":"/api/w8t/rule/ruleList"},{"key":"查看用户权限","api":"/api/w8t/permissions/permsList"},{"key":"查看静默规则","api":"/api/w8t/silence/silenceList"},{"key":"查看通知对象","api":"/api/w8t/notice/noticeList"},{"key":"查看数据源","api":"/api/w8t/datasource/dataSourceList"},{"key":"查看历史告警","api":"/api/w8t/event/hisEvent"},{"key":"查看当前告警事件","api":"/api/w8t/event/curEvent"},{"key":"查看仪表盘","api":"/api/w8t/dashboard/listDashboard"},{"key":"查看通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateList"},{"key":"查看用户列表","api":"/api/w8t/user/userList"},{"key":"查看规则模版","api":"/api/w8t/ruleTmpl/ruleTmplList"},{"key":"查看租户","api":"/api/w8t/tenant/getTenantList"},{"key":"查看规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupList"},{"key":"更新数据源","api":"/api/w8t/datasource/dataSourceUpdate"},{"key":"更新告警规则","api":"/api/w8t/rule/ruleUpdate"},{"key":"更新通知对象","api":"/api/w8t/notice/noticeUpdate"},{"key":"更新静默规则","api":"/api/w8t/silence/silenceUpdate"},{"key":"更新值班表","api":"/api/w8t/dutyManage/dutyManageDelete"},{"key":"更新通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateUpdate"},{"key":"更新仪表盘","api":"/api/w8t/dashboard/updateDashboard"},{"key":"更新告警规则组","api":"/api/w8t/ruleGroup/ruleGroupUpdate"},{"key":"更新用户信息","api":"/api/w8t/user/userUpdate"},{"key":"更新用户角色","api":"/api/w8t/role/roleUpdate"},{"key":"更新日历表","api":"/api/w8t/calendar/calendarUpdate"},{"key":"更新租户信息","api":"/api/w8t/tenant/updateTenant"},{"key":"创建值班表","api":"/api/w8t/dutyManage/dutyManageCreate"},{"key":"创建静默规则","api":"/api/w8t/silence/silenceCreate"},{"key":"创建用户角色","api":"/api/w8t/role/roleCreate"},{"key":"创建通知对象","api":"/api/w8t/notice/noticeCreate"},{"key":"创建告警规则组","api":"/api/w8t/ruleGroup/ruleGroupCreate"},{"key":"创建规则模版","api":"/api/w8t/ruleTmpl/ruleTmplCreate"},{"key":"创建数据源","api":"/api/w8t/datasource/dataSourceCreate"},{"key":"创建告警规则","api":"/api/w8t/rule/ruleCreate"},{"key":"创建租户","api":"/api/w8t/tenant/createTenant"},{"key":"创建仪表盘","api":"/api/w8t/dashboard/createDashboard"},{"key":"创建通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateCreate"},{"key":"创建规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupCreate"}]', '1720678988'); -INSERT ignore INTO `user_roles`(`id`, `name`, `description`, `permissions`, `create_at`) VALUES ('ur-cq7nkthd6gviooaigqj0', '只读', '拥有系统只读操作权限', '[{"key":"Prometheus指标查询","api":"/api/w8t/datasource/promQuery"},{"key":"获取租户详细信息","api":"/api/w8t/tenant/getTenant"},{"key":"获取租户成员列表","api":"/api/w8t/tenant/getUsersForTenant"},{"key":"搜索通知对象","api":"/api/w8t/notice/noticeSearch"},{"key":"搜索用户","api":"/api/w8t/user/searchUser"},{"key":"搜索值班表","api":"/api/w8t/dutyManage/dutyManageSearch"},{"key":"搜索仪表盘","api":"/api/w8t/dashboard/searchDashboard"},{"key":"搜索通知模版","api":"/api/w8t/noticeTemplate/searchNoticeTmpl"},{"key":"搜索日历表","api":"/api/w8t/calendar/calendarSearch"},{"key":"搜索数据源","api":"/api/w8t/datasource/dataSourceSearch"},{"key":"搜索告警规则","api":"/api/w8t/rule/ruleSearch"},{"key":"搜索值班用户","api":"/api/w8t/user/searchDutyUser"},{"key":"获取Jaeger服务列表","api":"/api/w8t/c/getJaegerService"},{"key":"获取仪表盘","api":"/api/w8t/dashboard/getDashboard"},{"key":"获取数据源","api":"/api/w8t/datasource/dataSourceGet"},{"key":"获取系统配置","api":"/api/w8t/setting/getSystemSetting"},{"key":"查看值班表","api":"/api/w8t/dutyManage/dutyManageList"},{"key":"查看用户角色","api":"/api/w8t/role/roleList"},{"key":"查看告警规则组","api":"/api/w8t/ruleGroup/ruleGroupList"},{"key":"查看告警规则","api":"/api/w8t/rule/ruleList"},{"key":"查看用户权限","api":"/api/w8t/permissions/permsList"},{"key":"查看静默规则","api":"/api/w8t/silence/silenceList"},{"key":"查看通知对象","api":"/api/w8t/notice/noticeList"},{"key":"查看数据源","api":"/api/w8t/datasource/dataSourceList"},{"key":"查看历史告警","api":"/api/w8t/event/hisEvent"},{"key":"查看当前告警事件","api":"/api/w8t/event/curEvent"},{"key":"查看仪表盘","api":"/api/w8t/dashboard/listDashboard"},{"key":"查看通知模版","api":"/api/w8t/noticeTemplate/noticeTemplateList"},{"key":"查看用户列表","api":"/api/w8t/user/userList"},{"key":"查看规则模版","api":"/api/w8t/ruleTmpl/ruleTmplList"},{"key":"查看租户","api":"/api/w8t/tenant/getTenantList"},{"key":"查看规则模版组","api":"/api/w8t/ruleTmplGroup/ruleTmplGroupList"}]', '1720679030'); diff --git a/initialization/sql.go b/initialization/sql.go index c6d67eb..412c69c 100644 --- a/initialization/sql.go +++ b/initialization/sql.go @@ -6,7 +6,6 @@ import ( "time" "watchAlert/internal/models" "watchAlert/pkg/ctx" - "watchAlert/pkg/tools" ) var perms []models.UserPermissions @@ -28,7 +27,7 @@ func InitUserRolesSQL(ctx *ctx.Context) { var db = ctx.DB.DB().Model(&models.UserRole{}) roles := models.UserRole{ - ID: "ur-" + tools.RandId(), + ID: "admin", Name: "admin", Description: "system", Permissions: perms,