fix: rollover insert and max
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// import { z } from "zod";
|
||||
// import { EntityBalance, EntityBalanceSchema } from "../../../index.js";
|
||||
// import { jsonb } from "drizzle-orm/pg-core";
|
||||
|
||||
// export const RolloverModelSchema = z.object({
|
||||
// id: z.string(),
|
||||
// cus_ent_id: z.string(),
|
||||
// balance: z.number(),
|
||||
// entities: z.record(z.string(), EntityBalanceSchema),
|
||||
// expires_at: z.number().nullable(),
|
||||
// });
|
||||
|
||||
// export type RolloverModel = z.infer<typeof RolloverModelSchema>;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { rollovers } from "./rolloverTable.js";
|
||||
import { customerEntitlements } from "../cusEntTable.js";
|
||||
|
||||
export const rolloverRelations = relations(rollovers, ({ one }) => ({
|
||||
customer_entitlement: one(customerEntitlements, {
|
||||
fields: [rollovers.cus_ent_id],
|
||||
references: [customerEntitlements.id],
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,52 @@
|
||||
import { z } from "zod";
|
||||
import { customerEntitlements } from "../cusEntTable.js";
|
||||
import {
|
||||
foreignKey,
|
||||
pgTable,
|
||||
numeric,
|
||||
jsonb,
|
||||
text,
|
||||
index,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const EntityRolloverBalanceSchema = z.object({
|
||||
id: z.string(),
|
||||
balance: z.number(),
|
||||
});
|
||||
|
||||
export const RolloverSchema = z.object({
|
||||
id: z.string(),
|
||||
cus_ent_id: z.string(),
|
||||
balance: z.number(),
|
||||
expires_at: z.number().nullable(),
|
||||
entities: z.record(z.string(), EntityRolloverBalanceSchema),
|
||||
});
|
||||
|
||||
export const rollovers = pgTable(
|
||||
"rollovers",
|
||||
{
|
||||
id: text("id").primaryKey().notNull(),
|
||||
cus_ent_id: text("cus_ent_id").notNull(),
|
||||
balance: numeric({ mode: "number" }).notNull(),
|
||||
expires_at: numeric({ mode: "number" }),
|
||||
entities: jsonb("entities")
|
||||
.$type<Record<string, EntityRolloverBalance>>()
|
||||
.notNull()
|
||||
.default({}),
|
||||
},
|
||||
(table) => [
|
||||
foreignKey({
|
||||
columns: [table.cus_ent_id],
|
||||
foreignColumns: [customerEntitlements.id],
|
||||
name: "rollover_cus_ent_id_fkey",
|
||||
})
|
||||
.onUpdate("cascade")
|
||||
.onDelete("cascade"),
|
||||
|
||||
index("idx_rollovers_cus_ent_id").on(table.cus_ent_id),
|
||||
]
|
||||
).enableRLS();
|
||||
|
||||
export type Rollover = z.infer<typeof RolloverSchema>;
|
||||
export type InsertRollover = typeof rollovers.$inferInsert;
|
||||
export type EntityRolloverBalance = z.infer<typeof EntityRolloverBalanceSchema>;
|
||||
Reference in New Issue
Block a user