mirror of
https://github.com/Fabio286/antares.git
synced 2025-03-09 16:00:17 +01:00
perf: support of scale in field's length setting
This commit is contained in:
parent
aa8fc545d7
commit
eef7c1dcec
@ -66,6 +66,7 @@ module.exports = [
|
||||
{
|
||||
name: 'DECIMAL',
|
||||
length: true,
|
||||
scale: true,
|
||||
collation: false,
|
||||
unsigned: false,
|
||||
zerofill: false
|
||||
|
@ -22,11 +22,6 @@ module.exports = [
|
||||
length: false,
|
||||
unsigned: true
|
||||
},
|
||||
{
|
||||
name: 'NUMERIC',
|
||||
length: true,
|
||||
unsigned: true
|
||||
},
|
||||
{
|
||||
name: 'SMALLSERIAL',
|
||||
length: false,
|
||||
@ -52,6 +47,12 @@ module.exports = [
|
||||
length: false,
|
||||
unsigned: true
|
||||
},
|
||||
{
|
||||
name: 'NUMERIC',
|
||||
length: true,
|
||||
unsigned: true,
|
||||
scale: true
|
||||
},
|
||||
{
|
||||
name: 'DOUBLE PRECISION',
|
||||
length: false,
|
||||
|
@ -435,7 +435,7 @@ export class MySQLClient extends AntaresCore {
|
||||
|
||||
return rows.map(field => {
|
||||
let numLength = field.COLUMN_TYPE.match(/int\(([^)]+)\)/);
|
||||
numLength = numLength ? +numLength.pop() : null;
|
||||
numLength = numLength ? +numLength.pop() : field.NUMERIC_PRECISION || null;
|
||||
const enumValues = /(enum|set)/.test(field.COLUMN_TYPE)
|
||||
? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1)
|
||||
: null;
|
||||
@ -443,10 +443,13 @@ export class MySQLClient extends AntaresCore {
|
||||
return {
|
||||
name: field.COLUMN_NAME,
|
||||
key: field.COLUMN_KEY.toLowerCase(),
|
||||
type: (remappedFields && remappedFields[field.COLUMN_NAME]) ? remappedFields[field.COLUMN_NAME].type : field.DATA_TYPE,
|
||||
type: (remappedFields && remappedFields[field.COLUMN_NAME])
|
||||
? remappedFields[field.COLUMN_NAME].type
|
||||
: field.DATA_TYPE.toUpperCase(),
|
||||
schema: field.TABLE_SCHEMA,
|
||||
table: field.TABLE_NAME,
|
||||
numPrecision: field.NUMERIC_PRECISION,
|
||||
numScale: field.NUMERIC_SCALE,
|
||||
numLength,
|
||||
enumValues,
|
||||
datePrecision: field.DATETIME_PRECISION,
|
||||
@ -1295,7 +1298,7 @@ export class MySQLClient extends AntaresCore {
|
||||
const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false;
|
||||
|
||||
newColumns.push(`\`${field.name}\`
|
||||
${field.type.toUpperCase()}${length ? `(${length})` : ''}
|
||||
${field.type.toUpperCase()}${length ? `(${length}${field.numScale !== null ? `,${field.numScale}` : ''})` : ''}
|
||||
${field.unsigned ? 'UNSIGNED' : ''}
|
||||
${field.zerofill ? 'ZEROFILL' : ''}
|
||||
${field.nullable ? 'NULL' : 'NOT NULL'}
|
||||
@ -1364,7 +1367,7 @@ export class MySQLClient extends AntaresCore {
|
||||
const length = typeInfo.length ? addition.enumValues || addition.numLength || addition.charLength || addition.datePrecision : false;
|
||||
|
||||
alterColumns.push(`ADD COLUMN \`${addition.name}\`
|
||||
${addition.type.toUpperCase()}${length ? `(${length})` : ''}
|
||||
${addition.type.toUpperCase()}${length ? `(${length}${addition.numScale !== null ? `,${addition.numScale}` : ''})` : ''}
|
||||
${addition.unsigned ? 'UNSIGNED' : ''}
|
||||
${addition.zerofill ? 'ZEROFILL' : ''}
|
||||
${addition.nullable ? 'NULL' : 'NOT NULL'}
|
||||
@ -1402,7 +1405,7 @@ export class MySQLClient extends AntaresCore {
|
||||
const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false;
|
||||
|
||||
alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\`
|
||||
${change.type.toUpperCase()}${length ? `(${length})` : ''}
|
||||
${change.type.toUpperCase()}${length ? `(${length}${change.numScale !== null ? `,${change.numScale}` : ''})` : ''}
|
||||
${change.unsigned ? 'UNSIGNED' : ''}
|
||||
${change.zerofill ? 'ZEROFILL' : ''}
|
||||
${change.nullable ? 'NULL' : 'NOT NULL'}
|
||||
|
@ -326,6 +326,7 @@ export class PostgreSQLClient extends AntaresCore {
|
||||
isArray,
|
||||
schema: field.table_schema,
|
||||
table: field.table_name,
|
||||
numScale: field.numeric_scale,
|
||||
numPrecision: field.numeric_precision,
|
||||
datePrecision: field.datetime_precision,
|
||||
charLength: field.character_maximum_length,
|
||||
@ -1144,7 +1145,7 @@ export class PostgreSQLClient extends AntaresCore {
|
||||
const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false;
|
||||
|
||||
newColumns.push(`"${field.name}"
|
||||
${field.type.toUpperCase()}${length ? `(${length})` : ''}
|
||||
${field.type.toUpperCase()}${length ? `(${length}${field.numScale !== null ? `,${field.numScale}` : ''})` : ''}
|
||||
${field.unsigned ? 'UNSIGNED' : ''}
|
||||
${field.zerofill ? 'ZEROFILL' : ''}
|
||||
${field.nullable ? 'NULL' : 'NOT NULL'}
|
||||
@ -1208,7 +1209,7 @@ export class PostgreSQLClient extends AntaresCore {
|
||||
const length = typeInfo.length ? addition.numLength || addition.charLength || addition.datePrecision : false;
|
||||
|
||||
alterColumns.push(`ADD COLUMN "${addition.name}"
|
||||
${addition.type.toUpperCase()}${length ? `(${length})` : ''}${addition.isArray ? '[]' : ''}
|
||||
${addition.type.toUpperCase()}${length ? `(${length}${addition.numScale !== null ? `,${addition.numScale}` : ''})` : ''}${addition.isArray ? '[]' : ''}
|
||||
${addition.unsigned ? 'UNSIGNED' : ''}
|
||||
${addition.zerofill ? 'ZEROFILL' : ''}
|
||||
${addition.nullable ? 'NULL' : 'NOT NULL'}
|
||||
@ -1254,7 +1255,7 @@ export class PostgreSQLClient extends AntaresCore {
|
||||
localType = change.type.toLowerCase();
|
||||
}
|
||||
|
||||
alterColumns.push(`ALTER COLUMN "${change.name}" TYPE ${localType}${length ? `(${length})` : ''}${change.isArray ? '[]' : ''} USING "${change.name}"::${localType}`);
|
||||
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}" ${change.nullable ? 'DROP NOT NULL' : 'SET NOT NULL'}`);
|
||||
alterColumns.push(`ALTER COLUMN "${change.name}" ${change.default ? `SET DEFAULT ${change.default}` : 'DROP DEFAULT'}`);
|
||||
|
||||
|
@ -99,6 +99,9 @@
|
||||
<span v-if="localRow.enumValues">
|
||||
{{ localRow.enumValues }}
|
||||
</span>
|
||||
<span v-else-if="localRow.numScale">
|
||||
{{ localLength }}, {{ localRow.numScale }}
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ localLength }}
|
||||
</span>
|
||||
@ -112,6 +115,16 @@
|
||||
class="editable-field form-input input-sm px-1"
|
||||
@blur="editOFF"
|
||||
>
|
||||
<input
|
||||
v-else-if="fieldType.scale"
|
||||
ref="editField"
|
||||
v-model="editingContent"
|
||||
type="text"
|
||||
autofocus
|
||||
class="editable-field form-input input-sm px-1"
|
||||
@keypress="checkLengthScale"
|
||||
@blur="editOFF"
|
||||
>
|
||||
<input
|
||||
v-else
|
||||
ref="editField"
|
||||
@ -480,6 +493,10 @@ export default {
|
||||
this.editingContent = this.localRow.enumValues;
|
||||
this.originalContent = this.localRow.enumValues;
|
||||
}
|
||||
else if (this.localRow.numScale !== null && field === 'length') {
|
||||
this.editingContent = `${content}, ${this.localRow.numScale}`;
|
||||
this.originalContent = `${content}, ${this.localRow.numScale}`;
|
||||
}
|
||||
else {
|
||||
this.editingContent = content;
|
||||
this.originalContent = content;
|
||||
@ -502,10 +519,17 @@ export default {
|
||||
if (this.editingField === 'name')
|
||||
this.$emit('rename-field', { old: this.localRow[this.editingField], new: this.editingContent });
|
||||
|
||||
this.localRow[this.editingField] = this.editingContent;
|
||||
if (this.editingField === 'numLength' && this.localRow.numScale !== null && this.editingContent.includes(',')) {
|
||||
const [length, scale] = this.editingContent.split(',');
|
||||
this.localRow.numLength = +length;
|
||||
this.localRow.numScale = +scale;
|
||||
}
|
||||
else
|
||||
this.localRow[this.editingField] = this.editingContent;
|
||||
|
||||
if (this.editingField === 'type' && this.editingContent !== this.originalContent) {
|
||||
this.localRow.numLength = null;
|
||||
this.localRow.numScale = null;
|
||||
this.localRow.charLength = null;
|
||||
this.localRow.datePrecision = null;
|
||||
this.localRow.enumValues = '';
|
||||
@ -560,6 +584,15 @@ export default {
|
||||
this.originalContent = null;
|
||||
this.editingField = null;
|
||||
},
|
||||
checkLengthScale (e) {
|
||||
e = (e) || window.event;
|
||||
const charCode = (e.which) ? e.which : e.keyCode;
|
||||
|
||||
if (((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode !== 44) || (charCode === 44 && e.target.value.includes(',')))
|
||||
e.preventDefault();
|
||||
else
|
||||
return true;
|
||||
},
|
||||
hideDefaultModal () {
|
||||
this.isDefaultModal = false;
|
||||
}
|
||||
|
@ -280,6 +280,7 @@ export default {
|
||||
fieldLength (field) {
|
||||
if ([...BLOB, ...LONG_TEXT].includes(field.type)) return null;
|
||||
else if (TEXT.includes(field.type)) return field.charLength;
|
||||
else if (field.numScale) return `${field.numPrecision}, ${field.numScale}`;
|
||||
return field.length;
|
||||
},
|
||||
keyName (key) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user