Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
fix(backend): fix incorrect status/stop commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Sep 17, 2024
1 parent e2937d6 commit 06b5a58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
27 changes: 23 additions & 4 deletions packages/backend/cli/commands/db/instance/status.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { z } from "zod";
import { globalOptsSchema, initProject } from "../../../common.ts";
import { getDefaultPostgresManager } from "../../../../toolchain/postgres/mod.ts";
import { stop } from "../../../../toolchain/postgres/manager.ts";
import { success, warn } from "../../../../toolchain/term/status.ts";
import { Status, status } from "../../../../toolchain/postgres/manager.ts";
import { info, warn } from "../../../../toolchain/term/status.ts";
import { UnreachableError } from "../../../../toolchain/error/mod.ts";

export const optsSchema = globalOptsSchema;

Expand All @@ -12,8 +13,26 @@ export async function execute(opts: Opts) {
const project = await initProject(opts);
const manager = await getDefaultPostgresManager(project);
if (manager) {
await stop(manager);
success("Postgres instance stopped");
let statusText: string;
const currentStatus = await status(manager);
if (currentStatus === Status.NotInstalled) {
statusText = "Not installed";
} else if (currentStatus === Status.Installed) {
statusText = "Installed";
} else if (currentStatus === Status.Initialized) {
statusText = "Initialized";
} else if (currentStatus === Status.DefaultDatabaseNotCreated) {
statusText = "Default database not created";
} else if (currentStatus === Status.Stopped) {
statusText = "Stopped";
} else if (currentStatus === Status.Started) {
statusText = "Started";
} else if (currentStatus === Status.Connectable) {
statusText = "Connectable";
} else {
throw new UnreachableError(currentStatus);
}
info("Status", statusText);
} else {
warn("Postgres is disabled");
}
Expand Down
25 changes: 4 additions & 21 deletions packages/backend/cli/commands/db/instance/stop.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { z } from "zod";
import { globalOptsSchema, initProject } from "../../../common.ts";
import { getDefaultPostgresManager } from "../../../../toolchain/postgres/mod.ts";
import { Status, status } from "../../../../toolchain/postgres/manager.ts";
import { info, warn } from "../../../../toolchain/term/status.ts";
import { UnreachableError } from "../../../../toolchain/error/mod.ts";
import { stop } from "../../../../toolchain/postgres/manager.ts";
import { success, warn } from "../../../../toolchain/term/status.ts";

export const optsSchema = globalOptsSchema;

Expand All @@ -13,24 +12,8 @@ export async function execute(opts: Opts) {
const project = await initProject(opts);
const manager = await getDefaultPostgresManager(project);
if (manager) {
let statusText: string;
const currentStatus = await status(manager);
if (currentStatus === Status.NotInstalled) {
statusText = "Not installed";
} else if (currentStatus === Status.Installed) {
statusText = "Installed";
} else if (currentStatus === Status.Initialized) {
statusText = "Initialized";
} else if (currentStatus === Status.DefaultDatabaseNotCreated) {
statusText = "Default database not created";
} else if (currentStatus === Status.Stopped) {
statusText = "Stopped";
} else if (currentStatus === Status.Started) {
statusText = "Started";
} else {
throw new UnreachableError(currentStatus);
}
info("Status", statusText);
await stop(manager);
success("Postgres instance stopped");
} else {
warn("Postgres is disabled");
}
Expand Down

0 comments on commit 06b5a58

Please sign in to comment.