UNPKG

@mikro-orm/postgresql

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

565 lines (564 loc) • 29.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostgreSqlSchemaHelper = void 0; const core_1 = require("@mikro-orm/core"); const knex_1 = require("@mikro-orm/knex"); class PostgreSqlSchemaHelper extends knex_1.SchemaHelper { static DEFAULT_VALUES = { 'now()': ['now()', 'current_timestamp'], 'current_timestamp(?)': ['current_timestamp(?)'], "('now'::text)::timestamp(?) with time zone": ['current_timestamp(?)'], "('now'::text)::timestamp(?) without time zone": ['current_timestamp(?)'], 'null::character varying': ['null'], 'null::timestamp with time zone': ['null'], 'null::timestamp without time zone': ['null'], }; getSchemaBeginning(charset, disableForeignKeys) { if (disableForeignKeys) { return `set names '${charset}';\n${this.disableForeignKeysSQL()}\n\n`; } return `set names '${charset}';\n\n`; } getCreateDatabaseSQL(name) { return `create database ${name}`; } getListTablesSQL() { return `select table_name, table_schema as schema_name, ` + `(select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment ` + `from information_schema.tables ` + `where ${this.getIgnoredNamespacesConditionSQL('table_schema')} ` + `and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' ` + `and table_name not in (select inhrelid::regclass::text from pg_inherits) ` + `order by table_name`; } async getNamespaces(connection) { const sql = `select schema_name from information_schema.schemata ` + `where ${this.getIgnoredNamespacesConditionSQL()} ` + `order by schema_name`; const res = await connection.execute(sql); return res.map(row => row.schema_name); } getIgnoredNamespacesConditionSQL(column = 'schema_name') { /* istanbul ignore next */ const ignored = [ 'information_schema', 'tiger', 'topology', ...this.platform.getConfig().get('schemaGenerator').ignoreSchema ?? [], ].map(s => this.platform.quoteValue(s)).join(', '); const ignoredPrefixes = [ 'pg_', 'crdb_', '_timescaledb_', ].map(p => `"${column}" not like '${p}%'`).join(' and '); return `${ignoredPrefixes} and "${column}" not in (${ignored})`; } async loadInformationSchema(schema, connection, tables, schemas) { schemas ??= tables.length === 0 ? [schema.name] : tables.map(t => t.schema_name ?? schema.name); const nativeEnums = await this.getNativeEnumDefinitions(connection, schemas); schema.setNativeEnums(nativeEnums); if (tables.length === 0) { return; } const tablesBySchema = this.getTablesGroupedBySchemas(tables); const columns = await this.getAllColumns(connection, tablesBySchema, nativeEnums); const indexes = await this.getAllIndexes(connection, tables); const checks = await this.getAllChecks(connection, tablesBySchema); const fks = await this.getAllForeignKeys(connection, tablesBySchema); for (const t of tables) { const key = this.getTableKey(t); const table = schema.addTable(t.table_name, t.schema_name, t.table_comment); const pks = await this.getPrimaryKeys(connection, indexes[key], table.name, table.schema); const enums = await this.getEnumDefinitions(connection, checks[key] ?? []); table.init(columns[key], indexes[key], checks[key], pks, fks[key], enums); } } async getAllIndexes(connection, tables) { const sql = this.getIndexesSQL(tables); const unquote = (str) => str.replace(/['"`]/g, ''); const allIndexes = await connection.execute(sql); const ret = {}; for (const index of allIndexes) { const key = this.getTableKey(index); const indexDef = { columnNames: index.index_def.map((name) => unquote(name)), composite: index.index_def.length > 1, // JSON columns can have unique index but not unique constraint, and we need to distinguish those, so we can properly drop them constraint: index.contype === 'u', keyName: index.constraint_name, unique: index.unique, primary: index.primary, }; if (index.condeferrable) { indexDef.deferMode = index.condeferred ? core_1.DeferMode.INITIALLY_DEFERRED : core_1.DeferMode.INITIALLY_IMMEDIATE; } if (index.index_def.some((col) => col.match(/[(): ,"'`]/)) || index.expression?.match(/ where /i)) { indexDef.expression = index.expression; } if (index.deferrable) { indexDef.deferMode = index.initially_deferred ? core_1.DeferMode.INITIALLY_DEFERRED : core_1.DeferMode.INITIALLY_IMMEDIATE; } ret[key] ??= []; ret[key].push(indexDef); } return ret; } async getAllColumns(connection, tablesBySchemas, nativeEnums) { const sql = `select table_schema as schema_name, table_name, column_name, column_default, is_nullable, udt_name, udt_schema, coalesce(datetime_precision, character_maximum_length) length, atttypmod custom_length, numeric_precision, numeric_scale, data_type, is_identity, identity_generation, generation_expression, pg_catalog.col_description(pgc.oid, cols.ordinal_position::int) column_comment from information_schema.columns cols join pg_class pgc on cols.table_name = pgc.relname join pg_attribute pga on pgc.oid = pga.attrelid and cols.column_name = pga.attname where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(table_schema = ${this.platform.quoteValue(schema)} and table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}))`).join(' or ')}) order by ordinal_position`; const allColumns = await connection.execute(sql); const str = (val) => val != null ? '' + val : val; const ret = {}; for (const col of allColumns) { const mappedType = connection.getPlatform().getMappedType(col.data_type); const increments = (col.column_default?.includes('nextval') || col.is_identity === 'YES') && connection.getPlatform().isNumericColumn(mappedType); const key = this.getTableKey(col); ret[key] ??= []; let type = col.data_type.toLowerCase() === 'array' ? col.udt_name.replace(/^_(.*)$/, '$1[]') : col.udt_name; if (col.data_type === 'USER-DEFINED' && col.udt_schema && col.udt_schema !== this.platform.getDefaultSchemaName()) { type = `${col.udt_schema}.${type}`; } if (type === 'bpchar') { type = 'char'; } if (type === 'vector' && col.length == null && col.custom_length != null && col.custom_length !== -1) { col.length = col.custom_length; } if (col.length != null && !type.endsWith(`(${col.length})`) && !['text', 'date'].includes(type)) { type += `(${col.length})`; } if (type === 'numeric' && col.numeric_precision != null && col.numeric_scale != null) { type += `(${col.numeric_precision},${col.numeric_scale})`; } const length = this.inferLengthFromColumnType(type) === -1 ? -1 : col.length; const column = { name: col.column_name, type, mappedType, length, precision: col.numeric_precision, scale: col.numeric_scale, nullable: col.is_nullable === 'YES', default: str(this.normalizeDefaultValue(col.column_default, col.length)), unsigned: increments, autoincrement: increments, generated: col.is_identity === 'YES' ? (col.identity_generation === 'BY DEFAULT' ? 'by default as identity' : 'identity') : (col.generation_expression ? col.generation_expression + ' stored' : undefined), comment: col.column_comment, }; if (nativeEnums?.[column.type]) { column.mappedType = core_1.Type.getType(core_1.EnumType); column.nativeEnumName = column.type; column.enumItems = nativeEnums[column.type]?.items; } ret[key].push(column); } return ret; } async getAllChecks(connection, tablesBySchemas) { const sql = this.getChecksSQL(tablesBySchemas); const allChecks = await connection.execute(sql); const ret = {}; for (const check of allChecks) { const key = this.getTableKey(check); ret[key] ??= []; const m = check.expression.match(/^check \(\((.*)\)\)$/i); const def = m?.[1].replace(/\((.*?)\)::\w+/g, '$1'); ret[key].push({ name: check.name, columnName: check.column_name, definition: check.expression, expression: def, }); } return ret; } async getAllForeignKeys(connection, tablesBySchemas) { const sql = `select nsp1.nspname schema_name, cls1.relname table_name, nsp2.nspname referenced_schema_name, cls2.relname referenced_table_name, a.attname column_name, af.attname referenced_column_name, conname constraint_name, confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred, pg_get_constraintdef(con.oid) as constraint_def from pg_attribute a join pg_constraint con on con.conrelid = a.attrelid AND a.attnum = ANY (con.conkey) join pg_attribute af on af.attnum = con.confkey[array_position(con.conkey,a.attnum)] AND af.attrelid = con.confrelid join pg_namespace nsp1 on nsp1.oid = con.connamespace join pg_class cls1 on cls1.oid = con.conrelid join pg_class cls2 on cls2.oid = confrelid join pg_namespace nsp2 on nsp2.oid = cls2.relnamespace where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(cls1.relname in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and nsp1.nspname = ${this.platform.quoteValue(schema)})`).join(' or ')}) and confrelid > 0 order by nsp1.nspname, cls1.relname, constraint_name, ord`; const allFks = await connection.execute(sql); const ret = {}; function mapReferentialIntegrity(value, def) { const match = ['n', 'd'].includes(value) && def.match(/ON DELETE (SET (NULL|DEFAULT) \(.*?\))/); if (match) { return match[1]; } /* istanbul ignore next */ switch (value) { case 'r': return 'RESTRICT'; case 'c': return 'CASCADE'; case 'n': return 'SET NULL'; case 'd': return 'SET DEFAULT'; case 'a': default: return 'NO ACTION'; } } for (const fk of allFks) { fk.update_rule = mapReferentialIntegrity(fk.update_rule, fk.constraint_def); fk.delete_rule = mapReferentialIntegrity(fk.delete_rule, fk.constraint_def); if (fk.condeferrable) { fk.defer_mode = fk.condeferred ? core_1.DeferMode.INITIALLY_DEFERRED : core_1.DeferMode.INITIALLY_IMMEDIATE; } const key = this.getTableKey(fk); ret[key] ??= []; ret[key].push(fk); } Object.keys(ret).forEach(key => { const [schemaName, tableName] = key.split('.'); ret[key] = this.mapForeignKeys(ret[key], tableName, schemaName); }); return ret; } async getNativeEnumDefinitions(connection, schemas) { const uniqueSchemas = core_1.Utils.unique(schemas); const res = await connection.execute(`select t.typname as enum_name, n.nspname as schema_name, array_agg(e.enumlabel order by e.enumsortorder) as enum_value from pg_type t join pg_enum e on t.oid = e.enumtypid join pg_catalog.pg_namespace n on n.oid = t.typnamespace where n.nspname in (${Array(uniqueSchemas.length).fill('?').join(', ')}) group by t.typname, n.nspname`, uniqueSchemas); return res.reduce((o, row) => { let name = row.enum_name; if (row.schema_name && row.schema_name !== this.platform.getDefaultSchemaName()) { name = row.schema_name + '.' + name; } let items = row.enum_value; if (!Array.isArray(items)) { items = this.platform.unmarshallArray(row.enum_value); } o[name] = { name: row.enum_name, schema: row.schema_name, items, }; return o; }, {}); } getCreateNativeEnumSQL(name, values, schema) { if (schema && schema !== this.platform.getDefaultSchemaName()) { name = schema + '.' + name; } return `create type ${this.platform.quoteIdentifier(name)} as enum (${values.map(value => this.platform.quoteValue(value)).join(', ')})`; } getDropNativeEnumSQL(name, schema) { if (schema && schema !== this.platform.getDefaultSchemaName()) { name = schema + '.' + name; } return `drop type ${this.platform.quoteIdentifier(name)}`; } getAlterNativeEnumSQL(name, schema, value, items, oldItems) { if (schema && schema !== this.platform.getDefaultSchemaName()) { name = schema + '.' + name; } let suffix = ''; if (items && value && oldItems) { const position = items.indexOf(value); if (position > 0) { suffix = ` after ${this.platform.quoteValue(items[position - 1])}`; } else if (items.length > 1 && oldItems.length > 0) { suffix = ` before ${this.platform.quoteValue(oldItems[0])}`; } } return `alter type ${this.platform.quoteIdentifier(name)} add value if not exists ${this.platform.quoteValue(value)}${suffix}`; } async getEnumDefinitions(connection, checks, tableName, schemaName) { const found = []; const enums = checks.reduce((o, item, index) => { // check constraints are defined as one of: // `CHECK ((type = ANY (ARRAY['local'::text, 'global'::text])))` // `CHECK (("columnName" = ANY (ARRAY['local'::text, 'global'::text])))` // `CHECK (((enum_test)::text = ANY ((ARRAY['a'::character varying, 'b'::character varying, 'c'::character varying])::text[])))` // `CHECK ((("enumTest")::text = ANY ((ARRAY['a'::character varying, 'b'::character varying, 'c'::character varying])::text[])))` // `CHECK ((type = 'a'::text))` const m1 = item.definition?.match(/check \(\(\("?(\w+)"?\)::/i) || item.definition?.match(/check \(\("?(\w+)"? = /i); const m2 = item.definition?.match(/\(array\[(.*)]\)/i) || item.definition?.match(/ = (.*)\)/i); if (item.columnName && m1 && m2) { const m3 = m2[1].match(/('[^']*'::text)/g); let items; /* istanbul ignore else */ if (m3) { items = m3.map((item) => item.trim().match(/^\(?'(.*)'/)?.[1]); } else { items = m2[1].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)?.[1]); } items = items.filter(item => item !== undefined); if (items.length > 0) { o[item.columnName] = items; found.push(index); } } return o; }, {}); found.reverse().forEach(index => checks.splice(index, 1)); return enums; } createTableColumn(table, column, fromTable, changedProperties, alter) { const pk = fromTable.getPrimaryKey(); const primaryKey = column.primary && !changedProperties && !this.hasNonDefaultPrimaryKeyName(fromTable); if (column.autoincrement && !column.generated && !pk?.composite && !changedProperties) { if (column.mappedType instanceof core_1.BigIntType) { return table.bigIncrements(column.name, { primaryKey }); } return table.increments(column.name, { primaryKey }); } if (column.nativeEnumName && column.enumItems) { let schemaPrefix = fromTable.schema && fromTable.schema !== this.platform.getDefaultSchemaName() ? `${fromTable.schema}.` : ''; let enumName = column.nativeEnumName; if (enumName.includes('.')) { const [schemaName, ...parts] = enumName.split('.'); enumName = parts.join('.'); schemaPrefix = schemaName + '.'; } const type = this.platform.quoteIdentifier(schemaPrefix + enumName); if (column.type.endsWith('[]')) { return table.specificType(column.name, type + '[]'); } return table.specificType(column.name, type); } if (changedProperties && column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) { const checkName = this.platform.getConfig().getNamingStrategy().indexName(fromTable.name, [column.name], 'check'); if (changedProperties.has('enumItems') || (!column.nativeEnumName && fromTable.getColumn(column.name)?.nativeEnumName)) { table.check(`${this.platform.quoteIdentifier(column.name)} in ('${(column.enumItems.join("', '"))}')`, {}, this.platform.quoteIdentifier(checkName)); } if (changedProperties.has('type')) { return table.specificType(column.name, column.type); } if (changedProperties.has('default')) { return column.default ? table.specificType(column.name, column.type).defaultTo(column.default) : table.specificType(column.name, column.type); } if (changedProperties.has('nullable')) { return column.nullable ? table.specificType(column.name, column.type).nullable() : table.specificType(column.name, column.type).notNullable(); } return undefined; } if (column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) { return table.enum(column.name, column.enumItems); } // serial is just a pseudo type, it cannot be used for altering /* istanbul ignore next */ if (changedProperties && column.type.includes('serial')) { column.type = column.type.replace('serial', 'int'); } let columnType = column.type; if (column.generated === 'by default as identity') { columnType += ` generated ${column.generated}`; } else if (column.generated) { columnType += ` generated always as ${column.generated}`; } return table.specificType(column.name, columnType); } configureColumn(column, col, knex, changedProperties) { const guard = (key) => !changedProperties || changedProperties.has(key); core_1.Utils.runIfNotEmpty(() => col.nullable(), column.nullable && guard('nullable')); core_1.Utils.runIfNotEmpty(() => col.notNullable(), !column.nullable && guard('nullable')); core_1.Utils.runIfNotEmpty(() => col.unsigned(), column.unsigned && guard('unsigned')); core_1.Utils.runIfNotEmpty(() => col.comment(column.comment), column.comment && !changedProperties); this.configureColumnDefault(column, col, knex, changedProperties); return col; } getPreAlterTable(tableDiff, safe) { const ret = []; const parts = tableDiff.name.split('.'); const tableName = parts.pop(); const schemaName = parts.pop(); /* istanbul ignore next */ const name = (schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName; const quotedName = this.platform.quoteIdentifier(name); // detect that the column was an enum before and remove the check constraint in such case here const changedEnums = Object.values(tableDiff.changedColumns).filter(col => col.fromColumn.mappedType instanceof core_1.EnumType); for (const col of changedEnums) { if (!col.fromColumn.nativeEnumName && col.column.nativeEnumName && col.fromColumn.default) { ret.push(`alter table ${quotedName} alter column "${col.column.name}" drop default`); } if (col.fromColumn.nativeEnumName && !col.column.nativeEnumName && col.fromColumn.default) { ret.push(`alter table ${quotedName} alter column "${col.column.name}" drop default`); } if (!col.fromColumn.nativeEnumName) { if (col.changedProperties.has('enumItems') || col.column.nativeEnumName) { const constraintName = `${tableName}_${col.column.name}_check`; ret.push(`alter table ${quotedName} drop constraint if exists "${constraintName}"`); } } } // changing uuid column type requires to cast it to text first const uuids = Object.values(tableDiff.changedColumns).filter(col => col.changedProperties.has('type') && col.fromColumn.type === 'uuid'); for (const col of uuids) { ret.push(`alter table ${quotedName} alter column "${col.column.name}" type text using ("${col.column.name}"::text)`); } return ret.join(';\n'); } getPostAlterTable(tableDiff, safe) { const ret = []; const parts = tableDiff.name.split('.'); const tableName = parts.pop(); const schemaName = parts.pop(); /* istanbul ignore next */ const name = (schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName; const quotedName = this.platform.quoteIdentifier(name); // detect that the column was an enum before and remove the check constraint in such case here const changedEnums = Object.values(tableDiff.changedColumns).filter(col => col.fromColumn.mappedType instanceof core_1.EnumType); for (const col of changedEnums) { if (!col.fromColumn.nativeEnumName && col.column.nativeEnumName && col.column.default) { ret.push(`alter table ${quotedName} alter column "${col.column.name}" set default ${col.column.default}`); } if (col.fromColumn.nativeEnumName && !col.column.nativeEnumName && col.column.default) { ret.push(`alter table ${quotedName} alter column "${col.column.name}" set default ${col.column.default}`); } } return ret.join(';\n'); } getAlterColumnAutoincrement(tableName, column, schemaName) { const ret = []; const quoted = (val) => this.platform.quoteIdentifier(val); /* istanbul ignore next */ const name = (schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName; /* istanbul ignore else */ if (column.autoincrement) { const seqName = this.platform.getIndexName(tableName, [column.name], 'sequence'); ret.push(`create sequence if not exists ${quoted(seqName)}`); ret.push(`select setval('${seqName}', (select max(${quoted(column.name)}) from ${quoted(name)}))`); ret.push(`alter table ${quoted(name)} alter column ${quoted(column.name)} set default nextval('${seqName}')`); } else if (column.default == null) { ret.push(`alter table ${quoted(name)} alter column ${quoted(column.name)} drop default`); } return ret.join(';\n'); } getChangeColumnCommentSQL(tableName, to, schemaName) { const name = this.platform.quoteIdentifier((schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName); const value = to.comment ? this.platform.quoteValue(to.comment) : 'null'; return `comment on column ${name}."${to.name}" is ${value}`; } normalizeDefaultValue(defaultValue, length) { if (!defaultValue || typeof defaultValue !== 'string') { return super.normalizeDefaultValue(defaultValue, length, PostgreSqlSchemaHelper.DEFAULT_VALUES); } const match = defaultValue.match(/^'(.*)'::(.*)$/); if (match) { if (match[2] === 'integer') { return +match[1]; } return `'${match[1]}'`; } return super.normalizeDefaultValue(defaultValue, length, PostgreSqlSchemaHelper.DEFAULT_VALUES); } getDatabaseExistsSQL(name) { return `select 1 from pg_database where datname = '${name}'`; } getDatabaseNotExistsError(dbName) { return `database "${dbName}" does not exist`; } getManagementDbName() { return this.platform.getConfig().get('schemaGenerator', {}).managementDbName ?? 'postgres'; } disableForeignKeysSQL() { return `set session_replication_role = 'replica';`; } enableForeignKeysSQL() { return `set session_replication_role = 'origin';`; } getRenameIndexSQL(tableName, index, oldIndexName) { oldIndexName = this.platform.quoteIdentifier(oldIndexName); const keyName = this.platform.quoteIdentifier(index.keyName); return `alter index ${oldIndexName} rename to ${keyName}`; } getIndexesSQL(tables) { return `select indrelid::regclass as table_name, ns.nspname as schema_name, relname as constraint_name, idx.indisunique as unique, idx.indisprimary as primary, contype, condeferrable, condeferred, array( select pg_get_indexdef(idx.indexrelid, k + 1, true) from generate_subscripts(idx.indkey, 1) as k order by k ) as index_def, pg_get_indexdef(idx.indexrelid) as expression, c.condeferrable as deferrable, c.condeferred as initially_deferred from pg_index idx join pg_class as i on i.oid = idx.indexrelid join pg_namespace as ns on i.relnamespace = ns.oid left join pg_constraint as c on c.conname = i.relname where indrelid in (${tables.map(t => `${this.platform.quoteValue(`${this.platform.quoteIdentifier(t.schema_name ?? this.platform.getDefaultSchemaName() ?? '')}.${this.platform.quoteIdentifier(t.table_name)}`)}::regclass`).join(', ')}) order by relname`; } getChecksSQL(tablesBySchemas) { return `select ccu.table_name as table_name, ccu.table_schema as schema_name, pgc.conname as name, conrelid::regclass as table_from, ccu.column_name as column_name, pg_get_constraintdef(pgc.oid) as expression from pg_constraint pgc join pg_namespace nsp on nsp.oid = pgc.connamespace join pg_class cls on pgc.conrelid = cls.oid join information_schema.constraint_column_usage ccu on pgc.conname = ccu.constraint_name and nsp.nspname = ccu.constraint_schema where contype = 'c' and (${[...tablesBySchemas.entries()].map(([schema, tables]) => `ccu.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ccu.table_schema = ${this.platform.quoteValue(schema ?? this.platform.getDefaultSchemaName() ?? '')}`).join(' or ')}) order by pgc.conname`; } /* istanbul ignore next */ async getChecks(connection, tableName, schemaName, columns) { const res = await this.getAllChecks(connection, new Map([[schemaName, [{ table_name: tableName, schema_name: schemaName }]]])); return res[tableName]; } /* istanbul ignore next */ async getColumns(connection, tableName, schemaName) { const res = await this.getAllColumns(connection, new Map([[schemaName, [{ table_name: tableName, schema_name: schemaName }]]])); return res[tableName]; } /* istanbul ignore next */ async getIndexes(connection, tableName, schemaName) { const res = await this.getAllIndexes(connection, [{ table_name: tableName, schema_name: schemaName }]); return res[tableName]; } inferLengthFromColumnType(type) { const match = type.match(/^(\w+(?:\s+\w+)*)\s*(?:\(\s*(\d+)\s*\)|$)/); if (!match) { return; } if (!match[2]) { switch (match[1]) { case 'character varying': case 'varchar': case 'bpchar': case 'char': case 'character': return -1; case 'interval': case 'time': case 'timestamp': case 'timestamptz': return this.platform.getDefaultDateTimeLength(); } return; } return +match[2]; } } exports.PostgreSqlSchemaHelper = PostgreSqlSchemaHelper;