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

feat: replace mysql keywords/reserved words #14

Merged
merged 2 commits into from
May 9, 2022

Conversation

morfies
Copy link
Contributor

@morfies morfies commented May 6, 2022

This is for issue X-Profiler/xprofiler-console#36
It's tested against my self-hosted xprofiler console.
Let me know if the changes are not proper.

Thanks

@@ -91,14 +91,15 @@ class MysqlService extends Service {

/* table <apps> */
getAppByAppId(appId) {
const sql = 'SELECT * FROM apps WHERE id = ?';
const sql = 'SELECT *, app_name as name, app_owner as owner FROM apps WHERE id = ?';
const params = [appId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些改动没有必要,表格就是 appsapp_ 的前缀属于冗余信息。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, 这个PR的目的其实是因为name / owner 这些属于mysql的 reserved words, 有很多DBA会要求开发人员重命名的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我持保留意见,Mysql 的保留字包含太多常见的使用名了,尤其是 Account 这些名词是重灾区,关于列名的重新设计我得再思考下,就当下而言没有遇到这块的太强烈的需求

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,明白

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以单独留下列属性的修改,譬如 DOUBLE -> DECIMAL,这些确实很有用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以的,我改下

const params = [appId];
return this.consoleQuery(sql, params).then(data => data[0] || {});
}

/* table <files> */
updateFileStatusByAppAgentFile(appId, agentId, filePath) {
const sql = 'UPDATE files SET status = ? WHERE app = ? AND agent = ? AND file = ? AND status = ?';
const sql =
'UPDATE files SET file_status = ? WHERE app = ? AND agent = ? AND file = ? AND file_status = ?';
const params = [1, appId, agentId, filePath, 0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@@ -154,7 +154,7 @@ CREATE TABLE `osinfo`(
`http_response_sent` INT UNSIGNED COMMENT 'http responeses sent in last 1 min',
`http_request_timeout` INT UNSIGNED COMMENT 'timeout http requests in last 1 min',
`http_patch_timeout` INT UNSIGNED COMMENT 'http patch timeout (s)',
`http_rt` DOUBLE COMMENT 'http average response time (ms)',
`http_rt` DECIMAL(5,2) COMMENT 'http average response time (ms)',

`gm_modified` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'system modify timestamp',
`gm_create` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'system create timestamp',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DATETIME 其实也可以改为更加通用的 timestamp 类型

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也不好说,我现在这家的dba要求我们用bigint 存

@hyj1991 hyj1991 merged commit 2e4c9c8 into X-Profiler:master May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants