diff --git a/api/migrations/20200526035358-add-is-public-and-is-open-to-calendar-events.js b/api/migrations/20200526035358-add-is-public-and-is-open-to-calendar-events.js new file mode 100644 index 0000000..dbf3a24 --- /dev/null +++ b/api/migrations/20200526035358-add-is-public-and-is-open-to-calendar-events.js @@ -0,0 +1,25 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return Promise.all([ + queryInterface.addColumn('calendar_events', 'is_open', { + allowNull: false, + type: Sequelize.BOOLEAN, + defaultValue: false, + }), + queryInterface.addColumn('calendar_events', 'is_public', { + allowNull: false, + type: Sequelize.BOOLEAN, + defaultValue: false, + }), + ]); + }, + + down: (queryInterface, Sequelize) => { + return Promise.all([ + queryInterface.removeColumn('calendar_events', 'is_open'), + queryInterface.removeColumn('calendar_events', 'is_public'), + ]); + }, +}; diff --git a/api/migrations/20200526035531-add-slug-to-calendar-events.js b/api/migrations/20200526035531-add-slug-to-calendar-events.js new file mode 100644 index 0000000..294ef46 --- /dev/null +++ b/api/migrations/20200526035531-add-slug-to-calendar-events.js @@ -0,0 +1,18 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return Promise.all([ + queryInterface.addColumn('calendar_events', 'slug', { + allowNull: true, + type: Sequelize.STRING, + }), + ]); + }, + + down: (queryInterface, Sequelize) => { + return Promise.all([ + queryInterface.removeColumn('calendar_events', 'slug'), + ]); + }, +}; diff --git a/api/migrations/20200603194408-add-slug-to-not-null.js b/api/migrations/20200603194408-add-slug-to-not-null.js new file mode 100644 index 0000000..d66c06f --- /dev/null +++ b/api/migrations/20200603194408-add-slug-to-not-null.js @@ -0,0 +1,39 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.sequelize + .query( + ` + UPDATE calendar_events SET slug = BTRIM(REGEXP_REPLACE(lower(title), '[^a-z0-9\\-_]+', '-', 'gi'), '-') + WHERE slug is NULL; + `, + ) + .then(() => { + return [ + queryInterface.changeColumn('calendar_events', 'slug', { + type: Sequelize.STRING, + allowNull: false, + }), + queryInterface.addIndex('calendar_events', { + unique: true, + fields: ['slug'], + }), + ]; + }) + .catch((error) => { + console.log(error); + }); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.sequelize + .query(` UPDATE calendar_events SET slug = '';`) + .then(() => { + queryInterface.changeColumn('calendar_events', 'slug', { + type: Sequelize.STRING, + allowNull: true, + }); + }); + }, +};