Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-api
Commits
103d7c34
Commit
103d7c34
authored
Dec 20, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop sql
parent
46d0c0bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
dbsync.js
app/controller/dbsync.js
+22
-1
package.json
package.json
+1
-0
No files found.
app/controller/dbsync.js
View file @
103d7c34
const
Router
=
require
(
'
koa-router
'
)
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
_
=
require
(
'
lodash
'
)
const
mysql
=
require
(
'
mysql2/promise
'
);
const
jenkinsService
=
require
(
'
../service/jenkinsService
'
)
const
k8sService
=
require
(
'
../service/k8sService
'
)
const
{
DBConfig
}
=
require
(
'
../service/mongoService
'
)
...
...
@@ -128,10 +128,31 @@ const dbSyncQuery = async function (ctx) {
ctx
.
body
=
ctx
.
ok
({
status
:
'
queue
'
,
log
:
{
body
:
''
}
})
}
const
getDropSQL
=
async
(
ctx
)
=>
{
const
{
dbName
}
=
ctx
.
request
.
query
const
select
=
`select \`sql\`,base from core_sqlrecord where to_days(date) = to_days(now())
and state='Execute Successfully' and \`sql\` like '%drop %'`
const
connection
=
await
mysql
.
createConnection
({
host
:
'
172.30.4.8
'
,
user
:
'
sync_del
'
,
password
:
'
JhHgXdbopEPO6r6K
'
,
database
:
'
yearning
'
,
})
const
[
rows
]
=
await
connection
.
execute
(
select
)
const
res
=
rows
.
reduce
((
a
,
b
)
=>
{
if
(
b
.
base
===
dbName
)
{
a
+=
`
${
b
.
sql
}
;`
}
return
a
},
''
)
ctx
.
body
=
res
}
const
router
=
new
Router
()
router
.
get
(
'
/get_dbs
'
,
getDBs
)
.
get
(
'
/get_name_space
'
,
getNamespace
)
.
get
(
'
/getDropSQL
'
,
getDropSQL
)
.
post
(
'
/db_sync
'
,
bodyParser
(),
dbSync
)
.
post
(
'
/tke
'
,
bodyParser
(),
dbSyncTke
)
.
post
(
'
/db_sync_query
'
,
bodyParser
(),
dbSyncQuery
)
...
...
package.json
View file @
103d7c34
...
...
@@ -34,6 +34,7 @@
"
lodash
"
:
"
^4.17.11
"
,
"
moment
"
:
"
^2.24.0
"
,
"
mongoose
"
:
"
^5.3.4
"
,
"
mysql2
"
:
"
^2.0.2
"
,
"
node-etcd
"
:
"
^7.0.0
"
,
"
node-schedule
"
:
"
^1.3.0
"
,
"
nodemailer
"
:
"
^6.3.1
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment