feat(member): add away billing policies

This commit is contained in:
2026-03-11 14:05:52 +04:00
parent 773abf2531
commit 98988159eb
34 changed files with 4218 additions and 39 deletions

View File

@@ -0,0 +1,14 @@
CREATE TABLE "member_absence_policies" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"household_id" uuid NOT NULL,
"member_id" uuid NOT NULL,
"effective_from_period" text NOT NULL,
"policy" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "member_absence_policies" ADD CONSTRAINT "member_absence_policies_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "member_absence_policies" ADD CONSTRAINT "member_absence_policies_member_id_members_id_fk" FOREIGN KEY ("member_id") REFERENCES "public"."members"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "member_absence_policies_household_member_period_unique" ON "member_absence_policies" USING btree ("household_id","member_id","effective_from_period");--> statement-breakpoint
CREATE INDEX "member_absence_policies_household_member_idx" ON "member_absence_policies" USING btree ("household_id","member_id");

File diff suppressed because it is too large Load Diff

View File

@@ -106,6 +106,13 @@
"when": 1773222186943,
"tag": "0014_empty_risque",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1773223414625,
"tag": "0015_white_owl",
"breakpoints": true
}
]
}

View File

@@ -209,6 +209,32 @@ export const members = pgTable(
})
)
export const memberAbsencePolicies = pgTable(
'member_absence_policies',
{
id: uuid('id').defaultRandom().primaryKey(),
householdId: uuid('household_id')
.notNull()
.references(() => households.id, { onDelete: 'cascade' }),
memberId: uuid('member_id')
.notNull()
.references(() => members.id, { onDelete: 'cascade' }),
effectiveFromPeriod: text('effective_from_period').notNull(),
policy: text('policy').notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
},
(table) => ({
householdMemberPeriodUnique: uniqueIndex(
'member_absence_policies_household_member_period_unique'
).on(table.householdId, table.memberId, table.effectiveFromPeriod),
householdMemberIdx: index('member_absence_policies_household_member_idx').on(
table.householdId,
table.memberId
)
})
)
export const billingCycles = pgTable(
'billing_cycles',
{