This commit is contained in:
@@ -33,6 +33,13 @@ import {
|
||||
timestamp,
|
||||
uuid,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { ALLOCATION_STATUSES, GUARANTEE_TYPES } from '@pig/core';
|
||||
export {
|
||||
ALLOCATION_STATUSES,
|
||||
CONSUMING_ALLOCATION_STATUSES,
|
||||
RESERVING_ALLOCATION_STATUSES,
|
||||
} from '@pig/core';
|
||||
export type { AllocationStatus } from '@pig/core';
|
||||
import { capacityCommitments } from './supply';
|
||||
import { demandDeals } from './demand';
|
||||
import { users } from './identity';
|
||||
@@ -95,7 +102,7 @@ export const allocations = pgTable(
|
||||
* allocations are shown separately so a seller can see what the pipeline
|
||||
* would do to utilisation without letting forecasts pollute the actuals.
|
||||
*/
|
||||
status: text('status').notNull().default('planned'),
|
||||
status: text('status', { enum: ALLOCATION_STATUSES }).notNull().default('planned'),
|
||||
|
||||
/**
|
||||
* A capacity HOLD with an expiry.
|
||||
@@ -129,7 +136,9 @@ export const allocations = pgTable(
|
||||
* system answer "can I actually sell this?" rather than "is something
|
||||
* technically free?"
|
||||
*/
|
||||
guaranteeType: text('guarantee_type').notNull().default('committed'),
|
||||
guaranteeType: text('guarantee_type', { enum: GUARANTEE_TYPES })
|
||||
.notNull()
|
||||
.default('committed'),
|
||||
priority: integer('priority').notNull().default(100),
|
||||
|
||||
/**
|
||||
@@ -160,35 +169,5 @@ export const allocations = pgTable(
|
||||
],
|
||||
);
|
||||
|
||||
/**
|
||||
* Statuses that actually consume committed capacity.
|
||||
*
|
||||
* Kept here beside the column it describes so the definition cannot drift away
|
||||
* from the schema. Utilisation and idle-capacity figures filter on this;
|
||||
* including `planned` would let optimistic forecasting hide idle hardware.
|
||||
*/
|
||||
export const CONSUMING_ALLOCATION_STATUSES = ['committed', 'active', 'completed'] as const;
|
||||
|
||||
/**
|
||||
* Statuses that block the capacity from being sold to somebody else.
|
||||
*
|
||||
* Deliberately WIDER than the set that counts toward utilisation and margin.
|
||||
* A live hold must remove inventory from availability — otherwise two sellers
|
||||
* promise the same GPUs — while not yet counting as sold, because it has not
|
||||
* been. Conflating "cannot be offered to anyone else" with "earning revenue"
|
||||
* is how a pipeline of optimistic holds comes to look like a full book.
|
||||
*/
|
||||
export const RESERVING_ALLOCATION_STATUSES = [
|
||||
'planned',
|
||||
...CONSUMING_ALLOCATION_STATUSES,
|
||||
] as const;
|
||||
|
||||
export const ALLOCATION_STATUSES = [
|
||||
'planned',
|
||||
...CONSUMING_ALLOCATION_STATUSES,
|
||||
'released',
|
||||
] as const;
|
||||
|
||||
export type AllocationStatus = (typeof ALLOCATION_STATUSES)[number];
|
||||
export type Allocation = typeof allocations.$inferSelect;
|
||||
export type NewAllocation = typeof allocations.$inferInsert;
|
||||
|
||||
Reference in New Issue
Block a user