fix: scale on numeric fields that doesn't support it

This commit is contained in:
Fabio Di Stasio 2022-01-27 09:12:01 +01:00
parent 745b55a942
commit 0cfd7938ee
3 changed files with 10 additions and 9 deletions

View File

@ -1298,7 +1298,7 @@ export class MySQLClient extends AntaresCore {
const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false;
newColumns.push(`\`${field.name}\` newColumns.push(`\`${field.name}\`
${field.type.toUpperCase()}${length ? `(${length}${field.numScale !== null ? `,${field.numScale}` : ''})` : ''} ${field.type.toUpperCase()}${length ? `(${length}${field.numScale ? `,${field.numScale}` : ''})` : ''}
${field.unsigned ? 'UNSIGNED' : ''} ${field.unsigned ? 'UNSIGNED' : ''}
${field.zerofill ? 'ZEROFILL' : ''} ${field.zerofill ? 'ZEROFILL' : ''}
${field.nullable ? 'NULL' : 'NOT NULL'} ${field.nullable ? 'NULL' : 'NOT NULL'}
@ -1367,7 +1367,7 @@ export class MySQLClient extends AntaresCore {
const length = typeInfo.length ? addition.enumValues || addition.numLength || addition.charLength || addition.datePrecision : false; const length = typeInfo.length ? addition.enumValues || addition.numLength || addition.charLength || addition.datePrecision : false;
alterColumns.push(`ADD COLUMN \`${addition.name}\` alterColumns.push(`ADD COLUMN \`${addition.name}\`
${addition.type.toUpperCase()}${length ? `(${length}${addition.numScale !== null ? `,${addition.numScale}` : ''})` : ''} ${addition.type.toUpperCase()}${length ? `(${length}${addition.numScale ? `,${addition.numScale}` : ''})` : ''}
${addition.unsigned ? 'UNSIGNED' : ''} ${addition.unsigned ? 'UNSIGNED' : ''}
${addition.zerofill ? 'ZEROFILL' : ''} ${addition.zerofill ? 'ZEROFILL' : ''}
${addition.nullable ? 'NULL' : 'NOT NULL'} ${addition.nullable ? 'NULL' : 'NOT NULL'}
@ -1405,7 +1405,7 @@ export class MySQLClient extends AntaresCore {
const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false; const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false;
alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\` alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\`
${change.type.toUpperCase()}${length ? `(${length}${change.numScale !== null ? `,${change.numScale}` : ''})` : ''} ${change.type.toUpperCase()}${length ? `(${length}${change.numScale ? `,${change.numScale}` : ''})` : ''}
${change.unsigned ? 'UNSIGNED' : ''} ${change.unsigned ? 'UNSIGNED' : ''}
${change.zerofill ? 'ZEROFILL' : ''} ${change.zerofill ? 'ZEROFILL' : ''}
${change.nullable ? 'NULL' : 'NOT NULL'} ${change.nullable ? 'NULL' : 'NOT NULL'}

View File

@ -1255,7 +1255,7 @@ export class PostgreSQLClient extends AntaresCore {
localType = change.type.toLowerCase(); localType = change.type.toLowerCase();
} }
alterColumns.push(`ALTER COLUMN "${change.name}" TYPE ${localType}${length ? `(${length}${change.numScale !== null ? `,${change.numScale}` : ''})` : ''}${change.isArray ? '[]' : ''} USING "${change.name}"::${localType}`); alterColumns.push(`ALTER COLUMN "${change.name}" TYPE ${localType}${length ? `(${length}${change.numScale ? `,${change.numScale}` : ''})` : ''}${change.isArray ? '[]' : ''} USING "${change.name}"::${localType}`);
alterColumns.push(`ALTER COLUMN "${change.name}" ${change.nullable ? 'DROP NOT NULL' : 'SET NOT NULL'}`); alterColumns.push(`ALTER COLUMN "${change.name}" ${change.nullable ? 'DROP NOT NULL' : 'SET NOT NULL'}`);
alterColumns.push(`ALTER COLUMN "${change.name}" ${change.default ? `SET DEFAULT ${change.default}` : 'DROP DEFAULT'}`); alterColumns.push(`ALTER COLUMN "${change.name}" ${change.default ? `SET DEFAULT ${change.default}` : 'DROP DEFAULT'}`);

View File

@ -493,9 +493,10 @@ export default {
this.editingContent = this.localRow.enumValues; this.editingContent = this.localRow.enumValues;
this.originalContent = this.localRow.enumValues; this.originalContent = this.localRow.enumValues;
} }
else if (this.localRow.numScale !== null && field === 'length') { else if (this.fieldType.scale && field === 'length') {
this.editingContent = `${content}, ${this.localRow.numScale}`; const scale = this.localRow.numScale !== null ? this.localRow.numScale : 0;
this.originalContent = `${content}, ${this.localRow.numScale}`; this.editingContent = `${content}, ${scale}`;
this.originalContent = `${content}, ${scale}`;
} }
else { else {
this.editingContent = content; this.editingContent = content;
@ -519,10 +520,10 @@ export default {
if (this.editingField === 'name') if (this.editingField === 'name')
this.$emit('rename-field', { old: this.localRow[this.editingField], new: this.editingContent }); this.$emit('rename-field', { old: this.localRow[this.editingField], new: this.editingContent });
if (this.editingField === 'numLength' && this.localRow.numScale !== null && this.editingContent.includes(',')) { if (this.editingField === 'numLength' && this.fieldType.scale) {
const [length, scale] = this.editingContent.split(','); const [length, scale] = this.editingContent.split(',');
this.localRow.numLength = +length; this.localRow.numLength = +length;
this.localRow.numScale = +scale; this.localRow.numScale = scale ? +scale : null;
} }
else else
this.localRow[this.editingField] = this.editingContent; this.localRow[this.editingField] = this.editingContent;