hysteria-orm 10.4.7 → 10.4.8
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.js +1 -1
- package/lib/cli.js.map +1 -1
- package/package.json +8 -6
package/lib/cli.js
CHANGED
|
@@ -369,5 +369,5 @@ export default class extends BaseSeeder {
|
|
|
369
369
|
}
|
|
370
370
|
`}};var _f=(i,t,e)=>{let r=e||"database/seeders",o=t?".js":".ts",s=`${Date.now()}_${i}${o}`;ue.existsSync(r)||(ue.mkdirSync(r,{recursive:true}),g.info(`Created seeders directory: ${r}`));let a=je.join(r,s),l=$r.seederTemplate();ue.writeFileSync(a,l),g.info(`Seeder created successfully: ${a}`);},np=_f;var Cf=async(i,t,e)=>{let r=[];for(let o of t){let n=je.resolve(process.cwd(),o);ue.existsSync(n)||(g.error(`Path not found: ${n}`),process.exit(1));let s=ue.statSync(n);if(s.isDirectory()){let a=ue.readdirSync(n).filter(l=>l.endsWith(".ts")||l.endsWith(".js")).sort();for(let l of a)r.push({file:l,folder:n});}else if(s.isFile()){let a=je.basename(n),l=je.dirname(n);a.endsWith(".ts")||a.endsWith(".js")?r.push({file:a,folder:l}):(g.error(`File must be a .ts or .js file: ${a}`),process.exit(1));}}if(!r.length){g.info("No seeders found");return}g.info(`Found ${r.length} seeder(s) to run`),i.isConnected||await i.connect();for(let{file:o,folder:n}of r)try{g.info(`Running seeder: ${o}`);let s=je.resolve(n,o),a=await ie(s,e);if(!a.default){g.error(`Seeder ${o} does not export a default class`);continue}let l=new a.default(i);if(typeof l.run!="function"){g.error(`Seeder ${o} must have a run() method. Make sure it extends BaseSeeder from hysteria-orm`);continue}await l.run(),g.info(`\u2713 Completed seeder: ${o}`);}catch(s){throw g.error(`Failed to run seeder ${o}: ${s}`),s}g.info("All seeders completed successfully");},sp=Cf;var ap=()=>ue.existsSync(je.join(process.cwd(),"yarn.lock"))?["yarn","add"]:ue.existsSync(je.join(process.cwd(),"pnpm-lock.yaml"))?["pnpm","add"]:ue.existsSync(je.join(process.cwd(),"package-lock.json"))?["npm","install"]:ue.existsSync(je.join(process.cwd(),"bun.lockb"))?["bun","add"]:ue.existsSync(je.join(process.cwd(),"deno.lock"))?["deno","add"]:["npm","install"],ip=async(i,t,e,r)=>{let o=Af.createInterface({input:process.stdin,output:process.stdout}),n=e.join(", "),s=`Do you want to install the following dependencies using ${t}?
|
|
371
371
|
${n}
|
|
372
|
-
(y/n): `;return new Promise(a=>{o.question(s,l=>{if(o.close(),l.toLowerCase()==="y"||l.toLowerCase()==="yes"){execSync(i,r),a(true);return}a(false);});})},lp=async(i,t,e)=>{let r=Er.includes(e)?["bundle-require@^5.1.0","typescript@^5.9.3","esbuild@^0.27.0"]:[],o="";switch(e){case "mariadb":case "mysql":o="mysql2@^3.15.3",r.push("@types/mysql2@github:types/mysql2");break;case "cockroachdb":case "postgres":o="pg@^8.16.3",r.push("@types/pg@^8.16.0");break;case "sqlite":o="sqlite3@^5.1.7",r.push("@types/sqlite3@^5.1.0");break;case "mongo":o="mongodb@^7.0.0",r.push("@types/mongodb@^4.0.7");break;case "redis":o="ioredis@^5.8.2",r.push("@types/ioredis@^5.0.0");break;case "mssql":o="mssql@^12.2.0",r.push("@types/mssql@^9.1.8");break;case "oracledb":o="oracledb@^6.10.0",r.push("@types/oracledb@^6.10.0");break;default:throw new Error(`Invalid database type: ${e}`)}if(o){let s=await ip(`${i} ${t} ${o}`,i,[o],{stdio:"inherit"});s&&g.info("Driver dependency installed successfully"),s||g.info("Driver dependency installation skipped");}let n=i==="deno"?"--dev":"-D";if(r.length){let s=await ip(`${i} ${t} ${r.join(" ")} ${n}`,i,r,{stdio:"inherit"});s&&g.info("Dev dependencies installed successfully"),s||g.info("Dev dependencies installation skipped");}};var Er=["sqlite","mysql","postgres","mariadb","cockroachdb","mssql"],kr=Er.concat("mongodb","redis"),Ne=new Command;Ne.command("init",{isDefault:false}).option("-t, --type [type]",`Type of the database to connect to, available types: ${kr.join(", ")}`,void 0).description("Initialize the hysteria-orm with standard configuration, it will create a database if not exists and a migrations folder inside it if not exists, it will also create a index.ts file in the database folder").action(async i=>{let t=kr.join(", ");i.type||(g.error(`Database type is required (-t|--type), available types: ${t}`),process.exit(1)),kr.includes(i.type)||(g.error(`Invalid database type: ${i.type}, available types: ${kr.join(", ")}`),process.exit(1)),g.info("Initializing hysteria-orm with standard configuration"),g.info(`Database type: ${i.type||"not specified (will use env DB_TYPE)"}`);let[e,r]=ap();g.info(`Package manager: ${e}`),g.info("Installing base dependencies"),await lp(e,r,i.type);let o=Or.initTemplate(i.type);ue.existsSync("database")?g.info("database folder already exists, skipping"):ue.mkdirSync("database",{recursive:true}),ue.existsSync("database/index.ts")?g.info("database/index.ts file already exists, skipping"):ue.writeFileSync("database/index.ts",o),Er.includes(i.type)&&!ue.existsSync("database/migrations")?ue.mkdirSync("database/migrations",{recursive:true}):g.info("database/migrations folder already exists or is not a sql database, skipping"),g.info("Initialization completed successfully");});Ne.command("sql [sql]").alias("run:sql").option("-f, --file [path]","Path to the sql file",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-o, --out [query]","File path to save the query result",void 0).option("-t, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).description("Run a sql file or a sql query directly from the command line for the given connection defined in the env file").action(async(i,t)=>{g.info("Starting SQL execution"),t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let e=t?.file;!i&&!e&&(g.error("SQL query or file path is required"),process.exit(1)),i&&e&&(g.error("Cannot provide both sql query and file path"),process.exit(1));let r=je.resolve(process.cwd(),t.datasource),{default:o}=await ie(r,t?.tsconfigPath);if(i){g.info("Executing SQL query directly from command line");try{await Ir(i,o,t?.out),g.info("SQL execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL execution failed: ${s}`),process.exit(1);}}e||(g.error("No SQL statement or file provided"),process.exit(1)),g.info(`Reading SQL from file: ${e}`),e=je.resolve(process.cwd(),e),ue.existsSync(e)||(g.error(`File not found: ${e}`),process.exit(1));let n=ue.readFileSync(e,"utf-8");g.info(`SQL file loaded successfully (${n.length} characters)`);try{await Ir(n,o,t?.out),g.info("SQL file execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL file execution failed: ${s}`),process.exit(1);}});Ne.command("create:migration <name>").description("Create a new migration file, standard folder is migrations from the current directory you are now, you can change it in the env MIGRATION_PATH").option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-a, --alter","Generate a template for an alter table migration",false).option("-c, --create","Generate a template for a create table migration",false).option("-t, --table <table>","Specifies the target table name for the migration",false).action((i,t)=>{g.info(`Creating migration: ${i}`),g.info(`Migration options: javascript=${t.javascript}, alter=${t.alter}, create=${t.create}, table=${t.table||"not specified"}`),i||(g.error("Migration name is required"),process.exit(1)),t.alter&&t.create&&(g.error("Cannot use --alter and --create at the same time"),process.exit(1)),t.table&&!(t.create||t.alter)&&(g.error("Cannot use --table without --create or --alter"),process.exit(1));let e=t.alter?"alter":t.create?"create":"basic";g.info(`Migration mode: ${e}`),Fa(i,t.javascript,e,t.table||i);});Ne.command("migrate [runUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, only applies to postgres",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Run pending migrations, if runUntil is provided, it will run all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await ut(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("rollback [rollbackUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Rollbacks every migration that has been run, if rollbackUntil is provided, it will rollback all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await Mt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("refresh").option("-f, --force","Drop all tables in the database before running the migrations instead of running the down migrations",false).option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).option("-m, --migration-path [path]","Path to the migrations",void 0).description("Rollbacks every migration that has been run and then run the migrations").action(async i=>{let t=i?.force||false;i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),r=i?.migrationPath||e.migrationConfig.path,o=i?.tsconfigPath||e.migrationConfig.tsconfig,n=i?.lock??e.migrationConfig.lock,s=i?.lockTimeout?parseInt(i.lockTimeout,10):e.migrationConfig.lockTimeout,a=i?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock for refresh operation"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}t?await Lr(e,!1,a):await Mt(e,void 0,r,o,a),await ut(e,void 0,r,o,a);}catch(d){console.error(d);}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("generate:migrations").description("Generate a migration file based on the database schema and the models metadata, not supported for sqlite").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-f, --dry","Does not create a migration file but only outputs sql statements",false).option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-m, --migration-path [path]","Path to the migrations",void 0).option("-n, --name [name]","Name of the migration",void 0).action(async i=>{i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1)),i?.name||(i.name="auto_generated_migration"),i.name=`${Date.now()}_${i.name}`;let{default:t}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e=i?.migrationPath||t.migrationConfig.path;["mysql","postgres","mariadb","cockroachdb"].includes(t.getDbType())||(g.error(`generate:migrations is not supported for ${t.getDbType()}, it's suggested to use manual migrations instead`),process.exit(1));try{let n=(await tt.makeDiff(t)).getSqlStatements();if(n.length||(g.info("No new changes detected between database schema and models metadata"),process.exit(0)),i.dry){for(let l of n)console.log(l);process.exit(0);}ue.existsSync(e)||ue.mkdirSync(e,{recursive:!0});let s=await Dr.generate(n),a=i?.javascript?".js":".ts";ue.writeFileSync(`${e}/${i?.name}${a}`,s),g.info(`Migration file created successfully: ${i?.name}${a}`),await t.disconnect(),process.exit(0);}catch(o){console.error(o),await t.disconnect(),process.exit(1);}});Ne.command("create:seeder <name>").description("Create a new seeder file").option("-j, --javascript","Generate a javascript seeder file instead of a default typescript one",false).option("-s, --seeder-path [path]","Path to the seeders",void 0).action((i,t)=>{g.info(`Creating seeder: ${i}`),g.info(`Seeder options: javascript=${t.javascript}`),i||(g.error("Seeder name is required"),process.exit(1)),np(i,t.javascript,t.seederPath);});Ne.command("seed").description("Run database seeders from folder or specific files").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-s, --seeder-path [path]","Path to seeder folder or file (can be specified multiple times or comma-separated)",(i,t=[])=>[...t,i]).action(async i=>{g.info("Starting seeder execution"),i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:t}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e;i?.seederPath&&i.seederPath.length>0?e=i.seederPath.flatMap(o=>o.split(",").map(n=>n.trim())):e=[t.seederConfig.path];let r=i?.tsconfigPath||t.seederConfig.tsconfig;try{await sp(t,e,r),await t.disconnect(),g.info("Seeding completed successfully"),process.exit(0);}catch(o){console.error(o),await t.disconnect(),process.exit(1);}});Ne.parse(process.argv);export{Er as sqlDatabaseTypes};//# sourceMappingURL=cli.js.map
|
|
372
|
+
(y/n): `;return new Promise(a=>{o.question(s,l=>{if(o.close(),l.toLowerCase()==="y"||l.toLowerCase()==="yes"){execSync(i,r),a(true);return}a(false);});})},lp=async(i,t,e)=>{let r=Er.includes(e)?["bundle-require@^5.1.0","typescript@^5.9.3","esbuild@^0.27.2"]:[],o="";switch(e){case "mariadb":case "mysql":o="mysql2@^3.15.3",r.push("@types/mysql2@github:types/mysql2");break;case "cockroachdb":case "postgres":o="pg@^8.16.3",r.push("@types/pg@^8.16.0");break;case "sqlite":o="sqlite3@^5.1.7",r.push("@types/sqlite3@^5.1.0");break;case "mongo":o="mongodb@^7.0.0",r.push("@types/mongodb@^4.0.7");break;case "redis":o="ioredis@^5.8.2",r.push("@types/ioredis@^5.0.0");break;case "mssql":o="mssql@^12.2.0",r.push("@types/mssql@^9.1.8");break;case "oracledb":o="oracledb@^6.10.0",r.push("@types/oracledb@^6.10.0");break;default:throw new Error(`Invalid database type: ${e}`)}if(o){let s=await ip(`${i} ${t} ${o}`,i,[o],{stdio:"inherit"});s&&g.info("Driver dependency installed successfully"),s||g.info("Driver dependency installation skipped");}let n=i==="deno"?"--dev":"-D";if(r.length){let s=await ip(`${i} ${t} ${r.join(" ")} ${n}`,i,r,{stdio:"inherit"});s&&g.info("Dev dependencies installed successfully"),s||g.info("Dev dependencies installation skipped");}};var Er=["sqlite","mysql","postgres","mariadb","cockroachdb","mssql"],kr=Er.concat("mongodb","redis"),Ne=new Command;Ne.command("init",{isDefault:false}).option("-t, --type [type]",`Type of the database to connect to, available types: ${kr.join(", ")}`,void 0).description("Initialize the hysteria-orm with standard configuration, it will create a database if not exists and a migrations folder inside it if not exists, it will also create a index.ts file in the database folder").action(async i=>{let t=kr.join(", ");i.type||(g.error(`Database type is required (-t|--type), available types: ${t}`),process.exit(1)),kr.includes(i.type)||(g.error(`Invalid database type: ${i.type}, available types: ${kr.join(", ")}`),process.exit(1)),g.info("Initializing hysteria-orm with standard configuration"),g.info(`Database type: ${i.type||"not specified (will use env DB_TYPE)"}`);let[e,r]=ap();g.info(`Package manager: ${e}`),g.info("Installing base dependencies"),await lp(e,r,i.type);let o=Or.initTemplate(i.type);ue.existsSync("database")?g.info("database folder already exists, skipping"):ue.mkdirSync("database",{recursive:true}),ue.existsSync("database/index.ts")?g.info("database/index.ts file already exists, skipping"):ue.writeFileSync("database/index.ts",o),Er.includes(i.type)&&!ue.existsSync("database/migrations")?ue.mkdirSync("database/migrations",{recursive:true}):g.info("database/migrations folder already exists or is not a sql database, skipping"),g.info("Initialization completed successfully");});Ne.command("sql [sql]").alias("run:sql").option("-f, --file [path]","Path to the sql file",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-o, --out [query]","File path to save the query result",void 0).option("-t, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).description("Run a sql file or a sql query directly from the command line for the given connection defined in the env file").action(async(i,t)=>{g.info("Starting SQL execution"),t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let e=t?.file;!i&&!e&&(g.error("SQL query or file path is required"),process.exit(1)),i&&e&&(g.error("Cannot provide both sql query and file path"),process.exit(1));let r=je.resolve(process.cwd(),t.datasource),{default:o}=await ie(r,t?.tsconfigPath);if(i){g.info("Executing SQL query directly from command line");try{await Ir(i,o,t?.out),g.info("SQL execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL execution failed: ${s}`),process.exit(1);}}e||(g.error("No SQL statement or file provided"),process.exit(1)),g.info(`Reading SQL from file: ${e}`),e=je.resolve(process.cwd(),e),ue.existsSync(e)||(g.error(`File not found: ${e}`),process.exit(1));let n=ue.readFileSync(e,"utf-8");g.info(`SQL file loaded successfully (${n.length} characters)`);try{await Ir(n,o,t?.out),g.info("SQL file execution completed successfully"),process.exit(0);}catch(s){g.error(`SQL file execution failed: ${s}`),process.exit(1);}});Ne.command("create:migration <name>").description("Create a new migration file, standard folder is migrations from the current directory you are now, you can change it in the env MIGRATION_PATH").option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-a, --alter","Generate a template for an alter table migration",false).option("-c, --create","Generate a template for a create table migration",false).option("-t, --table <table>","Specifies the target table name for the migration",false).action((i,t)=>{g.info(`Creating migration: ${i}`),g.info(`Migration options: javascript=${t.javascript}, alter=${t.alter}, create=${t.create}, table=${t.table||"not specified"}`),i||(g.error("Migration name is required"),process.exit(1)),t.alter&&t.create&&(g.error("Cannot use --alter and --create at the same time"),process.exit(1)),t.table&&!(t.create||t.alter)&&(g.error("Cannot use --table without --create or --alter"),process.exit(1));let e=t.alter?"alter":t.create?"create":"basic";g.info(`Migration mode: ${e}`),Fa(i,t.javascript,e,t.table||i);});Ne.command("migrate [runUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, only applies to postgres",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Run pending migrations, if runUntil is provided, it will run all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await ut(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("rollback [rollbackUntil]").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-m, --migration-path [migrationPath]","Path to the migrations",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).description("Rollbacks every migration that has been run, if rollbackUntil is provided, it will rollback all migrations until the provided migration name").action(async(i,t)=>{t?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),t.datasource),t?.tsconfigPath),r=t?.migrationPath||e.migrationConfig.path,o=t?.tsconfigPath||e.migrationConfig.tsconfig,n=t?.lock??e.migrationConfig.lock,s=t?.lockTimeout?parseInt(t.lockTimeout,10):e.migrationConfig.lockTimeout,a=t?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}await Mt(e,i,r,o,a);}catch(d){throw console.error(d),d}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("refresh").option("-f, --force","Drop all tables in the database before running the migrations instead of running the down migrations",false).option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-t, --transactional","Runs all the pending migrations in a single transaction, this does not apply to mysql since it does not support transactions inside schema changes",true).option("-l, --lock","Acquire advisory lock before running migrations to prevent concurrent execution",true).option("--lock-timeout [lockTimeout]","Lock timeout in milliseconds for migration advisory lock acquisition",void 0).option("-m, --migration-path [path]","Path to the migrations",void 0).description("Rollbacks every migration that has been run and then run the migrations").action(async i=>{let t=i?.force||false;i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:e}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),r=i?.migrationPath||e.migrationConfig.path,o=i?.tsconfigPath||e.migrationConfig.tsconfig,n=i?.lock??e.migrationConfig.lock,s=i?.lockTimeout?parseInt(i.lockTimeout,10):e.migrationConfig.lockTimeout,a=i?.transactional??e.migrationConfig.transactional,l=false;try{if(n){if(g.info("Acquiring migration lock for refresh operation"),l=await e.acquireLock("hysteria_migration_lock",s),!l)throw g.error("Failed to acquire migration lock. Another migration may be running."),new Error("Failed to acquire migration lock");g.info("Migration lock acquired successfully");}t?await Lr(e,!1,a):await Mt(e,void 0,r,o,a),await ut(e,void 0,r,o,a);}catch(d){console.error(d);}finally{n&&l&&(g.info("Releasing migration lock"),await e.releaseLock("hysteria_migration_lock")||g.warn("Failed to release migration lock")),await e.disconnect();}});Ne.command("generate:migrations").description("Generate a migration file based on the database schema and the models metadata, not supported for sqlite").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-f, --dry","Does not create a migration file but only outputs sql statements",false).option("-j, --javascript","Generate a javascript migration file instead of a default typescript one",false).option("-m, --migration-path [path]","Path to the migrations",void 0).option("-n, --name [name]","Name of the migration",void 0).action(async i=>{i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1)),i?.name||(i.name="auto_generated_migration"),i.name=`${Date.now()}_${i.name}`;let{default:t}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e=i?.migrationPath||t.migrationConfig.path;["mysql","postgres","mariadb","cockroachdb"].includes(t.getDbType())||(g.error(`generate:migrations is not supported for ${t.getDbType()}, it's suggested to use manual migrations instead`),process.exit(1));try{let n=(await tt.makeDiff(t)).getSqlStatements();if(n.length||(g.info("No new changes detected between database schema and models metadata"),process.exit(0)),i.dry){for(let l of n)console.log(l);process.exit(0);}ue.existsSync(e)||ue.mkdirSync(e,{recursive:!0});let s=await Dr.generate(n),a=i?.javascript?".js":".ts";ue.writeFileSync(`${e}/${i?.name}${a}`,s),g.info(`Migration file created successfully: ${i?.name}${a}`),await t.disconnect(),process.exit(0);}catch(o){console.error(o),await t.disconnect(),process.exit(1);}});Ne.command("create:seeder <name>").description("Create a new seeder file").option("-j, --javascript","Generate a javascript seeder file instead of a default typescript one",false).option("-s, --seeder-path [path]","Path to the seeders",void 0).action((i,t)=>{g.info(`Creating seeder: ${i}`),g.info(`Seeder options: javascript=${t.javascript}`),i||(g.error("Seeder name is required"),process.exit(1)),np(i,t.javascript,t.seederPath);});Ne.command("seed").description("Run database seeders from folder or specific files").option("-c, --tsconfig [tsconfigPath]","Path to the tsconfig.json file, defaults to ./tsconfig.json",void 0).option("-d, --datasource [path]","Path to SqlDataSource (default export)",void 0).option("-s, --seeder-path [path]","Path to seeder folder or file (can be specified multiple times or comma-separated)",(i,t=[])=>[...t,i]).action(async i=>{g.info("Starting seeder execution"),i?.datasource||(g.error("SqlDataSource file path is required (-d|--datasource)"),process.exit(1));let{default:t}=await ie(je.resolve(process.cwd(),i.datasource),i?.tsconfigPath),e;i?.seederPath&&i.seederPath.length>0?e=i.seederPath.flatMap(o=>o.split(",").map(n=>n.trim())):e=[t.seederConfig.path];let r=i?.tsconfigPath||t.seederConfig.tsconfig;try{await sp(t,e,r),await t.disconnect(),g.info("Seeding completed successfully"),process.exit(0);}catch(o){console.error(o),await t.disconnect(),process.exit(1);}});Ne.parse(process.argv);export{Er as sqlDatabaseTypes};//# sourceMappingURL=cli.js.map
|
|
373
373
|
//# sourceMappingURL=cli.js.map
|