Koishi Database Migration Plugin

0.2.1 · active · verified Wed Apr 22

koishi-plugin-migrate-database is a utility plugin for the Koishi chatbot framework, designed to facilitate the migration of data between different database instances. As of version 0.2.1, it provides basic functionality for moving existing Koishi data, which is critical for developers managing evolving bot infrastructures or changing database backends. This plugin is typically released on an as-needed basis to support specific migration scenarios or Koishi core updates. Its primary differentiator is its integration directly into the Koishi ecosystem, allowing for migrations that are aware of Koishi's internal data structures, unlike generic database migration tools. Users should be aware that, as a 0.x.x version, its API and internal workings may still evolve, and thorough testing is recommended before production use.

Common errors

Warnings

Install

Imports

Quickstart

Installs and registers the koishi-plugin-migrate-database plugin within a Koishi application, demonstrating its integration into `koishi.config.ts` for database migration. It highlights the cautious approach needed due to data operations.

import { Context, Schema } from 'koishi';
import { apply, Config } from 'koishi-plugin-migrate-database';

// Assuming you have a koishi.config.ts or similar configuration setup
// This demonstrates how to register the plugin within your Koishi application.

const ctx = new Context({
  // Your Koishi configuration, e.g., database, adapters, etc.
  database: {
    // Example database configuration for a new database
    // type: 'sqlite',
    // path: 'data.db',
  },
  // ... other configurations
});

// Register the migration plugin. Be extremely cautious when using this in production.
// Ensure you have backups and understand the migration process.
ctx.plugin(apply, {
  // Example configuration for the migration plugin (adjust as needed)
  // sourceDatabase: 'sqlite',
  // sourcePath: 'old_data.db',
  // targetDatabase: 'mysql',
  // targetUri: process.env.MYSQL_URI ?? '',
  // dryRun: true, // It is highly recommended to use dryRun first
  // enable: true, // Only enable when explicitly ready to migrate
});

ctx.start();

console.log('Koishi application started with migration plugin registered.');
console.log('Ensure to check plugin logs for migration status and potential errors.');

view raw JSON →