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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pesalink/pesalink-database-package

v1.0.2

Published

Create migrations & seeds folder in src

Readme

Pesalink Database Package

Steps to integrate and utilize the DB migration package

make directory for keeping migration & seed files

Create migrations & seeds folder in src

Install migration package

Install the migration package
npm i @pesalink/pesalink-database-package 

Install dependencies

npm install knex mysql2 dotenv

Create a file with name knexfile.js in root directory

Pass connection details like host, user, password, database name, and client type
Provide a table name to store migrations file records
Give directory path for migrations and seeds

To create migrations file

npx knex migrate:make your_migration_file modify the migration file as per you requirement

Follow below steps to run migration files

Create a file in root directory with name runMigrations.js
Import the @pesalink/pesalink-database-package 
Import the knexfile.js of the project to pass env variable to package


import { runMigrations } from '@pesalink/pesalink-database-package';  // Import migration function
import knexConfig from './knexfile.js';  // Correct the import for knexfile.js

// Run migration
runMigrations(knexConfig.development)
  .then(() => {
    console.log('Service Migrations ran successfully!');
  })
  .catch((error) => {
    console.error('Error running migrations:', error);
  });

To run specific migration file

npx knex migrate:up your_migration_file.js

To run all migration files

node runMigrations.js

To rollback a specific migration file

npx knex migrate:down your_migration_file.js

To check migrations file status in service

npx knex migrate:status --knexfile knexfile.js (path of knexfile.js)

To rollback all migrations files

npx knex migrate:rollback or npx knex migrate:rollback --all

To create seed file

npx knex seed:make you_seed_file modify the seed file as per you requirement

Follow below steps to run seed files

Create a file in root directory with name runSeeds.js
Import the @pesalink/pesalink-database-package
Import the knexfile.js of the project to pass env variable to package


import { runSeeds } from '@pesalink/pesalink-database-package';  // Import runSeeds from shared package
import knexConfig from './knexfile.js';  // Import knex configuration

const runUserManagementSeeds = async () => {
  try {
    // Pass the knexConfig to runSeeds function
    await runSeeds(knexConfig.development);  // Use the correct config (like development)
    console.log('Service Seeds ran successfully!');
  } catch (error) {
    console.error('Error running seeds:', error);
  }
};

runUserManagementSeeds();  // Run the seeds

To run specific seed

npx knex seed:run --specific=you_seed_file.js

To run all seeds

node run runSeeds.js

To insert fake record use following steps

install facker package by npm install @faker-js/faker
Import this package into seed file

import { faker } from '@faker-js/faker';
/**
 * @param { import("knex").Knex } knex
 * @returns { Promise<void> } 
 */

export async function seed(knex) {
  await knex('company').del(); // Clear existing data

  const companies = Array.from({ length: 5 }).map(() => ({
    company_name: faker.company.name(),  // Generating fake company names
  }));

  await knex('company').insert(companies);
  console.log('Fake companies have been added!');

}

Structure of project

/ServiceDirectory
│── node_modules/
│── src/
│   │── migrations/        # Contains all migration files
│   │── seeds/             # Contains all seed files
│   │── services/          # Other services in the project
│── package.json
│── knexfile.js            # Knex configuration file
│── runSeeds.js            # Script to run specific seed files
│── runMigrations.js       # Script to run migrations