Skip to content

Commit 87310fb

Browse files
committed
use migrate-mongo to update the db
1 parent bf19ba3 commit 87310fb

7 files changed

+98
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
/*.js
33
*.js.map
4+
!migrate-mongo-config.js
45

56
_leveldb
67
_leveldb_testnet

migrate-mongo-config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const Config = require('./config').Config;
2+
3+
const config = {
4+
mongodb: {
5+
url: Config.db.url,
6+
databaseName: Config.db.name,
7+
8+
options: {
9+
useNewUrlParser: true // removes a deprecation warning when connecting
10+
// connectTimeoutMS: 3600000, // increase connection timeout to 1 hour
11+
// socketTimeoutMS: 3600000, // increase socket timeout to 1 hour
12+
}
13+
},
14+
15+
// The migrations dir, can be an relative or absolute path. Only edit this when really necessary.
16+
migrationsDir: "migrations",
17+
18+
// The mongodb collection where the applied changes are stored. Only edit this when really necessary.
19+
changelogCollectionName: "changelog"
20+
};
21+
22+
//Return the config as a promise
23+
module.exports = config;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
async up(db) {
3+
console.log(await db.collection('graphs').dropIndex('tokenDetails.name_1'))
4+
console.log(await db.collection('graphs').dropIndex('tokenDetails.symbol_1'))
5+
console.log(await db.collection('graphs').dropIndex('fulltext'))
6+
7+
console.log(await db.collection('addresses').dropIndex('tokenDetails.name_1'))
8+
console.log(await db.collection('addresses').dropIndex('tokenDetails.symbol_1'))
9+
console.log(await db.collection('addresses').dropIndex('fulltext'))
10+
11+
console.log(await db.collection('utxos').dropIndex('tokenDetails.name_1'))
12+
console.log(await db.collection('utxos').dropIndex('tokenDetails.symbol_1'))
13+
console.log(await db.collection('utxos').dropIndex('fulltext'))
14+
},
15+
16+
async down(db) {
17+
console.log(await db.collection('graphs').createIndex('tokenDetails.name'))
18+
console.log(await db.collection('graphs').createIndex('tokenDetails.symbol'))
19+
console.log(await db.collection('graphs').createIndex({
20+
'tokenDetails.name': 'text',
21+
'tokenDetails.symbol': 'text'
22+
}, {
23+
'name': 'fulltext'
24+
}))
25+
26+
console.log(await db.collection('addresses').createIndex('tokenDetails.name'))
27+
console.log(await db.collection('addresses').createIndex('tokenDetails.symbol'))
28+
console.log(await db.collection('addresses').createIndex({
29+
'tokenDetails.name': 'text',
30+
'tokenDetails.symbol': 'text'
31+
}, {
32+
'name': 'fulltext'
33+
}))
34+
35+
console.log(await db.collection('utxos').createIndex('tokenDetails.name'))
36+
console.log(await db.collection('utxos').createIndex('tokenDetails.symbol'))
37+
console.log(await db.collection('utxos').createIndex({
38+
'tokenDetails.name': 'text',
39+
'tokenDetails.symbol': 'text'
40+
}, {
41+
'name': 'fulltext'
42+
}))
43+
}
44+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
async up(db) {
3+
console.log(await db.collection('graphs').createIndex({ 'graphTxn.txid': 1 }))
4+
},
5+
6+
async down(db) {
7+
console.log(await db.collection('graphs').dropIndex('graphTxn.txid_1'))
8+
}
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
async up(db) {
3+
console.log(await db.collection('addresses').createIndex({ 'address': 1 }))
4+
},
5+
6+
async down(db) {
7+
console.log(await db.collection('addresses').dropIndex('address_1'))
8+
}
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
async up(db) {
3+
console.log(await db.collection('utxos').createIndex({ 'utxo': 1 }))
4+
},
5+
6+
async down(db) {
7+
console.log(await db.collection('utxos').dropIndex('utxo_1'))
8+
}
9+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "tsc && test",
88
"start": "tsc && node index",
9-
"lint": "./node_modules/.bin/eslint ."
9+
"lint": "./node_modules/.bin/eslint .",
10+
"migrate": "./node_modules/.bin/migrate-mongo"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -42,6 +43,7 @@
4243
"ip": "^1.1.5",
4344
"level": "^4.0.0",
4445
"leveldown": "^4.0.1",
46+
"migrate-mongo": "^5.0.1",
4547
"mingo": "^2.2.4",
4648
"mongodb": "^3.1.4",
4749
"p-limit": "2.0.0",

0 commit comments

Comments
 (0)