-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: SamTv12345 <[email protected]>
- Loading branch information
1 parent
d010d53
commit d4cbbf1
Showing
7 changed files
with
245 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// DB migration | ||
import {readFileSync} from 'node:fs' | ||
import {Database, DatabaseType} from "ueberdb2"; | ||
import path from "node:path"; | ||
const settings = require('ep_etherpad-lite/node/utils/Settings'); | ||
|
||
|
||
// file1 = source, file2 = target | ||
// pnpm run migrateDB --file1 <db1.json> --file2 <db2.json> | ||
const arg = process.argv.slice(2); | ||
|
||
if (arg.length != 4) { | ||
console.error('Wrong number of arguments!. Call with pnpm run migrateDB --file1 source.json target.json') | ||
process.exit(1) | ||
} | ||
|
||
type SettingsConfig = { | ||
dbType: string, | ||
dbSettings: any | ||
} | ||
|
||
/* | ||
{ | ||
"dbType": "<your-db-type>", | ||
"dbSettings": { | ||
<your-db-settings> | ||
} | ||
} | ||
*/ | ||
|
||
let firstDBSettingsFile: string | ||
let secondDBSettingsFile: string | ||
|
||
|
||
if (arg[0] == "--file1") { | ||
firstDBSettingsFile = arg[1] | ||
} else if (arg[0] === "--file2") { | ||
secondDBSettingsFile = arg[1] | ||
} | ||
|
||
if (arg[2] == "--file1") { | ||
firstDBSettingsFile = arg[3] | ||
} else if (arg[2] === "--file2") { | ||
secondDBSettingsFile = arg[3] | ||
} | ||
|
||
|
||
|
||
const settingsfile = JSON.parse(readFileSync(path.join(settings.root,firstDBSettingsFile!)).toString()) as SettingsConfig | ||
const settingsfile2 = JSON.parse(readFileSync(path.join(settings.root,secondDBSettingsFile!)).toString()) as SettingsConfig | ||
|
||
console.log(settingsfile2) | ||
if ("filename" in settingsfile.dbSettings) { | ||
settingsfile.dbSettings.filename = path.join(settings.root, settingsfile.dbSettings.filename) | ||
console.log(settingsfile.dbType + " location is "+ settingsfile.dbSettings.filename) | ||
} | ||
|
||
if ("filename" in settingsfile2.dbSettings) { | ||
settingsfile2.dbSettings.filename = path.join(settings.root, settingsfile2.dbSettings.filename) | ||
console.log(settingsfile2.dbType + " location is "+ settingsfile2.dbSettings.filename) | ||
} | ||
|
||
const ueberdb1 = new Database(settingsfile.dbType as DatabaseType, settingsfile.dbSettings) | ||
const ueberdb2 = new Database(settingsfile2.dbType as DatabaseType, settingsfile2.dbSettings) | ||
|
||
const handleSync = async ()=>{ | ||
await ueberdb1.init() | ||
await ueberdb2.init() | ||
|
||
const allKeys = await ueberdb1.findKeys('*','') | ||
for (const key of allKeys) { | ||
const foundVal = await ueberdb1.get(key)! | ||
await ueberdb2.set(key, foundVal) | ||
} | ||
} | ||
|
||
handleSync().then(()=>{ | ||
console.log("Done syncing dbs") | ||
}).catch(e=>{ | ||
console.log(`Error syncing db ${e}`) | ||
}) | ||
|
||
|
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,29 @@ | ||
# CLI | ||
|
||
You can find different tools for migrating things, checking your Etherpad health in the bin directory. | ||
One of these is the migrateDB command. It takes two settings.json files and copies data from one source to another one. | ||
In this example we migrate from the old dirty db to the new rustydb engine. So we copy these files to the root of the etherpad-directory. | ||
|
||
````json | ||
{ | ||
"dbType": "dirty", | ||
"dbSettings": { | ||
"filename": "./var/rusty.db" | ||
} | ||
} | ||
```` | ||
|
||
|
||
|
||
````json | ||
{ | ||
"dbType": "rustydb", | ||
"dbSettings": { | ||
"filename": "./var/rusty2.db" | ||
} | ||
} | ||
```` | ||
|
||
|
||
After that we need to move the data from dirty to rustydb. | ||
Therefore, we call `pnpm run migrateDB --file1 test1.json --file2 test2.json` with these two files in our root directories. After some time the data should be copied over to the new database. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
sqlite.db | ||
minified* | ||
installed_plugins.json | ||
installed_plugins.json | ||
dirty.db | ||
rusty.db |