hysteria-orm 10.0.9 → 10.1.0
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.
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3 -3
- package/lib/index.d.ts +3 -3
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -4074,7 +4074,7 @@ declare abstract class Model extends Entity {
|
|
|
4074
4074
|
/**
|
|
4075
4075
|
* @description Finds records for the given column and value
|
|
4076
4076
|
*/
|
|
4077
|
-
static findBy<T extends Model, S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(this: new () => T | typeof Model, column:
|
|
4077
|
+
static findBy<T extends Model, S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(this: new () => T | typeof Model, column: ModelKey<T>, value: string | number | boolean | Date | null, options?: BaseModelMethodOptions): Promise<FindReturnType<T, S, R>[]>;
|
|
4078
4078
|
/**
|
|
4079
4079
|
* @description Finds the first record for the given column and value
|
|
4080
4080
|
*/
|
|
@@ -4492,7 +4492,7 @@ declare class AutogeneratedModel extends Model {
|
|
|
4492
4492
|
/**
|
|
4493
4493
|
* @description Mixin to add a user model with id, email, createdAt, updatedAt and deletedAt columns
|
|
4494
4494
|
*/
|
|
4495
|
-
declare class
|
|
4495
|
+
declare class UserMixin extends Model {
|
|
4496
4496
|
id: BigInt;
|
|
4497
4497
|
email: string;
|
|
4498
4498
|
createdAt: Date;
|
|
@@ -5326,4 +5326,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5326
5326
|
modelName: string;
|
|
5327
5327
|
}>;
|
|
5328
5328
|
|
|
5329
|
-
export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput,
|
|
5329
|
+
export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
|
package/lib/index.d.ts
CHANGED
|
@@ -4074,7 +4074,7 @@ declare abstract class Model extends Entity {
|
|
|
4074
4074
|
/**
|
|
4075
4075
|
* @description Finds records for the given column and value
|
|
4076
4076
|
*/
|
|
4077
|
-
static findBy<T extends Model, S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(this: new () => T | typeof Model, column:
|
|
4077
|
+
static findBy<T extends Model, S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(this: new () => T | typeof Model, column: ModelKey<T>, value: string | number | boolean | Date | null, options?: BaseModelMethodOptions): Promise<FindReturnType<T, S, R>[]>;
|
|
4078
4078
|
/**
|
|
4079
4079
|
* @description Finds the first record for the given column and value
|
|
4080
4080
|
*/
|
|
@@ -4492,7 +4492,7 @@ declare class AutogeneratedModel extends Model {
|
|
|
4492
4492
|
/**
|
|
4493
4493
|
* @description Mixin to add a user model with id, email, createdAt, updatedAt and deletedAt columns
|
|
4494
4494
|
*/
|
|
4495
|
-
declare class
|
|
4495
|
+
declare class UserMixin extends Model {
|
|
4496
4496
|
id: BigInt;
|
|
4497
4497
|
email: string;
|
|
4498
4498
|
createdAt: Date;
|
|
@@ -5326,4 +5326,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5326
5326
|
modelName: string;
|
|
5327
5327
|
}>;
|
|
5328
5328
|
|
|
5329
|
-
export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput,
|
|
5329
|
+
export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
|
package/lib/index.js
CHANGED
|
@@ -179,5 +179,5 @@ export default class extends Migration {
|
|
|
179
179
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
180
180
|
name TEXT NOT NULL,
|
|
181
181
|
timestamp TEXT NOT NULL DEFAULT '${new Date().toISOString()}'
|
|
182
|
-
);`}},Ee=new ys;var Kd=async(i,t)=>{if(i.endsWith(".ts"))return await import('typescript').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `typeScript` installed in your project. Please install it with `npm install typescript --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),await import('esbuild').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `esbuild` installed in your project. Please install it with `npm install esbuild --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),await import('bundle-require').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `bundle-require` installed in your project. Please install it with `npm install bundle-require --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),Il(i);try{return import(pathToFileURL(i).href)}catch{let o=createRequire(import.meta.url);try{let n=o(i);return {default:n.default||n,...n}}catch{throw new u(`MigrationUtils::importMigrationFile Failed to import migration file: ${i}. Both ESM and CommonJS imports failed.`,"MIGRATION_MODULE_NOT_FOUND")}}};async function pr(i,t){switch(i){case "mariadb":case "mysql":let e=t;return await e.query(Ee.migrationTableTemplateMysql()),(await e.query(Ee.selectAllFromMigrationsTemplate()))[0];case "postgres":case "cockroachdb":let o=t;return await o.query(Ee.migrationTableTemplatePg()),(await o.query(Ee.selectAllFromMigrationsTemplate())).rows;case "sqlite":return await Bl(Ee.migrationTableTemplateSQLite(),[],t),await Bl(Ee.selectAllFromMigrationsTemplate(),[],t)||[];default:throw new u("MigrationUtils::getMigrationTable Unsupported database type","DEVELOPMENT_ERROR")}}async function yr(i,t,e){let r=Fd(t),o=[];for(let n of r){let s=await kd(n,t),a=new s(i||M.DB_TYPE);a.migrationName=n,o.push(a);}return o}async function Qd(i,t){let e=await Kd(i);if(!e.default)throw new u("MigrationUtils::loadMigrationModule Migration module does not have a default export","MIGRATION_MODULE_NOT_FOUND");return e.default}async function kd(i,t=M.MIGRATION_PATH||"database/migrations",e){t=join(t,i);let r=ut.resolve(process.cwd(),t),o=await Qd(r);if(!o)throw new u("MigrationUtils::findMigrationModule migrations module not found for migration: "+i,"MIGRATION_MODULE_NOT_FOUND");return o}function Fd(i){let t=process.cwd(),e=ut.resolve(i||M.MIGRATION_PATH||"database/migrations"),r=ut.resolve(t,e);try{let o=ml.readdirSync(r).filter(n=>{let s=ut.extname(n),a=ut.join(r,n);return ml.statSync(a).isFile()&&(s===".ts"||s===".js")});if(o.length)return o;throw new u("MigrationUtils::findMigrationNames No database migration files found on path: "+r,"MIGRATION_MODULE_NOT_FOUND")}catch{throw new u("MigrationUtils::findMigrationNames No database migration files found on path: "+r,"MIGRATION_MODULE_NOT_FOUND")}}async function Bl(i,t,e){return new Promise((r,o)=>{e.all(i,t,(n,s)=>{n&&o(n),r(s);});})}async function fs(i,t,e,r,o){let n=i.getDbType(),s=null;N.info("Rolling back migrations for database type: "+n);try{let a=await pr(n,i.getPool()),l=await yr(n,e,r),d=a.map(c=>c.name),m=l.filter(c=>d.includes(c.migrationName));if(m.length===0){N.info("No pending migrations.");return}if(t);let p=new _e(i);o&&(s=await i.startTransaction(),i=s.sql),await p.downMigrations(m),o&&await s?.commit();}catch(a){throw a}N.info("Migrations rolled back successfully");}async function hs(i,t,e,r,o){let n=i.getDbType(),s=null;N.info("Running migrations for database type: "+n);try{let a=await pr(n,i.getPool()),d=(await yr(n,e,r)).filter(p=>!a.map(c=>c.name).includes(p.migrationName));if(!d.length){N.info("No pending migrations.");return}if(t);let m=new _e(i);o&&(s=await i.startTransaction(),i=s.sql),await m.upMigrations(d),o&&await s?.commit();}catch(a){throw a}N.info("Migrations ran successfully");}var _e=class{constructor(t){this.migrationTable="migrations";this.sql=t||ne.getInstance();}async upMigrations(t){for(let e of t){N.info(`Running migration ${e.migrationName}`),await e.up();let r=e.schema.queryStatements;for(let o of r)o&&await this.sql.rawQuery(o);await this.addMigrationToMigrationTable(e),e.afterMigration&&await e.afterMigration(this.sql);}}async downMigrations(t){t=t.reverse();for(let e of t){N.info(`Rolling back migration ${e.migrationName}`),await e.down();let r=e.schema.queryStatements;for(let o of r)o&&await this.sql.rawQuery(o);await this.deleteMigrationFromMigrationTable(e),e.afterMigration&&await e.afterMigration(this.sql);}}async addMigrationToMigrationTable(t){let r=new Date().toISOString().replace("T"," ").replace(/\.\d{3}Z$/,"");await this.sql.query(this.migrationTable).insert({name:t.migrationName,timestamp:r});}async deleteMigrationFromMigrationTable(t){await this.sql.query(this.migrationTable).where("name",t.migrationName).delete();}},gs=class{constructor(t=M.MIGRATION_PATH||"database/migrations",e){this.migrationPath=t,this.sqlDataSourceInput=e;}async up(){return this.migrate("up")}async down(){return this.migrate("down")}async migrate(t){M.MIGRATION_PATH=this.migrationPath;let e=this.sqlDataSourceInput instanceof ne?this.sqlDataSourceInput:await ne.connect({...this.sqlDataSourceInput});return t==="up"?hs(e,void 0,this.migrationPath):fs(e,void 0,this.migrationPath)}},Ld=(i,t)=>new gs(i,t);export{cs as AutogeneratedModel,Ue as Collection,u as HysteriaError,ps as Migration,Z as Model,We as ModelQueryBuilder,dt as MongoDataSource,lt as TimestampedModel,Pe as
|
|
182
|
+
);`}},Ee=new ys;var Kd=async(i,t)=>{if(i.endsWith(".ts"))return await import('typescript').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `typeScript` installed in your project. Please install it with `npm install typescript --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),await import('esbuild').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `esbuild` installed in your project. Please install it with `npm install esbuild --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),await import('bundle-require').catch(()=>{throw new u("MigrationUtils::importMigrationFile In order to use TypeScript migrations, you must have `bundle-require` installed in your project. Please install it with `npm install bundle-require --save-dev`, if you're in a production environment, it's recommended to transpile your migrations to JavaScript before running the application.","MIGRATION_MODULE_NOT_FOUND")}),Il(i);try{return import(pathToFileURL(i).href)}catch{let o=createRequire(import.meta.url);try{let n=o(i);return {default:n.default||n,...n}}catch{throw new u(`MigrationUtils::importMigrationFile Failed to import migration file: ${i}. Both ESM and CommonJS imports failed.`,"MIGRATION_MODULE_NOT_FOUND")}}};async function pr(i,t){switch(i){case "mariadb":case "mysql":let e=t;return await e.query(Ee.migrationTableTemplateMysql()),(await e.query(Ee.selectAllFromMigrationsTemplate()))[0];case "postgres":case "cockroachdb":let o=t;return await o.query(Ee.migrationTableTemplatePg()),(await o.query(Ee.selectAllFromMigrationsTemplate())).rows;case "sqlite":return await Bl(Ee.migrationTableTemplateSQLite(),[],t),await Bl(Ee.selectAllFromMigrationsTemplate(),[],t)||[];default:throw new u("MigrationUtils::getMigrationTable Unsupported database type","DEVELOPMENT_ERROR")}}async function yr(i,t,e){let r=Fd(t),o=[];for(let n of r){let s=await kd(n,t),a=new s(i||M.DB_TYPE);a.migrationName=n,o.push(a);}return o}async function Qd(i,t){let e=await Kd(i);if(!e.default)throw new u("MigrationUtils::loadMigrationModule Migration module does not have a default export","MIGRATION_MODULE_NOT_FOUND");return e.default}async function kd(i,t=M.MIGRATION_PATH||"database/migrations",e){t=join(t,i);let r=ut.resolve(process.cwd(),t),o=await Qd(r);if(!o)throw new u("MigrationUtils::findMigrationModule migrations module not found for migration: "+i,"MIGRATION_MODULE_NOT_FOUND");return o}function Fd(i){let t=process.cwd(),e=ut.resolve(i||M.MIGRATION_PATH||"database/migrations"),r=ut.resolve(t,e);try{let o=ml.readdirSync(r).filter(n=>{let s=ut.extname(n),a=ut.join(r,n);return ml.statSync(a).isFile()&&(s===".ts"||s===".js")});if(o.length)return o;throw new u("MigrationUtils::findMigrationNames No database migration files found on path: "+r,"MIGRATION_MODULE_NOT_FOUND")}catch{throw new u("MigrationUtils::findMigrationNames No database migration files found on path: "+r,"MIGRATION_MODULE_NOT_FOUND")}}async function Bl(i,t,e){return new Promise((r,o)=>{e.all(i,t,(n,s)=>{n&&o(n),r(s);});})}async function fs(i,t,e,r,o){let n=i.getDbType(),s=null;N.info("Rolling back migrations for database type: "+n);try{let a=await pr(n,i.getPool()),l=await yr(n,e,r),d=a.map(c=>c.name),m=l.filter(c=>d.includes(c.migrationName));if(m.length===0){N.info("No pending migrations.");return}if(t);let p=new _e(i);o&&(s=await i.startTransaction(),i=s.sql),await p.downMigrations(m),o&&await s?.commit();}catch(a){throw a}N.info("Migrations rolled back successfully");}async function hs(i,t,e,r,o){let n=i.getDbType(),s=null;N.info("Running migrations for database type: "+n);try{let a=await pr(n,i.getPool()),d=(await yr(n,e,r)).filter(p=>!a.map(c=>c.name).includes(p.migrationName));if(!d.length){N.info("No pending migrations.");return}if(t);let m=new _e(i);o&&(s=await i.startTransaction(),i=s.sql),await m.upMigrations(d),o&&await s?.commit();}catch(a){throw a}N.info("Migrations ran successfully");}var _e=class{constructor(t){this.migrationTable="migrations";this.sql=t||ne.getInstance();}async upMigrations(t){for(let e of t){N.info(`Running migration ${e.migrationName}`),await e.up();let r=e.schema.queryStatements;for(let o of r)o&&await this.sql.rawQuery(o);await this.addMigrationToMigrationTable(e),e.afterMigration&&await e.afterMigration(this.sql);}}async downMigrations(t){t=t.reverse();for(let e of t){N.info(`Rolling back migration ${e.migrationName}`),await e.down();let r=e.schema.queryStatements;for(let o of r)o&&await this.sql.rawQuery(o);await this.deleteMigrationFromMigrationTable(e),e.afterMigration&&await e.afterMigration(this.sql);}}async addMigrationToMigrationTable(t){let r=new Date().toISOString().replace("T"," ").replace(/\.\d{3}Z$/,"");await this.sql.query(this.migrationTable).insert({name:t.migrationName,timestamp:r});}async deleteMigrationFromMigrationTable(t){await this.sql.query(this.migrationTable).where("name",t.migrationName).delete();}},gs=class{constructor(t=M.MIGRATION_PATH||"database/migrations",e){this.migrationPath=t,this.sqlDataSourceInput=e;}async up(){return this.migrate("up")}async down(){return this.migrate("down")}async migrate(t){M.MIGRATION_PATH=this.migrationPath;let e=this.sqlDataSourceInput instanceof ne?this.sqlDataSourceInput:await ne.connect({...this.sqlDataSourceInput});return t==="up"?hs(e,void 0,this.migrationPath):fs(e,void 0,this.migrationPath)}},Ld=(i,t)=>new gs(i,t);export{cs as AutogeneratedModel,Ue as Collection,u as HysteriaError,ps as Migration,Z as Model,We as ModelQueryBuilder,dt as MongoDataSource,lt as TimestampedModel,Pe as UserMixin,us as UuidModel,Sl as belongsTo,A as column,Dd as createModelFactory,Ld as defineMigrator,hu as generateOpenApiModel,gu as generateOpenApiModelSchema,Cs as generateOpenApiModelWithMetadata,bs as getCollectionProperties,_l as getIndexes,ft as getModelColumns,Rl as getPrimaryKey,Wt as getRelations,Cl as getRelationsMetadata,Ol as getUniques,Ml as hasMany,Nl as hasOne,cR as index,N as logger,ql as manyToMany,dt as mongo,gr as property,ms as redis,ne as sql,mR as unique,pR as view,B as withPerformance};//# sourceMappingURL=index.js.map
|
|
183
183
|
//# sourceMappingURL=index.js.map
|