-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2615 from huridocs/multidb
support easy yarn dump-db and restore-db & allow easy db switching via .env
- Loading branch information
Showing
11 changed files
with
89 additions
and
21 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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const { DBHOST } = process.env; | ||
const { DATABASE_NAME } = process.env; | ||
|
||
// Keep in sync with elasticindexes.js! | ||
export default { | ||
demo: 'mongodb://localhost/uwazi_demo', | ||
development: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_development', | ||
testing: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_testing', | ||
production: DBHOST ? `mongodb://${DBHOST}/${DATABASE_NAME}` : 'mongodb://localhost/uwazi_development' | ||
development: `mongodb://${DBHOST || 'localhost'}/${DATABASE_NAME || 'uwazi_development'}`, | ||
testing: `mongodb://${DBHOST || 'localhost'}/${DATABASE_NAME || 'uwazi_testing'}`, | ||
production: `mongodb://${DBHOST || 'localhost'}/${DATABASE_NAME || 'uwazi_development'}` | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
const { INDEX_NAME } = process.env; | ||
const { DATABASE_NAME, INDEX_NAME } = process.env; | ||
|
||
// Keep in sync with database.js! | ||
export default { | ||
production: INDEX_NAME || 'uwazi_development', | ||
testing: INDEX_NAME || 'testing', | ||
development: INDEX_NAME || 'uwazi_development', | ||
demo: INDEX_NAME || 'uwazi_demo' | ||
demo: INDEX_NAME || DATABASE_NAME || 'uwazi_demo', | ||
development: INDEX_NAME || DATABASE_NAME || 'uwazi_development', | ||
testing: INDEX_NAME || DATABASE_NAME || 'testing', | ||
production: INDEX_NAME || DATABASE_NAME || 'uwazi_development', | ||
}; |
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,16 @@ | ||
#!/bin/bash | ||
|
||
[[ -f ".env" ]] && source ".env" | ||
|
||
OLDWD=$( cd "$(dirname "${BASH_SOURCE[0]}")"/.. ; pwd -P ) | ||
cd /tmp | ||
|
||
DB=${1:-${DATABASE_NAME:-uwazi_development}} | ||
HOST=${2:-${DBHOST:-127.0.0.1}} | ||
|
||
rm -rf $DB* | ||
mongodump -h $HOST --gzip --db $DB -o $DB | ||
cp -r $OLDWD/uploaded_documents $DB/ | ||
tar czf $OLDWD/$DB.tar.gz $DB/ | ||
|
||
echo "Wrote $DB.tar.gz." |
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,27 @@ | ||
#!/bin/bash | ||
|
||
[[ -f ".env" ]] && source ".env" | ||
|
||
OLDWD=$( cd "$(dirname "${BASH_SOURCE[0]}")"/.. ; pwd -P ) | ||
cd /tmp | ||
|
||
DB=${1:-${DATABASE_NAME:-uwazi_development}} | ||
HOST=${2:-${DBHOST:-127.0.0.1}} | ||
|
||
if [ ! -f "$OLDWD/$DB.tar.gz" ]; then | ||
echo "Did not find expected $OLDWD/$DB.tar.gz - run restore-db <database name> to pick a different db." | ||
exit -1 | ||
fi | ||
|
||
rm -rf $DB* | ||
tar xzf $OLDWD/$DB.tar.gz | ||
mongo -host $HOST $DB --eval "db.dropDatabase()" | ||
mongorestore -h $HOST --gzip --db $DB $DB/$DB | ||
cp $DB/uploaded_documents/* $OLDWD/uploaded_documents | ||
|
||
echo "Restored $DB.tar.gz." | ||
|
||
cd $OLDWD | ||
export DATABASE_NAME=$DB | ||
yarn migrate | ||
yarn reindex |
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