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

my-migration-sql

v1.0.3

Published

Node module used for migrating MySQL table

Downloads

11

Readme

my-migration-sql

Latest release Latest tag Created Updated License NPM Version

Table of content

Installation

NodeJS module to automatically load migrations and other queries using MySQL node instance Install NodeJS from the official website by downloading the version based on your O/S Then in your project workspace console run this command

npm install my-migration-sql

You'll install the package

Basic

const { migrations } = require('my-migration-sql');

let Migration = new migrations({
  Connection: MySQLConnection,
  saveOptions: {
    type: 'mysql',

  },
  path: 'migrations'
});

Migration.up();

This code'll use a MySQL instance to load all the migrations files in the folder called migrations using up method and save the migrated ones in a table in MySQL

Options

Costructor

my-migration-sql

| Option | Type | Explanation | |---------------------------|----------------------------|--------------------------| | Connection | MySQL instance |Instance of MySQL using createConnection method| | path | String |Path to the migration folder, can be helpful using Node Path | | saveOptions | saveOptions instance or object|Options used to manage (save or remove) already migrated files|

saveOptions

| Option | Type | Explanation | |---------------------|--------------------|--------------------| | type | String | Type of saving method of migrated files.Available type:'mysql'Default: 'mysql'| | Connection | MySQL instance | Same instance of MySQL from the migrations, used to make queries to the database| | table_meta | String | only mysql type, assign custom name to the table where saving migrations.Default: 'mysql-meta'

Methods

my-migration-sql

| Method | Return type | Accepted parameter | What does it do? | |-------------|-------------|---------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | up | Promise | migration_name or [migration_names] | Execute and load migration_name or migration_names present in the migration path to the database and save the changes. If none migration_name used the method'll load all pending migrations | | down | none | migration_name | Downgrade and unload migration_name or migration_names present in the database. If none migration_name used the method'll unload all migrations (TODO) | | pending | none | none | Get the migrations that are still not loaded to the database |

saveOptions

| Method | Return type | Accepted parameter | What does it do? | |----------------------|-------------|--------------------|-------------------------------------------------------------| | getAllMigrated | Promise | none | Return all migrated files to the database | | load | none | migration_name | Save the migration_name as migrated to the storage option | | unload | none | migration_name | Remove the migration_name from the storage option | | isValid | Boolean | none | Return true if the storageOption is valid to operate |

Migration generate tool

It's also available a tool that can generate a new migration file, by running

node node_modules/my-migration-sql/src/generateMigration.js

you'll create a new migration file called default_name in the folder migrations. To customize the options of the file you can use add some args to the command | Args | What does? | |---------------------|---------------------| | name | Customize the name of the migration. Default: 'default_name' | | path | Customize the path where save the migration. Default: 'migrations' |

For example:

node node_modules/my-migration-sql/src/generateMigration.js --name=ExampleName --path=./example/test_migration 

Create a new migration called ExampleName and save into the folder ./example/test_migration

This is just a demo for this feature because it would be much better have a much cleaner command to run.

IMPORTANT Due to the requirement of node_modules folder if you have a dockerized application you have to run npm install anyway to run the use command

REMEMBER For now in the down and in the up variable is just allowed use a String to declare the query

Other information

https://nodei.co/npm/my-migration-sql.png?downloads=true&downloadRank=true&stars=true

Issues and Feature

If you have an idea for a new feature or you found a bug please report it in the issues section

Contributors

Contributors