forked from TencentBlueKing/blueking-dbm
-
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.
feat(dbm-services): 区分数据库存储的语法规则的db类型 TencentBlueKing#8094
- Loading branch information
Showing
16 changed files
with
556 additions
and
157 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
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,72 @@ | ||
/* | ||
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
* 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 assets TODO | ||
package assets | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
|
||
"github.com/golang-migrate/migrate/v4" | ||
_ "github.com/golang-migrate/migrate/v4/database/mysql" // mysql TODO | ||
"github.com/golang-migrate/migrate/v4/source" | ||
"github.com/golang-migrate/migrate/v4/source/iofs" | ||
"github.com/pkg/errors" | ||
|
||
"dbm-services/common/go-pubpkg/logger" | ||
) | ||
|
||
// Migrations embed migrations sqlfile | ||
|
||
//go:embed migrations/*.sql | ||
var fs embed.FS | ||
|
||
// DoMigrateFromEmbed do migrate from embed | ||
func DoMigrateFromEmbed(user, addr, password, dbname string) (err error) { | ||
var mig *migrate.Migrate | ||
var d source.Driver | ||
if d, err = iofs.New(fs, "migrations"); err != nil { | ||
return err | ||
} | ||
dbURL := fmt.Sprintf( | ||
"mysql://%s:%s@tcp(%s)/%s?charset=%s&parseTime=true&loc=Local&multiStatements=true&interpolateParams=true", | ||
user, | ||
password, | ||
addr, | ||
dbname, | ||
"utf8", | ||
) | ||
mig, err = migrate.NewWithSourceInstance("iofs", d, dbURL) | ||
if err != nil { | ||
return errors.WithMessage(err, "migrate from embed") | ||
} | ||
defer mig.Close() | ||
if err = mig.Up(); err != nil { | ||
if err == migrate.ErrNoChange { | ||
logger.Info("migrate source from embed success with", "msg", err.Error()) | ||
return nil | ||
} | ||
logger.Error("migrate source from embed failed", err) | ||
return err | ||
} | ||
logger.Info("migrate source from embed success") | ||
return nil | ||
} |
Empty file.
82 changes: 82 additions & 0 deletions
82
dbm-services/mysql/db-simulation/assets/migrations/000001_init_sql.up.sql
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,82 @@ | ||
CREATE TABLE IF NOT EXISTS `tb_container_records` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`uid` varchar(255) NOT NULL, | ||
`container` varchar(255) NOT NULL, | ||
`create_pod_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`pod_ready_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`) | ||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; | ||
CREATE TABLE IF NOT EXISTS `tb_request_records` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`request_id` varchar(64) NOT NULL, | ||
`request_body` json DEFAULT NULL, | ||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`method` varchar(16) NOT NULL, | ||
`user` varchar(32) NOT NULL, | ||
`path` varchar(32) NOT NULL, | ||
`source_ip` varchar(32) NOT NULL, | ||
`response_code` int(11) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `request_id` (`request_id`) | ||
) ENGINE = InnoDB AUTO_INCREMENT = 77006 DEFAULT CHARSET = utf8mb4; | ||
CREATE TABLE IF NOT EXISTS `tb_simulation_img_cfgs` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`component_type` varchar(64) NOT NULL, | ||
`version` varchar(64) NOT NULL, | ||
`image` varchar(128) NOT NULL, | ||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `component_type` (`component_type`), | ||
UNIQUE KEY `version` (`version`) | ||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; | ||
CREATE TABLE IF NOT EXISTS `tb_simulation_tasks` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`task_id` varchar(256) NOT NULL, | ||
`request_id` varchar(64) NOT NULL, | ||
`phase` varchar(16) NOT NULL, | ||
`status` varchar(16) NOT NULL, | ||
`stdout` mediumtext, | ||
`stderr` mediumtext, | ||
`sys_err_msg` text, | ||
`extra` varchar(512) NOT NULL, | ||
`heartbeat_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`bill_task_id` varchar(128) NOT NULL, | ||
`mysql_version` varchar(64) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `task_id` (`task_id`), | ||
UNIQUE KEY `request_id` (`request_id`) | ||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; | ||
CREATE TABLE IF NOT EXISTS `tb_sql_file_simulation_infos` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`task_id` varchar(128) NOT NULL, | ||
`file_name_hash` varchar(65) DEFAULT NULL, | ||
`file_name` text NOT NULL, | ||
`status` varchar(16) NOT NULL, | ||
`err_msg` varchar(512) NOT NULL, | ||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`bill_task_id` varchar(128) NOT NULL, | ||
`line_id` int(11) NOT NULL, | ||
`mysql_version` varchar(64) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `uk_tk_file` (`task_id`, `file_name_hash`) | ||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; | ||
CREATE TABLE IF NOT EXISTS `tb_syntax_rules` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`group_name` varchar(64) NOT NULL, | ||
`rule_name` varchar(64) NOT NULL, | ||
`item` varchar(1024) NOT NULL, | ||
`item_type` varchar(128) NOT NULL, | ||
`expr` varchar(128) NOT NULL, | ||
`desc` varchar(512) NOT NULL, | ||
`warn_level` smallint(2) NOT NULL, | ||
`status` tinyint(1) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `group` (`group_name`, `rule_name`) | ||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; |
Empty file.
6 changes: 6 additions & 0 deletions
6
dbm-services/mysql/db-simulation/assets/migrations/000002_add_db_type_for_rule_table.up.sql
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,6 @@ | ||
ALTER TABLE tb_syntax_rules | ||
ADD COLUMN `db_type` varchar(64) NOT NULL DEFAULT '' | ||
AFTER `id`; | ||
ALTER TABLE tb_syntax_rules DROP INDEX `group`; | ||
ALTER TABLE tb_syntax_rules | ||
ADD UNIQUE INDEX `group`(`group_name`, `db_type`, `rule_name`); |
Empty file.
Oops, something went wrong.