node-mysql-migrate
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

node-mysql-migrate

Public project to perform migrations on mysql database.

How to run

  1. First step, install the dependency for your project. To make it, to do this you have to run this command:
  npm install node-mysql-migrate

Obs: You need install mysql dependency too.

  1. Create your migrations, example below:
  import { createTable } from 'node-mysql-migrate'

  export default function users(){
      createTable({
          tableName: 'users',
          fields: [
              {
                  name: 'id',
                  type: 'INT',
                  pk: true,
                  isNull: false,
                  increment: true
              },
              {
                  name: 'fullname',
                  type: 'VARCHAR(255)',
                  isNull: false
              },
              {
                  name: 'email',
                  type: 'VARCHAR(255)',
                  isNull: false
              },
              {
                  name: 'password',
                  type: 'VARCHAR(255)',
                  isNull: false
              },
              {
                  name: 'typeAccess_id',
                  type: 'INT', 
                  fk: {
                      tableName: 'typeAccess',
                      fieldName: 'id'
                  },
                  isNull: false
              },
              {
                  name: 'created_at',
                  type: 'DATETIME',
                  default: 'NOW()',
                  isNull: false
              }
          ]
      })
  }
  1. Create the migration data source, example below:
  import MigrationDataSource from 'node-mysql-migrate'
  import users from './migrations/users'
  import typeAccess from './migrations/typeAccess'

  export default new MigrationDataSource({
      db_config: {    
          host     : '...yourHost',
          port     : 3306, //your port
          user     : '...yourUser',
          password : '...yourPass',
          database : '...yourDatabase',
      },
      migrations: [users, typeAccess]  
  })

Obs: In the 'migrations' field you must add your migrations.

That's all folks.

Readme

Keywords

none

Package Sidebar

Install

npm i node-mysql-migrate

Weekly Downloads

1

Version

1.1.3

License

ISC

Unpacked Size

174 kB

Total Files

40

Last publish

Collaborators

  • tiagomol1