Giter Site home page Giter Site logo

sequelize-auto's Introduction

Sequelize-Auto

Build Status Build status Code Climate Test Coverage

Automatically generate models for SequelizeJS via the command line.

Install

npm install sequelize-auto

Prerequisites

You will need to install sequelize; it's no longer installed by sequelize-auto.

You will need to install the correct dialect binding before using sequelize-auto.

Dialect Install
MySQL/MariaDB npm install sequelize mysql2
Postgres npm install sequelize pg pg-hstore
Sqlite npm install sequelize sqlite3
MSSQL npm install sequelize tedious

Usage

sequelize-auto -h <host> -d <database> -u <user> -x [password] -p [port]  --dialect [dialect] -c [/path/to/config] -o [/path/to/models] -t [tableName]
Options:
    --help               Show help                                   [boolean]
    --version            Show version number                         [boolean]
-h, --host               IP/Hostname for the database.                [string]
-d, --database           Database name.                               [string]
-u, --user               Username for database.                       [string]
-x, --pass               Password for database. If specified without providing
                          a password, it will be requested interactively from
                          the terminal.
-p, --port               Port number for database (not for sqlite). Ex:
                          MySQL/MariaDB: 3306, Postgres: 5432, MSSQL: 1433
                                                                      [number]
-c, --config             Path to JSON file for Sequelize-Auto options and
                          Sequelize's constructor "options" flag object as
                          defined here:
                          https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-constructor
                                                                      [string]
-o, --output             What directory to place the models.          [string]
-e, --dialect            The dialect/engine that you're using: postgres,
                          mysql, sqlite, mssql                         [string]
-a, --additional         Path to JSON file containing model options (for all
                          tables). See the options: https://sequelize.org/api/v6/class/src/model.js~model#static-method-init
                                                                      [string]
    --indentation        Number of spaces to indent                   [number]
-t, --tables             Space-separated names of tables to import     [array]
-T, --skipTables         Space-separated names of tables to skip       [array]
--caseModel, --cm        Set case of model names: c|l|o|p|u
                          c = camelCase
                          l = lower_case
                          o = original (default)
                          p = PascalCase
                          u = UPPER_CASE
--caseProp, --cp         Set case of property names: c|l|o|p|u
--caseFile, --cf         Set case of file names: c|l|o|p|u|k
                          k = kebab-case
--noAlias                Avoid creating alias `as` property in relations
                                                                     [boolean]
--noInitModels           Prevent writing the init-models file        [boolean]
-n, --noWrite            Prevent writing the models to disk          [boolean]
-s, --schema             Database schema from which to retrieve tables[string]
-v, --views              Include database views in generated models  [boolean]
-l, --lang               Language for Model output: es5|es6|esm|ts
                          es5 = ES5 CJS modules (default)
                          es6 = ES6 CJS modules
                          esm = ES6 ESM modules
                          ts = TypeScript                             [string]
--useDefine              Use `sequelize.define` instead of `init` for es6|esm|ts
--singularize, --sg      Singularize model and file names from plural table
                          names                                      [boolean]

On Windows, provide the path to sequelize-auto: node_modules\.bin\sequelize-auto [args]

Example

sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -p 5432 -x my_password -e postgres

Produces a file/files such as ./models/User.js which looks like:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('User', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },
    username: {
      type: DataTypes.STRING(20),
      allowNull: true
    },
    aNumber: {
      type: DataTypes.SMALLINT,
      allowNull: true
    },
    dateAllowNullTrue: {
      type: DataTypes.DATE,
      allowNull: true
    },
    defaultValueBoolean: {
      type: DataTypes.BOOLEAN,
      allowNull: true,
      defaultValue: true
    }
  }, {
    tableName: 'User',
  });
};

Sequelize-auto also generates an initialization file, ./models/init-models.js, which contains the code to load each model definition into Sequelize:

var DataTypes = require("sequelize").DataTypes;
var _User = require("./User");
var _Product = require("./Product");

function initModels(sequelize) {
  var User = _User(sequelize, DataTypes);
  var Product = _Product(sequelize, DataTypes);

  return {
    User,
    Product,
  };
}
module.exports = { initModels };

This makes it easy to import all your models into Sequelize by calling initModels(sequelize).

var initModels = require("./models/init-models");
...
var models = initModels(sequelize);

models.User.findAll({ where: { username: "tony" }}).then(...);

Alternatively, you can Sequelize.import each model (for Sequelize versions < 6), or require each file and call the returned function:

var User = require('path/to/user')(sequelize, DataTypes);

ES6

You can use the -l es6 option to create the model definition files as ES6 classes, or -l esm option to create ES6 modules. Then you would require or import the classes and call the init(sequelize, DataTypes) method on each class.

TypeScript

Add -l ts to cli options or lang: 'ts' to programmatic options. This will generate a TypeScript class in each model file, and an init-model.ts file to import and initialize all the classes.

Note that you need TypeScript 4.x to compile the generated files.

The TypeScript model classes are created as described in the Sequelize manual

Example model class, order.ts:

import Sequelize, { DataTypes, Model, Optional } from 'sequelize';
import type { Customer, CustomerId } from './customer';
import type { OrderItem, OrderItemId } from './order_item';

export interface OrderAttributes {
  id: number;
  orderDate: Date;
  orderNumber?: string;
  customerId: number;
  totalAmount?: number;
  status: 'PROCESSING' | 'SHIPPED' | 'UNKNOWN';
}

