Sign In

@mikro-orm/sql

Package Overview
Dependencies
Maintainers
1
Versions
805
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mikro-orm/sql - npm Package Compare versions

Comparing version
7.2.0-dev.6
to
7.2.0-dev.7
+4
-0
dialects/postgresql/PostgreSqlSchemaHelper.d.ts

@@ -72,2 +72,4 @@ import { type Dictionary, type Transaction } from '@mikro-orm/core';

dropTrigger(table: DatabaseTable, trigger: SqlTriggerDef): string;
/** Flattens `;\n` inside the dollar-quoted blocks of a raw DDL expression, which are not statement boundaries. */
private flattenDollarQuotedBodies;
createRoutine(routine: SqlRoutineDef): string;

@@ -135,2 +137,4 @@ dropRoutine(routine: SqlRoutineDef): string;

protected getIndexColumns(index: IndexDef): string;
/** Non-default index access methods (gin, gist, brin, hash, ...), normalized to lower case. */
getIndexAccessMethod(index: IndexDef): string;
/**

@@ -137,0 +141,0 @@ * PostgreSQL-specific index options like fill factor.

+3
-3
{
"name": "@mikro-orm/sql",
"version": "7.2.0-dev.6",
"version": "7.2.0-dev.7",
"description": "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.",

@@ -50,3 +50,3 @@ "keywords": [

"dependencies": {
"kysely": "0.29.4"
"kysely": "0.29.5"
},

@@ -57,3 +57,3 @@ "devDependencies": {

"peerDependencies": {
"@mikro-orm/core": "7.2.0-dev.6"
"@mikro-orm/core": "7.2.0-dev.7"
},

@@ -60,0 +60,0 @@ "engines": {

@@ -1033,4 +1033,8 @@ import { DecimalType, EntitySchema, isRaw, ReferenceKind, t, Type, UnknownType, Utils, } from '@mikro-orm/core';

let defaultValue = c.default ?? null;
if (defaultValue != null && c.mappedType instanceof DecimalType && Number.isFinite(+defaultValue)) {
defaultValue = this.#platform.formatDecimal(defaultValue, c.scale).toString();
if (defaultValue != null && c.mappedType instanceof DecimalType) {
// string defaults like `default: '0.00'` are quoted in metadata, so strip the quotes first
const unquoted = defaultValue.replace(/^'(.*)'$/, '$1');
if (Number.isFinite(+unquoted)) {
defaultValue = this.#platform.formatDecimal(unquoted, c.scale).toString();
}
}

@@ -1037,0 +1041,0 @@ const normalized = {

@@ -92,2 +92,3 @@ import { type Dictionary } from '@mikro-orm/core';

parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
private parseDecimalDefault;
hasSameDefaultValue(from: Column, to: Column): boolean;

@@ -94,0 +95,0 @@ private mapColumnToProperty;

@@ -823,2 +823,6 @@ import { ArrayType, BooleanType, DateTimeType, DecimalType, inspect, JsonType, parseJsonSafe, Utils, } from '@mikro-orm/core';

}
// Compare the index access method (e.g. `using gin` on PostgreSQL); unset means the platform default
if (this.#helper.getIndexAccessMethod(index1) !== this.#helper.getIndexAccessMethod(index2)) {
return false;
}
// Compare WHERE predicate of partial indexes structurally (whitespace/quoting/casing

@@ -993,2 +997,6 @@ // are normalized via the same helper used for check constraints).

}
parseDecimalDefault(defaultValue) {
const value = +('' + defaultValue).replace(/^'(.+)'$/, '$1');
return Number.isFinite(value) ? value : null;
}
hasSameDefaultValue(from, to) {

@@ -1019,6 +1027,11 @@ if (from.default == null ||

}
// mysql stores decimal defaults padded to scale (`0` → `0.00`); compare numerically so the
// entity-side raw literal and the introspected padded form don't churn the no-op migration
if (to.mappedType instanceof DecimalType && Number.isFinite(+from.default) && Number.isFinite(+to.default)) {
return (this.#platform.formatDecimal(from.default, to.scale) === this.#platform.formatDecimal(to.default, to.scale));
// mysql pads decimal defaults to scale (`0` → `0.00`) and postgres reports them unquoted
// while metadata keeps them quoted; compare numerically so neither churns a no-op migration
if (to.mappedType instanceof DecimalType) {
const defaultValueFrom = this.parseDecimalDefault(from.default);
const defaultValueTo = this.parseDecimalDefault(to.default);
if (defaultValueFrom != null && defaultValueTo != null) {
return (this.#platform.formatDecimal(defaultValueFrom, to.scale) ===
this.#platform.formatDecimal(defaultValueTo, to.scale));
}
}

@@ -1025,0 +1038,0 @@ if (from.default && to.default) {

@@ -74,2 +74,9 @@ import { type Connection, type Dictionary, type Options, type Transaction, type RawQueryFragment } from '@mikro-orm/core';

/**
* Normalized index access method (e.g. `gin` on PostgreSQL), empty string when the
* platform default applies. Used for both DDL emission and index diffing.
*/
getIndexAccessMethod(_index: IndexDef): string;
/** Emits the access method between the table name and the column list (e.g. ` using gin`). */
protected getIndexAccessMethodClause(index: IndexDef): string;
/**
* Default emits ` where <predicate>` for partial indexes. Only Oracle overrides this to

@@ -76,0 +83,0 @@ * return `''` (it emulates partials via CASE-WHEN columns). MySQL sidesteps the whole path

@@ -170,3 +170,4 @@ import { isRaw, Utils, } from '@mikro-orm/core';

const defer = index.deferMode ? ` deferrable initially ${index.deferMode}` : '';
let sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}`;
const using = this.getIndexAccessMethodClause(index);
let sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}${using}`;
if (index.unique && index.constraint) {

@@ -177,3 +178,3 @@ sql = `alter table ${tableName} add constraint ${keyName} unique`;

// JSON columns can have unique index but not unique constraint, and we need to distinguish those, so we can properly drop them
sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}`;
sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}${using}`;
const columns = this.platform.getJsonIndexDefinition(index);

@@ -198,2 +199,14 @@ return `${sql} (${columns.join(', ')})${this.getCreateIndexSuffix(index)}${this.getIndexWhereClause(index)}${defer}`;

/**
* Normalized index access method (e.g. `gin` on PostgreSQL), empty string when the
* platform default applies. Used for both DDL emission and index diffing.
*/
getIndexAccessMethod(_index) {
return '';
}
/** Emits the access method between the table name and the column list (e.g. ` using gin`). */
getIndexAccessMethodClause(index) {
const method = this.getIndexAccessMethod(index);
return method ? ` using ${method}` : '';
}
/**
* Default emits ` where <predicate>` for partial indexes. Only Oracle overrides this to

@@ -200,0 +213,0 @@ * return `''` (it emulates partials via CASE-WHEN columns). MySQL sidesteps the whole path

@@ -311,18 +311,2 @@ import { CommitOrderCalculator, TableNotFoundException, Utils, } from '@mikro-orm/core';

}
if (this.helper.supportsSchemaConstraints()) {
for (const newTable of Object.values(schemaDiff.newTables)) {
const sql = [];
if (this.options.createForeignKeyConstraints) {
const fks = Object.values(newTable.getForeignKeys()).map(fk => this.helper.createForeignKey(newTable, fk));
this.append(sql, fks);
}
for (const check of newTable.getChecks()) {
this.append(sql, this.helper.createCheck(newTable, check));
}
for (const trigger of newTable.getTriggers()) {
this.append(sql, this.helper.createTrigger(newTable, trigger));
}
this.append(ret, sql, true);
}
}
if (options.dropTables && !options.safe) {

@@ -357,2 +341,19 @@ for (const table of Object.values(schemaDiff.removedTables)) {

}
// after the alters, so a new table's FK can reference a unique constraint an existing table gains in the same diff
if (this.helper.supportsSchemaConstraints()) {
for (const newTable of Object.values(schemaDiff.newTables)) {
const sql = [];
if (this.options.createForeignKeyConstraints) {
const fks = Object.values(newTable.getForeignKeys()).map(fk => this.helper.createForeignKey(newTable, fk));
this.append(sql, fks);
}
for (const check of newTable.getChecks()) {
this.append(sql, this.helper.createCheck(newTable, check));
}
for (const trigger of newTable.getTriggers()) {
this.append(sql, this.helper.createTrigger(newTable, trigger));
}
this.append(ret, sql, true);
}
}
if (!options.safe && this.platform.supportsNativeEnums()) {

@@ -359,0 +360,0 @@ for (const removedNativeEnum of schemaDiff.removedNativeEnums) {

@@ -78,4 +78,3 @@ import { EntityManager, raw, Utils, } from '@mikro-orm/core';

const em = this.getContext(false);
options = { ...options };
em.prepareOptions(options);
options = em.prepareOptions(options);
const meta = em.getMetadata().find(entityName);

@@ -82,0 +81,0 @@ const fields = Utils.asArray(groupBy);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display