Files
cfw-autumn/shared/models/featureModels/featureTable.ts
John Yeo 272e61c712 refactor: migrate event names from config.filters to top-level field
This refactors the Feature data model to use a top-level `event_names`
array field instead of the nested `config.filters[0].value` structure.

**Backend Changes:**
- Updated event routing logic in eventRouter.ts to use event_names
- Updated analytics endpoints to check event_names field
- Simplified validateMeteredConfig to remove filters initialization
- Updated feature create/update handlers to handle event_names

**Frontend Changes:**
- Refactored FeatureConfig component to manage event_names directly
- Simplified FilterInput component to work with string array
- Updated CreateFeature and UpdateFeature to send event_names
- Updated analytics views and tables to display event_names

**Database:**
- event_names column already exists in features table

This is a critical change for billing/usage tracking. All event mapping
logic has been carefully preserved to ensure no disruption to existing
functionality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 15:03:08 +01:00

48 lines
1.2 KiB
TypeScript

import { sql } from "drizzle-orm";
import {
boolean,
foreignKey,
jsonb,
numeric,
pgTable,
text,
unique,
} from "drizzle-orm/pg-core";
import { collatePgColumn } from "../../db/utils.js";
import { organizations } from "../orgModels/orgTable.js";
import type { CreditSystemConfig } from "./featureConfig/creditConfig.js";
import type { MeteredConfig } from "./featureConfig/meteredConfig.js";
type FeatureDisplay = {
singular: string;
plural: string;
};
export const features = pgTable(
"features",
{
internal_id: text("internal_id").primaryKey().notNull(),
org_id: text("org_id").notNull(),
created_at: numeric({ mode: "number" }),
env: text(),
id: text().notNull(),
name: text(),
type: text().notNull(),
config: jsonb().$type<MeteredConfig | CreditSystemConfig>(),
display: jsonb().default(sql`null`).$type<FeatureDisplay>(),
archived: boolean("archived").notNull().default(false),
event_names: text("event_names").array().default([]),
},
(table) => [
foreignKey({
columns: [table.org_id],
foreignColumns: [organizations.id],
name: "features_org_id_fkey",
}).onDelete("cascade"),
unique("feature_id_constraint").on(table.org_id, table.id, table.env),
],
);
collatePgColumn(features.internal_id, "C");