Skip to content

Commit

Permalink
Merge pull request #2899 from FlowFuse/fix-db-constraint
Browse files Browse the repository at this point in the history
Remove not null constraint on ProjectSnapshot.ProjectId column
  • Loading branch information
knolleary authored Oct 5, 2023
2 parents d39204d + 78795c5 commit 225ffc4
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Remove not null on ProjectSnapshots.ProjectId
*/
const { DataTypes } = require('sequelize')

module.exports = {
up: async (context) => {
const dialect = context.sequelize.options.dialect
if (dialect === 'sqlite') {
// We have to do this the hard way due to limitations of sqlite and
// changing table constraints. The changeColumn approach causes all
// table constraints to be lost. We can keep them on the one column
// we're modifying, but it also strips them for the others.
await context.sequelize.query('pragma writable_schema=1;')
const sql = "update SQLITE_MASTER set sql = replace(sql, '`ProjectId` UUID NOT NULL', '`ProjectId` UUID') where name = 'ProjectSnapshots' and type = 'table';"
context.sequelize.query(sql)
await context.sequelize.query('pragma writable_schema=0;')
} else {
// Postgres allows us to modify a constraint without breaking all
// the other properties
await context.changeColumn('ProjectSnapshots', 'ProjectId', {
type: DataTypes.UUID,
allowNull: true
})
}
},
down: async (context) => {
}
}

0 comments on commit 225ffc4

Please sign in to comment.