var Bookshelf = require('bookshelf');
// Establish connection with mysql database

/********************
make sure to create a local database called scheming_thunder
and change username and password accordingly
**********************/
var Sequelize = require('sequelize');
var orm = new Sequelize('scheming_thunder', 'root', '', {
  dialect: 'mysql',
});

orm.authenticate().complete(function(err){
  if(!!err){
    console.log('Unable to connect to database:', err)
  } else {
    console.log('Connection has been established successfully.')
  }
})

var User = orm.define('User', {
  username: {type: Sequelize.STRING, unique: true},
  password: Sequelize.STRING,
});

var Meal = orm.define('Meal', {
  title: Sequelize.STRING,
});

var Recipe = orm.define('Recipe', {
  title: {type: Sequelize.STRING, unique: true}
});

var Ingredient = orm.define('Ingredient', {
  name: {type: Sequelize.STRING, unique: true}
});

User.hasMany(Meal);
Meal.belongsTo(User);
Meal.hasMany(Recipe);
Recipe.hasMany(Meal);
Recipe.hasMany(Ingredient);
Ingredient.hasMany(Recipe);

User.sync();
Meal.sync();
Recipe.sync();
Ingredient.sync();

exports.User = User;
exports.Meal = Meal;
exports.Recipe = Recipe;
exports.Ingredient = Ingredient;


Add mysql database and tables via sequelize
Add mysql database and tables via sequelize
