@ttoss/postgresdb-cli
Advanced tools
+161
| /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */ | ||
| //#region \0rolldown/runtime.js | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { | ||
| key = keys[i]; | ||
| if (!__hasOwnProp.call(to, key) && key !== except) { | ||
| __defProp(to, key, { | ||
| get: (k => from[k]).bind(null, key), | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { | ||
| value: mod, | ||
| enumerable: true | ||
| }) : target, mod)); | ||
| //#endregion | ||
| let commander = require("commander"); | ||
| let node_fs = require("node:fs"); | ||
| node_fs = __toESM(node_fs, 1); | ||
| let sequelize_erd = require("sequelize-erd"); | ||
| sequelize_erd = __toESM(sequelize_erd, 1); | ||
| let node_module = require("node:module"); | ||
| node_module = __toESM(node_module, 1); | ||
| let node_path = require("node:path"); | ||
| node_path = __toESM(node_path, 1); | ||
| let dotenv = require("dotenv"); | ||
| let esbuild = require("esbuild"); | ||
| esbuild = __toESM(esbuild, 1); | ||
| let node_readline = require("node:readline"); | ||
| node_readline = __toESM(node_readline, 1); | ||
| //#region package.json | ||
| var version = "0.2.12"; | ||
| //#endregion | ||
| //#region src/getDbDynamically.ts | ||
| const nodeBuiltins = node_module.builtinModules; | ||
| const getDbDynamically = async ({ | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| if (environment) { | ||
| (0, dotenv.config)({ | ||
| path: node_path.default.resolve(process.cwd(), `.env.${environment}`), | ||
| override: true | ||
| }); | ||
| console.info(`Loaded environment variables from .env.${environment}`); | ||
| } | ||
| const filename = dbPath.split("/").pop()?.split(".")[0]; | ||
| const outfile = node_path.default.resolve(process.cwd(), "out", filename + ".js"); | ||
| const entryPoint = node_path.default.resolve(process.cwd(), dbPath); | ||
| const result = esbuild.buildSync({ | ||
| bundle: true, | ||
| entryPoints: [entryPoint], | ||
| external: ["@ttoss/postgresdb", ...nodeBuiltins], | ||
| format: "esm", | ||
| outfile, | ||
| platform: "node", | ||
| target: "esnext", | ||
| treeShaking: true | ||
| }); | ||
| if (result.errors.length > 0) { | ||
| console.error("Error building config file: ", filename); | ||
| throw result.errors; | ||
| } | ||
| const { | ||
| db | ||
| } = await import(outfile); | ||
| return db; | ||
| }; | ||
| //#endregion | ||
| //#region src/erd.ts | ||
| const erd = async ({ | ||
| dbPath, | ||
| engine | ||
| }) => { | ||
| console.info("Generating ERD...", dbPath); | ||
| const db = await getDbDynamically({ | ||
| dbPath | ||
| }); | ||
| const svg = await (0, sequelize_erd.default)({ | ||
| source: db.sequelize, | ||
| engine | ||
| }); | ||
| await node_fs.promises.writeFile("erd.svg", svg); | ||
| console.info("ERD generated at erd.svg"); | ||
| db.sequelize.close(); | ||
| }; | ||
| //#endregion | ||
| //#region src/sync.ts | ||
| const confirmAlter = () => { | ||
| return new Promise(resolve => { | ||
| const rl = node_readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
| rl.question("Do you want to continue? (yes/no): ", answer => { | ||
| rl.close(); | ||
| resolve(answer.toLowerCase() === "yes" || answer.toLowerCase() === "y"); | ||
| }); | ||
| }); | ||
| }; | ||
| const sync = async ({ | ||
| alter, | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| console.info("Starting database synchronization..."); | ||
| console.info("Environment: %s", environment || "default (.env)"); | ||
| console.info("DB Path: %s", dbPath); | ||
| console.info("Mode: %s", alter ? "ALTER (will modify schema)" : "SAFE (create tables only)"); | ||
| if (alter) { | ||
| console.warn("\n⚠️ WARNING: ALTER mode will modify your database schema!"); | ||
| console.warn(" - Columns not in models will be DELETED (data loss!)"); | ||
| console.warn(" - New columns will be added"); | ||
| console.warn(" - Tables not in models will be preserved\n"); | ||
| if (!(await confirmAlter())) { | ||
| console.info("Synchronization cancelled."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| console.info("\nConnecting to database..."); | ||
| const db = await getDbDynamically({ | ||
| dbPath, | ||
| environment | ||
| }); | ||
| console.info("Synchronizing schema..."); | ||
| await db.sequelize.sync({ | ||
| /** | ||
| * Don't force anymore because it's better to run migrations. | ||
| */ | ||
| force: false, | ||
| alter | ||
| }); | ||
| console.info("✓ Database synchronized successfully (alter: %s)", alter); | ||
| db.sequelize.close(); | ||
| }; | ||
| //#endregion | ||
| //#region src/index.ts | ||
| const program = new commander.Command(); | ||
| program.name("ttoss-postgresdb").version(version).description("ttoss postgresdb CLI"); | ||
| program.command("sync").description("Sync database").action(sync).option("--alter", "Alter sync", false).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").requiredOption("-e, --environment <environment>", "Environment name to load .env.<environment> file"); | ||
| program.command("erd").description("Generate ERD").action(erd).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").option("--engine <engine>", "Layout engine to use", "circo"); | ||
| program.parse(process.argv); | ||
| //#endregion |
| export { }; |
| export { }; |
+129
| /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */ | ||
| import * as builtinModules from "node:module"; | ||
| import { Command } from "commander"; | ||
| import * as fs from "node:fs"; | ||
| import sequelizeErd from "sequelize-erd"; | ||
| import path from "node:path"; | ||
| import { config } from "dotenv"; | ||
| import * as esbuild from "esbuild"; | ||
| import * as readline from "node:readline"; | ||
| //#region package.json | ||
| var version = "0.2.12"; | ||
| //#endregion | ||
| //#region src/getDbDynamically.ts | ||
| const nodeBuiltins = builtinModules.builtinModules; | ||
| const getDbDynamically = async ({ | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| if (environment) { | ||
| config({ | ||
| path: path.resolve(process.cwd(), `.env.${environment}`), | ||
| override: true | ||
| }); | ||
| console.info(`Loaded environment variables from .env.${environment}`); | ||
| } | ||
| const filename = dbPath.split("/").pop()?.split(".")[0]; | ||
| const outfile = path.resolve(process.cwd(), "out", filename + ".js"); | ||
| const entryPoint = path.resolve(process.cwd(), dbPath); | ||
| const result = esbuild.buildSync({ | ||
| bundle: true, | ||
| entryPoints: [entryPoint], | ||
| external: ["@ttoss/postgresdb", ...nodeBuiltins], | ||
| format: "esm", | ||
| outfile, | ||
| platform: "node", | ||
| target: "esnext", | ||
| treeShaking: true | ||
| }); | ||
| if (result.errors.length > 0) { | ||
| console.error("Error building config file: ", filename); | ||
| throw result.errors; | ||
| } | ||
| const { | ||
| db | ||
| } = await import(outfile); | ||
| return db; | ||
| }; | ||
| //#endregion | ||
| //#region src/erd.ts | ||
| const erd = async ({ | ||
| dbPath, | ||
| engine | ||
| }) => { | ||
| console.info("Generating ERD...", dbPath); | ||
| const db = await getDbDynamically({ | ||
| dbPath | ||
| }); | ||
| const svg = await sequelizeErd({ | ||
| source: db.sequelize, | ||
| engine | ||
| }); | ||
| await fs.promises.writeFile("erd.svg", svg); | ||
| console.info("ERD generated at erd.svg"); | ||
| db.sequelize.close(); | ||
| }; | ||
| //#endregion | ||
| //#region src/sync.ts | ||
| const confirmAlter = () => { | ||
| return new Promise(resolve => { | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
| rl.question("Do you want to continue? (yes/no): ", answer => { | ||
| rl.close(); | ||
| resolve(answer.toLowerCase() === "yes" || answer.toLowerCase() === "y"); | ||
| }); | ||
| }); | ||
| }; | ||
| const sync = async ({ | ||
| alter, | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| console.info("Starting database synchronization..."); | ||
| console.info("Environment: %s", environment || "default (.env)"); | ||
| console.info("DB Path: %s", dbPath); | ||
| console.info("Mode: %s", alter ? "ALTER (will modify schema)" : "SAFE (create tables only)"); | ||
| if (alter) { | ||
| console.warn("\n⚠️ WARNING: ALTER mode will modify your database schema!"); | ||
| console.warn(" - Columns not in models will be DELETED (data loss!)"); | ||
| console.warn(" - New columns will be added"); | ||
| console.warn(" - Tables not in models will be preserved\n"); | ||
| if (!(await confirmAlter())) { | ||
| console.info("Synchronization cancelled."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| console.info("\nConnecting to database..."); | ||
| const db = await getDbDynamically({ | ||
| dbPath, | ||
| environment | ||
| }); | ||
| console.info("Synchronizing schema..."); | ||
| await db.sequelize.sync({ | ||
| /** | ||
| * Don't force anymore because it's better to run migrations. | ||
| */ | ||
| force: false, | ||
| alter | ||
| }); | ||
| console.info("✓ Database synchronized successfully (alter: %s)", alter); | ||
| db.sequelize.close(); | ||
| }; | ||
| //#endregion | ||
| //#region src/index.ts | ||
| const program = new Command(); | ||
| program.name("ttoss-postgresdb").version(version).description("ttoss postgresdb CLI"); | ||
| program.command("sync").description("Sync database").action(sync).option("--alter", "Alter sync", false).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").requiredOption("-e, --environment <environment>", "Environment name to load .env.<environment> file"); | ||
| program.command("erd").description("Generate ERD").action(erd).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").option("--engine <engine>", "Layout engine to use", "circo"); | ||
| program.parse(process.argv); | ||
| //#endregion | ||
| export {}; |
+1
-1
| #!/usr/bin/env node | ||
| import '../dist/esm/index.js'; | ||
| import '../dist/index.mjs'; |
+4
-4
| { | ||
| "name": "@ttoss/postgresdb-cli", | ||
| "version": "0.2.12", | ||
| "version": "0.2.13", | ||
| "description": "A library to handle PostgreSQL database actions through the command line", | ||
@@ -37,4 +37,4 @@ "keywords": [ | ||
| "jest": "^30.3.0", | ||
| "tsup": "^8.5.1", | ||
| "@ttoss/config": "^1.37.12" | ||
| "tsdown": "^0.22.0", | ||
| "@ttoss/config": "^1.37.13" | ||
| }, | ||
@@ -46,4 +46,4 @@ "publishConfig": { | ||
| "scripts": { | ||
| "build-config": "tsup-node" | ||
| "build-config": "tsdown" | ||
| } | ||
| } |
| /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */ | ||
| var __defProp = Object.defineProperty; | ||
| var __name = (target, value) => __defProp(target, "name", { | ||
| value, | ||
| configurable: true | ||
| }); | ||
| // src/index.ts | ||
| import { Command } from "commander"; | ||
| // package.json | ||
| var package_default = { | ||
| name: "@ttoss/postgresdb-cli", | ||
| version: "0.2.11", | ||
| description: "A library to handle PostgreSQL database actions through the command line", | ||
| keywords: ["database", "postgres", "postgresql"], | ||
| repository: { | ||
| type: "git", | ||
| url: "https://github.com/ttoss/ttoss.git", | ||
| directory: "packages/postgresdb-cli" | ||
| }, | ||
| license: "MIT", | ||
| author: "ttoss", | ||
| contributors: ["Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"], | ||
| sideEffects: false, | ||
| type: "module", | ||
| bin: { | ||
| "ttoss-postgresdb": "./bin/cli.js" | ||
| }, | ||
| files: ["bin", "dist"], | ||
| scripts: { | ||
| "build-config": "tsup-node" | ||
| }, | ||
| dependencies: { | ||
| commander: "^14.0.3", | ||
| dotenv: "^17.4.2", | ||
| esbuild: "^0.28.0", | ||
| "sequelize-erd": "^1.3.1" | ||
| }, | ||
| devDependencies: { | ||
| "@ttoss/config": "workspace:^", | ||
| jest: "^30.3.0", | ||
| tsup: "^8.5.1" | ||
| }, | ||
| publishConfig: { | ||
| access: "public", | ||
| provenance: true | ||
| } | ||
| }; | ||
| // src/erd.ts | ||
| import * as fs from "fs"; | ||
| import sequelizeErd from "sequelize-erd"; | ||
| // src/getDbDynamically.ts | ||
| import * as builtinModules from "module"; | ||
| import path from "path"; | ||
| import { config } from "dotenv"; | ||
| import * as esbuild from "esbuild"; | ||
| var nodeBuiltins = builtinModules.builtinModules; | ||
| var getDbDynamically = /* @__PURE__ */__name(async ({ | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| if (environment) { | ||
| const envPath = path.resolve(process.cwd(), `.env.${environment}`); | ||
| config({ | ||
| path: envPath, | ||
| override: true | ||
| }); | ||
| console.info(`Loaded environment variables from .env.${environment}`); | ||
| } | ||
| const lastEntryPointName = dbPath.split("/").pop(); | ||
| const filename = lastEntryPointName?.split(".")[0]; | ||
| const outfile = path.resolve(process.cwd(), "out", filename + ".js"); | ||
| const entryPoint = path.resolve(process.cwd(), dbPath); | ||
| const result = esbuild.buildSync({ | ||
| bundle: true, | ||
| entryPoints: [entryPoint], | ||
| external: ["@ttoss/postgresdb", ...nodeBuiltins], | ||
| format: "esm", | ||
| outfile, | ||
| platform: "node", | ||
| target: "esnext", | ||
| treeShaking: true | ||
| }); | ||
| if (result.errors.length > 0) { | ||
| console.error("Error building config file: ", filename); | ||
| throw result.errors; | ||
| } | ||
| const { | ||
| db | ||
| } = await import(outfile); | ||
| return db; | ||
| }, "getDbDynamically"); | ||
| // src/erd.ts | ||
| var erd = /* @__PURE__ */__name(async ({ | ||
| dbPath, | ||
| engine | ||
| }) => { | ||
| console.info("Generating ERD...", dbPath); | ||
| const db = await getDbDynamically({ | ||
| dbPath | ||
| }); | ||
| const svg = await sequelizeErd({ | ||
| source: db.sequelize, | ||
| engine | ||
| }); | ||
| await fs.promises.writeFile("erd.svg", svg); | ||
| console.info("ERD generated at erd.svg"); | ||
| db.sequelize.close(); | ||
| }, "erd"); | ||
| // src/sync.ts | ||
| import * as readline from "readline"; | ||
| var confirmAlter = /* @__PURE__ */__name(() => { | ||
| return new Promise(resolve => { | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
| rl.question("Do you want to continue? (yes/no): ", answer => { | ||
| rl.close(); | ||
| resolve(answer.toLowerCase() === "yes" || answer.toLowerCase() === "y"); | ||
| }); | ||
| }); | ||
| }, "confirmAlter"); | ||
| var sync = /* @__PURE__ */__name(async ({ | ||
| alter, | ||
| dbPath, | ||
| environment | ||
| }) => { | ||
| console.info("Starting database synchronization..."); | ||
| console.info("Environment: %s", environment || "default (.env)"); | ||
| console.info("DB Path: %s", dbPath); | ||
| console.info("Mode: %s", alter ? "ALTER (will modify schema)" : "SAFE (create tables only)"); | ||
| if (alter) { | ||
| console.warn("\n\u26A0\uFE0F WARNING: ALTER mode will modify your database schema!"); | ||
| console.warn(" - Columns not in models will be DELETED (data loss!)"); | ||
| console.warn(" - New columns will be added"); | ||
| console.warn(" - Tables not in models will be preserved\n"); | ||
| const confirmed = await confirmAlter(); | ||
| if (!confirmed) { | ||
| console.info("Synchronization cancelled."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| console.info("\nConnecting to database..."); | ||
| const db = await getDbDynamically({ | ||
| dbPath, | ||
| environment | ||
| }); | ||
| console.info("Synchronizing schema..."); | ||
| await db.sequelize.sync({ | ||
| /** | ||
| * Don't force anymore because it's better to run migrations. | ||
| */ | ||
| force: false, | ||
| alter | ||
| }); | ||
| console.info("\u2713 Database synchronized successfully (alter: %s)", alter); | ||
| db.sequelize.close(); | ||
| }, "sync"); | ||
| // src/index.ts | ||
| var program = new Command(); | ||
| program.name("ttoss-postgresdb").version(package_default.version).description("ttoss postgresdb CLI"); | ||
| program.command("sync").description("Sync database").action(sync).option("--alter", "Alter sync", false).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").requiredOption("-e, --environment <environment>", "Environment name to load .env.<environment> file"); | ||
| program.command("erd").description("Generate ERD").action(erd).option("-d, --db-path <dbPath>", "db initialization file path", "src/db.ts").option("--engine <engine>", "Layout engine to use", "circo"); | ||
| program.parse(process.argv); |
| export { } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
15073
38.3%8
33.33%279
67.07%0
-100%1
Infinity%