export type OrderPk = "id";
export type OrderId = Order[OrderPk];
export type OrderCreationAttributes = Optional<OrderAttributes, OrderPk>;

export class Order extends Model<OrderAttributes, OrderCreationAttributes> implements OrderAttributes {
  id!: number;
  orderDate!: Date;
  orderNumber?: string;
  customerId!: number;
  totalAmount?: number;
  status!: 'PROCESSING' | 'SHIPPED' | 'UNKNOWN';

  // Order belongsTo Customer via customerId
  customer!: Customer;
  getCustomer!: Sequelize.BelongsToGetAssociationMixin<Customer>;
  setCustomer!: Sequelize.BelongsToSetAssociationMixin<Customer, CustomerId>;
  createCustomer!: Sequelize.BelongsToCreateAssociationMixin<Customer>;
  // Order hasMany OrderItem via orderId
  orderItems!: OrderItem[];
  getOrderItems!: Sequelize.HasManyGetAssociationsMixin<OrderItem>;
  setOrderItems!: Sequelize.HasManySetAssociationsMixin<OrderItem, OrderItemId>;
  addOrderItem!: Sequelize.HasManyAddAssociationMixin<OrderItem, OrderItemId>;
  addOrderItems!: Sequelize.HasManyAddAssociationsMixin<OrderItem, OrderItemId>;
  createOrderItem!: Sequelize.HasManyCreateAssociationMixin<OrderItem>;
  removeOrderItem!: Sequelize.HasManyRemoveAssociationMixin<OrderItem, OrderItemId>;
  removeOrderItems!: Sequelize.HasManyRemoveAssociationsMixin<OrderItem, OrderItemId>;
  hasOrderItem!: Sequelize.HasManyHasAssociationMixin<OrderItem, OrderItemId>;
  hasOrderItems!: Sequelize.HasManyHasAssociationsMixin<OrderItem, OrderItemId>;
  countOrderItems!: Sequelize.HasManyCountAssociationsMixin;

  static initModel(sequelize: Sequelize.Sequelize): typeof Order {
    Order.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    orderDate: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
      field: 'OrderDate'
    },
    orderNumber: {
      type: DataTypes.STRING(10),
      allowNull: true,
      field: 'OrderNumber'
    },
    customerId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'customer',
        key: 'Id'
      },
      field: 'CustomerId'
    },
    totalAmount: {
      type: DataTypes.DECIMAL(12,2),
      allowNull: true,
      defaultValue: 0.00,
      field: 'TotalAmount'
    },
    status: {
      type: DataTypes.ENUM('PROCESSING','SHIPPED','UNKNOWN'),
      allowNull: false,
      defaultValue: "UNKNOWN",
      field: 'Status'
    }
  }, {
    sequelize,
    tableName: 'order',
    timestamps: false,
  });
  return Order;
  }
}

Example init-models.ts:

import { Sequelize } from "sequelize";
import { Customer, CustomerAttributes, CustomerCreationAttributes } from "./customer";
import { Order, OrderAttributes, OrderCreationAttributes } from "./order";
import { OrderItem, OrderItemAttributes, OrderItemCreationAttributes } from "./order_item";
import { Product, ProductAttributes, ProductCreationAttributes } from "./product";
import { Supplier, SupplierAttributes, SupplierCreationAttributes } from "./supplier";

export {
  Customer, CustomerAttributes, CustomerCreationAttributes,
  Order, OrderAttributes, OrderCreationAttributes,
  OrderItem, OrderItemAttributes, OrderItemCreationAttributes,
  Product, ProductAttributes, ProductCreationAttributes,
  Supplier, SupplierAttributes, SupplierCreationAttributes,
};

export function initModels(sequelize: Sequelize) {
  Customer.initModel(sequelize);
  Order.initModel(sequelize);
  OrderItem.initModel(sequelize);
  Product.initModel(sequelize);
  Supplier.initModel(sequelize);

  Order.belongsTo(Customer, { as: "customer", foreignKey: "customerId"});
  Customer.hasMany(Order, { as: "orders", foreignKey: "customerId"});
  OrderItem.belongsTo(Order, { as: "order", foreignKey: "orderId"});
  Order.hasMany(OrderItem, { as: "orderItems", foreignKey: "orderId"});
  OrderItem.belongsTo(Product, { as: "product", foreignKey: "productId"});
  Product.hasMany(OrderItem, { as: "orderItems", foreignKey: "productId"});
  Product.belongsTo(Supplier, { as: "supplier", foreignKey: "supplierId"});
  Supplier.hasMany(Product, { as: "products", foreignKey: "supplierId"});

  return {
    Customer: Customer,
    OrderItem: OrderItem,
    Order: Order,
    Product: Product,
    Supplier: Supplier,
  };
}

Model usage in a TypeScript program:

// Order is the sequelize Model class
// OrderAttributes is the interface defining the fields
// OrderCreationAttributes is the interface defining the fields when creating a new record
import { initModels, Order, OrderCreationAttributes } from "./models/init-models";

// import models into sequelize instance
initModels(this.sequelize);

const myOrders = await Order.findAll({ where: { "customerId": cust.id }, include: ['customer'] });

const attr: OrderCreationAttributes = {
  customerId: cust.id,
  orderDate: new Date(),
  orderNumber: "ORD123",
  totalAmount: 223.45
};
const newOrder = await Order.create(attr);

Configuration options

For the -c, --config option, various JSON/configuration parameters are defined by Sequelize's options flag within the constructor. See the Sequelize docs for more info.

