Skip to content

Instantly share code, notes, and snippets.

@Eth3rnit3
Created November 28, 2018 09:47
Show Gist options
  • Save Eth3rnit3/8186ca6e24917fa3c08b8c1d923d84b6 to your computer and use it in GitHub Desktop.
Save Eth3rnit3/8186ca6e24917fa3c08b8c1d923d84b6 to your computer and use it in GitHub Desktop.
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Companies', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Companies');
}
};
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING
},
firstName: {
type: Sequelize.STRING
},
lastName: {
type: Sequelize.STRING
},
companyId: {
type: Sequelize.INTEGER,
allowNull: false,
references: { // User belongsTo Company 1:1
model: 'Companies',
key: 'id'
}
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
}
};
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('WorkingDays', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
weekDay: {
type: Sequelize.STRING
},
workingDate: {
type: Sequelize.DATE
},
isWorking: {
type: Sequelize.BOOLEAN
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('WorkingDays');
}
};
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('UsersWorkingDays', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
references: { // User hasMany WorkingDays n:n
model: 'Users',
key: 'id'
}
},
workingDayId: {
type: Sequelize.INTEGER,
allowNull: false,
references: { // WorkingDays hasMany Users n:n
model: 'WorkingDays',
key: 'id'
}
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('UsersWorkingDays');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment