From ac6fd0ef1d6651449d96ea26b29ff91561b1150c Mon Sep 17 00:00:00 2001 From: garrettmills Date: Tue, 7 Nov 2023 21:08:05 -0600 Subject: [PATCH] 0.14.14: Misc bugfixes in migrations & AsyncCollection keys --- package.json | 2 +- src/auth/provider/oauth/CoreIDLoginProvider.ts | 3 +++ src/orm/dialect/PostgreSQLDialect.ts | 6 +++++- src/orm/dialect/SQLDialect.ts | 9 ++++++--- src/orm/schema/TableBuilder.ts | 11 ++++++++++- src/util/collection/AsyncCollection.ts | 7 +++++-- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index b944ba3..1207fcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.14.13", + "version": "0.14.14", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/auth/provider/oauth/CoreIDLoginProvider.ts b/src/auth/provider/oauth/CoreIDLoginProvider.ts index dd8f29b..8d4c1bf 100644 --- a/src/auth/provider/oauth/CoreIDLoginProvider.ts +++ b/src/auth/provider/oauth/CoreIDLoginProvider.ts @@ -92,5 +92,8 @@ export class CoreIDLoginProvider extends OAuth2LoginProvider { const alters: string[] = [] const columns = builder.getColumns() @@ -628,6 +628,10 @@ export class PostgreSQLDialect extends SQLDialect { alters.push(` RENAME TO "${builder.getRename()}"`) } + if ( !alters.length ) { + return undefined + } + return 'ALTER TABLE ' + builder.name + '\n' + alters.join(',\n') } diff --git a/src/orm/dialect/SQLDialect.ts b/src/orm/dialect/SQLDialect.ts index 244b5a3..0b9da2b 100644 --- a/src/orm/dialect/SQLDialect.ts +++ b/src/orm/dialect/SQLDialect.ts @@ -2,7 +2,7 @@ import {Constraint, QuerySource} from '../types' import {AbstractBuilder} from '../builder/AbstractBuilder' import {AppClass} from '../../lifecycle/AppClass' import {ColumnBuilder, IndexBuilder, TableBuilder} from '../schema/TableBuilder' -import {Collectable, Collection} from '../../util' +import {Collectable, Collection, Maybe} from '../../util' /** A scalar value which can be interpolated safely into an SQL query. */ export type ScalarEscapeValue = null | undefined | string | number | boolean | Date | QuerySafeValue; @@ -198,7 +198,7 @@ export abstract class SQLDialect extends AppClass { * Given a table schema-builder, render an `ALTER TABLE...` query. * @param builder */ - public abstract renderAlterTable(builder: TableBuilder): string; + public abstract renderAlterTable(builder: TableBuilder): Maybe; /** * Given a table schema-builder, render a `DROP TABLE...` query. @@ -314,7 +314,10 @@ export abstract class SQLDialect extends AppClass { if ( !builder.isExisting() && builder.isDirty() ) { parts.push(this.renderCreateTable(builder)) } else if ( builder.isExisting() && builder.isDirty() ) { - parts.push(this.renderAlterTable(builder)) + const alterTable = this.renderAlterTable(builder) + if ( alterTable ) { + parts.push(alterTable) + } } // Render the various schema queries as a single transaction diff --git a/src/orm/schema/TableBuilder.ts b/src/orm/schema/TableBuilder.ts index b4f4943..3d8a2f8 100644 --- a/src/orm/schema/TableBuilder.ts +++ b/src/orm/schema/TableBuilder.ts @@ -223,7 +223,16 @@ export class ColumnBuilder extends SchemaBuilderBase { * @param type */ public type(type: FieldType): this { - if ( this.targetType === type ) { + if ( + this.targetType === type + || ( + this.existsInSchema + && ( + (this.targetType === FieldType.integer && type === FieldType.serial) + || (this.targetType === FieldType.bigint && type === FieldType.bigserial) + ) + ) + ) { return this } diff --git a/src/util/collection/AsyncCollection.ts b/src/util/collection/AsyncCollection.ts index 3be9462..d80af45 100644 --- a/src/util/collection/AsyncCollection.ts +++ b/src/util/collection/AsyncCollection.ts @@ -43,7 +43,8 @@ export class AsyncCollection { if ( typeof key !== 'function' ) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - key = x => x[key] + await callback(items.map(x => x[key])) + return } await callback(items.map(key)) @@ -56,7 +57,9 @@ export class AsyncCollection { if ( typeof key !== 'function' ) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - key = x => x[key] + await callback(items.map(x => x[key]).map(x => Number(x)) + .all()) + return } await callback(items.map(key).map(x => Number(x))