Programmatic API

const SequelizeAuto = require('sequelize-auto');
const auto = new SequelizeAuto('database', 'user', 'pass');

auto.run().then(data => {
  console.log(data.tables);      // table and field list
  console.log(data.foreignKeys); // table foreign key list
  console.log(data.indexes);     // table indexes
  console.log(data.hasTriggerTables); // tables that have triggers
  console.log(data.relations);   // relationships between models
  console.log(data.text)         // text of generated models
});

With options:

const auto = new SequelizeAuto('database', 'user', 'pass', {
    host: 'localhost',
    dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql',
    directory: './models', // where to write files
    port: 'port',
    caseModel: 'c', // convert snake_case column names to camelCase field names: user_id -> userId
    caseFile: 'c', // file names created for each model use camelCase.js not snake_case.js
    singularize: true, // convert plural table names to singular model names
    additional: {
        timestamps: false
        // ...options added to each model
    },
    tables: ['table1', 'table2', 'myschema.table3'] // use all tables, if omitted
    //...
})

Or you can create the sequelize instance first, using a connection string, and then pass it to SequelizeAuto:

const SequelizeAuto = require('sequelize-auto');
const Sequelize = require('sequelize');

// const sequelize = new Sequelize('sqlite::memory:');
const sequelize = new Sequelize('postgres://user:[email protected]:5432/dbname');
const options = { caseFile: 'l', caseModel: 'p', caseProp: 'c' };

const auto = new SequelizeAuto(sequelize, null, null, options);
auto.run();

Resources

Testing

To set up:

  1. Create an empty database called sequelize_auto_test on your database server (sqlite excepted)

  2. Create a .env file from sample.env and set your username/password/port etc. The env is read by test/config.js

  3. Build the TypeScript from the src directory into the lib directory:

    npm run build

Then run one of the test commands below:

# mysql only
npm run test-mysql

# postgres only
npm run test-postgres

# mssql  only
npm run test-mssql

# sqlite only
npm run test-sqlite

Also see the sample directory which has an example including database scripts, export script, and a sample app.

sequelize-auto's People

Contributors

cedrouck avatar dbpolito avatar demus avatar dpomerantz-jci avatar durango avatar erickfmm avatar greenkeeper[bot] avatar gsdnano avatar honzajerabek avatar ihorskyi avatar isac322 avatar jaredbrookswhite avatar jiaxingzheng avatar joaoe avatar jonathanwolfe avatar karpikpl avatar locene avatar mat813 avatar radiergummi avatar rainabba avatar ray0427 avatar retfah avatar sdepold avatar simov avatar sjfkai avatar sseewald avatar steveschmitt avatar strumwolf avatar zhfish avatar zypa13510 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sequelize-auto's Issues

error _.contains is not a function in Postgres

Hello I have Postgres db.
When I write command
sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -p 5432 -x my_password -e postgres
with my params I have this error in console:

Unhandled rejection TypeError: _.contains is not a function
    at Object.exports.postgres.isSerialKey (/usr/local/lib/node_modules/sequelize-auto/lib/dialects/index.js:130:14)
    at /usr/local/lib/node_modules/sequelize-auto/lib/index.js:124:110
    at arrayEach (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/lodash/lodash.js:473:11)
    at Function.forEach (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/lodash/lodash.js:7607:11)
    at /usr/local/lib/node_modules/sequelize-auto/lib/index.js:123:11
    at arrayEach (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/lodash/lodash.js:473:11)
    at Function.forEach (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/lodash/lodash.js:7607:11)
    at /usr/local/lib/node_modules/sequelize-auto/lib/index.js:103:9
    at /usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:181:20
    at Object.async.forEachOf.async.eachOf (/usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:233:13)
    at Object.async.forEach.async.each (/usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:209:22)
    at generateText (/usr/local/lib/node_modules/sequelize-auto/lib/index.js:91:11)
    at /usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:52:16
    at done (/usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:246:17)
    at /usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:44:16
    at /usr/local/lib/node_modules/sequelize-auto/lib/index.js:83:7

table names need adding to models

The models generated ok but half the table names were wrong as sequelize-restful does some weird pluralisation on the table names that you can't turn off, meaning that you have to add a declaration

{
    tableName:'<actual-table-name-rather-than-pluralised-version>'
}

to most if not all models if you don't use the same pluralisation convention. This is as much a fault with sequelize-restful as it is with the generator but the models could be more strictly generated to match the schema.

Reference different schemas under the same database?

How can I build models from different schemas inside the same database?

I have a database called 'transform' and under that database I have a schema called 'public' and another called 'schema2'. This module seems to select which ever is designated as the default schema, which is 'public' in my case. How can select 'schema2'?

interacting with the heroku

Hi,

Trying to generate the models from the Heroku db, received the next error:

ERR: error: no pg_hba.conf entry for host "IP", user "user", database "database", SSL off

As I understand the case is in the SSL. Do we have any method to overcome this?

Regards,

id autoIncrement is not set while generating models from mysql db

I have a mysql db, and generate the models like so:

$ sequelize-auto -o "./models" -d MY_DATABASE -h localhost -u USERNAME -p 3306 -x USERPASSWORD -e mysql

For the id table fields, which are set to AUTOINCREMENT in the mysql database, the sequelize-auto does not provide the autoincrement descriptor, and subsequently the insert operation generates SequelizeValidationError.

If I add autoincrement by hand, however, like so:

id: {
      type: DataTypes.INTEGER(10),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },

Everything works.

