forked from coding-blocks/gondor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slug migration to change allownull (coding-blocks#118)
* Slug migration to change allownull * Updated Migration * migration to allow slug to not null * Final Corrections in File Name
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
api/migrations/20200526035358-add-is-public-and-is-open-to-calendar-events.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'), | ||
]); | ||
}, | ||
}; |
18 changes: 18 additions & 0 deletions
18
api/migrations/20200526035531-add-slug-to-calendar-events.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'), | ||
]); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
}); | ||
}, | ||
}; |