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

clickhouse-migration-tool

v1.1.1

Published

Node migration tool for Clickhouse. ESM Support

Downloads

7

Readme

ClickHouse Migration Tool

This npm package provides functionality for managing migrations in ClickHouse databases. It allows you to easily create, run, and manage database migrations using simple commands.

Installation

You can install the package either globally to use the CLI globally or locally within your project.

Global Installation

You can install the package globally using npm:

npm install -g clickhouse-migration-tool

This will make the clickhouse-migrate command available globally on your system.

Local Installation

For local usage within your project, install the package locally:

npm install clickhouse-migration-tool

You can then use the CLI within your project's npm scripts or by running it with npx.

Usage

The primary command for interacting with this tool is clickhouse-migrate. Below are the available options and commands:

Usage: clickhouse-migrate [options] [command]

Options:
  -V, --version        output the version number
  -c, --config [path]  Specify the config path
  -h, --help           display help for command

Commands:
  init                 Initialize clickhouse-migration-tool configuration
  create <name>        Create a migration template file in the specified migration directory
  migrate              Run all pending migrations
  help [command]       display help for command

Initializing Configuration

To initialize the configuration for the migration tool, use the init command. This will create a configuration file (clickhouse-migrate-config.js) in your project directory.

clickhouse-migrate init

The generated configuration file will have the following structure:

export default {
    connection: {
        host: 'http://127.0.0.1:8123', /** Clickhouse connection host */
        username: 'non-root', /** Clickhouse connection username */
        database: 'test', /** Clickhouse connection database */
        password: '12345678' /** Clickhouse connection password */
    },
    options: {
        migrations: {
            tableName: 'migrations', /** Name of the table where the script will store system data related to executed migrations. DO NOT modify after running migrations. */
            path: './migrations' /** Path to the migrations directory */
        },
        database: {
            createIfNotExists: true, /** If this option is set to 'true' and your database does not exist, the script will create the database using the specified engine. */
            engine: 'Atomic' /** Can be: 'Atomic', 'MySQL', 'MaterializedMySQL', 'Lazy', 'PostgreSQL', 'MaterializedPostgreSQL', 'Replicated', 'SQLite' */
        }
    }
};

Creating Migrations

You can create a new migration file using the create command followed by a name for the migration. This will generate a migration template file in the specified migration directory.

clickhouse-migrate create <name>

Running Migrations

To execute all pending migrations, use the migrate command.

clickhouse-migrate migrate

Configuration

By default, the migration tool looks for the configuration file (clickhouse-migrate-config.js) in the root of your project. If you need to specify a custom path, you can use the -c, --config [path] option.

Important Notes

  • Generated Migration File Name: The migration tool generates migration file names automatically. Do not change the generated migration file name.
  • CommonJS Modules Not Supported: This package currently only supports ESM (ECMAScript Modules) imports.
  • Using Environment Variables: You can utilize process.env in the configuration file. Below is an example:
/* Import env parser or your own logic for parsing .env files goes here */

export default {
    connection: {
        host: process.env.CLICKHOUSE_HOST || 'http://127.0.0.1:8123', /** Clickhouse connection host */
        username: process.env.CLICKHOUSE_USERNAME || 'non-root', /** Clickhouse connection username */
        database: process.env.CLICKHOUSE_DATABASE || 'test', /** Clickhouse connection database */
        password: process.env.CLICKHOUSE_PASSWORD || '12345678' /** Clickhouse connection password */
    },
    options: {
        migrations: {
            tableName: 'migrations', /** Name of the table where the script will store system data related to executed migrations. DO NOT modify after running migrations. */
            path: './migrations' /** Path to the migrations directory */
        },
        database: {
            createIfNotExists: true, /** If this option is set to 'true' and your database does not exist, the script will create the database using the specified engine. */
            engine: 'Atomic' /** Can be: 'Atomic', 'MySQL', 'MaterializedMySQL', 'Lazy', 'PostgreSQL', 'MaterializedPostgreSQL', 'Replicated', 'SQLite' */
        }
    }
};