Options for config.json

i think there should be an explanation on what can be set in the configuration file, or atleast how it is structured

Auto increment missing in postgreSQL?

I have a table:

CREATE TABLE "user"
(
  user_id serial NOT NULL,
  CONSTRAINT pk_user PRIMARY KEY (user_id)
)

And a result is:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('user', {
    user_id: {
      type: DataTypes.INTEGER,
      primaryKey: true
    }
  }, {
    tableName: 'user',
    freezeTableName: true,
    timestamps: false,
  });
};

However I expected to see "autoIncrement: true" for the "user_id" column.

I'm new to postgreSQL db, but I believe auto increment should be there.

Associations of Model

Does it generate associations of all foreign / primary keys as well from the tables definition?

Postgres - default TIMESTAMP value causing error

Steps to reproduce:
Table

CREATE TABLE test
(
    id          SERIAL        NOT NULL,
    sometime    TIMESTAMP     WITH TIME ZONE NOT NULL DEFAULT NOW(),

    CONSTRAINT  test_pk       PRIMARY KEY (id)
);

info.json

{
  "timestamps"      : false,
  "underscored"     : true,
  "freezeTableName" : true
}

Run

$ sequelize-auto -a info.json -d db_name -h localhost -u postgres -p 5432 -x postgres -e postgres 

Generated model

/* jshint indent: 2 */

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('test', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },
    sometime: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: 'now()'             // <--- this 'now()' causes error
    }
  }, {
    tableName: 'test',
    timestamps: false,
    underscored: true,
    freezeTableName: true
  });
};

Main point of test code is to create entity with default value for timestamp:

const Sequelize = require('sequelize')
const sequelize = new Sequelize('db_name', 'postgres', 'postgres', { dialect:'postgres' })
const TestModel = sequelize.import(__dirname + '/sequelize-models/test')

TestModel.create()
  .then (showResult)
  .catch(onError)

function showResult(result) { console.log(result) }
function onError   (err)    { console.error(err)  }

Error is

 { [error: invalid input syntax for type timestamp with time zone: "Invalid date"]
   ... 
   sql: 'INSERT INTO "test" ("id","sometime") VALUES (DEFAULT,\'Invalid date\') RETURNING *;' },

Temporary fix in my case is to change

      defaultValue: 'now()' 
      to
      defaultValue: new Date()

But that is really temporary as on production server timezone will be different, thus default value should be taken from server. So generated query should be:

INSERT INTO "test" ("id","sometime") VALUES (DEFAULT, NOW()) RETURNING *;
OR
INSERT INTO "test" ("id","sometime") VALUES (DEFAULT, DEFAULT) RETURNING *;
OR
INSERT INTO "test" ("id") VALUES (DEFAULT) RETURNING *;
etc..

Auto generate primaryKey and autoIncrement

Dear All,

I have used sequelize-auto to auto generate data model with DB MySQL. And the lib generate well.
But It is not auto generate primaryKey and autoIncrement for primary key field in DB.
Could anyone help me config to auto gen these field.

Thanks so much.

Doesn't work with belongsTo when non-standard foreign keys are present

If I have a DB with a table accounts but in another section, a badly-named foreign key userid tracking back to it, the generator does account for this when making the column reference in the define statement, but if I manually add belongsTo, it does not do this and instead looks for accountId.

Is this something I'm supposed to handle or can the generator do that for me?
Might be similar to #34

Support to generate the associate fn when generating models in MSSQL?

I'm curious if there's already functionality, on generation, to automatically include any hasMany, hasOne associations in the defines. If there is, it's not working in MSSQL.

If there isn't, it'd be nice to have since, every time I regenerate the models, I have to put back in the associate manually and it's getting tedious.

Also, as of the current version, what's the way to at least define that logic elsewhere and have it included in generation? The docs make reference of it, but I can't figure out the structure for defining it for multiple models. I can't do it in json because functions aren't valid in .json file format.

For instance, I have these two models that I'm putting the associate fn in manually:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('UseCase', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    ResourcesID: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'Resource',
        key: 'id'
      }
    },
    Description: {
      type: DataTypes.STRING,
      allowNull: false
    },
    LastTested: {
      type: DataTypes.DATE,
      allowNull: true
    },
    IsSuccess: {
      type: 'BIT',
      allowNull: true
    }
  }, {
    tableName: 'UseCase',
    freezeTableName: true,
    classMethods: {
      associate: function(models) {
        this.hasMany(models.Param);
      }
    }
  });
};
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('Param', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    UseCasesID: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'UseCase',
        key: 'id'
      }
    },
    Name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    Value: {
      type: DataTypes.TEXT,
      allowNull: false
    },
    LastTested: {
      type: DataTypes.DATE,
      allowNull: true
    },
    IsSuccess: {
      type: 'BIT',
      allowNull: true
    }
  }, {
    tableName: 'Param',
    freezeTableName: true,
    classMethods: {
      associate: function(models) {
        this.hasMany(models.Content);
      }
    }
  });
};

I assume the include file would be something like:

module.exports = {
  'UseCase': {classMethods: {
    associate: function(models){
      this.hasMany(models.Param);
    }
  }},
  'Param': {classMethods: {
    associate: function(models){
      this.hasMany(models.Content);
    }
  }}
}

Is that how you structure it so that it'll be included in the generation? A concrete example would help in this situation.

Documentation needs a better tutorial for newbies

Hi, I am new to sequelize and sequelize-auto and I was wondering if some questions could be answered and put in the readme.

