Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve import-db/export-db with --target-db and --no-drop flags, fixes
#1961, fixes #1652 (#2037) * Add import-db --target-db and --no-drop flags, fixes #1961 * Change to drop-by-default on import * Add targetDB to export-db * Allow import-db and export-db to take project arg * Use -f as shorthand for --src in import-db
- Loading branch information
Showing
12 changed files
with
504 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/drud/ddev/pkg/ddevapp" | ||
"github.com/drud/ddev/pkg/fileutil" | ||
"github.com/drud/ddev/pkg/testcommon" | ||
asrt "github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
// TestCmdExportDB does an export-db | ||
func TestCmdExportDB(t *testing.T) { | ||
assert := asrt.New(t) | ||
|
||
testDir, _ := os.Getwd() | ||
site := TestSites[0] | ||
cleanup := site.Chdir() | ||
|
||
app, err := ddevapp.NewApp(site.Dir, false, "") | ||
assert.NoError(err) | ||
|
||
defer func() { | ||
// Make sure all databases are back to default empty | ||
_ = app.Stop(true, false) | ||
_ = app.Start() | ||
cleanup() | ||
}() | ||
|
||
// Read in a database | ||
inputFileName := filepath.Join(testDir, "testdata", t.Name(), "users.sql") | ||
_ = os.MkdirAll("tmp", 0755) | ||
// Run the import-db command with stdin coming from users.sql | ||
command := exec.Command(DdevBin, "import-db", "-f="+inputFileName) | ||
importDBOutput, err := command.CombinedOutput() | ||
require.NoError(t, err, "failed import-db from %s: %v", inputFileName, importDBOutput) | ||
|
||
_, _, err = app.Exec(&ddevapp.ExecOpts{ | ||
Service: "db", | ||
Cmd: "mysql -e 'SHOW TABLES;'", | ||
}) | ||
assert.NoError(err) | ||
|
||
// Export the database and verify content of output | ||
_ = os.MkdirAll(filepath.Join("tmp", t.Name()), 0755) | ||
outputFileName := filepath.Join(site.Dir, "tmp", t.Name(), "output.sql") | ||
_ = os.RemoveAll(outputFileName) | ||
command = exec.Command(DdevBin, "export-db", "-f="+outputFileName, "--gzip=false") | ||
byteout, err := command.CombinedOutput() | ||
require.NoError(t, err, "byteout=%s", string(byteout)) | ||
assert.FileExists(outputFileName) | ||
assert.True(fileutil.FgrepStringInFile(outputFileName, "13751eca-19cf-41c2-90d4-9363f3a07c45")) | ||
|
||
// Test with named project (outside project directory) | ||
tmpDir := testcommon.CreateTmpDir("TestCmdExportDB") | ||
err = os.Chdir(tmpDir) | ||
assert.NoError(err) | ||
|
||
err = os.RemoveAll(outputFileName) | ||
assert.NoError(err) | ||
command = exec.Command(DdevBin, "export-db", site.Name, "-f="+outputFileName, "--gzip=false") | ||
byteout, err = command.CombinedOutput() | ||
assert.NoError(err, "export-db failure output=%s", string(byteout)) | ||
assert.FileExists(outputFileName) | ||
assert.True(fileutil.FgrepStringInFile(outputFileName, "13751eca-19cf-41c2-90d4-9363f3a07c45")) | ||
} |
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,55 @@ | ||
-- MySQL dump 10.13 Distrib 5.5.54, for debian-linux-gnu (x86_64) | ||
-- | ||
-- Host: db Database: data | ||
-- ------------------------------------------------------ | ||
-- Server version 5.7.17-log | ||
|
||
/*!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 */; | ||
/*!40101 SET NAMES utf8 */; | ||
/*!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 */; | ||
|
||
-- | ||
-- Table structure for table `users` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `users`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `users` ( | ||
`uid` int(10) unsigned NOT NULL, | ||
`uuid` varchar(128) CHARACTER SET ascii NOT NULL, | ||
`langcode` varchar(12) CHARACTER SET ascii NOT NULL, | ||
PRIMARY KEY (`uid`), | ||
UNIQUE KEY `user_field__uuid__value` (`uuid`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='The base table for user entities.'; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `users` | ||
-- | ||
|
||
LOCK TABLES `users` WRITE; | ||
/*!40000 ALTER TABLE `users` DISABLE KEYS */; | ||
set autocommit=0; | ||
INSERT INTO `users` VALUES (0,'13751eca-19cf-41c2-90d4-9363f3a07c45','en'),(1,'186efa0a-8aa3-4eeb-90ce-6302fb9c4e07','en'); | ||
/*!40000 ALTER TABLE `users` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
commit; | ||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
|
||
-- Dump completed on 2017-05-31 14:03:34 |
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
Oops, something went wrong.