-
Notifications
You must be signed in to change notification settings - Fork 17
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
Mydumper integration #1962
Mydumper integration #1962
Changes from 33 commits
a7b3113
9b4a143
52cb749
12874f8
fd67819
20104e1
d683089
6cf1100
b3f6f25
4485a2f
b4aab5b
893fdd6
fbc3cae
39b9a85
bd1aaf1
7d01388
062e29a
35ae6a2
6d2b707
7f80865
c07d6b5
b9d2d1d
6d7ae75
f9e717d
ec587ee
6b7b15a
4a01b34
55377bf
68d2b25
a7416dc
d7792bc
83b3e1c
286feff
62918e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
-- metadata.header -1 | ||
# Started dump at: 2024-07-26 03:00:36 | ||
[config] | ||
quote_character = BACKTICK | ||
|
||
[myloader_session_variables] | ||
SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' /*!40101 | ||
|
||
|
||
-- some_db-schema-create.sql -1 | ||
/*!40101 SET NAMES utf8mb4*/; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=0*/; | ||
/*!40101 SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'*/; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `some_db` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
-- metadata.header 198 | ||
# Started dump at: 2024-07-26 03:00:36 | ||
[config] | ||
quote_character = BACKTICK | ||
|
||
[myloader_session_variables] | ||
SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' /*!40101 | ||
|
||
|
||
-- some_db-schema-create.sql 370 | ||
/*!40101 SET NAMES utf8mb4*/; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=0*/; | ||
/*!40101 SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'*/; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `some_db` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- MySQL dump 10.13 Distrib 8.0.28, for Linux (x86_64) | ||
-- | ||
-- Host: localhost Database: some_db | ||
-- ------------------------------------------------------ | ||
-- Server version 8.0.28 | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!50503 SET NAMES utf8mb4 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import chalk from 'chalk'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
|
||
import * as exit from '../lib/cli/exit'; | ||
import { getFileMeta, unzipFile } from '../lib/client-file-uploader'; | ||
import { getSqlDumpDetails, SqlDumpDetails, SqlDumpType } from '../lib/database'; | ||
import { | ||
processBooleanOption, | ||
validateDependencies, | ||
|
@@ -43,6 +45,9 @@ export class DevEnvImportSQLCommand { | |
|
||
validateImportFileExtension( this.fileName ); | ||
|
||
const dumpDetails = await getSqlDumpDetails( this.fileName ); | ||
const isMyDumper = dumpDetails.type === SqlDumpType.MYDUMPER; | ||
|
||
// Check if file is compressed and if so, extract the | ||
const fileMeta = await getFileMeta( this.fileName ); | ||
if ( fileMeta.isCompressed ) { | ||
|
@@ -83,13 +88,13 @@ export class DevEnvImportSQLCommand { | |
const expectedDomain = `${ this.slug }.${ lando.config.domain }`; | ||
await validateSQL( resolvedPath, { | ||
isImport: false, | ||
skipChecks: [], | ||
skipChecks: isMyDumper ? [ 'dropTable', 'dropDB' ] : [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
extraCheckParams: { siteHomeUrlLando: expectedDomain }, | ||
} ); | ||
} | ||
|
||
const fd = await fs.promises.open( resolvedPath, 'r' ); | ||
const importArg = this.getImportArgs(); | ||
const importArg = this.getImportArgs( dumpDetails ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted to a function to satisfy |
||
|
||
const origIsTTY = process.stdin.isTTY; | ||
|
||
|
@@ -131,10 +136,27 @@ export class DevEnvImportSQLCommand { | |
await addAdminUser( lando, this.slug ); | ||
} | ||
|
||
public getImportArgs() { | ||
const importArg = [ 'db', '--disable-auto-rehash' ].concat( | ||
public getImportArgs( dumpDetails: SqlDumpDetails ) { | ||
let importArg = [ 'db', '--disable-auto-rehash' ].concat( | ||
this.options.quiet ? '--silent' : [] | ||
); | ||
const threadCount = Math.max( os.cpus().length - 2, 1 ); | ||
if ( dumpDetails.type === SqlDumpType.MYDUMPER ) { | ||
importArg = [ | ||
'db-myloader', | ||
'--overwrite-tables', | ||
`--source-db=${ dumpDetails.sourceDb }`, | ||
`--threads=${ threadCount }`, | ||
'--max-threads-for-schema-creation=10', | ||
'--max-threads-for-index-creation=10', | ||
'--skip-triggers', | ||
'--skip-post', | ||
'--innodb-optimize-keys', | ||
'--checksum=SKIP', | ||
'--metadata-refresh-interval=2000000', | ||
'--stream', | ||
].concat( this.options.quiet ? [ '--verbose=0' ] : [ '--verbose=3' ] ); | ||
} | ||
|
||
return importArg; | ||
abdullah-kasim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to refactor the tests by quite a bit - it's mocking too much and adjusting the mock is starting to take too much time. Instead, I don't mock it but instead, provide a small fixture that is also speedy.