Skip to content

Commit 81f35c9

Browse files
committed
fix(table): coerce env table limits to number for skipValidation env
1 parent c00437c commit 81f35c9

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

apps/sim/lib/table/constants.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ export interface TablePlanLimits {
5858

5959
export type TablePlanLimitsByPlan = Record<PlanName, TablePlanLimits>
6060

61+
/**
62+
* Coerce an env value to a number. `env.ts` runs with `skipValidation: true`,
63+
* so values declared as `z.number()` arrive as raw strings (e.g. when set via
64+
* Helm). Falls back to the default when the value is unset, empty, or not a
65+
* finite number.
66+
*/
67+
function envNumber(value: number | string | undefined, fallback: number): number {
68+
if (value === undefined || value === null || value === '') return fallback
69+
const parsed = typeof value === 'number' ? value : Number(value)
70+
return Number.isFinite(parsed) ? parsed : fallback
71+
}
72+
6173
/**
6274
* Returns plan-based table limits, applying env var overrides on top of the
6375
* defaults. When no override is set the value falls back to the hosted-default
@@ -66,21 +78,35 @@ export type TablePlanLimitsByPlan = Record<PlanName, TablePlanLimits>
6678
export function getTablePlanLimits(): TablePlanLimitsByPlan {
6779
return {
6880
free: {
69-
maxTables: env.FREE_TABLES_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.free.maxTables,
70-
maxRowsPerTable: env.FREE_TABLE_ROWS_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.free.maxRowsPerTable,
81+
maxTables: envNumber(env.FREE_TABLES_LIMIT, DEFAULT_TABLE_PLAN_LIMITS.free.maxTables),
82+
maxRowsPerTable: envNumber(
83+
env.FREE_TABLE_ROWS_LIMIT,
84+
DEFAULT_TABLE_PLAN_LIMITS.free.maxRowsPerTable
85+
),
7186
},
7287
pro: {
73-
maxTables: env.PRO_TABLES_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.pro.maxTables,
74-
maxRowsPerTable: env.PRO_TABLE_ROWS_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.pro.maxRowsPerTable,
88+
maxTables: envNumber(env.PRO_TABLES_LIMIT, DEFAULT_TABLE_PLAN_LIMITS.pro.maxTables),
89+
maxRowsPerTable: envNumber(
90+
env.PRO_TABLE_ROWS_LIMIT,
91+
DEFAULT_TABLE_PLAN_LIMITS.pro.maxRowsPerTable
92+
),
7593
},
7694
team: {
77-
maxTables: env.TEAM_TABLES_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.team.maxTables,
78-
maxRowsPerTable: env.TEAM_TABLE_ROWS_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.team.maxRowsPerTable,
95+
maxTables: envNumber(env.TEAM_TABLES_LIMIT, DEFAULT_TABLE_PLAN_LIMITS.team.maxTables),
96+
maxRowsPerTable: envNumber(
97+
env.TEAM_TABLE_ROWS_LIMIT,
98+
DEFAULT_TABLE_PLAN_LIMITS.team.maxRowsPerTable
99+
),
79100
},
80101
enterprise: {
81-
maxTables: env.ENTERPRISE_TABLES_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.enterprise.maxTables,
82-
maxRowsPerTable:
83-
env.ENTERPRISE_TABLE_ROWS_LIMIT ?? DEFAULT_TABLE_PLAN_LIMITS.enterprise.maxRowsPerTable,
102+
maxTables: envNumber(
103+
env.ENTERPRISE_TABLES_LIMIT,
104+
DEFAULT_TABLE_PLAN_LIMITS.enterprise.maxTables
105+
),
106+
maxRowsPerTable: envNumber(
107+
env.ENTERPRISE_TABLE_ROWS_LIMIT,
108+
DEFAULT_TABLE_PLAN_LIMITS.enterprise.maxRowsPerTable
109+
),
84110
},
85111
}
86112
}

0 commit comments

Comments
 (0)