forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Added command to migrate content to different storage
- Loading branch information
Showing
13 changed files
with
261 additions
and
28 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,54 @@ | ||
import { PositionalOptions, Options } from 'yargs'; | ||
import Logger from '@joplin/lib/Logger'; | ||
import BaseCommand, { RunContext } from './BaseCommand'; | ||
import parseStorageConnectionString from '../models/items/storage/parseStorageConnectionString'; | ||
|
||
const logger = Logger.create('ImportContentCommand'); | ||
|
||
interface Argv { | ||
toStorage: string; | ||
batchSize?: number; | ||
} | ||
|
||
export default class ImportContentCommand extends BaseCommand { | ||
|
||
public command() { | ||
return 'import-content <to-storage>'; | ||
} | ||
|
||
public description() { | ||
return 'import content to storage'; | ||
} | ||
|
||
public positionals(): Record<string, PositionalOptions> { | ||
return { | ||
'to-storage': { | ||
description: 'storage connection string', | ||
type: 'string', | ||
}, | ||
}; | ||
} | ||
|
||
public options(): Record<string, Options> { | ||
return { | ||
'batch-size': { | ||
type: 'number', | ||
description: 'Item batch size', | ||
}, | ||
}; | ||
} | ||
|
||
public async run(argv: Argv, runContext: RunContext): Promise<void> { | ||
const toStorageConfig = parseStorageConnectionString(argv.toStorage); | ||
const batchSize = argv.batchSize || 1000; | ||
|
||
logger.info('Importing to storage:', toStorageConfig); | ||
logger.info(`Batch size: ${batchSize}`); | ||
|
||
await runContext.models.item().importContentToStorage(toStorageConfig, { | ||
batchSize: batchSize || 1000, | ||
logger: logger as Logger, | ||
}); | ||
} | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
packages/server/src/migrations/20211111134329_storage_index.ts
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,14 @@ | ||
import { Knex } from 'knex'; | ||
import { DbConnection } from '../db'; | ||
|
||
export async function up(db: DbConnection): Promise<any> { | ||
await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => { | ||
table.index('content_storage_id'); | ||
}); | ||
} | ||
|
||
export async function down(db: DbConnection): Promise<any> { | ||
await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => { | ||
table.dropIndex('content_storage_id'); | ||
}); | ||
} |
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
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
Oops, something went wrong.