typeorm 0.3.13-dev.a868979 → 0.3.13-dev.de1228d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,7 @@ export class AbstractSqliteDriver {
63
63
  "date",
64
64
  "time",
65
65
  "datetime",
66
+ "json",
66
67
  ];
67
68
  /**
68
69
  * Returns type of upsert supported by driver if any
@@ -222,6 +223,9 @@ export class AbstractSqliteDriver {
222
223
  // TODO: think about `toUTC` conversion
223
224
  return DateUtils.mixedDateToUtcDatetimeString(value);
224
225
  }
226
+ else if (columnMetadata.type === "json") {
227
+ return JSON.stringify(value);
228
+ }
225
229
  else if (columnMetadata.type === "simple-array") {
226
230
  return DateUtils.simpleArrayToString(value);
227
231
  }
@@ -277,6 +281,9 @@ export class AbstractSqliteDriver {
277
281
  else if (columnMetadata.type === "time") {
278
282
  value = DateUtils.mixedTimeToString(value);
279
283
  }
284
+ else if (columnMetadata.type === "json") {
285
+ value = typeof value === "string" ? JSON.parse(value) : value;
286
+ }
280
287
  else if (columnMetadata.type === "simple-array") {
281
288
  value = DateUtils.stringToSimpleArray(value);
282
289
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqlite-abstract/AbstractSqliteDriver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAS5E,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAY5D;;GAEG;AACH,MAAM,OAAgB,oBAAoB;IA4MtC,4EAA4E;IAC5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,QAAQ;YACR,mBAAmB;YACnB,uBAAuB;YACvB,gCAAgC;YAChC,kDAAkD;YAClD,QAAQ;YACR,mBAAmB;YACnB,mBAAmB;YACnB,8BAA8B;YAC9B,qCAAqC;YACrC,uCAAuC;YACvC,oCAAoC;YACpC,8DAA8D;YAC9D,iBAAiB;YACjB,QAAQ;YACR,mBAAmB;YACnB,0BAA0B;YAC1B,mCAAmC;YACnC,sCAAsC;YACtC,QAAQ;YACR,IAAI;YAEJ,OAAO,eAAe,CAAA;QAC1B,CAAC,CAAC,CAAA;IACN,CAAC;IAED;;OAEG;IACH,uBAAuB;QACnB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,yBAAyB;QACrB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,6BAA6B;QACzB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,aAAqB,EAAE,KAAa;QAChD,4BAA4B;QAC5B,OAAO,GAAG,CAAA;QACV,8BAA8B;IAClC,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,wBAAwB;QAC9B,MAAM,IAAI,YAAY,CAClB,sFAAsF,CACzF,CAAA;IACL,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,wDAAwD;IAC5D,CAAC;CACJ","file":"AbstractSqliteDriver.js","sourcesContent":["import { Driver } from \"../Driver\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { DateUtils } from \"../../util/DateUtils\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { RdbmsSchemaBuilder } from \"../../schema-builder/RdbmsSchemaBuilder\"\nimport { CteCapabilities } from \"../types/CteCapabilities\"\nimport { MappedColumnTypes } from \"../types/MappedColumnTypes\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataTypeDefaults } from \"../types/DataTypeDefaults\"\nimport { TableColumn } from \"../../schema-builder/table/TableColumn\"\nimport { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ApplyValueTransformers } from \"../../util/ApplyValueTransformers\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { DriverUtils } from \"../DriverUtils\"\nimport { TypeORMError } from \"../../error\"\nimport { Table } from \"../../schema-builder/table/Table\"\nimport { View } from \"../../schema-builder/view/View\"\nimport { TableForeignKey } from \"../../schema-builder/table/TableForeignKey\"\nimport { InstanceChecker } from \"../../util/InstanceChecker\"\nimport { UpsertType } from \"../types/UpsertType\"\n\ntype DatabasesMap = Record<\n string,\n {\n attachFilepathAbsolute: string\n attachFilepathRelative: string\n attachHandle: string\n }\n>\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport abstract class AbstractSqliteDriver implements Driver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by driver.\n */\n connection: DataSource\n\n /**\n * Sqlite has a single QueryRunner because it works on a single database connection.\n */\n queryRunner?: QueryRunner\n\n /**\n * Real database connection with sqlite database.\n */\n databaseConnection: any\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: BaseDataSourceOptions\n\n /**\n * Master database used to perform all write queries.\n */\n database?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean = false\n\n /**\n * SQLite underlying library.\n */\n sqlite: any\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport = true\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport: \"simple\" | \"nested\" | \"none\" = \"nested\"\n\n /**\n * Gets list of supported column data types by a driver.\n *\n * @see https://www.tutorialspoint.com/sqlite/sqlite_data_types.htm\n * @see https://sqlite.org/datatype3.html\n */\n supportedDataTypes: ColumnType[] = [\n \"int\",\n \"integer\",\n \"tinyint\",\n \"smallint\",\n \"mediumint\",\n \"bigint\",\n \"unsigned big int\",\n \"int2\",\n \"int8\",\n \"integer\",\n \"character\",\n \"varchar\",\n \"varying character\",\n \"nchar\",\n \"native character\",\n \"nvarchar\",\n \"text\",\n \"clob\",\n \"text\",\n \"blob\",\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n \"boolean\",\n \"date\",\n \"time\",\n \"datetime\",\n ]\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[] = [\"on-conflict-do-update\"]\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[] = [\n \"character\",\n \"varchar\",\n \"varying character\",\n \"nchar\",\n \"native character\",\n \"nvarchar\",\n \"text\",\n \"blob\",\n \"clob\",\n ]\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[] = [\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n \"date\",\n \"time\",\n \"datetime\",\n ]\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[] = [\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n ]\n\n /**\n * Orm has special columns and we need to know what database column types should be for those types.\n * Column types are driver dependant.\n */\n mappedDataTypes: MappedColumnTypes = {\n createDate: \"datetime\",\n createDateDefault: \"datetime('now')\",\n updateDate: \"datetime\",\n updateDateDefault: \"datetime('now')\",\n deleteDate: \"datetime\",\n deleteDateNullable: true,\n version: \"integer\",\n treeLevel: \"integer\",\n migrationId: \"integer\",\n migrationName: \"varchar\",\n migrationTimestamp: \"bigint\",\n cacheId: \"int\",\n cacheIdentifier: \"varchar\",\n cacheTime: \"bigint\",\n cacheDuration: \"int\",\n cacheQuery: \"text\",\n cacheResult: \"text\",\n metadataType: \"varchar\",\n metadataDatabase: \"varchar\",\n metadataSchema: \"varchar\",\n metadataTable: \"varchar\",\n metadataName: \"varchar\",\n metadataValue: \"text\",\n }\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * No documentation specifying a maximum length for identifiers could be found\n * for SQLite.\n */\n maxAliasLength?: number\n\n cteCapabilities: CteCapabilities = {\n enabled: true,\n requiresRecursiveHint: true,\n }\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Any attached databases (excepting default 'main')\n */\n attachedDatabases: DatabasesMap = {}\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n this.connection = connection\n this.options = connection.options as BaseDataSourceOptions\n\n this.database = DriverUtils.buildDriverOptions(this.options).database\n }\n\n // -------------------------------------------------------------------------\n // Public Abstract\n // -------------------------------------------------------------------------\n\n /**\n * Creates a query runner used to execute database queries.\n */\n abstract createQueryRunner(mode: ReplicationMode): QueryRunner\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Makes any action after connection (e.g. create extensions in Postgres driver).\n */\n afterConnect(): Promise<void> {\n return Promise.resolve()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.queryRunner = undefined\n this.databaseConnection.close((err: any) =>\n err ? fail(err) : ok(),\n )\n })\n }\n\n hasAttachedDatabases(): boolean {\n return !!Object.keys(this.attachedDatabases).length\n }\n\n getAttachedDatabaseHandleByRelativePath(path: string): string | undefined {\n return this.attachedDatabases?.[path]?.attachHandle\n }\n\n getAttachedDatabasePathRelativeByHandle(\n handle: string,\n ): string | undefined {\n return Object.values(this.attachedDatabases).find(\n ({ attachHandle }) => handle === attachHandle,\n )?.attachFilepathRelative\n }\n\n /**\n * Creates a schema builder used to build and sync a schema.\n */\n createSchemaBuilder() {\n return new RdbmsSchemaBuilder(this.connection)\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type and metadata.\n */\n preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformTo(\n columnMetadata.transformer,\n value,\n )\n\n if (value === null || value === undefined) return value\n\n if (\n columnMetadata.type === Boolean ||\n columnMetadata.type === \"boolean\"\n ) {\n return value === true ? 1 : 0\n } else if (columnMetadata.type === \"date\") {\n return DateUtils.mixedDateToDateString(value)\n } else if (columnMetadata.type === \"time\") {\n return DateUtils.mixedDateToTimeString(value)\n } else if (\n columnMetadata.type === \"datetime\" ||\n columnMetadata.type === Date\n ) {\n // to string conversation needs because SQLite stores date as integer number, when date came as Object\n // TODO: think about `toUTC` conversion\n return DateUtils.mixedDateToUtcDatetimeString(value)\n } else if (columnMetadata.type === \"simple-array\") {\n return DateUtils.simpleArrayToString(value)\n } else if (columnMetadata.type === \"simple-json\") {\n return DateUtils.simpleJsonToString(value)\n } else if (columnMetadata.type === \"simple-enum\") {\n return DateUtils.simpleEnumToString(value)\n }\n\n return value\n }\n\n /**\n * Prepares given value to a value to be hydrated, based on its column type or metadata.\n */\n prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any {\n if (value === null || value === undefined)\n return columnMetadata.transformer\n ? ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n : value\n\n if (\n columnMetadata.type === Boolean ||\n columnMetadata.type === \"boolean\"\n ) {\n value = value ? true : false\n } else if (\n columnMetadata.type === \"datetime\" ||\n columnMetadata.type === Date\n ) {\n /**\n * Fix date conversion issue\n *\n * If the format of the date string is \"2018-03-14 02:33:33.906\", Safari (and iOS WKWebView) will convert it to an invalid date object.\n * We need to modify the date string to \"2018-03-14T02:33:33.906Z\" and Safari will convert it correctly.\n *\n * ISO 8601\n * https://www.w3.org/TR/NOTE-datetime\n */\n if (value && typeof value === \"string\") {\n // There are various valid time string formats a sqlite time string might have:\n // https://www.sqlite.org/lang_datefunc.html\n // There are two separate fixes we may need to do:\n // 1) Add 'T' separator if space is used instead\n // 2) Add 'Z' UTC suffix if no timezone or offset specified\n\n if (/^\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d/.test(value)) {\n value = value.replace(\" \", \"T\")\n }\n if (\n /^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d(:\\d\\d(\\.\\d\\d\\d)?)?$/.test(\n value,\n )\n ) {\n value += \"Z\"\n }\n }\n\n value = DateUtils.normalizeHydratedDate(value)\n } else if (columnMetadata.type === \"date\") {\n value = DateUtils.mixedDateToDateString(value)\n } else if (columnMetadata.type === \"time\") {\n value = DateUtils.mixedTimeToString(value)\n } else if (columnMetadata.type === \"simple-array\") {\n value = DateUtils.stringToSimpleArray(value)\n } else if (columnMetadata.type === \"simple-json\") {\n value = DateUtils.stringToSimpleJson(value)\n } else if (columnMetadata.type === \"simple-enum\") {\n value = DateUtils.stringToSimpleEnum(value, columnMetadata)\n } else if (columnMetadata.type === Number) {\n // convert to number if number\n value = !isNaN(+value) ? parseInt(value) : value\n }\n\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n\n return value\n }\n\n /**\n * Replaces parameters in the given sql with special escaping character\n * and an array of parameter names to be passed to a query.\n */\n escapeQueryWithParameters(\n sql: string,\n parameters: ObjectLiteral,\n nativeParameters: ObjectLiteral,\n ): [string, any[]] {\n const escapedParameters: any[] = Object.keys(nativeParameters).map(\n (key) => {\n // Mapping boolean values to their numeric representation\n if (typeof nativeParameters[key] === \"boolean\") {\n return nativeParameters[key] === true ? 1 : 0\n }\n\n if (nativeParameters[key] instanceof Date) {\n return DateUtils.mixedDateToUtcDatetimeString(\n nativeParameters[key],\n )\n }\n\n return nativeParameters[key]\n },\n )\n\n if (!parameters || !Object.keys(parameters).length)\n return [sql, escapedParameters]\n\n sql = sql.replace(\n /:(\\.\\.\\.)?([A-Za-z0-9_.]+)/g,\n (full, isArray: string, key: string): string => {\n if (!parameters.hasOwnProperty(key)) {\n return full\n }\n\n let value: any = parameters[key]\n\n if (isArray) {\n return value\n .map((v: any) => {\n escapedParameters.push(v)\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n })\n .join(\", \")\n }\n\n if (typeof value === \"function\") {\n return value()\n } else if (typeof value === \"number\") {\n return String(value)\n }\n\n // Sqlite does not have a boolean data type so we have to transform\n // it to 1 or 0\n if (typeof value === \"boolean\") {\n escapedParameters.push(+value)\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n }\n\n if (value instanceof Date) {\n escapedParameters.push(\n DateUtils.mixedDateToUtcDatetimeString(value),\n )\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n }\n\n escapedParameters.push(value)\n return this.createParameter(key, escapedParameters.length - 1)\n },\n ) // todo: make replace only in value statements, otherwise problems\n return [sql, escapedParameters]\n }\n\n /**\n * Escapes a column name.\n */\n escape(columnName: string): string {\n return '\"' + columnName + '\"'\n }\n\n /**\n * Build full table name with database name, schema name and table name.\n * E.g. myDB.mySchema.myTable\n *\n * Returns only simple table name because all inherited drivers does not supports schema and database.\n */\n buildTableName(\n tableName: string,\n schema?: string,\n database?: string,\n ): string {\n return tableName\n }\n\n /**\n * Parse a target table name or other types and return a normalized table definition.\n */\n parseTableName(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): { database?: string; schema?: string; tableName: string } {\n const driverDatabase = this.database\n const driverSchema = undefined\n\n if (InstanceChecker.isTable(target) || InstanceChecker.isView(target)) {\n const parsed = this.parseTableName(\n target.schema\n ? `\"${target.schema}\".\"${target.name}\"`\n : target.name,\n )\n\n return {\n database: target.database || parsed.database || driverDatabase,\n schema: target.schema || parsed.schema || driverSchema,\n tableName: parsed.tableName,\n }\n }\n\n if (InstanceChecker.isTableForeignKey(target)) {\n const parsed = this.parseTableName(target.referencedTableName)\n\n return {\n database:\n target.referencedDatabase ||\n parsed.database ||\n driverDatabase,\n schema:\n target.referencedSchema || parsed.schema || driverSchema,\n tableName: parsed.tableName,\n }\n }\n\n if (InstanceChecker.isEntityMetadata(target)) {\n // EntityMetadata tableName is never a path\n\n return {\n database: target.database || driverDatabase,\n schema: target.schema || driverSchema,\n tableName: target.tableName,\n }\n }\n\n const parts = target.split(\".\")\n\n if (parts.length === 3) {\n return {\n database: parts[0] || driverDatabase,\n schema: parts[1] || driverSchema,\n tableName: parts[2],\n }\n } else if (parts.length === 2) {\n const database =\n this.getAttachedDatabasePathRelativeByHandle(parts[0]) ??\n driverDatabase\n return {\n database: database,\n schema: parts[0],\n tableName: parts[1],\n }\n } else {\n return {\n database: driverDatabase,\n schema: driverSchema,\n tableName: target,\n }\n }\n }\n\n /**\n * Creates a database type from a given column metadata.\n */\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n if (column.type === Number || column.type === \"int\") {\n return \"integer\"\n } else if (column.type === String) {\n return \"varchar\"\n } else if (column.type === Date) {\n return \"datetime\"\n } else if (column.type === Boolean) {\n return \"boolean\"\n } else if (column.type === \"uuid\") {\n return \"varchar\"\n } else if (column.type === \"simple-array\") {\n return \"text\"\n } else if (column.type === \"simple-json\") {\n return \"text\"\n } else if (column.type === \"simple-enum\") {\n return \"varchar\"\n } else {\n return (column.type as string) || \"\"\n }\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n normalizeDefault(columnMetadata: ColumnMetadata): string | undefined {\n const defaultValue = columnMetadata.default\n\n if (typeof defaultValue === \"number\") {\n return \"\" + defaultValue\n }\n\n if (typeof defaultValue === \"boolean\") {\n return defaultValue ? \"1\" : \"0\"\n }\n\n if (typeof defaultValue === \"function\") {\n return defaultValue()\n }\n\n if (typeof defaultValue === \"string\") {\n return `'${defaultValue}'`\n }\n\n if (defaultValue === null || defaultValue === undefined) {\n return undefined\n }\n\n return `${defaultValue}`\n }\n\n /**\n * Normalizes \"isUnique\" value of the column.\n */\n normalizeIsUnique(column: ColumnMetadata): boolean {\n return column.entityMetadata.uniques.some(\n (uq) => uq.columns.length === 1 && uq.columns[0] === column,\n )\n }\n\n /**\n * Calculates column length taking into account the default length values.\n */\n getColumnLength(column: ColumnMetadata): string {\n return column.length ? column.length.toString() : \"\"\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n createFullType(column: TableColumn): string {\n let type = column.type\n if (column.enum) {\n return \"varchar\"\n }\n if (column.length) {\n type += \"(\" + column.length + \")\"\n } else if (\n column.precision !== null &&\n column.precision !== undefined &&\n column.scale !== null &&\n column.scale !== undefined\n ) {\n type += \"(\" + column.precision + \",\" + column.scale + \")\"\n } else if (\n column.precision !== null &&\n column.precision !== undefined\n ) {\n type += \"(\" + column.precision + \")\"\n }\n\n if (column.isArray) type += \" array\"\n\n return type\n }\n\n /**\n * Obtains a new database connection to a master server.\n * Used for replication.\n * If replication is not setup then returns default connection's database connection.\n */\n obtainMasterConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Obtains a new database connection to a slave server.\n * Used for replication.\n * If replication is not setup then returns master (default) connection's database connection.\n */\n obtainSlaveConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(\n metadata: EntityMetadata,\n insertResult: any,\n entityIndex: number,\n entityNum: number,\n ) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n let value: any\n if (\n generatedColumn.generationStrategy === \"increment\" &&\n insertResult\n ) {\n // NOTE: When INSERT statement is successfully completed, the last inserted row ID is returned.\n // see also: SqliteQueryRunner.query()\n value = insertResult - entityNum + entityIndex + 1\n // } else if (generatedColumn.generationStrategy === \"uuid\") {\n // value = insertValue[generatedColumn.databaseName];\n }\n\n if (!value) return map\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(value),\n )\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n /**\n * Differentiate columns of this table and columns from the given column metadatas columns\n * and returns only changed.\n */\n findChangedColumns(\n tableColumns: TableColumn[],\n columnMetadatas: ColumnMetadata[],\n ): ColumnMetadata[] {\n return columnMetadatas.filter((columnMetadata) => {\n const tableColumn = tableColumns.find(\n (c) => c.name === columnMetadata.databaseName,\n )\n if (!tableColumn) return false // we don't need new columns, we only need exist and changed\n\n const isColumnChanged =\n tableColumn.name !== columnMetadata.databaseName ||\n tableColumn.type !== this.normalizeType(columnMetadata) ||\n tableColumn.length !== columnMetadata.length ||\n tableColumn.precision !== columnMetadata.precision ||\n tableColumn.scale !== columnMetadata.scale ||\n this.normalizeDefault(columnMetadata) !== tableColumn.default ||\n tableColumn.isPrimary !== columnMetadata.isPrimary ||\n tableColumn.isNullable !== columnMetadata.isNullable ||\n tableColumn.generatedType !== columnMetadata.generatedType ||\n tableColumn.asExpression !== columnMetadata.asExpression ||\n tableColumn.isUnique !==\n this.normalizeIsUnique(columnMetadata) ||\n (tableColumn.enum &&\n columnMetadata.enum &&\n !OrmUtils.isArraysEqual(\n tableColumn.enum,\n columnMetadata.enum.map((val) => val + \"\"),\n )) ||\n (columnMetadata.generationStrategy !== \"uuid\" &&\n tableColumn.isGenerated !== columnMetadata.isGenerated)\n\n // DEBUG SECTION\n // if (isColumnChanged) {\n // console.log(\"table:\", columnMetadata.entityMetadata.tableName)\n // console.log(\n // \"name:\",\n // tableColumn.name,\n // columnMetadata.databaseName,\n // )\n // console.log(\n // \"type:\",\n // tableColumn.type,\n // this.normalizeType(columnMetadata),\n // )\n // console.log(\n // \"length:\",\n // tableColumn.length,\n // columnMetadata.length,\n // )\n // console.log(\n // \"precision:\",\n // tableColumn.precision,\n // columnMetadata.precision,\n // )\n // console.log(\"scale:\", tableColumn.scale, columnMetadata.scale)\n // console.log(\n // \"default:\",\n // this.normalizeDefault(columnMetadata),\n // columnMetadata.default,\n // )\n // console.log(\n // \"isPrimary:\",\n // tableColumn.isPrimary,\n // columnMetadata.isPrimary,\n // )\n // console.log(\n // \"isNullable:\",\n // tableColumn.isNullable,\n // columnMetadata.isNullable,\n // )\n // console.log(\n // \"generatedType:\",\n // tableColumn.generatedType,\n // columnMetadata.generatedType,\n // )\n // console.log(\n // \"asExpression:\",\n // tableColumn.asExpression,\n // columnMetadata.asExpression,\n // )\n // console.log(\n // \"isUnique:\",\n // tableColumn.isUnique,\n // this.normalizeIsUnique(columnMetadata),\n // )\n // console.log(\n // \"enum:\",\n // tableColumn.enum &&\n // columnMetadata.enum &&\n // !OrmUtils.isArraysEqual(\n // tableColumn.enum,\n // columnMetadata.enum.map((val) => val + \"\"),\n // ),\n // )\n // console.log(\n // \"isGenerated:\",\n // tableColumn.isGenerated,\n // columnMetadata.isGenerated,\n // )\n // }\n\n return isColumnChanged\n })\n }\n\n /**\n * Returns true if driver supports RETURNING / OUTPUT statement.\n */\n isReturningSqlSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports uuid values generation on its own.\n */\n isUUIDGenerationSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports fulltext indices.\n */\n isFullTextColumnTypeSupported(): boolean {\n return false\n }\n\n /**\n * Creates an escaped parameter.\n */\n createParameter(parameterName: string, index: number): string {\n // return \"$\" + (index + 1);\n return \"?\"\n // return \"$\" + parameterName;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected createDatabaseConnection() {\n throw new TypeORMError(\n \"Do not use AbstractSqlite directly, it has to be used with one of the sqlite drivers\",\n )\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n // dependencies have to be loaded in the specific driver\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":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O,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,6BAA6B;QACzB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,aAAqB,EAAE,KAAa;QAChD,4BAA4B;QAC5B,OAAO,GAAG,CAAA;QACV,8BAA8B;IAClC,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,wBAAwB;QAC9B,MAAM,IAAI,YAAY,CAClB,sFAAsF,CACzF,CAAA;IACL,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,wDAAwD;IAC5D,CAAC;CACJ","file":"AbstractSqliteDriver.js","sourcesContent":["import { Driver } from \"../Driver\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { DateUtils } from \"../../util/DateUtils\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { RdbmsSchemaBuilder } from \"../../schema-builder/RdbmsSchemaBuilder\"\nimport { CteCapabilities } from \"../types/CteCapabilities\"\nimport { MappedColumnTypes } from \"../types/MappedColumnTypes\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataTypeDefaults } from \"../types/DataTypeDefaults\"\nimport { TableColumn } from \"../../schema-builder/table/TableColumn\"\nimport { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ApplyValueTransformers } from \"../../util/ApplyValueTransformers\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { DriverUtils } from \"../DriverUtils\"\nimport { TypeORMError } from \"../../error\"\nimport { Table } from \"../../schema-builder/table/Table\"\nimport { View } from \"../../schema-builder/view/View\"\nimport { TableForeignKey } from \"../../schema-builder/table/TableForeignKey\"\nimport { InstanceChecker } from \"../../util/InstanceChecker\"\nimport { UpsertType } from \"../types/UpsertType\"\n\ntype DatabasesMap = Record<\n string,\n {\n attachFilepathAbsolute: string\n attachFilepathRelative: string\n attachHandle: string\n }\n>\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport abstract class AbstractSqliteDriver implements Driver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by driver.\n */\n connection: DataSource\n\n /**\n * Sqlite has a single QueryRunner because it works on a single database connection.\n */\n queryRunner?: QueryRunner\n\n /**\n * Real database connection with sqlite database.\n */\n databaseConnection: any\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: BaseDataSourceOptions\n\n /**\n * Master database used to perform all write queries.\n */\n database?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean = false\n\n /**\n * SQLite underlying library.\n */\n sqlite: any\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport = true\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport: \"simple\" | \"nested\" | \"none\" = \"nested\"\n\n /**\n * Gets list of supported column data types by a driver.\n *\n * @see https://www.tutorialspoint.com/sqlite/sqlite_data_types.htm\n * @see https://sqlite.org/datatype3.html\n */\n supportedDataTypes: ColumnType[] = [\n \"int\",\n \"integer\",\n \"tinyint\",\n \"smallint\",\n \"mediumint\",\n \"bigint\",\n \"unsigned big int\",\n \"int2\",\n \"int8\",\n \"integer\",\n \"character\",\n \"varchar\",\n \"varying character\",\n \"nchar\",\n \"native character\",\n \"nvarchar\",\n \"text\",\n \"clob\",\n \"text\",\n \"blob\",\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n \"boolean\",\n \"date\",\n \"time\",\n \"datetime\",\n \"json\",\n ]\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[] = [\"on-conflict-do-update\"]\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[] = [\n \"character\",\n \"varchar\",\n \"varying character\",\n \"nchar\",\n \"native character\",\n \"nvarchar\",\n \"text\",\n \"blob\",\n \"clob\",\n ]\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[] = []\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[] = [\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n \"date\",\n \"time\",\n \"datetime\",\n ]\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[] = [\n \"real\",\n \"double\",\n \"double precision\",\n \"float\",\n \"real\",\n \"numeric\",\n \"decimal\",\n ]\n\n /**\n * Orm has special columns and we need to know what database column types should be for those types.\n * Column types are driver dependant.\n */\n mappedDataTypes: MappedColumnTypes = {\n createDate: \"datetime\",\n createDateDefault: \"datetime('now')\",\n updateDate: \"datetime\",\n updateDateDefault: \"datetime('now')\",\n deleteDate: \"datetime\",\n deleteDateNullable: true,\n version: \"integer\",\n treeLevel: \"integer\",\n migrationId: \"integer\",\n migrationName: \"varchar\",\n migrationTimestamp: \"bigint\",\n cacheId: \"int\",\n cacheIdentifier: \"varchar\",\n cacheTime: \"bigint\",\n cacheDuration: \"int\",\n cacheQuery: \"text\",\n cacheResult: \"text\",\n metadataType: \"varchar\",\n metadataDatabase: \"varchar\",\n metadataSchema: \"varchar\",\n metadataTable: \"varchar\",\n metadataName: \"varchar\",\n metadataValue: \"text\",\n }\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * No documentation specifying a maximum length for identifiers could be found\n * for SQLite.\n */\n maxAliasLength?: number\n\n cteCapabilities: CteCapabilities = {\n enabled: true,\n requiresRecursiveHint: true,\n }\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Any attached databases (excepting default 'main')\n */\n attachedDatabases: DatabasesMap = {}\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n this.connection = connection\n this.options = connection.options as BaseDataSourceOptions\n\n this.database = DriverUtils.buildDriverOptions(this.options).database\n }\n\n // -------------------------------------------------------------------------\n // Public Abstract\n // -------------------------------------------------------------------------\n\n /**\n * Creates a query runner used to execute database queries.\n */\n abstract createQueryRunner(mode: ReplicationMode): QueryRunner\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Makes any action after connection (e.g. create extensions in Postgres driver).\n */\n afterConnect(): Promise<void> {\n return Promise.resolve()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n this.queryRunner = undefined\n this.databaseConnection.close((err: any) =>\n err ? fail(err) : ok(),\n )\n })\n }\n\n hasAttachedDatabases(): boolean {\n return !!Object.keys(this.attachedDatabases).length\n }\n\n getAttachedDatabaseHandleByRelativePath(path: string): string | undefined {\n return this.attachedDatabases?.[path]?.attachHandle\n }\n\n getAttachedDatabasePathRelativeByHandle(\n handle: string,\n ): string | undefined {\n return Object.values(this.attachedDatabases).find(\n ({ attachHandle }) => handle === attachHandle,\n )?.attachFilepathRelative\n }\n\n /**\n * Creates a schema builder used to build and sync a schema.\n */\n createSchemaBuilder() {\n return new RdbmsSchemaBuilder(this.connection)\n }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type and metadata.\n */\n preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any {\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformTo(\n columnMetadata.transformer,\n value,\n )\n\n if (value === null || value === undefined) return value\n\n if (\n columnMetadata.type === Boolean ||\n columnMetadata.type === \"boolean\"\n ) {\n return value === true ? 1 : 0\n } else if (columnMetadata.type === \"date\") {\n return DateUtils.mixedDateToDateString(value)\n } else if (columnMetadata.type === \"time\") {\n return DateUtils.mixedDateToTimeString(value)\n } else if (\n columnMetadata.type === \"datetime\" ||\n columnMetadata.type === Date\n ) {\n // to string conversation needs because SQLite stores date as integer number, when date came as Object\n // TODO: think about `toUTC` conversion\n return DateUtils.mixedDateToUtcDatetimeString(value)\n } else if (columnMetadata.type === \"json\") {\n return JSON.stringify(value)\n } else if (columnMetadata.type === \"simple-array\") {\n return DateUtils.simpleArrayToString(value)\n } else if (columnMetadata.type === \"simple-json\") {\n return DateUtils.simpleJsonToString(value)\n } else if (columnMetadata.type === \"simple-enum\") {\n return DateUtils.simpleEnumToString(value)\n }\n\n return value\n }\n\n /**\n * Prepares given value to a value to be hydrated, based on its column type or metadata.\n */\n prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any {\n if (value === null || value === undefined)\n return columnMetadata.transformer\n ? ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n : value\n\n if (\n columnMetadata.type === Boolean ||\n columnMetadata.type === \"boolean\"\n ) {\n value = value ? true : false\n } else if (\n columnMetadata.type === \"datetime\" ||\n columnMetadata.type === Date\n ) {\n /**\n * Fix date conversion issue\n *\n * If the format of the date string is \"2018-03-14 02:33:33.906\", Safari (and iOS WKWebView) will convert it to an invalid date object.\n * We need to modify the date string to \"2018-03-14T02:33:33.906Z\" and Safari will convert it correctly.\n *\n * ISO 8601\n * https://www.w3.org/TR/NOTE-datetime\n */\n if (value && typeof value === \"string\") {\n // There are various valid time string formats a sqlite time string might have:\n // https://www.sqlite.org/lang_datefunc.html\n // There are two separate fixes we may need to do:\n // 1) Add 'T' separator if space is used instead\n // 2) Add 'Z' UTC suffix if no timezone or offset specified\n\n if (/^\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d/.test(value)) {\n value = value.replace(\" \", \"T\")\n }\n if (\n /^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d(:\\d\\d(\\.\\d\\d\\d)?)?$/.test(\n value,\n )\n ) {\n value += \"Z\"\n }\n }\n\n value = DateUtils.normalizeHydratedDate(value)\n } else if (columnMetadata.type === \"date\") {\n value = DateUtils.mixedDateToDateString(value)\n } else if (columnMetadata.type === \"time\") {\n value = DateUtils.mixedTimeToString(value)\n } else if (columnMetadata.type === \"json\") {\n value = typeof value === \"string\" ? JSON.parse(value) : value\n } else if (columnMetadata.type === \"simple-array\") {\n value = DateUtils.stringToSimpleArray(value)\n } else if (columnMetadata.type === \"simple-json\") {\n value = DateUtils.stringToSimpleJson(value)\n } else if (columnMetadata.type === \"simple-enum\") {\n value = DateUtils.stringToSimpleEnum(value, columnMetadata)\n } else if (columnMetadata.type === Number) {\n // convert to number if number\n value = !isNaN(+value) ? parseInt(value) : value\n }\n\n if (columnMetadata.transformer)\n value = ApplyValueTransformers.transformFrom(\n columnMetadata.transformer,\n value,\n )\n\n return value\n }\n\n /**\n * Replaces parameters in the given sql with special escaping character\n * and an array of parameter names to be passed to a query.\n */\n escapeQueryWithParameters(\n sql: string,\n parameters: ObjectLiteral,\n nativeParameters: ObjectLiteral,\n ): [string, any[]] {\n const escapedParameters: any[] = Object.keys(nativeParameters).map(\n (key) => {\n // Mapping boolean values to their numeric representation\n if (typeof nativeParameters[key] === \"boolean\") {\n return nativeParameters[key] === true ? 1 : 0\n }\n\n if (nativeParameters[key] instanceof Date) {\n return DateUtils.mixedDateToUtcDatetimeString(\n nativeParameters[key],\n )\n }\n\n return nativeParameters[key]\n },\n )\n\n if (!parameters || !Object.keys(parameters).length)\n return [sql, escapedParameters]\n\n sql = sql.replace(\n /:(\\.\\.\\.)?([A-Za-z0-9_.]+)/g,\n (full, isArray: string, key: string): string => {\n if (!parameters.hasOwnProperty(key)) {\n return full\n }\n\n let value: any = parameters[key]\n\n if (isArray) {\n return value\n .map((v: any) => {\n escapedParameters.push(v)\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n })\n .join(\", \")\n }\n\n if (typeof value === \"function\") {\n return value()\n } else if (typeof value === \"number\") {\n return String(value)\n }\n\n // Sqlite does not have a boolean data type so we have to transform\n // it to 1 or 0\n if (typeof value === \"boolean\") {\n escapedParameters.push(+value)\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n }\n\n if (value instanceof Date) {\n escapedParameters.push(\n DateUtils.mixedDateToUtcDatetimeString(value),\n )\n return this.createParameter(\n key,\n escapedParameters.length - 1,\n )\n }\n\n escapedParameters.push(value)\n return this.createParameter(key, escapedParameters.length - 1)\n },\n ) // todo: make replace only in value statements, otherwise problems\n return [sql, escapedParameters]\n }\n\n /**\n * Escapes a column name.\n */\n escape(columnName: string): string {\n return '\"' + columnName + '\"'\n }\n\n /**\n * Build full table name with database name, schema name and table name.\n * E.g. myDB.mySchema.myTable\n *\n * Returns only simple table name because all inherited drivers does not supports schema and database.\n */\n buildTableName(\n tableName: string,\n schema?: string,\n database?: string,\n ): string {\n return tableName\n }\n\n /**\n * Parse a target table name or other types and return a normalized table definition.\n */\n parseTableName(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): { database?: string; schema?: string; tableName: string } {\n const driverDatabase = this.database\n const driverSchema = undefined\n\n if (InstanceChecker.isTable(target) || InstanceChecker.isView(target)) {\n const parsed = this.parseTableName(\n target.schema\n ? `\"${target.schema}\".\"${target.name}\"`\n : target.name,\n )\n\n return {\n database: target.database || parsed.database || driverDatabase,\n schema: target.schema || parsed.schema || driverSchema,\n tableName: parsed.tableName,\n }\n }\n\n if (InstanceChecker.isTableForeignKey(target)) {\n const parsed = this.parseTableName(target.referencedTableName)\n\n return {\n database:\n target.referencedDatabase ||\n parsed.database ||\n driverDatabase,\n schema:\n target.referencedSchema || parsed.schema || driverSchema,\n tableName: parsed.tableName,\n }\n }\n\n if (InstanceChecker.isEntityMetadata(target)) {\n // EntityMetadata tableName is never a path\n\n return {\n database: target.database || driverDatabase,\n schema: target.schema || driverSchema,\n tableName: target.tableName,\n }\n }\n\n const parts = target.split(\".\")\n\n if (parts.length === 3) {\n return {\n database: parts[0] || driverDatabase,\n schema: parts[1] || driverSchema,\n tableName: parts[2],\n }\n } else if (parts.length === 2) {\n const database =\n this.getAttachedDatabasePathRelativeByHandle(parts[0]) ??\n driverDatabase\n return {\n database: database,\n schema: parts[0],\n tableName: parts[1],\n }\n } else {\n return {\n database: driverDatabase,\n schema: driverSchema,\n tableName: target,\n }\n }\n }\n\n /**\n * Creates a database type from a given column metadata.\n */\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n if (column.type === Number || column.type === \"int\") {\n return \"integer\"\n } else if (column.type === String) {\n return \"varchar\"\n } else if (column.type === Date) {\n return \"datetime\"\n } else if (column.type === Boolean) {\n return \"boolean\"\n } else if (column.type === \"uuid\") {\n return \"varchar\"\n } else if (column.type === \"simple-array\") {\n return \"text\"\n } else if (column.type === \"simple-json\") {\n return \"text\"\n } else if (column.type === \"simple-enum\") {\n return \"varchar\"\n } else {\n return (column.type as string) || \"\"\n }\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n normalizeDefault(columnMetadata: ColumnMetadata): string | undefined {\n const defaultValue = columnMetadata.default\n\n if (typeof defaultValue === \"number\") {\n return \"\" + defaultValue\n }\n\n if (typeof defaultValue === \"boolean\") {\n return defaultValue ? \"1\" : \"0\"\n }\n\n if (typeof defaultValue === \"function\") {\n return defaultValue()\n }\n\n if (typeof defaultValue === \"string\") {\n return `'${defaultValue}'`\n }\n\n if (defaultValue === null || defaultValue === undefined) {\n return undefined\n }\n\n return `${defaultValue}`\n }\n\n /**\n * Normalizes \"isUnique\" value of the column.\n */\n normalizeIsUnique(column: ColumnMetadata): boolean {\n return column.entityMetadata.uniques.some(\n (uq) => uq.columns.length === 1 && uq.columns[0] === column,\n )\n }\n\n /**\n * Calculates column length taking into account the default length values.\n */\n getColumnLength(column: ColumnMetadata): string {\n return column.length ? column.length.toString() : \"\"\n }\n\n /**\n * Normalizes \"default\" value of the column.\n */\n createFullType(column: TableColumn): string {\n let type = column.type\n if (column.enum) {\n return \"varchar\"\n }\n if (column.length) {\n type += \"(\" + column.length + \")\"\n } else if (\n column.precision !== null &&\n column.precision !== undefined &&\n column.scale !== null &&\n column.scale !== undefined\n ) {\n type += \"(\" + column.precision + \",\" + column.scale + \")\"\n } else if (\n column.precision !== null &&\n column.precision !== undefined\n ) {\n type += \"(\" + column.precision + \")\"\n }\n\n if (column.isArray) type += \" array\"\n\n return type\n }\n\n /**\n * Obtains a new database connection to a master server.\n * Used for replication.\n * If replication is not setup then returns default connection's database connection.\n */\n obtainMasterConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Obtains a new database connection to a slave server.\n * Used for replication.\n * If replication is not setup then returns master (default) connection's database connection.\n */\n obtainSlaveConnection(): Promise<any> {\n return Promise.resolve()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(\n metadata: EntityMetadata,\n insertResult: any,\n entityIndex: number,\n entityNum: number,\n ) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n let value: any\n if (\n generatedColumn.generationStrategy === \"increment\" &&\n insertResult\n ) {\n // NOTE: When INSERT statement is successfully completed, the last inserted row ID is returned.\n // see also: SqliteQueryRunner.query()\n value = insertResult - entityNum + entityIndex + 1\n // } else if (generatedColumn.generationStrategy === \"uuid\") {\n // value = insertValue[generatedColumn.databaseName];\n }\n\n if (!value) return map\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(value),\n )\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n /**\n * Differentiate columns of this table and columns from the given column metadatas columns\n * and returns only changed.\n */\n findChangedColumns(\n tableColumns: TableColumn[],\n columnMetadatas: ColumnMetadata[],\n ): ColumnMetadata[] {\n return columnMetadatas.filter((columnMetadata) => {\n const tableColumn = tableColumns.find(\n (c) => c.name === columnMetadata.databaseName,\n )\n if (!tableColumn) return false // we don't need new columns, we only need exist and changed\n\n const isColumnChanged =\n tableColumn.name !== columnMetadata.databaseName ||\n tableColumn.type !== this.normalizeType(columnMetadata) ||\n tableColumn.length !== columnMetadata.length ||\n tableColumn.precision !== columnMetadata.precision ||\n tableColumn.scale !== columnMetadata.scale ||\n this.normalizeDefault(columnMetadata) !== tableColumn.default ||\n tableColumn.isPrimary !== columnMetadata.isPrimary ||\n tableColumn.isNullable !== columnMetadata.isNullable ||\n tableColumn.generatedType !== columnMetadata.generatedType ||\n tableColumn.asExpression !== columnMetadata.asExpression ||\n tableColumn.isUnique !==\n this.normalizeIsUnique(columnMetadata) ||\n (tableColumn.enum &&\n columnMetadata.enum &&\n !OrmUtils.isArraysEqual(\n tableColumn.enum,\n columnMetadata.enum.map((val) => val + \"\"),\n )) ||\n (columnMetadata.generationStrategy !== \"uuid\" &&\n tableColumn.isGenerated !== columnMetadata.isGenerated)\n\n // DEBUG SECTION\n // if (isColumnChanged) {\n // console.log(\"table:\", columnMetadata.entityMetadata.tableName)\n // console.log(\n // \"name:\",\n // tableColumn.name,\n // columnMetadata.databaseName,\n // )\n // console.log(\n // \"type:\",\n // tableColumn.type,\n // this.normalizeType(columnMetadata),\n // )\n // console.log(\n // \"length:\",\n // tableColumn.length,\n // columnMetadata.length,\n // )\n // console.log(\n // \"precision:\",\n // tableColumn.precision,\n // columnMetadata.precision,\n // )\n // console.log(\"scale:\", tableColumn.scale, columnMetadata.scale)\n // console.log(\n // \"default:\",\n // this.normalizeDefault(columnMetadata),\n // columnMetadata.default,\n // )\n // console.log(\n // \"isPrimary:\",\n // tableColumn.isPrimary,\n // columnMetadata.isPrimary,\n // )\n // console.log(\n // \"isNullable:\",\n // tableColumn.isNullable,\n // columnMetadata.isNullable,\n // )\n // console.log(\n // \"generatedType:\",\n // tableColumn.generatedType,\n // columnMetadata.generatedType,\n // )\n // console.log(\n // \"asExpression:\",\n // tableColumn.asExpression,\n // columnMetadata.asExpression,\n // )\n // console.log(\n // \"isUnique:\",\n // tableColumn.isUnique,\n // this.normalizeIsUnique(columnMetadata),\n // )\n // console.log(\n // \"enum:\",\n // tableColumn.enum &&\n // columnMetadata.enum &&\n // !OrmUtils.isArraysEqual(\n // tableColumn.enum,\n // columnMetadata.enum.map((val) => val + \"\"),\n // ),\n // )\n // console.log(\n // \"isGenerated:\",\n // tableColumn.isGenerated,\n // columnMetadata.isGenerated,\n // )\n // }\n\n return isColumnChanged\n })\n }\n\n /**\n * Returns true if driver supports RETURNING / OUTPUT statement.\n */\n isReturningSqlSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports uuid values generation on its own.\n */\n isUUIDGenerationSupported(): boolean {\n return false\n }\n\n /**\n * Returns true if driver supports fulltext indices.\n */\n isFullTextColumnTypeSupported(): boolean {\n return false\n }\n\n /**\n * Creates an escaped parameter.\n */\n createParameter(parameterName: string, index: number): string {\n // return \"$\" + (index + 1);\n return \"?\"\n // return \"$\" + parameterName;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected createDatabaseConnection() {\n throw new TypeORMError(\n \"Do not use AbstractSqlite directly, it has to be used with one of the sqlite drivers\",\n )\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n // dependencies have to be loaded in the specific driver\n }\n}\n"],"sourceRoot":"../.."}
@@ -1,5 +1,6 @@
1
1
  import { ObjectLiteral } from "../common/ObjectLiteral";
