npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

db-entity-migrate

v0.1.1

Published

Database Entity Migration Tool

Downloads

7

Readme

db-entity-migrate

Overview

db-entity-migrate is a cross database table or collection migration library that supports seamless data migration between different databases supporting both SQL and NoSQL databases.

Features

  • Database Support: MySQL, PostgreSQL, SQLite3, OracleDB, & MongoDB.

  • Project Support: Works wit TypeScript and Javascript (ESM & CommonJs).

  • Batch Processing: Efficiently handle large datasets by migrating data in configurable batches.

  • Field Mapping: Define custom mappings for fields, including transformations and default values.

  • Validation with Zod: Validate migrated data using Zod schemas with customizable logging options.

  • User-Level Configurations: Configure migrations at both the project level and user level using TypeScript.

  • Robust Logging: Provides options writing database results and schema validations logs to disk.

  • Dry Run: Review migration and validations without writing to the database.

Installation

npm install db-entity-migrate

Usage

Project Level (JavaScript/TypeScript)

  • Import the migrate method.

  • Pass the configuration to the migrate method.

  • Run your migration script.

const { migrate } = require('db-entity-migrate');
const config = require('./config');

migrate(config);

Configuration

Sample Config

// config.ts

import { Config } from 'db-entity-migrate';
import { z } from 'zod';

export const config: Config = {
  // Database configurations
  db: {
    source: {
      // Source database details
      client: 'mongodb',
      // Check below on how to provide connection info other databases
      connection: 'mongodb://localhost:27017',
      database: 'source_database',
      collection: 'source_collection',
    },
    destination: {
      // Destination database details
      client: 'mysql',
      connection: {
        host: '127.0.0.1',
        port: 3306,
        user: 'your_username',
        password: 'your_password',
      },
      database: 'destination_database',
      table: 'destination_table',
      createTableRawSql: `CREATE TABLE test2 (
        id VARCHAR(24) NOT NULL PRIMARY KEY,
        name VARCHAR(255),
        age INT,
        createdAt TIMESTAMP
      );`,
    },
  },

  // Migration configurations
  migration: {
    log: {
      // Logging configurations
      level: 'info',
      filePath: 'migration_log.json',
    },
    batchSize: {
      // Batch processing configurations
      read: 500,
      write: 500,
    },
    dryRun: false, // Set to true for a dry run without actual writes
  },

  // Field mapping configurations
  fieldMapping: {
    mapping: {
      // Custom field mappings
      _id: { 
        to: 'id', 
        transform: (o: any) => o._id.toString(),
      },
      name: { to: 'name' },
      age: { to: 'age' },
      createdAt: { to: 'createdAt' }, // Example: Snake case conversion
    },
    strictMapping: true, // Set to false to allow unmapped fields
    idField: 'id'
  },
  
  // Validation configurations
  validation: {
    zodValidator: z.object({}), // Zod schema for validation (customize as needed)
    zodParserType: 'safeParse', // Zod parser type (options: 'parse', 'safeParse')
    logPath: 'validation_log.json', // Validation log file path
  },
};

Detailed Documentation

Database connection options which can be used either in source config or at destination config.

MySQL

connection: {
  host: '127.0.0.1',
  port: 3306,
  user: 'your_username',
  password: 'your_password',
}

PostgreSQL

connection: 'postgresql://localhost:5432',

SQLite3

connection: {
  filename: "./mydb.sqlite"
}

OracleDB

connection: {
  host: 'localhost',
  user: 'your_username',
  password: 'your_password',
  database: 'your_database_name'
}

MongoDB

connection: 'mongodb://localhost:27017',

Contributing

Contributions are welcome! Feel free to open issues or pull requests.