Skip to content

Instantly share code, notes, and snippets.

@sdepold
Forked from nicholasf/gist:3301609
Created August 9, 2012 06:25
Show Gist options
  • Save sdepold/3301658 to your computer and use it in GitHub Desktop.
Save sdepold/3301658 to your computer and use it in GitHub Desktop.
var models = require('./models');
models.synchronize();
//models
var Sequelize = require('sequelize'),
async = require('async');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var sequelize = new Sequelize('moneytribe_' + process.env.NODE_ENV, 'root', null);
console.log(">>>>>>>>>>>>> ", 'moneytribe_' + process.env.NODE_ENV, " <<<<<<<<<<<<<<<<<<<");
//QuotesRequest
var QuotesRequest = sequelize.define('quotes_requests', {
id: { type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
postcode: { type: Sequelize.INTEGER, allowNull: false },
tribe_category_id: { type: Sequelize.INTEGER , allowNull: false },
url: { type: Sequelize.STRING, allowNull: false },
expiry: { type: Sequelize.DATE, allowNull: false }
}, {underscored: true, freezeTableName: true});
//Quote
var Quote = sequelize.define('quotes', {
id: { type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
quotes_request_id: { type: Sequelize.INTEGER, allowNull: false },
broker_id: { type: Sequelize.INTEGER, allowNull: false }
}, {underscored: true, freezeTableName: true});
//QuoteResponse
var QuoteResponse = sequelize.define('quote_responses', {
id: { type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
phone_number: { type: Sequelize.INTEGER, allowNull: false },
quote_id: { type: Sequelize.INTEGER, allowNull: false }
}, {underscored: true, freezeTableName: true});
//Broker
var Broker = sequelize.define('brokers', {
id: {type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
name: {type: Sequelize.STRING, allowNull: false},
is_active: {type: Sequelize.BOOLEAN, allowNull: false}
}, {underscored: true, freezeTableName: true});
var Location = sequelize.define('locations', {
id: {type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
postcode: {type: Sequelize.STRING, allowNull: false},
name: {type: Sequelize.STRING, allowNull:false, unique: true}
}, {underscored: true, freezeTableName: true});
var LocationRegion = sequelize.define('location_regions', {
id: {type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
name: {type: Sequelize.STRING, allowNull:false, unique: true},
code: {type: Sequelize.STRING, allowNull:false, unique: true}
}, {underscored: true, freezeTableName: true});
var TribeCategory = sequelize.define('tribe_categories', {
id: {type: Sequelize.INTEGER, autoIncrement: true, allowNull: false, primaryKey: true },
name: {type: Sequelize.STRING, allowNull: false},
is_active: {type: Sequelize.BOOLEAN, allowNull: false}
}, {underscored: true, freezeTableName: true});
//model associations
QuotesRequest.hasMany(Quote, { foreignKey: 'quote_request_id' });
QuotesRequest.hasMany(QuoteResponse, { foreignKey: 'quote_request_id' });
Quote.belongsTo(QuotesRequest);
Quote.belongsTo(Broker);
QuoteResponse.belongsTo(QuotesRequest);
Broker.hasMany(Quote, { foreignKey: 'broker_id' });
exports.QuotesRequest = QuotesRequest;
exports.QuoteRespone = QuoteResponse;
exports.Quote = Quote;
exports.Broker = Broker;
exports.Location = Location;
exports.LocationRegion = LocationRegion;
exports.TribeCategory = TribeCategory;
exports.synchronize = function() {
// QuotesRequest.sync()
// .success(
// function(){console.log('QuotesRequest synced')})
// .error(
// function(err){console.log('QuotesRequest failed', err)});
// QuoteResponse.sync()
// .success(
// function(){console.log('QuoteResponse synced')})
// .error(
// function(err){console.log('QuoteResponse failed', err)});
// Quote.sync()
// .success(
// function(){console.log('Quote synced')})
// .error(
// function(err){console.log('Quote failed', err)});
sequelize.sync()
.success(
function(){console.log('QuotesRequest synced')})
.error(
function(err){console.log('QuotesRequest failed', err)});
console.log('done!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment