mirror of
https://github.com/Fabio286/antares.git
synced 2025-03-10 00:10:16 +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',
|
name: 'DECIMAL',
|
||||||
length: true,
|
length: true,
|
||||||
|
scale: true,
|
||||||
collation: false,
|
collation: false,
|
||||||
unsigned: false,
|
unsigned: false,
|
||||||
zerofill: false
|
zerofill: false
|
||||||
|
@ -22,11 +22,6 @@ module.exports = [
|
|||||||
length: false,
|
length: false,
|
||||||
unsigned: true
|
unsigned: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'NUMERIC',
|
|
||||||
length: true,
|
|
||||||
unsigned: true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'SMALLSERIAL',
|
name: 'SMALLSERIAL',
|
||||||
length: false,
|
length: false,
|
||||||
@ -52,6 +47,12 @@ module.exports = [
|
|||||||
length: false,
|
length: false,
|
||||||
unsigned: true
|
unsigned: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'NUMERIC',
|
||||||
|
length: true,
|
||||||
|
unsigned: true,
|
||||||
|
scale: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'DOUBLE PRECISION',
|
name: 'DOUBLE PRECISION',
|
||||||
length: false,
|
length: false,
|
||||||
|
@ -435,7 +435,7 @@ export class MySQLClient extends AntaresCore {
|
|||||||
|
|
||||||
return rows.map(field => {
|
return rows.map(field => {
|
||||||
let numLength = field.COLUMN_TYPE.match(/int\(([^)]+)\)/);
|
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)
|
const enumValues = /(enum|set)/.test(field.COLUMN_TYPE)
|
||||||
? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1)
|
? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1)
|
||||||
: null;
|
: null;
|
||||||
@ -443,10 +443,13 @@ export class MySQLClient extends AntaresCore {
|
|||||||
return {
|
return {
|
||||||
name: field.COLUMN_NAME,
|
name: field.COLUMN_NAME,
|
||||||
key: field.COLUMN_KEY.toLowerCase(),
|
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,
|
schema: field.TABLE_SCHEMA,
|
||||||
table: field.TABLE_NAME,
|
table: field.TABLE_NAME,
|
||||||
numPrecision: field.NUMERIC_PRECISION,
|
numPrecision: field.NUMERIC_PRECISION,
|
||||||
|
numScale: field.NUMERIC_SCALE,
|
||||||
numLength,
|
numLength,
|
||||||
enumValues,
|
enumValues,
|
||||||
datePrecision: field.DATETIME_PRECISION,
|
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;
|
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.type.toUpperCase()}${length ? `(${length}${field.numScale !== null ? `,${field.numScale}` : ''})` : ''}
|
||||||
${field.unsigned ? 'UNSIGNED' : ''}
|
${field.unsigned ? 'UNSIGNED' : ''}
|
||||||
${field.zerofill ? 'ZEROFILL' : ''}
|
${field.zerofill ? 'ZEROFILL' : ''}
|
||||||
${field.nullable ? 'NULL' : 'NOT NULL'}
|
${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;
|
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.type.toUpperCase()}${length ? `(${length}${addition.numScale !== null ? `,${addition.numScale}` : ''})` : ''}
|
||||||
${addition.unsigned ? 'UNSIGNED' : ''}
|
${addition.unsigned ? 'UNSIGNED' : ''}
|
||||||
${addition.zerofill ? 'ZEROFILL' : ''}
|
${addition.zerofill ? 'ZEROFILL' : ''}
|
||||||
${addition.nullable ? 'NULL' : 'NOT NULL'}
|
${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;
|
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.type.toUpperCase()}${length ? `(${length}${change.numScale !== null ? `,${change.numScale}` : ''})` : ''}
|
||||||
${change.unsigned ? 'UNSIGNED' : ''}
|
${change.unsigned ? 'UNSIGNED' : ''}
|
||||||
${change.zerofill ? 'ZEROFILL' : ''}
|
${change.zerofill ? 'ZEROFILL' : ''}
|
||||||
${change.nullable ? 'NULL' : 'NOT NULL'}
|
${change.nullable ? 'NULL' : 'NOT NULL'}
|
||||||
|
@ -326,6 +326,7 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
isArray,
|
isArray,
|
||||||
schema: field.table_schema,
|
schema: field.table_schema,
|
||||||
table: field.table_name,
|
table: field.table_name,
|
||||||
|
numScale: field.numeric_scale,
|
||||||
numPrecision: field.numeric_precision,
|
numPrecision: field.numeric_precision,
|
||||||
datePrecision: field.datetime_precision,
|
datePrecision: field.datetime_precision,
|
||||||
charLength: field.character_maximum_length,
|
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;
|
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.type.toUpperCase()}${length ? `(${length}${field.numScale !== null ? `,${field.numScale}` : ''})` : ''}
|
||||||
${field.unsigned ? 'UNSIGNED' : ''}
|
${field.unsigned ? 'UNSIGNED' : ''}
|
||||||
${field.zerofill ? 'ZEROFILL' : ''}
|
${field.zerofill ? 'ZEROFILL' : ''}
|
||||||
${field.nullable ? 'NULL' : 'NOT NULL'}
|
${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;
|
const length = typeInfo.length ? 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.isArray ? '[]' : ''}
|
${addition.type.toUpperCase()}${length ? `(${length}${addition.numScale !== null ? `,${addition.numScale}` : ''})` : ''}${addition.isArray ? '[]' : ''}
|
||||||
${addition.unsigned ? 'UNSIGNED' : ''}
|
${addition.unsigned ? 'UNSIGNED' : ''}
|
||||||
${addition.zerofill ? 'ZEROFILL' : ''}
|
${addition.zerofill ? 'ZEROFILL' : ''}
|
||||||
${addition.nullable ? 'NULL' : 'NOT NULL'}
|
${addition.nullable ? 'NULL' : 'NOT NULL'}
|
||||||
@ -1254,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.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.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'}`);
|
||||||
|
|
||||||
|
@ -99,6 +99,9 @@
|
|||||||
<span v-if="localRow.enumValues">
|
<span v-if="localRow.enumValues">
|
||||||
{{ localRow.enumValues }}
|
{{ localRow.enumValues }}
|
||||||
</span>
|
</span>
|
||||||
|
<span v-else-if="localRow.numScale">
|
||||||
|
{{ localLength }}, {{ localRow.numScale }}
|
||||||
|
</span>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
{{ localLength }}
|
{{ localLength }}
|
||||||
</span>
|
</span>
|
||||||
@ -112,6 +115,16 @@
|
|||||||
class="editable-field form-input input-sm px-1"
|
class="editable-field form-input input-sm px-1"
|
||||||
@blur="editOFF"
|
@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
|
<input
|
||||||
v-else
|
v-else
|
||||||
ref="editField"
|
ref="editField"
|
||||||
@ -480,6 +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') {
|
||||||
|
this.editingContent = `${content}, ${this.localRow.numScale}`;
|
||||||
|
this.originalContent = `${content}, ${this.localRow.numScale}`;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.editingContent = content;
|
this.editingContent = content;
|
||||||
this.originalContent = content;
|
this.originalContent = content;
|
||||||
@ -502,10 +519,17 @@ 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(',')) {
|
||||||
|
const [length, scale] = this.editingContent.split(',');
|
||||||
|
this.localRow.numLength = +length;
|
||||||
|
this.localRow.numScale = +scale;
|
||||||
|
}
|
||||||
|
else
|
||||||
this.localRow[this.editingField] = this.editingContent;
|
this.localRow[this.editingField] = this.editingContent;
|
||||||
|
|
||||||
if (this.editingField === 'type' && this.editingContent !== this.originalContent) {
|
if (this.editingField === 'type' && this.editingContent !== this.originalContent) {
|
||||||
this.localRow.numLength = null;
|
this.localRow.numLength = null;
|
||||||
|
this.localRow.numScale = null;
|
||||||
this.localRow.charLength = null;
|
this.localRow.charLength = null;
|
||||||
this.localRow.datePrecision = null;
|
this.localRow.datePrecision = null;
|
||||||
this.localRow.enumValues = '';
|
this.localRow.enumValues = '';
|
||||||
@ -560,6 +584,15 @@ export default {
|
|||||||
this.originalContent = null;
|
this.originalContent = null;
|
||||||
this.editingField = 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 () {
|
hideDefaultModal () {
|
||||||
this.isDefaultModal = false;
|
this.isDefaultModal = false;
|
||||||
}
|
}
|
||||||
|
@ -280,6 +280,7 @@ export default {
|
|||||||
fieldLength (field) {
|
fieldLength (field) {
|
||||||
if ([...BLOB, ...LONG_TEXT].includes(field.type)) return null;
|
if ([...BLOB, ...LONG_TEXT].includes(field.type)) return null;
|
||||||
else if (TEXT.includes(field.type)) return field.charLength;
|
else if (TEXT.includes(field.type)) return field.charLength;
|
||||||
|
else if (field.numScale) return `${field.numPrecision}, ${field.numScale}`;
|
||||||
return field.length;
|
return field.length;
|
||||||
},
|
},
|
||||||
keyName (key) {
|
keyName (key) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user