mirror of
https://github.com/Dokploy/cli.git
synced 2026-07-03 13:05:22 +02:00
refactor: add commands
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../utils/utils.js";
|
||||
|
||||
export default class DatabaseCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> app create"];
|
||||
|
||||
static flags = {
|
||||
projectId: Flags.string({
|
||||
char: "p",
|
||||
description: "ID of the project",
|
||||
required: false,
|
||||
}),
|
||||
};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
const { flags } = await this.parse(DatabaseCreate);
|
||||
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to create the application in:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
}
|
||||
}
|
||||
|
||||
// Solicitar detalles de la nueva aplicación
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the database name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Application name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the application description (optional):",
|
||||
name: "appDescription",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const { appDescription, appName } = appDetails;
|
||||
|
||||
// Crear la aplicación en el proyecto seleccionado
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/database.create`,
|
||||
{
|
||||
json: {
|
||||
description: appDescription,
|
||||
name: appName,
|
||||
projectId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating application"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(
|
||||
`Application '${appName}' created successfully in project ID '${projectId}'.`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to create application: ${error.message}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,13 @@ import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMariadbCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
static description = "Create a new MariaDB database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mariadb create"];
|
||||
|
||||
@@ -24,121 +25,105 @@ export default class DatabaseMariadbCreate extends Command {
|
||||
|
||||
const { flags } = await this.parse(DatabaseMariadbCreate);
|
||||
|
||||
const { projectId } = flags;
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the MariaDB database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = project.projectId;
|
||||
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database Root Password (optional):",
|
||||
name: "databaseRootPassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
default: "mariadb:4",
|
||||
message: "Docker Image (default: mariadb:4):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mariadb",
|
||||
message: "Database User: (default: mariadb):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${dbDetails.name}`,
|
||||
message: "Enter the App name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mariadb.create`,
|
||||
{
|
||||
json: {
|
||||
...dbDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const { project } = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database Root Password (optional):",
|
||||
name: "databaseRootPassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mariadb:4",
|
||||
message: "Docker Image (default: mariadb:4):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mariadb",
|
||||
message: "Database User: (default: mariadb):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${appDetails.name}`,
|
||||
message: "Enter the App name: (optional):",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const responseDatabase = await axios.post(
|
||||
`${auth.url}/api/trpc/mariadb.create`,
|
||||
{
|
||||
json: {
|
||||
...appDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!responseDatabase.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(`Database '${appDetails.name}' created successfully.`),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating MariaDB database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(
|
||||
`MariaDB database '${dbDetails.name}' created successfully.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,15 @@ import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
|
||||
export default class DatabaseMariadbDelete extends Command {
|
||||
static description = "Delete an application from a project.";
|
||||
|
||||
static description = "Delete a MariaDB database from a project.";
|
||||
static examples = [
|
||||
"$ <%= config.bin %> mariadb delete",
|
||||
"$ <%= config.bin %> mariadb delete -p <projectId>",
|
||||
];
|
||||
|
||||
static flags = {
|
||||
projectId: Flags.string({
|
||||
char: "p",
|
||||
@@ -23,108 +22,68 @@ export default class DatabaseMariadbDelete extends Command {
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
const { flags } = await this.parse(DatabaseMariadbDelete);
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the mariadb database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching applications"));
|
||||
}
|
||||
|
||||
const apps = response.data.result.data.json;
|
||||
|
||||
if (apps.mariadb.length === 0) {
|
||||
this.log(chalk.yellow("No applications found in this project."));
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: "list",
|
||||
name: "selectedProject",
|
||||
message: "Select a project to delete the MariaDB database from:",
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
},
|
||||
]);
|
||||
projectId = answers.selectedProject;
|
||||
}
|
||||
|
||||
try {
|
||||
const project = await getProject(projectId, auth, this);
|
||||
|
||||
if (!project.mariadb || project.mariadb.length === 0) {
|
||||
this.log(chalk.yellow("No MariaDB databases found in this project."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar una aplicación
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
choices: apps.mariadb.map((app: any) => ({
|
||||
name: app.name,
|
||||
value: app.mariadbId,
|
||||
})),
|
||||
message: "Select the mariadb database to delete:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
name: "selectedDb",
|
||||
message: "Select the MariaDB database to delete:",
|
||||
choices: project.mariadb.map((db: any) => ({
|
||||
name: db.name,
|
||||
value: db.mariadbId,
|
||||
})),
|
||||
},
|
||||
]);
|
||||
|
||||
const mariadbId = appAnswers.selectedApp;
|
||||
const mariadbId = appAnswers.selectedDb;
|
||||
|
||||
// Confirmar eliminación
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to delete this mysql database?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
name: "confirmDelete",
|
||||
message: "Are you sure you want to delete this MariaDB database?",
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.log(chalk.yellow("Application deletion cancelled."));
|
||||
this.log(chalk.yellow("Database deletion cancelled."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Eliminar la aplicación seleccionada
|
||||
const deleteResponse = await axios.post(
|
||||
`${auth.url}/api/trpc/mariadb.remove`,
|
||||
{
|
||||
@@ -141,13 +100,14 @@ export default class DatabaseMariadbDelete extends Command {
|
||||
);
|
||||
|
||||
if (!deleteResponse.data.result.data.json) {
|
||||
this.error(chalk.red("Error deleting application"));
|
||||
this.error(chalk.red("Error deleting mariadb database"));
|
||||
}
|
||||
|
||||
this.log(chalk.green("Application deleted successfully."));
|
||||
this.log(chalk.green("MariaDB database deleted successfully."));
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to delete MariaDB database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMongoCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
static description = "Create a new MongoDB database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mongo create"];
|
||||
|
||||
@@ -21,95 +22,83 @@ export default class DatabaseMongoCreate extends Command {
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
const { flags } = await this.parse(DatabaseMongoCreate);
|
||||
|
||||
const { projectId } = flags;
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the MongoDB database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = project.projectId;
|
||||
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
default: "mongo:6",
|
||||
message: "Docker Image (default: mongo:6):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mongo",
|
||||
message: "Database User: (default: mongo):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${dbDetails.name}`,
|
||||
message: "Enter the App name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const { project } = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mongo:6",
|
||||
message: "Docker Image (default: mongo:6):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mongo",
|
||||
message: "Database User: (default: mongo):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${appDetails.name}`,
|
||||
message: "Enter the App name: (optional):",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const responseDatabase = await axios.post(
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mongo.create`,
|
||||
{
|
||||
json: {
|
||||
...appDetails,
|
||||
...dbDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
@@ -122,16 +111,20 @@ export default class DatabaseMongoCreate extends Command {
|
||||
},
|
||||
);
|
||||
|
||||
if (!responseDatabase.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating database"));
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating MongoDB database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(`Database '${appDetails.name}' created successfully.`),
|
||||
chalk.green(
|
||||
`MongoDB database '${dbDetails.name}' created successfully.`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to create MongoDB database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
|
||||
export default class DatabaseMongoDelete extends Command {
|
||||
static description = "Delete an application from a project.";
|
||||
static description = "Delete a MongoDB database from a project.";
|
||||
|
||||
static examples = [
|
||||
"$ <%= config.bin %> mongo delete",
|
||||
@@ -28,80 +29,45 @@ export default class DatabaseMongoDelete extends Command {
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the mongo database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching applications"));
|
||||
}
|
||||
|
||||
const apps = response.data.result.data.json;
|
||||
|
||||
if (apps.mongo.length === 0) {
|
||||
this.log(chalk.yellow("No applications found in this project."));
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the MongoDB database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
}
|
||||
|
||||
try {
|
||||
const project = await getProject(projectId, auth, this);
|
||||
|
||||
if (!project.mongo || project.mongo.length === 0) {
|
||||
this.log(chalk.yellow("No MongoDB databases found in this project."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar una aplicación
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
choices: apps.mongo.map((app: any) => ({
|
||||
name: app.name,
|
||||
value: app.mongoId,
|
||||
choices: project.mongo.map((db: any) => ({
|
||||
name: db.name,
|
||||
value: db.mongoId,
|
||||
})),
|
||||
message: "Select the mongo database to delete:",
|
||||
message: "Select the MongoDB database to delete:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
@@ -109,22 +75,20 @@ export default class DatabaseMongoDelete extends Command {
|
||||
|
||||
const mongoId = appAnswers.selectedApp;
|
||||
|
||||
// Confirmar eliminación
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to delete this mongo database?",
|
||||
message: "Are you sure you want to delete this MongoDB database?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.log(chalk.yellow("Application deletion cancelled."));
|
||||
this.log(chalk.yellow("Database deletion cancelled."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Eliminar la aplicación seleccionada
|
||||
const deleteResponse = await axios.post(
|
||||
`${auth.url}/api/trpc/mongo.remove`,
|
||||
{
|
||||
@@ -141,13 +105,15 @@ export default class DatabaseMongoDelete extends Command {
|
||||
);
|
||||
|
||||
if (!deleteResponse.data.result.data.json) {
|
||||
this.error(chalk.red("Error deleting application"));
|
||||
this.error(chalk.red("Error deleting MongoDB database"));
|
||||
}
|
||||
|
||||
this.log(chalk.green("Application deleted successfully."));
|
||||
this.log(chalk.green("MongoDB database deleted successfully."));
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to delete MongoDB database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import inquirer from "inquirer";
|
||||
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMysqlCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
static description = "Create a new MySQL database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mysql create"];
|
||||
|
||||
@@ -21,100 +23,88 @@ export default class DatabaseMysqlCreate extends Command {
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
const { flags } = await this.parse(DatabaseMysqlCreate);
|
||||
|
||||
const { projectId } = flags;
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the MySQL database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = project.projectId;
|
||||
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database Root Password (optional):",
|
||||
name: "databaseRootPassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
default: "mysql:8",
|
||||
message: "Docker Image (default: mysql:8):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mysql",
|
||||
message: "Database User: (default: mysql):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${dbDetails.name}`,
|
||||
message: "Enter the App name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const { project } = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database Root Password (optional):",
|
||||
name: "databaseRootPassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mysql:8",
|
||||
message: "Docker Image (default: mysql:8):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "mysql",
|
||||
message: "Database User: (default: mysql):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${appDetails.name}`,
|
||||
message: "Enter the App name: (optional):",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const responseDatabase = await axios.post(
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mysql.create`,
|
||||
{
|
||||
json: {
|
||||
...appDetails,
|
||||
...dbDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
@@ -127,16 +117,20 @@ export default class DatabaseMysqlCreate extends Command {
|
||||
},
|
||||
);
|
||||
|
||||
if (!responseDatabase.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating database"));
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating MySQL database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(`Database '${appDetails.name}' created successfully.`),
|
||||
chalk.green(
|
||||
`MySQL database '${dbDetails.name}' created successfully.`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to create MySQL database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
|
||||
export default class DatabaseMysqlDelete extends Command {
|
||||
static description = "Delete an application from a project.";
|
||||
static description = "Delete a MySQL database from a project.";
|
||||
|
||||
static examples = [
|
||||
"$ <%= config.bin %> mysql delete",
|
||||
@@ -28,80 +29,46 @@ export default class DatabaseMysqlDelete extends Command {
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the mysql database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the MySQL database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
const project = await getProject(projectId, auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching applications"));
|
||||
}
|
||||
|
||||
const apps = response.data.result.data.json;
|
||||
|
||||
if (apps.mysql.length === 0) {
|
||||
this.log(chalk.yellow("No applications found in this project."));
|
||||
if (!project.mysql || project.mysql.length === 0) {
|
||||
this.log(chalk.yellow("No MySQL databases found in this project."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar una aplicación
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
choices: apps.mysql.map((app: any) => ({
|
||||
choices: project.mysql.map((app: any) => ({
|
||||
name: app.name,
|
||||
value: app.mysqlId,
|
||||
})),
|
||||
message: "Select the mysql database to delete:",
|
||||
message: "Select the MySQL database to delete:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
|
||||
@@ -2,12 +2,12 @@ import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
export default class DatabasePostgresCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
static description = "Create a new PostgreSQL database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> postgres create"];
|
||||
|
||||
@@ -24,94 +24,80 @@ export default class DatabasePostgresCreate extends Command {
|
||||
|
||||
const { flags } = await this.parse(DatabasePostgresCreate);
|
||||
|
||||
const { projectId } = flags;
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the PostgreSQL database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = project.projectId;
|
||||
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
default: "postgres:15",
|
||||
message: "Docker Image (default: postgres:15):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "postgres",
|
||||
message: "Database User: (default: postgres):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${dbDetails.name}`,
|
||||
message: "Enter the App name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const { project } = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Database name:",
|
||||
name: "databaseName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "postgres:15",
|
||||
message: "Docker Image (default: postgres:15):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
|
||||
{
|
||||
default: "postgres",
|
||||
message: "Database User: (default: postgres):",
|
||||
name: "databaseUser",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${appDetails.name}`,
|
||||
message: "Enter the App name: (optional):",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const responseDatabase = await axios.post(
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/postgres.create`,
|
||||
{
|
||||
json: {
|
||||
...appDetails,
|
||||
...dbDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
@@ -124,16 +110,20 @@ export default class DatabasePostgresCreate extends Command {
|
||||
},
|
||||
);
|
||||
|
||||
if (!responseDatabase.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating database"));
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating PostgreSQL database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(`Database '${appDetails.name}' created successfully.`),
|
||||
chalk.green(
|
||||
`PostgreSQL database '${dbDetails.name}' created successfully.`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to create PostgreSQL database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
|
||||
export default class DatabasePostgresDelete extends Command {
|
||||
static description = "Delete an application from a project.";
|
||||
static description = "Delete a PostgreSQL database from a project.";
|
||||
|
||||
static examples = [
|
||||
"$ <%= config.bin %> postgres delete",
|
||||
@@ -28,80 +29,47 @@ export default class DatabasePostgresDelete extends Command {
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the postgres database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching applications"));
|
||||
}
|
||||
|
||||
const apps = response.data.result.data.json;
|
||||
|
||||
if (apps.postgres.length === 0) {
|
||||
this.log(chalk.yellow("No applications found in this project."));
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the PostgreSQL database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
}
|
||||
|
||||
try {
|
||||
const project = await getProject(projectId, auth, this);
|
||||
|
||||
if (!project.postgres || project.postgres.length === 0) {
|
||||
this.log(
|
||||
chalk.yellow("No PostgreSQL databases found in this project."),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar una aplicación
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
choices: apps.postgres.map((app: any) => ({
|
||||
name: app.name,
|
||||
value: app.postgresId,
|
||||
choices: project.postgres.map((db: any) => ({
|
||||
name: db.name,
|
||||
value: db.postgresId,
|
||||
})),
|
||||
message: "Select the postgres database to delete:",
|
||||
message: "Select the PostgreSQL database to delete:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
@@ -109,7 +77,6 @@ export default class DatabasePostgresDelete extends Command {
|
||||
|
||||
const postgresId = appAnswers.selectedApp;
|
||||
|
||||
// Confirmar eliminación
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
@@ -120,11 +87,10 @@ export default class DatabasePostgresDelete extends Command {
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.log(chalk.yellow("Application deletion cancelled."));
|
||||
this.log(chalk.yellow("Database deletion cancelled."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Eliminar la aplicación seleccionada
|
||||
const deleteResponse = await axios.post(
|
||||
`${auth.url}/api/trpc/postgres.remove`,
|
||||
{
|
||||
@@ -141,10 +107,10 @@ export default class DatabasePostgresDelete extends Command {
|
||||
);
|
||||
|
||||
if (!deleteResponse.data.result.data.json) {
|
||||
this.error(chalk.red("Error deleting application"));
|
||||
this.error(chalk.red("Error deleting PostgreSQL database"));
|
||||
}
|
||||
|
||||
this.log(chalk.green("Application deleted successfully."));
|
||||
this.log(chalk.green("PostgreSQL database deleted successfully."));
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseRedisCreate extends Command {
|
||||
static description = "Create a new database within a project.";
|
||||
static description = "Create a new Redis database within a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> redis create"];
|
||||
|
||||
@@ -21,82 +22,71 @@ export default class DatabaseRedisCreate extends Command {
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
const { flags } = await this.parse(DatabaseRedisCreate);
|
||||
const { projectId } = flags;
|
||||
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the Redis database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = project.projectId;
|
||||
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "password",
|
||||
},
|
||||
{
|
||||
default: "redis:7",
|
||||
message: "Docker Image (default: redis:7):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${dbDetails.name}`,
|
||||
message: "Enter the App name:",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "App name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const { project } = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to create the database in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const appDetails = await inquirer.prompt([
|
||||
{
|
||||
message: "Enter the name:",
|
||||
name: "name",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
{
|
||||
message: "Enter the database description (optional):",
|
||||
name: "description",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
message: "Database password (optional):",
|
||||
name: "databasePassword",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
default: "redis:7",
|
||||
message: "Docker Image (default: redis:7):",
|
||||
name: "dockerImage",
|
||||
type: "input",
|
||||
},
|
||||
]);
|
||||
|
||||
const appName = await inquirer.prompt([
|
||||
{
|
||||
default: `${slugify(project.name)}-${appDetails.name}`,
|
||||
message: "Enter the App name: (optional):",
|
||||
name: "appName",
|
||||
type: "input",
|
||||
validate: (input) => (input ? true : "Database name is required"),
|
||||
},
|
||||
]);
|
||||
|
||||
const responseDatabase = await axios.post(
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/redis.create`,
|
||||
{
|
||||
json: {
|
||||
...appDetails,
|
||||
...dbDetails,
|
||||
appName: appName.appName,
|
||||
projectId: project.projectId,
|
||||
},
|
||||
@@ -109,16 +99,20 @@ export default class DatabaseRedisCreate extends Command {
|
||||
},
|
||||
);
|
||||
|
||||
if (!responseDatabase.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating database"));
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error creating Redis database"));
|
||||
}
|
||||
|
||||
this.log(
|
||||
chalk.green(`Database '${appDetails.name}' created successfully.`),
|
||||
chalk.green(
|
||||
`Redis database '${dbDetails.name}' created successfully.`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// @ts-expect-error TODO: Fix this
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-ignore
|
||||
chalk.red(`Failed to create Redis database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
|
||||
export default class DatabaseRedisDelete extends Command {
|
||||
static description = "Delete an application from a project.";
|
||||
static description = "Delete an redis database from a project.";
|
||||
|
||||
static examples = [
|
||||
"$ <%= config.bin %> redis delete",
|
||||
@@ -28,78 +29,44 @@ export default class DatabaseRedisDelete extends Command {
|
||||
let { projectId } = flags;
|
||||
|
||||
if (!projectId) {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the mariadb database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
message: "Select a project to delete the redis database from:",
|
||||
name: "selectedProject",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
projectId = answers.selectedProject;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
const project = await getProject(projectId, auth, this);
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching applications"));
|
||||
}
|
||||
|
||||
const apps = response.data.result.data.json;
|
||||
|
||||
if (apps.redis.length === 0) {
|
||||
this.log(chalk.yellow("No applications found in this project."));
|
||||
if (!project.redis || project.redis.length === 0) {
|
||||
this.log(chalk.yellow("No redis databases found in this project."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar una aplicación
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
choices: apps.redis.map((app: any) => ({
|
||||
name: app.name,
|
||||
value: app.redisId,
|
||||
choices: project.redis.map((db: any) => ({
|
||||
name: db.name,
|
||||
value: db.redisId,
|
||||
})),
|
||||
message: "Select the redis database to delete:",
|
||||
name: "selectedApp",
|
||||
@@ -109,22 +76,20 @@ export default class DatabaseRedisDelete extends Command {
|
||||
|
||||
const redisId = appAnswers.selectedApp;
|
||||
|
||||
// Confirmar eliminación
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to delete this mysql database?",
|
||||
message: "Are you sure you want to delete this redis database?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.log(chalk.yellow("Application deletion cancelled."));
|
||||
this.log(chalk.yellow("Database deletion cancelled."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Eliminar la aplicación seleccionada
|
||||
const deleteResponse = await axios.post(
|
||||
`${auth.url}/api/trpc/redis.remove`,
|
||||
{
|
||||
@@ -141,13 +106,15 @@ export default class DatabaseRedisDelete extends Command {
|
||||
);
|
||||
|
||||
if (!deleteResponse.data.result.data.json) {
|
||||
this.error(chalk.red("Error deleting application"));
|
||||
this.error(chalk.red("Error deleting redis database"));
|
||||
}
|
||||
|
||||
this.log(chalk.green("Application deleted successfully."));
|
||||
this.log(chalk.green("Redis database deleted successfully."));
|
||||
} catch (error) {
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
this.error(chalk.red(`Failed to delete application: ${error.message}`));
|
||||
this.error(
|
||||
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
||||
chalk.red(`Failed to delete redis database: ${error.message}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user