Guest User

Untitled

a guest
Jun 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. exports.up = function(knex, Promise) {
  2. return Promise.all([
  3. knex.schema.hasTable('recipe').then((exists) => {
  4. console.log('does knex have recipe table?', exists);
  5. if (!exists) {
  6. return knex.schema.createTable('recipe', (table) => {
  7. table.uuid('id');
  8. table.string('name');
  9. table.string('description');
  10. })
  11. }
  12. }),
  13. knex.schema.hasTable('ingredient').then((exists) => {
  14. console.log('does knex have ingredient table?', exists);
  15. if (!exists) {
  16. return knex.schema.createTable('ingredient', (table) => {
  17. table.uuid('id');
  18. table.string('name');
  19. })
  20. }
  21. }),
  22. knex.schema.hasTable(`recipe-ingredient`).then((exists) => {
  23. console.log('does knex have recipe-ingredient table?', exists);
  24. if (!exists) {
  25. return knex.schema.createTable(`recipe-ingredient`, (table)=> {
  26. table.uuid('recipe_id').references('id').inTable('recipe').notNull();
  27. table.uuid('ingredient_id').references('id').inTable('ingredient').notNull();
  28. table.string('qty'); // <-- chose string instead of int because receipes include qty such as '1/3 cup', '1 teaspoon', etc.
  29. })
  30. }
  31. })
  32. ])
  33. };
  34.  
  35. exports.down = function(knex, Promise) {
  36. return Promise.all([
  37. knex.schema.dropTable('recipe-ingredient'),
  38. knex.schema.dropTable('ingredient'),
  39. knex.schema.dropTable('recipe')
  40. ])
  41. };
  42.  
  43. require('dotenv').config();
  44.  
  45. module.exports = {
  46.  
  47. development: {
  48. client: 'mysql',
  49. connection: {
  50. host: process.env.DATABASE_HOST_DEV || '127.0.0.1',
  51. user: process.env.DATABASE_USER_DEV,
  52. password: process.env.DATABASE_PASSWORD_DEV,
  53. database: process.env.DATABASE_NAME_DEV
  54. },
  55. migrations: {
  56. directory: __dirname+'/database/migrations'
  57. }
  58. },
  59.  
  60. staging: {
  61. client: 'mysql',
  62. connection: {
  63. host: '127.0.0.1',
  64. user: 'root',
  65. password: 'password',
  66. database: 'recipes'
  67. },
  68. pool: {
  69. min: 2,
  70. max: 10
  71. },
  72. migrations: {
  73. directory: __dirname+'/database/migrations'
  74. }
  75. },
  76.  
  77. production: {
  78. client: 'mysql',
  79. connection: {
  80. host: process.env.DATABASE_HOST,
  81. user: process.env.DATABASE_USER,
  82. password: process.env.DATABASE_PASSWORD,
  83. database: process.env.DATABASE_NAME
  84. },
  85. pool: {
  86. min: 2,
  87. max: 10
  88. },
  89. migrations: {
  90. directory: __dirname+'/database/migrations'
  91. }
  92. }
  93.  
  94. };
Add Comment
Please, Sign In to add comment