2
2
  import { FindOperatorType } from "./FindOperatorType";
3
+ import { ValueTransformer } from "../decorator/options/ValueTransformer";
3
4
  type SqlGeneratorType = (aliasPath: string) => string;
4
5
  /**
5
6
  * Find Operator used in Find Conditions.
@@ -61,5 +62,6 @@ export declare class FindOperator<T> {
61
62
  * Gets the SQL generator
62
63
  */
63
64
  get getSql(): SqlGeneratorType | undefined;
65
+ transformValue(transformer: ValueTransformer | ValueTransformer[]): void;
64
66
  }
65
67
  export {};
@@ -1,4 +1,5 @@
1
1
  import { InstanceChecker } from "../util/InstanceChecker";
2
+ import { ApplyValueTransformers } from "../util/ApplyValueTransformers";
2
3
  /**
3
4
  * Find Operator used in Find Conditions.
4
5
  */
@@ -74,6 +75,18 @@ export class FindOperator {
74
75
  return this._value.getSql;
75
76
  return this._getSql;
76
77
  }
78
+ transformValue(transformer) {
79
+ if (this._value instanceof FindOperator) {
80
+ this._value.transformValue(transformer);
81
+ }
82
+ else {
83
+ this._value =
84
+ Array.isArray(this._value) && this._multipleParameters
85
+ ? this._value.map((v) => transformer &&
86
+ ApplyValueTransformers.transformTo(transformer, v))
87
+ : ApplyValueTransformers.transformTo(transformer, this._value);
88
+ }
89
+ }
77
90
  }
