@ -41,6 +41,18 @@ exports.save = async function(ctx) {
oldTable = await db . get ( ctx . request . body . _ id )
}
// make sure that types don't change of a column, have to remove
// the column if you want to change the type
if ( oldTable && oldTable . schema ) {
for ( let propKey of Object . keys ( tableToSave . schema ) ) {
let column = tableToSave . schema [ propKey ]
let oldColumn = oldTable . schema [ propKey ]
if ( oldColumn && oldColumn . type !== column . type ) {
ctx . throw ( 400 , "Cannot change the type of a column" )
}
}
}
// Don't rename if the name is the same
let { _ rename } = tableToSave
if ( _ rename && _ rename . old === _ rename . updated ) {
@ -50,9 +62,9 @@ exports.save = async function(ctx) {
// rename row fields when table column is renamed
if ( _ rename && tableToSave . schema [ _ rename . updated ] . type === "link" ) {
throw "Cannot rename a linked field."
ctx . throw ( 400 , "Cannot rename a linked column." )
} else if ( _ rename && tableToSave . primaryDisplay === _ rename . old ) {
throw "Cannot rename the display column."
ctx . throw ( 400 , "Cannot rename the display column." )
} else if ( _ rename ) {
const rows = await db . allDocs (
getRowParams ( tableToSave . _ id , null , {