Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
chore: Update mysql-import-anonymous-data.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kulla committed Oct 30, 2023
1 parent 00050f9 commit 24509b8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions scripts/mysql/mysql-import-anonymous-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ main()

function main() {
const latestDump = getLatestDump()
if (!latestDump) {
console.error('❌ Could not fetch latest dump, check your gsutil setup')

Check failure on line 10 in scripts/mysql/mysql-import-anonymous-data.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
return
}
const fileName = getFileName(latestDump)
downloadDump(latestDump, fileName)

const container = getMySQLContainer()
if (!container) {
info(
'MySQL container not found. Please start the database first with "yarn start"!',
console.error(

Check failure on line 18 in scripts/mysql/mysql-import-anonymous-data.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
'MySQL container not found. Please start the database first with "yarn start"!',
)
return
}
Expand Down Expand Up @@ -55,7 +59,7 @@ function downloadDump(dumpPath: string, fileName: string) {
}

function getMySQLContainer(): string | null {
const container = spawnSync('docker-compose', ['ps', '-q', 'mysql'], {
const container = spawnSync('docker', ['compose', 'ps', '-q', 'mysql'], {
stdio: 'pipe',
encoding: 'utf-8',
})
Expand All @@ -76,9 +80,9 @@ function unzipAndCopyToContainer(fileName: string, container: string) {
}

function populateDumpInMySql() {
info('Start importing MySQL data')
console.log('🟢 Start importing MySQL data')

Check failure on line 83 in scripts/mysql/mysql-import-anonymous-data.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
execCommand(`pv ${TMP_DIR}/mysql.sql | serlo-mysql`)
info('Start importing anonymized user data')
console.log('🟢 Start importing anonymized user data')

Check failure on line 85 in scripts/mysql/mysql-import-anonymous-data.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement
execSql(
"LOAD DATA LOCAL INFILE '/tmp/user.csv' INTO TABLE user FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' IGNORE 1 ROWS;",
)
Expand All @@ -89,17 +93,12 @@ function execSql(command: string) {
}

function execCommand(command: string) {
const args = ['exec', 'mysql', 'sh', '-c', `${command}`]
const args = ['compose', 'exec', 'mysql', 'sh', '-c', `${command}`]

runCmd('docker-compose', args)
runCmd('docker', args)
}

function runCmd(cmd: string, args: string[]) {
const opt = { stdio: [process.stdin, process.stdout, process.stderr] }
spawnSync(cmd, args, opt)
}

function info(message: string) {
// eslint-disable-next-line no-console
console.error(`INFO: ${message}`)
}

0 comments on commit 24509b8

Please sign in to comment.