78
91
 
79
92
  //# sourceMappingURL=FindOperator.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/find-options/FindOperator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAIzD;;GAEG;AACH,MAAM,OAAO,YAAY;IAqCrB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,IAAsB,EACtB,KAA0B,EAC1B,eAAwB,IAAI,EAC5B,qBAA8B,KAAK,EACnC,MAAyB,EACzB,uBAAuC;QA9ClC,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAgD/C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAA;QACjC,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC7C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,wBAAwB,GAAG,uBAAuB,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;;OAGG;IACH,IAAI,YAAY;QACZ,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAA;QAEnC,OAAO,IAAI,CAAC,aAAa,CAAA;IAC7B,CAAC;IAED;;;OAGG;IACH,IAAI,kBAAkB;QAClB,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAA;QAEzC,OAAO,IAAI,CAAC,mBAAmB,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACL,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAA;QAE5B,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,uBAAuB;QACvB,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAA;QAE9C,OAAO,IAAI,CAAC,wBAAwB,CAAA;IACxC,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACL,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC,MAAM,CAAA;QAEnE,OAAO,SAAS,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACN,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAA;IACvB,CAAC;CACJ","file":"FindOperator.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOperatorType } from \"./FindOperatorType\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\ntype SqlGeneratorType = (aliasPath: string) => string\n\n/**\n * Find Operator used in Find Conditions.\n */\nexport class FindOperator<T> {\n readonly \"@instanceof\" = Symbol.for(\"FindOperator\")\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n /**\n * Operator type.\n */\n private _type: FindOperatorType\n\n /**\n * Parameter value.\n */\n private _value: T | FindOperator<T>\n\n /**\n * ObjectLiteral parameters.\n */\n private _objectLiteralParameters: ObjectLiteral | undefined\n\n /**\n * Indicates if parameter is used or not for this operator.\n */\n private _useParameter: boolean\n\n /**\n * Indicates if multiple parameters must be used for this operator.\n */\n private _multipleParameters: boolean\n\n /**\n * SQL generator\n */\n private _getSql: SqlGeneratorType | undefined\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n type: FindOperatorType,\n value: T | FindOperator<T>,\n useParameter: boolean = true,\n multipleParameters: boolean = false,\n getSql?: SqlGeneratorType,\n objectLiteralParameters?: ObjectLiteral,\n ) {\n this._type = type\n this._value = value\n this._useParameter = useParameter\n this._multipleParameters = multipleParameters\n this._getSql = getSql\n this._objectLiteralParameters = objectLiteralParameters\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Indicates if parameter is used or not for this operator.\n * Extracts final value if value is another find operator.\n */\n get useParameter(): boolean {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.useParameter\n\n return this._useParameter\n }\n\n /**\n * Indicates if multiple parameters must be used for this operator.\n * Extracts final value if value is another find operator.\n */\n get multipleParameters(): boolean {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.multipleParameters\n\n return this._multipleParameters\n }\n\n /**\n * Gets the Type of this FindOperator\n */\n get type(): FindOperatorType {\n return this._type\n }\n\n /**\n * Gets the final value needs to be used as parameter value.\n */\n get value(): T {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.value\n\n return this._value\n }\n\n /**\n * Gets ObjectLiteral parameters.\n */\n get objectLiteralParameters(): ObjectLiteral | undefined {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.objectLiteralParameters\n\n return this._objectLiteralParameters\n }\n\n /**\n * Gets the child FindOperator if it exists\n */\n get child(): FindOperator<T> | undefined {\n if (InstanceChecker.isFindOperator(this._value)) return this._value\n\n return undefined\n }\n\n /**\n * Gets the SQL generator\n */\n get getSql(): SqlGeneratorType | undefined {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.getSql\n\n return this._getSql\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/find-options/FindOperator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAIvE;;GAEG;AACH,MAAM,OAAO,YAAY;IAqCrB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,IAAsB,EACtB,KAA0B,EAC1B,eAAwB,IAAI,EAC5B,qBAA8B,KAAK,EACnC,MAAyB,EACzB,uBAAuC;QA9ClC,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAgD/C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAA;QACjC,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC7C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,wBAAwB,GAAG,uBAAuB,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;;OAGG;IACH,IAAI,YAAY;QACZ,IAAI,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAA;QAEn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AC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,mBAAmB;oBAClD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CACX,CAAC,CAAM,EAAE,EAAE,CACP,WAAW;wBACX,sBAAsB,CAAC,WAAW,CAC9B,WAAW,EACX,CAAC,CACJ,CACR;oBACH,CAAC,CAAC,sBAAsB,CAAC,WAAW,CAC9B,WAAW,EACX,IAAI,CAAC,MAAM,CACd,CAAA;SACd;IACL,CAAC;CACJ","file":"FindOperator.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { FindOperatorType } from \"./FindOperatorType\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { ValueTransformer } from \"../decorator/options/ValueTransformer\"\nimport { ApplyValueTransformers } from \"../util/ApplyValueTransformers\"\n\ntype SqlGeneratorType = (aliasPath: string) => string\n\n/**\n * Find Operator used in Find Conditions.\n */\nexport class FindOperator<T> {\n readonly \"@instanceof\" = Symbol.for(\"FindOperator\")\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n /**\n * Operator type.\n */\n private _type: FindOperatorType\n\n /**\n * Parameter value.\n */\n private _value: T | FindOperator<T>\n\n /**\n * ObjectLiteral parameters.\n */\n private _objectLiteralParameters: ObjectLiteral | undefined\n\n /**\n * Indicates if parameter is used or not for this operator.\n */\n private _useParameter: boolean\n\n /**\n * Indicates if multiple parameters must be used for this operator.\n */\n private _multipleParameters: boolean\n\n /**\n * SQL generator\n */\n private _getSql: SqlGeneratorType | undefined\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n type: FindOperatorType,\n value: T | FindOperator<T>,\n useParameter: boolean = true,\n multipleParameters: boolean = false,\n getSql?: SqlGeneratorType,\n objectLiteralParameters?: ObjectLiteral,\n ) {\n this._type = type\n this._value = value\n this._useParameter = useParameter\n this._multipleParameters = multipleParameters\n this._getSql = getSql\n this._objectLiteralParameters = objectLiteralParameters\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Indicates if parameter is used or not for this operator.\n * Extracts final value if value is another find operator.\n */\n get useParameter(): boolean {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.useParameter\n\n return this._useParameter\n }\n\n /**\n * Indicates if multiple parameters must be used for this operator.\n * Extracts final value if value is another find operator.\n */\n get multipleParameters(): boolean {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.multipleParameters\n\n return this._multipleParameters\n }\n\n /**\n * Gets the Type of this FindOperator\n */\n get type(): FindOperatorType {\n return this._type\n }\n\n /**\n * Gets the final value needs to be used as parameter value.\n */\n get value(): T {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.value\n\n return this._value\n }\n\n /**\n * Gets ObjectLiteral parameters.\n */\n get objectLiteralParameters(): ObjectLiteral | undefined {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.objectLiteralParameters\n\n return this._objectLiteralParameters\n }\n\n /**\n * Gets the child FindOperator if it exists\n */\n get child(): FindOperator<T> | undefined {\n if (InstanceChecker.isFindOperator(this._value)) return this._value\n\n return undefined\n }\n\n /**\n * Gets the SQL generator\n */\n get getSql(): SqlGeneratorType | undefined {\n if (InstanceChecker.isFindOperator(this._value))\n return this._value.getSql\n\n return this._getSql\n }\n\n transformValue(transformer: ValueTransformer | ValueTransformer[]) {\n if (this._value instanceof FindOperator) {\n this._value.transformValue(transformer)\n } else {\n this._value =\n Array.isArray(this._value) && this._multipleParameters\n ? this._value.map(\n (v: any) =>\n transformer &&\n ApplyValueTransformers.transformTo(\n transformer,\n v,\n ),\n )\n : ApplyValueTransformers.transformTo(\n transformer,\n this._value,\n )\n }\n }\n}\n"],"sourceRoot":".."}
