<commit_before>var Sequelize = require('sequelize');

/* CONNECTION */

var dbURL = process.env.DATABASE_URL;

if (dbURL) {
  var orm = new Sequelize(dbURL);
} else {
  var orm = new Sequelize('kim', 'root', '', {
    host: 'localhost',
    dialect: 'mysql',
    logging: false
  });
}


/* SCHEMA */

var Material = orm.define('Material', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: { type: Sequelize.STRING, allowNull: false, unique: true },
  costPerUnit: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  qtyInStock: { type: Sequelize.INTEGER, defaultValue: 0 },
  qtyOnOrder: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var Piece = orm.define('Piece', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: { type: Sequelize.STRING, allowNull: false, unique: true },
  laborTime: { type: Sequelize.INTEGER, defaultValue: 0 },
  totalCost: Sequelize.DECIMAL(10,2),
  wholesalePrice: Sequelize.DECIMAL(10,2),
  msrp: Sequelize.DECIMAL(10,2),
  qtyInStock: { type: Sequelize.INTEGER, defaultValue: 0 },
  qtyOnOrder: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var PieceMaterial = orm.define('PieceMaterial', {
  qty: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var MaterialType = orm.define('MaterialType', {
  name: { type: Sequelize.STRING, allowNull: false, unique: true },
  lowStock: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var PieceType = orm.define('PieceType', {
  name: { type: Sequelize.STRING, allowNull: false, unique: true },
  lowStock: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var MaterialUnit = orm.define('MaterialUnit', {
  unit: { type: Sequelize.STRING, allowNull: false, unique: true }
});

var MaterialPurchaseOrder = orm.define('MaterialPurchaseOrder', {
  metal: Sequelize.STRING,
  instructions: Sequelize.TEXT,
  qty: Sequelize.INTEGER
});

var PiecePurchaseOrder = orm.define('PiecePurchaseOrder', {
  notes: Sequelize.TEXT,
  qty: Sequelize.INTEGER,
  price: Sequelize.DECIMAL(10,2)
});

var Vendor = orm.define('Vendor', {
  company: { type: Sequelize.STRING, allowNull: false, unique: true },
  address: { type: Sequelize.STRING, unique: true },
  phone: { type: Sequelize.STRING, unique: true },
  email: { type: Sequelize.STRING, unique: true }
});

var Settings = orm.define('Settings', {
  laborCost: Sequelize.DECIMAL(10,2)
});

var Product = orm.define('Product', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: Sequelize.STRING,
  cost: Sequelize.DECIMAL(10,2),
  msrp: Sequelize.DECIMAL(10,2),
  qtyOnHand: Sequelize.INTEGER,
  qtyOnOrder: Sequelize.INTEGER
});


/* ASSOCIATIONS */

Piece.belongsToMany(Material, { through: 'PieceMaterial', foreignKey: 'pieceId' });
Material.belongsToMany(Piece, { through: 'PieceMaterial', foreignKey: 'materialId' });

Material.belongsTo(MaterialType, { as: 'type'});
Piece.belongsTo(PieceType, { as: 'type' });

Material.belongsTo(MaterialUnit, { as: 'unit' });

Material.belongsTo(Vendor, { as: 'vendor' }); // may end up being belongsToMany

Material.belongsToMany(MaterialPurchaseOrder, {
  as: 'PurchaseOrders',
  through: 'POMaterial',
  foreignKey: 'purchaseOrderId'
});

MaterialPurchaseOrder.belongsToMany(Material, { through: 'POMaterial', foreignKey: 'materialId' });

Piece.belongsToMany(PiecePurchaseOrder, {
  as: 'PurchaseOrders',
  through: 'POPiece',
  foreignKey: 'purchaseOrderId'
});

PiecePurchaseOrder.belongsToMany(Piece, { through: 'POPiece', foreignKey: 'pieceId' });


// create tables if they do not already exist
orm.sync();

module.exports = {
  Material,
  MaterialPurchaseOrder,
  MaterialType,
  MaterialUnit,
  Piece,
  PieceMaterial,
  PiecePurchaseOrder,
  PieceType,
  Product,
  Settings,
  Vendor
};
<commit_msg>Make prices default to zero<commit_after>var Sequelize = require('sequelize');

/* CONNECTION */

var dbURL = process.env.DATABASE_URL;

if (dbURL) {
  var orm = new Sequelize(dbURL);
} else {
  var orm = new Sequelize('kim', 'root', '', {
    host: 'localhost',
    dialect: 'mysql',
    logging: false
  });
}


/* SCHEMA */

var Material = orm.define('Material', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: { type: Sequelize.STRING, allowNull: false, unique: true },
  costPerUnit: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  qtyInStock: { type: Sequelize.INTEGER, defaultValue: 0 },
  qtyOnOrder: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var Piece = orm.define('Piece', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: { type: Sequelize.STRING, allowNull: false, unique: true },
  laborTime: { type: Sequelize.INTEGER, defaultValue: 0 },
  totalCost: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  wholesalePrice: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  msrp: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  qtyInStock: { type: Sequelize.INTEGER, defaultValue: 0 },
  qtyOnOrder: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var PieceMaterial = orm.define('PieceMaterial', {
  qty: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var MaterialType = orm.define('MaterialType', {
  name: { type: Sequelize.STRING, allowNull: false, unique: true },
  lowStock: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var PieceType = orm.define('PieceType', {
  name: { type: Sequelize.STRING, allowNull: false, unique: true },
  lowStock: { type: Sequelize.INTEGER, defaultValue: 0 }
});

var MaterialUnit = orm.define('MaterialUnit', {
  unit: { type: Sequelize.STRING, allowNull: false, unique: true }
});

var MaterialPurchaseOrder = orm.define('MaterialPurchaseOrder', {
  metal: Sequelize.STRING,
  instructions: Sequelize.TEXT,
  qty: Sequelize.INTEGER
});

var PiecePurchaseOrder = orm.define('PiecePurchaseOrder', {
  notes: Sequelize.TEXT,
  qty: Sequelize.INTEGER,
  price: Sequelize.DECIMAL(10,2)
});

var Vendor = orm.define('Vendor', {
  company: { type: Sequelize.STRING, allowNull: false, unique: true },
  address: { type: Sequelize.STRING, unique: true },
  phone: { type: Sequelize.STRING, unique: true },
  email: { type: Sequelize.STRING, unique: true }
});

var Settings = orm.define('Settings', {
  laborCost: Sequelize.DECIMAL(10,2)
});

var Product = orm.define('Product', {
  item: { type: Sequelize.STRING, allowNull: false, unique: true },
  description: Sequelize.STRING,
  cost: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  msrp: { type: Sequelize.DECIMAL(10,2), defaultValue: 0 },
  qtyOnHand: { type: Sequelize.INTEGER, defaultValue: 0 },
  qtyOnOrder: { type: Sequelize.INTEGER, defaultValue: 0 }
});


/* ASSOCIATIONS */

Piece.belongsToMany(Material, { through: 'PieceMaterial', foreignKey: 'pieceId' });
Material.belongsToMany(Piece, { through: 'PieceMaterial', foreignKey: 'materialId' });

Material.belongsTo(MaterialType, { as: 'type'});
Piece.belongsTo(PieceType, { as: 'type' });

Material.belongsTo(MaterialUnit, { as: 'unit' });

Material.belongsTo(Vendor, { as: 'vendor' }); // may end up being belongsToMany

Material.belongsToMany(MaterialPurchaseOrder, {
  as: 'PurchaseOrders',
  through: 'POMaterial',
  foreignKey: 'purchaseOrderId'
});

MaterialPurchaseOrder.belongsToMany(Material, { through: 'POMaterial', foreignKey: 'materialId' });

Piece.belongsToMany(PiecePurchaseOrder, {
  as: 'PurchaseOrders',
  through: 'POPiece',
  foreignKey: 'purchaseOrderId'
});

PiecePurchaseOrder.belongsToMany(Piece, { through: 'POPiece', foreignKey: 'pieceId' });


// create tables if they do not already exist
orm.sync();

module.exports = {
  Material,
  MaterialPurchaseOrder,
  MaterialType,
  MaterialUnit,
  Piece,
  PieceMaterial,
  PiecePurchaseOrder,
  PieceType,
  Product,
  Settings,
  Vendor
};

{'fraction_non_alphanumeric': 0.15096042284388295, 'fraction_numerical': 0.009410854711873147, 'mean_word_length': 5.013953488372093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1259480', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2767, 'n_words': 595}