Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db): make percentage column NOT NULL and add DEFAULT 0 #50

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DAL/entity/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class JobEntity {
@Column({ type: 'enum', enum: OperationStatus, default: OperationStatus.PENDING, nullable: false })
public status: OperationStatus;

@Column('smallint', { nullable: true })
@Column('smallint', { nullable: false, default: 0 })
public percentage: number;

@Column('varchar', { default: '', nullable: false })
Expand Down
2 changes: 1 addition & 1 deletion src/DAL/entity/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TaskEntity {
@Column({ type: 'enum', enum: OperationStatus, default: OperationStatus.PENDING, nullable: false })
public status: OperationStatus;

@Column('smallint', { nullable: true })
@Column('smallint', { nullable: false, default: 0 })
public percentage: number;

@Column('varchar', { default: '', nullable: false })
Expand Down
4 changes: 2 additions & 2 deletions src/DAL/migration/FullSchema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE TABLE "Job"
"creationTime" timestamp with time zone NOT NULL DEFAULT now(),
"updateTime" timestamp with time zone NOT NULL DEFAULT now(),
"status" "operation_status_enum" NOT NULL DEFAULT 'Pending'::"operation_status_enum",
"percentage" smallint,
"percentage" smallint NOT NULL DEFAULT 0,
"reason" text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
"isCleaned" boolean NOT NULL DEFAULT false,
"priority" int NOT NULL DEFAULT 1000,
Expand Down Expand Up @@ -79,7 +79,7 @@ CREATE TABLE "Task"
"creationTime" timestamp with time zone NOT NULL DEFAULT now(),
"updateTime" timestamp with time zone NOT NULL DEFAULT now(),
"status" "operation_status_enum" NOT NULL DEFAULT 'Pending'::"operation_status_enum",
"percentage" smallint,
"percentage" smallint NOT NULL DEFAULT 0,
"reason" text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
"attempts" integer NOT NULL DEFAULT 0,
"jobId" uuid NOT NULL,
Expand Down
24 changes: 24 additions & 0 deletions src/DAL/migration/v.2.10.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SET search_path TO "JobManager", public; -- CHANGE SCHEMA NAME TO MATCH ENVIRONMENT

-- Update existing null values to 0 in Job table
UPDATE "Job"
SET "percentage" = 0
WHERE "percentage" IS NULL;

-- Update existing null values to 0 in Task table
UPDATE "Task"
SET "percentage" = 0
WHERE "percentage" IS NULL;

-- Modify Job table column
ALTER TABLE "Job"
ALTER COLUMN "percentage" SET DEFAULT 0,
ALTER COLUMN "percentage" SET NOT NULL;

-- Modify Task table column
ALTER TABLE "Task"
ALTER COLUMN "percentage" SET DEFAULT 0,
ALTER COLUMN "percentage" SET NOT NULL;

COMMENT ON COLUMN "Job"."percentage" IS 'Percentage of job completion (0-100). Default is 0.';
COMMENT ON COLUMN "Task"."percentage" IS 'Percentage of task completion (0-100). Default is 0.';
Loading