@@ -201,6 +201,7 @@ export class MigrationExecutor {
201
201
  // start transaction if its not started yet
202
202
  let transactionStartedByUs = false;
203
203
  if (this.transaction === "all" && !queryRunner.isTransactionActive) {
204
+ await queryRunner.beforeMigration();
204
205
  await queryRunner.startTransaction();
205
206
  transactionStartedByUs = true;
206
207
  }
@@ -214,6 +215,7 @@ export class MigrationExecutor {
214
215
  continue;
215
216
  }
216
217
  if (migration.transaction && !queryRunner.isTransactionActive) {
218
+ await queryRunner.beforeMigration();
217
219
  await queryRunner.startTransaction();
218
220
  transactionStartedByUs = true;
219
221
  }
@@ -228,8 +230,10 @@ export class MigrationExecutor {
228
230
  // now when migration is executed we need to insert record about it into the database
229
231
  await this.insertExecutedMigration(queryRunner, migration);
230
232
  // commit transaction if we started it
231
- if (migration.transaction && transactionStartedByUs)
233
+ if (migration.transaction && transactionStartedByUs) {
232
234
  await queryRunner.commitTransaction();
235
+ await queryRunner.afterMigration();
236
+ }
233
237
  })
234
238
  .then(() => {
235
239
  // informative log about migration success
@@ -238,8 +242,10 @@ export class MigrationExecutor {
238
242
  });
239
243
  }