I used the programmatic API in order to call sequelize-auto and it generates the models properly.
I was wondering since sequelize-auto requires sequelize and uses the connection info in order to generate the models, is there an instance of sequelize somewhere inside my new SequelizeAuto() once run has been called? If so, where is it? And did it import the models?

In the programmatic API section of the README, I've modified like so:

var SequelizeAuto = require('sequelize-auto')
var auto = new SequelizeAuto('database', 'user', 'pass');

auto.run(function (err) {
if (err) throw err;

console.log(auto.tables); // table list
console.log(auto.foreignKeys); // foreign key list

// Sequelize API call...
auto.tables["User"].findAll({attributes: ["id", "name"]});
};

Which is not working since tables is only an array describing the model.
Do I need to import the models manually using sequelize?

Missing autoIncrement property in MSSQL

Looks like for MSSQL, the generators aren't adding the autoIncrement property to identity columns. Only discovered this because POSTs will throw a NULL exception if it's not there.

Here's the SQL create since my sql writting skills are a bit rusty:

USE [Test]
GO

/****** Object:  Table [dbo].[Content]    Script Date: 3/29/2016 12:20:17 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Content](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Contents] [text] NOT NULL,
 CONSTRAINT [PK_Contents] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

Definition

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('Content', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    Contents: {
      type: DataTypes.TEXT,
      allowNull: false
    }
  }, {
    tableName: 'Content',
    freezeTableName: true
  });
};

primary composite keys with foreign keys

using mysql.
3 composite key fields
2 of those fields have foreign keys.

the primaryKey attribute is not generated.
Traced the issue to this commit: 54d3753

removing the change fixed my issue, but I'm sure the commit was needed, -- how can I help?

cannot connect with user credentials

just used this components with the credentials i use normally, but returns an error

sequelize-auto -h 127.0.0.1 -d fettle -u root -x 1324 -e mysql -o "./modelss"

{ [SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)]
  name: 'SequelizeAccessDeniedError',
  message: 'ER_ACCESS_DENIED_ERROR: Access denied for user \'root\'@\'localhost\' (using password: YES)',
  parent:
   { [Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)]
     code: 'ER_ACCESS_DENIED_ERROR',
     errno: 1045,
     sqlState: '28000',
     fatal: true },
  original:
   { [Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)]
     code: 'ER_ACCESS_DENIED_ERROR',
     errno: 1045,
     sqlState: '28000',
     fatal: true } }

Example command

Into the example add "node" at the begging of the command (before sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -p 5432 -x my_password -e postgres)

Missing foreign key

Hi,
I'm using sequelize-auto to auto generate data model with DB MySQL. Everything seems go well but foreignKey aren't auto generate in models.

Does -c option works well

Hello guys,

I'm just curious how can I set default options for every model object e.g.

{
"timestamps" : false,
"freezeTableName": true
}

I tried this as config file, but it doesn't include this information in model files

Thanks in advance

Allow customizable model template instead of hardcoded one

Customizable template (EJS/Nunjucks) instead of hardcoded one would be great.

I've recently run across the issue that sequelize-auto defines the models with sequelize.define. This essentially makes the models non-extendable, while extending auto-generated ORM models is something that goes without saying.

This could solve several other issues, for example #19.

Error: The dialect mssql is not supported.

When I run the following command

sequelize-auto -h [server] -d [db name] -u [username] -x [pwd]   -e mssql -o './models'

I get the following error:
/Users/this-guy/.nvm/versions/io.js/v2.0.1/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/sequelize.js:125
throw new Error("The dialect " + this.getDialect() + " is not supported.
^
Error: The dialect mssql is not supported.

I'm trying to connect to a azure db if that makes a difference.

UUID primary key for MSSQL

After importing some MS SQL (2008R2) table i have following field definition in my model:

ID: {
     type: 'UNIQUEIDENTIFIER',
     allowNull: false,
     defaultValue: '(newid())',
     primaryKey: true
 }, 

Actually, IMHO, it should be like this:

ID: {
     type: DataTypes.UUIDV4,
     allowNull: false,
     primaryKey: true
 }, 

P.S. .UUIDV4 makes this field as uuid-type and auto-generate new value for it

MSSQL id isn't getting set with the primaryKey property in generation

I have the following table in mssql:

CREATE TABLE [Test].[dbo].[Domains](
    [id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Name] [varchar](50) NOT NULL,
    [LastTested] [datetime] NULL
);

But when I generate the model, the model's coming out as:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('Domains', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    Name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    LastTested: {
      type: DataTypes.DATE,
      allowNull: true
    }
  }, {
    tableName: 'Domains',
    freezeTableName: true
  });
};

Shouldn't it get generated with the primaryKey property on id?

Does not set primary key if column isn't `id`

One of my database tables had a primary key column which was the name of another table's id like so:

playthrough.id == scores.playthroughid where scores has a primary key of playthroughid. For whatever reason, this wasn't picked up by sequelize-auto, and I had to manually add primaryKey: true for it to work when I setup my associations.

Mention something about installing the dialect module globally in the docs ?

I tried using the tool as explained in the README file.

I installed the sequelize-auto module globally and then kept hitting:

You need to install mysql package manually

/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:306
    var connection = mysql.createConnection(connectionConfig);
                           ^
TypeError: Cannot call method 'createConnection' of undefined
    at module.exports.connect (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:306:28)
    at Object.pool.Pooling.Pool.create (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:131:19)
    at createResource (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:258:13)
    at dispense (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:250:9)
    at Object.me.acquire (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:316:5)
    at null.fct (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:241:19)
    at null.<anonymous> (/home/cristi/.nvm/v0.10.33/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
    at processImmediate [as _immediateCallback] (timers.js:345:15)

The issue was that I did not have mysql installed globally (npm install -g mysql). Maybe you could update the README file with a small note on this? Otherwise, at least someone having the same issue might have the fix here.

Not much of a big deal, so feel free to ignore.

Support for Azure SQL Database?

I am executing the following command, but it fails to produce any models. The database is an Azure SQL Database:

  sequelize-auto -o "./models" -h <myserver> -p 1433 -d <mydatabase> -u <myuser> -x <mypasswd> --dialect mssql -c "./config/auto.json"

My config json looks like this:

{
    "dialectOptions": {
            "encrypt": true
        }
}

And this is the output (note the timeout errors):

Executing (default): SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES;
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'County'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Event'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Product'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'District'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'database_firewall_rules'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Address'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'CommodityBalance'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DistributorProduct'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DistrictProduct'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DistrictDistributor'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DistrictManufacturer'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'sysdiagrams'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DistrictDetailsView'
{ [SequelizeDatabaseError: Timeout: Request failed to complete in 15000ms]
  name: 'SequelizeDatabaseError',
  message: 'Timeout: Request failed to complete in 15000ms',
  parent:
   { [RequestError: Timeout: Request failed to complete in 15000ms]
     message: 'Timeout: Request failed to complete in 15000ms',
     code: 'ETIMEOUT',
     sql: 'SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = \'DistrictDistributor\'' },
  original:
   { [RequestError: Timeout: Request failed to complete in 15000ms]
     message: 'Timeout: Request failed to complete in 15000ms',
     code: 'ETIMEOUT',
     sql: 'SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = \'DistrictDistributor\'' },
  sql: 'SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = \'DistrictDistributor\'' }
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'DirectorDetailView'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Coop'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'RA_Lookup'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Director'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'AllSales'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'AccountManager'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Manufacturer'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'ProductUsage'
Executing (default): SELECT         ccu.table_name AS source_table         ,ccu.constraint_name AS constraint_name         ,ccu.column_name AS source_column         ,kcu.table_name AS target_table         ,kcu.column_name AS target_column       FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu       INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc           ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME       INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu            ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME           WHERE ccu.table_name = 'Distributor'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'County'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Event'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Product'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'District'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'database_firewall_rules'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Address'
{ [SequelizeDatabaseError: Timeout: Request failed to complete in 15000ms]
  name: 'SequelizeDatabaseError',
  message: 'Timeout: Request failed to complete in 15000ms',
  parent:
   { [RequestError: Timeout: Request failed to complete in 15000ms]
     message: 'Timeout: Request failed to complete in 15000ms',
     code: 'ETIMEOUT',
     sql: 'SELECT c.COLUMN_NAME AS \'Name\', c.DATA_TYPE AS \'Type\', c.IS_NULLABLE as \'IsNull\', COLUMN_DEFAULT AS \'Default\', tc.CONSTRAINT_TYPE AS \'Constraint\' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = \'PRIMARY KEY\' WHERE t.TABLE_NAME = \'Event\'' },
  original:
   { [RequestError: Timeout: Request failed to complete in 15000ms]
     message: 'Timeout: Request failed to complete in 15000ms',
     code: 'ETIMEOUT',
     sql: 'SELECT c.COLUMN_NAME AS \'Name\', c.DATA_TYPE AS \'Type\', c.IS_NULLABLE as \'IsNull\', COLUMN_DEFAULT AS \'Default\', tc.CONSTRAINT_TYPE AS \'Constraint\' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = \'PRIMARY KEY\' WHERE t.TABLE_NAME = \'Event\'' },
  sql: 'SELECT c.COLUMN_NAME AS \'Name\', c.DATA_TYPE AS \'Type\', c.IS_NULLABLE as \'IsNull\', COLUMN_DEFAULT AS \'Default\', tc.CONSTRAINT_TYPE AS \'Constraint\' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = \'PRIMARY KEY\' WHERE t.TABLE_NAME = \'Event\'' }
Done!
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'CommodityBalance'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DistributorProduct'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DistrictProduct'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DistrictDistributor'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DistrictManufacturer'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'sysdiagrams'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DistrictDetailsView'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'DirectorDetailView'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Coop'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'RA_Lookup'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Director'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'AllSales'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'AccountManager'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Manufacturer'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'ProductUsage'
Executing (default): SELECT c.COLUMN_NAME AS 'Name', c.DATA_TYPE AS 'Type', c.IS_NULLABLE as 'IsNull', COLUMN_DEFAULT AS 'Default', tc.CONSTRAINT_TYPE AS 'Constraint' FROM INFORMATION_SCHEMA.TABLES t INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = c.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND t.TABLE_SCHEMA = cu.TABLE_SCHEMA LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' WHERE t.TABLE_NAME = 'Distributor'

Am I doing something wrong???

Char datatype not being used

Thanks for the great tool ๐Ÿ‘ made my day!

On a mysql DB - CHAR(XX) are not being transformed as DATATYPE.CHAR(XX) but as CHAR(XX)

This is causing sequelize-graphql issues when importing the models.

I added this line on index.js +217

else if (_attr.match(/^char/)) {
              var length = _attr.match(/\(\d+\)/);
              val = 'DataTypes.CHAR' + (!  _.isNull(length) ? length : '');
            }

And works as (I) expected.

Is this a real issue or a lack of deep understanding on my part?

Thanks

PK with autoincrement is set to false in "allowNull"

Sequelize doesn't let me create new records without setting the id in this case, which is an PK and autoIncrement column in database, this is by logic setting null to false, so sequelize must detect if autoIncrement is set so it could ignore this whenever i create a new record

Better documentation for config

There should be somewhere that explains how to use the config, also in this config, it would be a good idea to define which column are defined with default values

Unhandled rejection TypeError: undefined is not a function : lib\index.js:100:59 mssql dialect

Received this error when attempting to run against 'mssql' dialect (see hack in #12)

Unhandled rejection TypeError: undefined is not a function
    at .....\node_modules\sequelize-auto\lib\index.js:100:59
    at Array.forEach (native)
    at .....\node_modules\sequelize-auto\lib\index.js:77:25
    at Array.forEach (native)
    at .....\node_modules\sequelize-auto\lib\index.js:63:18
    at .....\node_modules\sequelize-auto\node_modules\async\lib\async.js:187:20
    at .....\node_modules\sequelize-auto\node_modules\async\lib\async.js:239:13
    at _arrayEach (.....\node_modules\sequelize-auto\node_modules\async\lib\async.js:91:13)
    at _each (.....\node_modules\sequelize-auto\node_modules\async\lib\async.js:82:13)

    at Object.async.forEachOf.async.eachOf (.....\node_modules\sequelize-auto\node_modules\async\lib\async.js:238:9)
    at Object.async.forEach.async.each (.....\node_modules\sequelize-auto\node_modules\async\lib\async.js:215:22)
    at .....\node_modules\sequelize-auto\lib\index.js:51:15
    at .....\node_modules\sequelize-auto\node_modules\async\lib\async.js:52:16
    at done (.....\node_modules\sequelize-auto\node_modules\async\lib\async.js:248:21)

    at .....\node_modules\sequelize-auto\node_modules\async\lib\async.js:44:16
    at .....\node_modules\sequelize-auto\lib\index.js:47:13

References for id generated with nulled model & key if key is VARCHAR (PostgreSQL)

PostgreSQL: 9.2
sequelize-auto: 0.2.7

SQL to reproduce:

CREATE TABLE article
(
    id          VARCHAR(32)       NOT NULL, -- <-- IF id is SERIAL then everything is fine here
    content     TEXT              NOT NULL,

    CONSTRAINT  article_pk        PRIMARY KEY (id)
);

CREATE TABLE main
(
    id          SERIAL            NOT NULL,
    article_id  VARCHAR(32)       NOT NULL,

    CONSTRAINT  main_pk           PRIMARY KEY (id),
    CONSTRAINT  main_article_fk   FOREIGN KEY (article_id)  REFERENCES article (id)
);

RESULT:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('article', {
    id: {
      type: DataTypes.STRING,
      allowNull: false,
      primaryKey: true,
      references: {
        model: 'null',   // WUT?
        key: 'null'      // 4kWUT?
      }
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: false
    }
  }, {
    tableName: 'article',
    freezeTableName: true
  });
};

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('main', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },
    article_id: {
      type: DataTypes.STRING,
      allowNull: false,
      primaryKey: true,
      references: {
        model: 'article',
        key: 'id'
      }
    }
  }, {
    tableName: 'main',
    freezeTableName: true
  });
};

Generate a single model

Add a function to generate a single model for a specific table instead of all models from the whole database

Generate models with 'timestamps: false"

Here I am working with a database that is already in production and I cant afford to implement the sequelize timestamps (createdat and deletedat).

I would really like to see a option that gets a more raw data from the database, like a --notimestamps.

Update:
Actually I tried to use the -a flag with the json described bellow, and no luck.

{
  "timestamps": false
}

Columns for foreign key are tagged as primary key

Hi.. I used your great module and I noticed that columns which are part of foreign key are tagged as "primary key", but they should be tagged as "references: {model: 'ModelName', key: 'keyName'}. I'm using PostgreSQL database and inside this database, these columns are part of foreign key.

It will be great to correct that issue if possible.

Thank you very much

"," present when allowNull is the last option

When i generate my models and that allowNull is the last option, there is a "," before the end of the JSON :

    cmd_value: {
  type: 'DOUBLE(14,4)',
  allowNull: false,
  defaultValue: '0.0000' //options generated perfectly
},
cmd_id: {
  type: DataTypes.BIGINT,
  allowNull: false, // , has nothing to do here ...
}

Thanks for this answone lib !

mssql -Unhandled rejection TypeError: undefined is not a function at Object.module.exports.removeTicks

โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

I am hitting this issue with the environment above when tried to retrieve mssql model

Executing (default): SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES;
Unhandled rejection TypeError: undefined is not a function
at Object.module.exports.removeTicks (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/utils.js:376:14)
at Object.module.exports.addTicks (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/utils.js:372:29)
at Object.exports.mssql.getForeignKeysQuery (/usr/local/lib/node_modules/sequelize-auto/lib/dialects/index.js:155:54)
at mapForeignKeys (/usr/local/lib/node_modules/sequelize-auto/lib/index.js:44:23)
at /usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:181:20
at Object.async.forEachOf.async.eachOf (/usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:233:13)
at Object.async.forEach.async.each (/usr/local/lib/node_modules/sequelize-auto/node_modules/async/lib/async.js:209:22)
at /usr/local/lib/node_modules/sequelize-auto/lib/index.js:38:11
at tryCatcher (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/util.js:11:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:491:31)
at Promise._settlePromise (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:548:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:593:10)
at Promise._settlePromises (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:676:18)
at Async._drainQueue (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/async.js:125:16)
at Async._drainQueues (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/bluebird/js/release/async.js:135:10)
at Immediate.Async.drainQueues as _onImmediate

Anyone having similar issue?

Cannot call method 'createConnection' of undefined

When running against a wordpress mysql db, its throwing an error back at me.

var connection = mysql.createConnection(connectionConfig);
                           ^
TypeError: Cannot call method 'createConnection' of undefined
    at module.exports.connect (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:306:28)
    at Object.pool.Pooling.Pool.create (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:131:19)
    at createResource (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:258:13)
    at dispense (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:250:9)
    at Object.me.acquire (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:316:5)
    at null.fct (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:241:19)
    at null.<anonymous> (/usr/local/lib/node_modules/sequelize-auto/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
    at processImmediate [as _immediateCallback] (timers.js:354:15

Feature: autoloading the database credentials

I think it would be a neat idea to keep below command line even simpler, by autoloading the database configuration, but still being able to enter the credentials manually if you want to:

sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -p 5432 -x my_password -e postgres

I mean like doctrine:

php vendor/bin/doctrine orm:schema-tool:create

As you can see you don't have to enter the database credentials, cause they're already specified inside the project. Doctrine uses the config/cli-config.php file for this:

<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;

// replace with file to your own project bootstrap
require_once 'app/bootstrap.php';

return ConsoleRunner::createHelperSet($entityManager);
?>

The above $entityManager contains the database connection singleton.

Maybe an idea for the sequelize-auto? So it uses the credentials of the current environment by default. Well actually above samples of Doctrine are for creating tables from your models, and not the opposite, but I just want to clarify my idea of autoloading the database configuration.

Cannot read property 'TABLE_SCHEMA' of undefined

My globally installed packages are:

[email protected]
[email protected]
[email protected]
[email protected]

and I am trying to run:

c:\>sequelize-auto -d toto -h localhost -u sa -p 1433 -x supersecret -e mssql -o "./models"

which gives me:

Unhandled rejection TypeError: Cannot read property 'TABLE_SCHEMA' of undefined.

I can successfully run my select:
SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES;
on my SQL SERVER 2014 (not sqlexpress)

I can successfully run raw select via given connection params in my app

Here is fullstack of error

Unhandled rejection TypeError: Cannot read property 'TABLE_SCHEMA' of undefined at C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\sequelize-auto\li b\index.js:43:34 at C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\sequelize-auto\no de_modules\async\lib\async.js:187:20 at C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\sequelize-auto\no de_modules\async\lib\async.js:239:13 at _arrayEach (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\seque lize-auto\node_modules\async\lib\async.js:91:13) at _each (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\sequelize- auto\node_modules\async\lib\async.js:82:13) at Object.async.forEachOf.async.eachOf (C:\Users\murat.oguzalp\AppData\Roami ng\npm\node_modules\sequelize-auto\node_modules\async\lib\async.js:238:9) at Object.async.forEach.async.each (C:\Users\murat.oguzalp\AppData\Roaming\n pm\node_modules\sequelize-auto\node_modules\async\lib\async.js:215:22) at C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\sequelize-auto\li b\index.js:33:13 at tryCatcher (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modules\seque lize-auto\node_modules\bluebird\js\main\util.js:26:23) at Promise._settlePromiseFromHandler (C:\Users\murat.oguzalp\AppData\Roaming \npm\node_modules\sequelize-auto\node_modules\bluebird\js\main\promise.js:507:31 ) at Promise._settlePromiseAt (C:\Users\murat.oguzalp\AppData\Roaming\npm\node _modules\sequelize-auto\node_modules\bluebird\js\main\promise.js:581:18) at Promise._settlePromises (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_ modules\sequelize-auto\node_modules\bluebird\js\main\promise.js:697:14) at Async._drainQueue (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_module s\sequelize-auto\node_modules\bluebird\js\main\async.js:123:16) at Async._drainQueues (C:\Users\murat.oguzalp\AppData\Roaming\npm\node_modul es\sequelize-auto\node_modules\bluebird\js\main\async.js:133:10) at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\murat.oguzalp\App Data\Roaming\npm\node_modules\sequelize-auto\node_modules\bluebird\js\main\async .js:15:14) at processImmediate [as _immediateCallback] (timers.js:374:17)

Auto generate models from views

It would be really nice if views would also generate models
In my case a postgresql materialized view.
Or did I miss how to do that?

Aliases for table names for use as model names

It would be cool to have ability to define alias for table name to use as model name in import (-t CLI option).

For ex: sequelize-auto .... -t "tbl_Task as Task, tbl_Contact as Contact".

In generated models, aliases should become model's names and original table names should go to TableName property of model.

P.S. Auto generating models for Sequelize mean that you dealing with some legacy database (or 3d party database), so you have no control about table names. But working with nice model names in code will make whole work nicer.

Bug: Foreign key detection not working for sqlite

๐Ÿ‘‹ I'm trying to generate the same models for different dialects:

screenshot from 2016-01-02 19 32 52

And it turns out that sequelize-auto doesn't expect the correct data structure returned after executing PRAGMA foreign_key_list(table);:

screenshot from 2016-01-02 19 37 08

Hence the above code fails always, I guess that's why I'm not getting the references key in the model?

Let me know if I need to supply more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.