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

@shagital/adonisjs-migrations-generator

v1.0.2

Published

An AdonisJS (nodejs) package to generate migration files from existing DB tables

Downloads

37

Readme

AdonisJS Migrations Generator

npm npm (scoped) NPM

This package allows you easily generate migration files for your AdonisJS app from an existing Database, including indexes and foreign keys!

Currently Supported

  • MySQL
  • SQLite
  • PostgreSQL

Installation

You can install the package via composer:

npm install @shagital/adonisjs-migrations-generator

Or with yarn

yarn add @shagital/adonisjs-migrations-generator

Usage

Open start/app.js and add @shagital/adonisjs-migrations-generator/src/Commands/MigrationsGeneratorCommand to the commands array

  • Note that you can replace the adonis with node ace if adonis is not installed globally on your system.

Basic usage

Will generate migration files for all tables in the DB set as default, and save files in database/migrations directory

adonis migration:generate

Specify tables to generate migrations for

adonis migration:generate  --include=table1,table2

Exclude specific tables

adonis migration:generate  --exclude=table1,table2

Specify DB connection to use

NOTE: Connection type must have been specified in config/databases

adonis migration:generate  --connection=mysql2

Save migration files in specified path

NOTE: The package will attempt to create the specified directory if it doesn't exist

adonis migration:generate  --path=/var/www/html/backups

Clear directory before creating migration files.

This option is suitable for a fresh application install

#f03c15 NOTE: The directory and all it's content will be deleted before the directory is recreated! ENSURE THE DIRECTORY DOESN'T CONTAIN FILES YOU PREFER TO KEEP!!!

adonis migration:generate --force

Disable foreign key constraint in migration files

[MySQL] Because we're generating migrations are being generated from an existing DB, when you run the migration, you might run into foreign key constraint errors because tables might not be created before been referenced in another table. This option adds a command to disable foreign key check so your migrations can run smoothly

adonis migration:generate --disable-fkc

Example Migration file

'use strict';

/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema');
/** @type {import('@adonisjs/lucid/src/Database')} */
const Database = use('Database');

class UsersSchema extends Schema {

  static get connection() {
    return 'mysql'
  }

  up() {
    return Promise.all([
      Database.raw("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS;"),
      Database.raw("SET FOREIGN_KEY_CHECKS=0;")
    ]).then(() => {
      this.create('users', (table) => {
        table.increments('id').unsigned();
        table.string('username', 80).unique();
        table.string('first_name', 80).nullable();
        table.string('last_name', 80).nullable();
        table.string('email', 100).unique();
        table.string('password', 255);
        table.timestamp('deleted_at').nullable();
        table.timestamp('created_at').defaultTo(Database.fn.now());
        table.timestamp('updated_at').defaultTo(Database.fn.now());

        table.index(['username'], 'users_username_unique_22');
        table.index(['email'], 'users_email_unique_76');
      });
    });
  }

  down() {
    return Promise.all([
      Database.raw("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS;"),
      Database.raw("SET FOREIGN_KEY_CHECKS=0;")
    ]).then(() => {
      this.dropIfExists('users');
    });
  }
}

module.exports = UsersSchema

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

If you have a feature you'd like to add, kindly send a Pull Request (PR)

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.