240
244
  // commit transaction if we started it
241
- if (this.transaction === "all" && transactionStartedByUs)
245
+ if (this.transaction === "all" && transactionStartedByUs) {
242
246
  await queryRunner.commitTransaction();
247
+ await queryRunner.afterMigration();
248
+ }
243
249
  }
244
250
  catch (err) {
245
251
  // rollback transaction if we started it
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/migration/MigrationExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,qCAAqC,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IA+B1B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,UAAsB,EACtB,WAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,gBAAW,GAAX,WAAW,CA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,KAAK,SAAS,EAAE;YACnD,MAAM,WAAW,GAAG,WAA+B,CAAA;YACnD,MAAM,WAAW,CAAC,kBAAkB;iBAC/B,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAS,CAAC;iBACpC,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC;iBACpC,SAAS,CAAC,UAAU,CAAC,CAAA;SAC7B;aAAM;YACH,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACnD,MAAM,EAAE;iBACH,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;iBAC1B,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC;iBAC/C,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;iBACxC,aAAa,CAAC,UAAU,CAAC;iBACzB,OAAO,EAAE,CAAA;SACjB;IACL,CAAC;IAES,KAAK,CAAC,eAAe,CAC3B,QAAsD;QAEtD,MAAM,WAAW,GACb,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;QAE3D,IAAI;YACA,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAA;SAC/B;gBAAS;YACN,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBACnB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;aAC9B;SACJ;IACL,CAAC;CACJ","file":"MigrationExecutor.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Migration } from \"./Migration\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { MongoQueryRunner } from \"../driver/mongodb/MongoQueryRunner\"\nimport { ForbiddenTransactionModeOverrideError, TypeORMError } from \"../error\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates how migrations should be run in transactions.\n * all: all migrations are run in a single transaction\n * none: all migrations are run without a transaction\n * each: each migration is run in a separate transaction\n */\n transaction: \"all\" | \"none\" | \"each\" = \"all\"\n\n /**\n * Option to fake-run or fake-revert a migration, adding to the\n * executed migrations table, but not actually running it. This feature is\n * useful for when migrations are added after the fact or for\n * interoperability between applications which are desired to each keep\n * a consistent migration history.\n */\n fake: boolean\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n private readonly migrationsDatabase?: string\n private readonly migrationsSchema?: string\n private readonly migrationsTable: string\n private readonly migrationsTableName: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n protected queryRunner?: QueryRunner,\n ) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n this.migrationsDatabase = database\n this.migrationsSchema = schema\n this.migrationsTableName =\n connection.options.migrationsTableName || \"migrations\"\n this.migrationsTable = this.connection.driver.buildTableName(\n this.migrationsTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Tries to execute a single migration given.\n */\n public async executeMigration(migration: Migration): Promise<Migration> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n await queryRunner.beforeMigration()\n await (migration.instance as any).up(queryRunner)\n await queryRunner.afterMigration()\n await this.insertExecutedMigration(queryRunner, migration)\n\n return migration\n })\n }\n\n /**\n * Returns an array of all migrations.\n */\n public async getAllMigrations(): Promise<Migration[]> {\n return Promise.resolve(this.getMigrations())\n }\n\n /**\n * Returns an array of all executed migrations.\n */\n public async getExecutedMigrations(): Promise<Migration[]> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n return await this.loadExecutedMigrations(queryRunner)\n })\n }\n\n /**\n * Returns an array of all pending migrations.\n */\n public async getPendingMigrations(): Promise<Migration[]> {\n const allMigrations = await this.getAllMigrations()\n const executedMigrations = await this.getExecutedMigrations()\n\n return allMigrations.filter(\n (migration) =>\n !executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n ),\n )\n }\n\n /**\n * Inserts an executed migration.\n */\n public insertMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.insertExecutedMigration(q, migration),\n )\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.deleteExecutedMigration(q, migration),\n )\n }\n\n /**\n * Lists all migrations and whether they have been executed or not\n * returns true if there are unapplied migrations\n */\n async showMigrations(): Promise<boolean> {\n let hasUnappliedMigrations = false\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n for (const migration of allMigrations) {\n const executedMigration = executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(\n `[X] ${executedMigration.id} ${migration.name}`,\n )\n } else {\n hasUnappliedMigrations = true\n this.connection.logger.logSchemaBuild(`[ ] ${migration.name}`)\n }\n }\n\n // if query runner was created by us then release it\n if (!this.queryRunner) {\n await queryRunner.release()\n }\n\n return hasUnappliedMigrations\n }\n\n /**\n * Executes all pending migrations. Pending migrations are migrations that are not yet executed,\n * thus not saved in the database.\n */\n async executePendingMigrations(): Promise<Migration[]> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create the typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestTimestampMigration(executedMigrations)\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n // variable to store all migrations we did successfully\n const successMigrations: Migration[] = []\n\n // find all migrations that needs to be executed\n const pendingMigrations = allMigrations.filter((migration) => {\n // check if we already have executed migration\n const executedMigration = executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n if (executedMigration) return false\n\n // migration is new and not executed. now check if its timestamp is correct\n // if (lastTimeExecutedMigration && migration.timestamp < lastTimeExecutedMigration.timestamp)\n // throw new TypeORMError(`New migration found: ${migration.name}, however this migration's timestamp is not valid. Migration's timestamp should not be older then migrations already executed in the database.`);\n\n // every check is passed means that migration was not run yet and we need to run it\n return true\n })\n\n // if no migrations are pending then nothing to do here\n if (!pendingMigrations.length) {\n this.connection.logger.logSchemaBuild(`No migrations are pending`)\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n return []\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${allMigrations.length} migrations were found in the source code.`,\n )\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(\n `${pendingMigrations.length} migrations are new migrations must be executed.`,\n )\n\n if (this.transaction === \"all\") {\n // If we desire to run all migrations in a single transaction\n // but there is a migration that explicitly overrides the transaction mode\n // then we have to fail since we cannot properly resolve that intent\n // In theory we could support overrides that are set to `true`,\n // however to keep the interface more rigid, we fail those too\n const migrationsOverridingTransactionMode =\n pendingMigrations.filter(\n (migration) =>\n !(migration.instance?.transaction === undefined),\n )\n\n if (migrationsOverridingTransactionMode.length > 0) {\n const error = new ForbiddenTransactionModeOverrideError(\n migrationsOverridingTransactionMode,\n )\n this.connection.logger.logMigration(\n `Migrations failed, error: ${error.message}`,\n )\n throw error\n }\n }\n\n // Set the per-migration defaults for the transaction mode\n // so that we have one centralized place that controls this behavior\n\n // When transaction mode is `each` the default is to run in a transaction\n // When transaction mode is `none` the default is to not run in a transaction\n // When transaction mode is `all` the default is to not run in a transaction\n // since all the migrations are already running in one single transaction\n\n const txModeDefault = {\n each: true,\n none: false,\n all: false,\n }[this.transaction]\n\n for (const migration of pendingMigrations) {\n if (migration.instance) {\n const instanceTx = migration.instance.transaction\n\n if (instanceTx === undefined) {\n migration.transaction = txModeDefault\n } else {\n migration.transaction = instanceTx\n }\n }\n }\n\n // start transaction if its not started yet\n let transactionStartedByUs = false\n if (this.transaction === \"all\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n // run all pending migrations in a sequence\n try {\n for (const migration of pendingMigrations) {\n if (this.fake) {\n // directly insert migration record into the database if it is fake\n await this.insertExecutedMigration(queryRunner, migration)\n\n // nothing else needs to be done, continue to next migration\n continue\n }\n\n if (migration.transaction && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n await migration\n .instance!.up(queryRunner)\n .catch((error) => {\n // informative log about migration failure\n this.connection.logger.logMigration(\n `Migration \"${migration.name}\" failed, error: ${error?.message}`,\n )\n throw error\n })\n .then(async () => {\n // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(\n queryRunner,\n migration,\n )\n // commit transaction if we started it\n if (migration.transaction && transactionStartedByUs)\n await queryRunner.commitTransaction()\n })\n .then(() => {\n // informative log about migration success\n successMigrations.push(migration)\n this.connection.logger.logSchemaBuild(\n `Migration ${migration.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } executed successfully.`,\n )\n })\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs)\n await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n return successMigrations\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestExecutedMigration(executedMigrations)\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(\n `No migrations were found in the database. Nothing to revert!`,\n )\n return\n }\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n // find the instance of the migration we need to remove\n const migrationToRevert = allMigrations.find(\n (migration) => migration.name === lastTimeExecutedMigration!.name,\n )\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(\n `No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options.`,\n )\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(`Now reverting it...`)\n\n // start transaction if its not started yet\n let transactionStartedByUs = false\n if (this.transaction !== \"none\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n try {\n if (!this.fake) {\n await queryRunner.beforeMigration()\n await migrationToRevert.instance!.down(queryRunner)\n await queryRunner.afterMigration()\n }\n\n await this.deleteExecutedMigration(queryRunner, migrationToRevert)\n this.connection.logger.logSchemaBuild(\n `Migration ${migrationToRevert.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } reverted successfully.`,\n )\n\n // commit transaction if we started it\n if (transactionStartedByUs) await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table \"migrations\" that will store information about executed migrations.\n */\n protected async createMigrationsTableIfNotExist(\n queryRunner: QueryRunner,\n ): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver.options.type === \"mongodb\") {\n return\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable) // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(\n new Table({\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationId,\n }),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false,\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationName,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n }\n\n /**\n * Loads all migrations that were executed and saved into the database (sorts by id).\n */\n protected async loadExecutedMigrations(\n queryRunner: QueryRunner,\n ): Promise<Migration[]> {\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n return await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .find<Migration>()\n .sort({ _id: -1 })\n .toArray()\n } else {\n const migrationsRaw: ObjectLiteral[] = await this.connection.manager\n .createQueryBuilder(queryRunner)\n .select()\n .orderBy(this.connection.driver.escape(\"id\"), \"DESC\")\n .from(this.migrationsTable, this.migrationsTableName)\n .getRawMany()\n return migrationsRaw.map((migrationRaw) => {\n return new Migration(\n parseInt(migrationRaw[\"id\"]),\n parseInt(migrationRaw[\"timestamp\"]),\n migrationRaw[\"name\"],\n )\n })\n }\n }\n\n /**\n * Gets all migrations that setup for this connection.\n */\n protected getMigrations(): Migration[] {\n const migrations = this.connection.migrations.map((migration) => {\n const migrationClassName =\n migration.name || (migration.constructor as any).name\n const migrationTimestamp = parseInt(\n migrationClassName.substr(-13),\n 10,\n )\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(\n `${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`,\n )\n }\n\n return new Migration(\n undefined,\n migrationTimestamp,\n migrationClassName,\n migration,\n )\n })\n\n this.checkForDuplicateMigrations(migrations)\n\n // sort them by timestamp\n return migrations.sort((a, b) => a.timestamp - b.timestamp)\n }\n\n protected checkForDuplicateMigrations(migrations: Migration[]) {\n const migrationNames = migrations.map((migration) => migration.name)\n const duplicates = Array.from(\n new Set(\n migrationNames.filter(\n (migrationName, index) =>\n migrationNames.indexOf(migrationName) < index,\n ),\n ),\n )\n if (duplicates.length > 0) {\n throw Error(`Duplicate migrations: ${duplicates.join(\", \")}`)\n }\n }\n\n /**\n * Finds the latest migration (sorts by timestamp) in the given array of migrations.\n */\n protected getLatestTimestampMigration(\n migrations: Migration[],\n ): Migration | undefined {\n const sortedMigrations = migrations\n .map((migration) => migration)\n .sort((a, b) => (a.timestamp - b.timestamp) * -1)\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined\n }\n\n /**\n * Finds the latest migration in the given array of migrations.\n * PRE: Migration array must be sorted by descending id.\n */\n protected getLatestExecutedMigration(\n sortedMigrations: Migration[],\n ): Migration | undefined {\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined\n }\n\n /**\n * Inserts new executed migration's data into migrations table.\n */\n protected async insertExecutedMigration(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const values: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n values[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n values[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n values[\"timestamp\"] = migration.timestamp\n values[\"name\"] = migration.name\n }\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .insertOne(values)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .insert()\n .into(this.migrationsTable)\n .values(values)\n .execute()\n }\n }\n\n /**\n * Delete previously executed migration's data from the migrations table.\n */\n protected async deleteExecutedMigration(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const conditions: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n conditions[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n conditions[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n conditions[\"timestamp\"] = migration.timestamp\n conditions[\"name\"] = migration.name\n }\n\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .deleteOne(conditions)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .delete()\n .from(this.migrationsTable)\n .where(`${qb.escape(\"timestamp\")} = :timestamp`)\n .andWhere(`${qb.escape(\"name\")} = :name`)\n .setParameters(conditions)\n .execute()\n }\n }\n\n protected async withQueryRunner<T extends any>(\n callback: (queryRunner: QueryRunner) => T | Promise<T>,\n ) {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n try {\n return callback(queryRunner)\n } finally {\n if (!this.queryRunner) {\n await queryRunner.release()\n }\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/migration/MigrationExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,qCAAqC,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CA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;gBACnB,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;aAC9B;SACJ;IACL,CAAC;CACJ","file":"MigrationExecutor.js","sourcesContent":["import { Table } from \"../schema-builder/table/Table\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { Migration } from \"./Migration\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { MongoQueryRunner } from \"../driver/mongodb/MongoQueryRunner\"\nimport { ForbiddenTransactionModeOverrideError, TypeORMError } from \"../error\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\n\n/**\n * Executes migrations: runs pending and reverts previously executed migrations.\n */\nexport class MigrationExecutor {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates how migrations should be run in transactions.\n * all: all migrations are run in a single transaction\n * none: all migrations are run without a transaction\n * each: each migration is run in a separate transaction\n */\n transaction: \"all\" | \"none\" | \"each\" = \"all\"\n\n /**\n * Option to fake-run or fake-revert a migration, adding to the\n * executed migrations table, but not actually running it. This feature is\n * useful for when migrations are added after the fact or for\n * interoperability between applications which are desired to each keep\n * a consistent migration history.\n */\n fake: boolean\n\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n private readonly migrationsDatabase?: string\n private readonly migrationsSchema?: string\n private readonly migrationsTable: string\n private readonly migrationsTableName: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected connection: DataSource,\n protected queryRunner?: QueryRunner,\n ) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n this.migrationsDatabase = database\n this.migrationsSchema = schema\n this.migrationsTableName =\n connection.options.migrationsTableName || \"migrations\"\n this.migrationsTable = this.connection.driver.buildTableName(\n this.migrationsTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Tries to execute a single migration given.\n */\n public async executeMigration(migration: Migration): Promise<Migration> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n await queryRunner.beforeMigration()\n await (migration.instance as any).up(queryRunner)\n await queryRunner.afterMigration()\n await this.insertExecutedMigration(queryRunner, migration)\n\n return migration\n })\n }\n\n /**\n * Returns an array of all migrations.\n */\n public async getAllMigrations(): Promise<Migration[]> {\n return Promise.resolve(this.getMigrations())\n }\n\n /**\n * Returns an array of all executed migrations.\n */\n public async getExecutedMigrations(): Promise<Migration[]> {\n return this.withQueryRunner(async (queryRunner) => {\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n return await this.loadExecutedMigrations(queryRunner)\n })\n }\n\n /**\n * Returns an array of all pending migrations.\n */\n public async getPendingMigrations(): Promise<Migration[]> {\n const allMigrations = await this.getAllMigrations()\n const executedMigrations = await this.getExecutedMigrations()\n\n return allMigrations.filter(\n (migration) =>\n !executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n ),\n )\n }\n\n /**\n * Inserts an executed migration.\n */\n public insertMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.insertExecutedMigration(q, migration),\n )\n }\n\n /**\n * Deletes an executed migration.\n */\n public deleteMigration(migration: Migration): Promise<void> {\n return this.withQueryRunner((q) =>\n this.deleteExecutedMigration(q, migration),\n )\n }\n\n /**\n * Lists all migrations and whether they have been executed or not\n * returns true if there are unapplied migrations\n */\n async showMigrations(): Promise<boolean> {\n let hasUnappliedMigrations = false\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if its not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n for (const migration of allMigrations) {\n const executedMigration = executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n\n if (executedMigration) {\n this.connection.logger.logSchemaBuild(\n `[X] ${executedMigration.id} ${migration.name}`,\n )\n } else {\n hasUnappliedMigrations = true\n this.connection.logger.logSchemaBuild(`[ ] ${migration.name}`)\n }\n }\n\n // if query runner was created by us then release it\n if (!this.queryRunner) {\n await queryRunner.release()\n }\n\n return hasUnappliedMigrations\n }\n\n /**\n * Executes all pending migrations. Pending migrations are migrations that are not yet executed,\n * thus not saved in the database.\n */\n async executePendingMigrations(): Promise<Migration[]> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create the typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestTimestampMigration(executedMigrations)\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n // variable to store all migrations we did successfully\n const successMigrations: Migration[] = []\n\n // find all migrations that needs to be executed\n const pendingMigrations = allMigrations.filter((migration) => {\n // check if we already have executed migration\n const executedMigration = executedMigrations.find(\n (executedMigration) =>\n executedMigration.name === migration.name,\n )\n if (executedMigration) return false\n\n // migration is new and not executed. now check if its timestamp is correct\n // if (lastTimeExecutedMigration && migration.timestamp < lastTimeExecutedMigration.timestamp)\n // throw new TypeORMError(`New migration found: ${migration.name}, however this migration's timestamp is not valid. Migration's timestamp should not be older then migrations already executed in the database.`);\n\n // every check is passed means that migration was not run yet and we need to run it\n return true\n })\n\n // if no migrations are pending then nothing to do here\n if (!pendingMigrations.length) {\n this.connection.logger.logSchemaBuild(`No migrations are pending`)\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n return []\n }\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${allMigrations.length} migrations were found in the source code.`,\n )\n if (lastTimeExecutedMigration)\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(\n `${pendingMigrations.length} migrations are new migrations must be executed.`,\n )\n\n if (this.transaction === \"all\") {\n // If we desire to run all migrations in a single transaction\n // but there is a migration that explicitly overrides the transaction mode\n // then we have to fail since we cannot properly resolve that intent\n // In theory we could support overrides that are set to `true`,\n // however to keep the interface more rigid, we fail those too\n const migrationsOverridingTransactionMode =\n pendingMigrations.filter(\n (migration) =>\n !(migration.instance?.transaction === undefined),\n )\n\n if (migrationsOverridingTransactionMode.length > 0) {\n const error = new ForbiddenTransactionModeOverrideError(\n migrationsOverridingTransactionMode,\n )\n this.connection.logger.logMigration(\n `Migrations failed, error: ${error.message}`,\n )\n throw error\n }\n }\n\n // Set the per-migration defaults for the transaction mode\n // so that we have one centralized place that controls this behavior\n\n // When transaction mode is `each` the default is to run in a transaction\n // When transaction mode is `none` the default is to not run in a transaction\n // When transaction mode is `all` the default is to not run in a transaction\n // since all the migrations are already running in one single transaction\n\n const txModeDefault = {\n each: true,\n none: false,\n all: false,\n }[this.transaction]\n\n for (const migration of pendingMigrations) {\n if (migration.instance) {\n const instanceTx = migration.instance.transaction\n\n if (instanceTx === undefined) {\n migration.transaction = txModeDefault\n } else {\n migration.transaction = instanceTx\n }\n }\n }\n\n // start transaction if its not started yet\n let transactionStartedByUs = false\n if (this.transaction === \"all\" && !queryRunner.isTransactionActive) {\n await queryRunner.beforeMigration()\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n // run all pending migrations in a sequence\n try {\n for (const migration of pendingMigrations) {\n if (this.fake) {\n // directly insert migration record into the database if it is fake\n await this.insertExecutedMigration(queryRunner, migration)\n\n // nothing else needs to be done, continue to next migration\n continue\n }\n\n if (migration.transaction && !queryRunner.isTransactionActive) {\n await queryRunner.beforeMigration()\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n await migration\n .instance!.up(queryRunner)\n .catch((error) => {\n // informative log about migration failure\n this.connection.logger.logMigration(\n `Migration \"${migration.name}\" failed, error: ${error?.message}`,\n )\n throw error\n })\n .then(async () => {\n // now when migration is executed we need to insert record about it into the database\n await this.insertExecutedMigration(\n queryRunner,\n migration,\n )\n // commit transaction if we started it\n if (migration.transaction && transactionStartedByUs) {\n await queryRunner.commitTransaction()\n await queryRunner.afterMigration()\n }\n })\n .then(() => {\n // informative log about migration success\n successMigrations.push(migration)\n this.connection.logger.logSchemaBuild(\n `Migration ${migration.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } executed successfully.`,\n )\n })\n }\n\n // commit transaction if we started it\n if (this.transaction === \"all\" && transactionStartedByUs) {\n await queryRunner.commitTransaction()\n await queryRunner.afterMigration()\n }\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n return successMigrations\n }\n\n /**\n * Reverts last migration that were run.\n */\n async undoLastMigration(): Promise<void> {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n // create migrations table if it's not created yet\n await this.createMigrationsTableIfNotExist(queryRunner)\n\n // create typeorm_metadata table if it's not created yet\n const schemaBuilder = this.connection.driver.createSchemaBuilder()\n if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {\n await schemaBuilder.createMetadataTableIfNecessary(queryRunner)\n }\n\n // get all migrations that are executed and saved in the database\n const executedMigrations = await this.loadExecutedMigrations(\n queryRunner,\n )\n\n // get the time when last migration was executed\n let lastTimeExecutedMigration =\n this.getLatestExecutedMigration(executedMigrations)\n\n // if no migrations found in the database then nothing to revert\n if (!lastTimeExecutedMigration) {\n this.connection.logger.logSchemaBuild(\n `No migrations were found in the database. Nothing to revert!`,\n )\n return\n }\n\n // get all user's migrations in the source code\n const allMigrations = this.getMigrations()\n\n // find the instance of the migration we need to remove\n const migrationToRevert = allMigrations.find(\n (migration) => migration.name === lastTimeExecutedMigration!.name,\n )\n\n // if no migrations found in the database then nothing to revert\n if (!migrationToRevert)\n throw new TypeORMError(\n `No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options.`,\n )\n\n // log information about migration execution\n this.connection.logger.logSchemaBuild(\n `${executedMigrations.length} migrations are already loaded in the database.`,\n )\n this.connection.logger.logSchemaBuild(\n `${\n lastTimeExecutedMigration.name\n } is the last executed migration. It was executed on ${new Date(\n lastTimeExecutedMigration.timestamp,\n ).toString()}.`,\n )\n this.connection.logger.logSchemaBuild(`Now reverting it...`)\n\n // start transaction if its not started yet\n let transactionStartedByUs = false\n if (this.transaction !== \"none\" && !queryRunner.isTransactionActive) {\n await queryRunner.startTransaction()\n transactionStartedByUs = true\n }\n\n try {\n if (!this.fake) {\n await queryRunner.beforeMigration()\n await migrationToRevert.instance!.down(queryRunner)\n await queryRunner.afterMigration()\n }\n\n await this.deleteExecutedMigration(queryRunner, migrationToRevert)\n this.connection.logger.logSchemaBuild(\n `Migration ${migrationToRevert.name} has been ${\n this.fake ? \"(fake)\" : \"\"\n } reverted successfully.`,\n )\n\n // commit transaction if we started it\n if (transactionStartedByUs) await queryRunner.commitTransaction()\n } catch (err) {\n // rollback transaction if we started it\n if (transactionStartedByUs) {\n try {\n // we throw original error even if rollback thrown an error\n await queryRunner.rollbackTransaction()\n } catch (rollbackError) {}\n }\n\n throw err\n } finally {\n // if query runner was created by us then release it\n if (!this.queryRunner) await queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates table \"migrations\" that will store information about executed migrations.\n */\n protected async createMigrationsTableIfNotExist(\n queryRunner: QueryRunner,\n ): Promise<void> {\n // If driver is mongo no need to create\n if (this.connection.driver.options.type === \"mongodb\") {\n return\n }\n const tableExist = await queryRunner.hasTable(this.migrationsTable) // todo: table name should be configurable\n if (!tableExist) {\n await queryRunner.createTable(\n new Table({\n database: this.migrationsDatabase,\n schema: this.migrationsSchema,\n name: this.migrationsTable,\n columns: [\n {\n name: \"id\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationId,\n }),\n isGenerated: true,\n generationStrategy: \"increment\",\n isPrimary: true,\n isNullable: false,\n },\n {\n name: \"timestamp\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"name\",\n type: this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationName,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n }\n\n /**\n * Loads all migrations that were executed and saved into the database (sorts by id).\n */\n protected async loadExecutedMigrations(\n queryRunner: QueryRunner,\n ): Promise<Migration[]> {\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n return await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .find<Migration>()\n .sort({ _id: -1 })\n .toArray()\n } else {\n const migrationsRaw: ObjectLiteral[] = await this.connection.manager\n .createQueryBuilder(queryRunner)\n .select()\n .orderBy(this.connection.driver.escape(\"id\"), \"DESC\")\n .from(this.migrationsTable, this.migrationsTableName)\n .getRawMany()\n return migrationsRaw.map((migrationRaw) => {\n return new Migration(\n parseInt(migrationRaw[\"id\"]),\n parseInt(migrationRaw[\"timestamp\"]),\n migrationRaw[\"name\"],\n )\n })\n }\n }\n\n /**\n * Gets all migrations that setup for this connection.\n */\n protected getMigrations(): Migration[] {\n const migrations = this.connection.migrations.map((migration) => {\n const migrationClassName =\n migration.name || (migration.constructor as any).name\n const migrationTimestamp = parseInt(\n migrationClassName.substr(-13),\n 10,\n )\n if (!migrationTimestamp || isNaN(migrationTimestamp)) {\n throw new TypeORMError(\n `${migrationClassName} migration name is wrong. Migration class name should have a JavaScript timestamp appended.`,\n )\n }\n\n return new Migration(\n undefined,\n migrationTimestamp,\n migrationClassName,\n migration,\n )\n })\n\n this.checkForDuplicateMigrations(migrations)\n\n // sort them by timestamp\n return migrations.sort((a, b) => a.timestamp - b.timestamp)\n }\n\n protected checkForDuplicateMigrations(migrations: Migration[]) {\n const migrationNames = migrations.map((migration) => migration.name)\n const duplicates = Array.from(\n new Set(\n migrationNames.filter(\n (migrationName, index) =>\n migrationNames.indexOf(migrationName) < index,\n ),\n ),\n )\n if (duplicates.length > 0) {\n throw Error(`Duplicate migrations: ${duplicates.join(\", \")}`)\n }\n }\n\n /**\n * Finds the latest migration (sorts by timestamp) in the given array of migrations.\n */\n protected getLatestTimestampMigration(\n migrations: Migration[],\n ): Migration | undefined {\n const sortedMigrations = migrations\n .map((migration) => migration)\n .sort((a, b) => (a.timestamp - b.timestamp) * -1)\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined\n }\n\n /**\n * Finds the latest migration in the given array of migrations.\n * PRE: Migration array must be sorted by descending id.\n */\n protected getLatestExecutedMigration(\n sortedMigrations: Migration[],\n ): Migration | undefined {\n return sortedMigrations.length > 0 ? sortedMigrations[0] : undefined\n }\n\n /**\n * Inserts new executed migration's data into migrations table.\n */\n protected async insertExecutedMigration(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const values: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n values[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n values[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n values[\"timestamp\"] = migration.timestamp\n values[\"name\"] = migration.name\n }\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .insertOne(values)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .insert()\n .into(this.migrationsTable)\n .values(values)\n .execute()\n }\n }\n\n /**\n * Delete previously executed migration's data from the migrations table.\n */\n protected async deleteExecutedMigration(\n queryRunner: QueryRunner,\n migration: Migration,\n ): Promise<void> {\n const conditions: ObjectLiteral = {}\n if (this.connection.driver.options.type === \"mssql\") {\n conditions[\"timestamp\"] = new MssqlParameter(\n migration.timestamp,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes\n .migrationTimestamp,\n }) as any,\n )\n conditions[\"name\"] = new MssqlParameter(\n migration.name,\n this.connection.driver.normalizeType({\n type: this.connection.driver.mappedDataTypes.migrationName,\n }) as any,\n )\n } else {\n conditions[\"timestamp\"] = migration.timestamp\n conditions[\"name\"] = migration.name\n }\n\n if (this.connection.driver.options.type === \"mongodb\") {\n const mongoRunner = queryRunner as MongoQueryRunner\n await mongoRunner.databaseConnection\n .db(this.connection.driver.database!)\n .collection(this.migrationsTableName)\n .deleteOne(conditions)\n } else {\n const qb = queryRunner.manager.createQueryBuilder()\n await qb\n .delete()\n .from(this.migrationsTable)\n .where(`${qb.escape(\"timestamp\")} = :timestamp`)\n .andWhere(`${qb.escape(\"name\")} = :name`)\n .setParameters(conditions)\n .execute()\n }\n }\n\n protected async withQueryRunner<T extends any>(\n callback: (queryRunner: QueryRunner) => T | Promise<T>,\n ) {\n const queryRunner =\n this.queryRunner || this.connection.createQueryRunner()\n\n try {\n return callback(queryRunner)\n } finally {\n if (!this.queryRunner) {\n await queryRunner.release()\n }\n }\n }\n}\n"],"sourceRoot":".."}