Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions app/components.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-lyra",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "",
"css": "app/globals.css",
"baseColor": "gray",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "~/components",
"utils": "~/lib/utils",
"ui": "~/components/ui",
"lib": "~/lib",
"hooks": "~/hooks"
},
"menuColor": "default",
"menuAccent": "subtle",
"registries": {}
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-lyra",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "",
"css": "app/globals.css",
"baseColor": "gray",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "~/components",
"utils": "~/lib/utils",
"ui": "~/components/ui",
"lib": "~/lib",
"hooks": "~/hooks"
},
"menuColor": "default",
"menuAccent": "subtle",
"registries": {}
}
2 changes: 1 addition & 1 deletion app/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default {
dbCredentials: {
url: env.DATABASE_URL,
},
strict: true
strict: true,
//tablesFilter: ["analytics-app_*"],
} satisfies Config;
62 changes: 31 additions & 31 deletions app/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"id": "00000000-0000-0000-0000-000000000000",
"prevId": "",
"version": "7",
"dialect": "postgresql",
"tables": {},
"enums": {},
"schemas": {},
"sequences": {
"public.company_id_seq": {
"name": "company_id_seq",
"schema": "public",
"startWith": "1",
"minValue": "1",
"maxValue": "9223372036854775807",
"increment": "1",
"cycle": false,
"cache": "1"
}
},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {}
}
}
"id": "00000000-0000-0000-0000-000000000000",
"prevId": "",
"version": "7",
"dialect": "postgresql",
"tables": {},
"enums": {},
"schemas": {},
"sequences": {
"public.company_id_seq": {
"name": "company_id_seq",
"schema": "public",
"startWith": "1",
"minValue": "1",
"maxValue": "9223372036854775807",
"increment": "1",
"cycle": false,
"cache": "1"
}
},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {}
}
}
24 changes: 12 additions & 12 deletions app/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1772187438831,
"tag": "0000_optimal_rachel_grey",
"breakpoints": true
}
]
}
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1772187438831,
"tag": "0000_optimal_rachel_grey",
"breakpoints": true
}
]
}
18 changes: 9 additions & 9 deletions app/drizzle/relations.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { relations } from "drizzle-orm/relations";
import { apikeys, requests, users, company } from "./schema";
import { apikeys, company, requests, users } from "./schema";

export const requestsRelations = relations(requests, ({one}) => ({
export const requestsRelations = relations(requests, ({ one }) => ({
apikey: one(apikeys, {
fields: [requests.apiKeyId],
references: [apikeys.uuid]
references: [apikeys.uuid],
}),
}));

export const apikeysRelations = relations(apikeys, ({one, many}) => ({
export const apikeysRelations = relations(apikeys, ({ one, many }) => ({
requests: many(requests),
user: one(users, {
fields: [apikeys.owner],
references: [users.id]
references: [users.id],
}),
}));

export const usersRelations = relations(users, ({one, many}) => ({
export const usersRelations = relations(users, ({ one, many }) => ({
apikeys: many(apikeys),
company: one(company, {
fields: [users.companyId],
references: [company.id]
references: [company.id],
}),
}));

export const companyRelations = relations(company, ({many}) => ({
export const companyRelations = relations(company, ({ many }) => ({
users: many(users),
}));
}));
157 changes: 105 additions & 52 deletions app/drizzle/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { pgTable, varchar, bigint, timestamp, text, jsonb, foreignKey, integer, boolean, primaryKey, date, char, pgEnum } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"


import {
bigint,
boolean,
char,
date,
foreignKey,
integer,
jsonb,
pgEnum,
pgTable,
primaryKey,
text,
timestamp,
varchar,
} from "drizzle-orm/pg-core";

export const atlasSchemaRevisions = pgTable("atlas_schema_revisions", {
version: varchar().primaryKey().notNull(),
Expand All @@ -12,7 +23,10 @@ export const atlasSchemaRevisions = pgTable("atlas_schema_revisions", {
applied: bigint({ mode: "number" }).default(0).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
total: bigint({ mode: "number" }).default(0).notNull(),
executedAt: timestamp("executed_at", { withTimezone: true, mode: 'string' }).notNull(),
executedAt: timestamp("executed_at", {
withTimezone: true,
mode: "string",
}).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
executionTime: bigint("execution_time", { mode: "number" }).notNull(),
error: text(),
Expand All @@ -24,71 +38,110 @@ export const atlasSchemaRevisions = pgTable("atlas_schema_revisions", {

export const company = pgTable("company", {
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
id: bigint({ mode: "number" }).primaryKey().generatedAlwaysAsIdentity({ name: "company_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
id: bigint({ mode: "number" }).primaryKey().generatedAlwaysAsIdentity({
name: "company_id_seq",
startWith: 1,
increment: 1,
minValue: 1,
// biome-ignore lint/correctness/noPrecisionLoss: matches Postgres BIGINT max.
maxValue: 9223372036854775807,
cache: 1,
}),
companyName: varchar("company_name", { length: 255 }).notNull(),
});

export const requests = pgTable("requests", {
id: varchar({ length: 255 }).primaryKey().notNull(),
requestTime: timestamp("request_time", { withTimezone: true, mode: 'string' }).defaultNow(),
model: varchar({ length: 255 }),
apiKeyId: varchar("api_key_id", { length: 255 }).notNull(),
inputTokenCount: integer("input_token_count").default(0).notNull(),
cachedInputTokenCount: integer("cached_input_token_count").default(0).notNull(),
outputTokenCount: integer("output_token_count").default(0).notNull(),
snapshotVersion: varchar("snapshot_version", { length: 255 }),
isApproximated: boolean("is_approximated").default(false).notNull(),
}, (table) => [
foreignKey({
export const requests = pgTable(
"requests",
{
id: varchar({ length: 255 }).primaryKey().notNull(),
requestTime: timestamp("request_time", {
withTimezone: true,
mode: "string",
}).defaultNow(),
model: varchar({ length: 255 }),
apiKeyId: varchar("api_key_id", { length: 255 }).notNull(),
inputTokenCount: integer("input_token_count").default(0).notNull(),
cachedInputTokenCount: integer("cached_input_token_count")
.default(0)
.notNull(),
outputTokenCount: integer("output_token_count").default(0).notNull(),
snapshotVersion: varchar("snapshot_version", { length: 255 }),
isApproximated: boolean("is_approximated").default(false).notNull(),
},
(table) => [
foreignKey({
columns: [table.apiKeyId],
foreignColumns: [apikeys.uuid],
name: "requests_api_key_id_fkey"
name: "requests_api_key_id_fkey",
}),
]);
],
);

export const apikeys = pgTable("apikeys", {
uuid: varchar({ length: 255 }).primaryKey().notNull(),
apikey: varchar({ length: 255 }).notNull(),
owner: varchar({ length: 255 }).notNull(),
aiapi: varchar({ length: 255 }),
description: varchar({ length: 255 }),
}, (table) => [
foreignKey({
export const apikeys = pgTable(
"apikeys",
{
uuid: varchar({ length: 255 }).primaryKey().notNull(),
apikey: varchar({ length: 255 }).notNull(),
owner: varchar({ length: 255 }).notNull(),
aiapi: varchar({ length: 255 }),
description: varchar({ length: 255 }),
},
(table) => [
foreignKey({
columns: [table.owner],
foreignColumns: [users.id],
name: "apikeys_owner_fkey"
name: "apikeys_owner_fkey",
}),
]);
],
);

export const users = pgTable("users", {
id: varchar({ length: 255 }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
companyId: bigint("company_id", { mode: "number" }),
name: varchar({ length: 255 }),
isAdmin: boolean("is_admin"),
}, (table) => [
foreignKey({
export const users = pgTable(
"users",
{
id: varchar({ length: 255 }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
companyId: bigint("company_id", { mode: "number" }),
name: varchar({ length: 255 }),
isAdmin: boolean("is_admin"),
},
(table) => [
foreignKey({
columns: [table.companyId],
foreignColumns: [company.id],
name: "users_company_id_fkey"
name: "users_company_id_fkey",
}),
]);
],
);

export const models = pgTable("models", {
id: varchar({ length: 255 }).primaryKey().notNull(),
});

export const costUnit = pgEnum("cost_unit", ["1M", "1K"]);

export const costs = pgTable("costs", {
model: varchar({ length: 255 }).notNull(),
price: integer().notNull(),
validFrom: date("valid_from").defaultNow().notNull(),
tokenType: varchar("token_type", { length: 255 }).notNull(),
unitOfMessure: costUnit("unit_of_messure"),
isRegional: boolean("is_regional").notNull(),
backendName: varchar("backend_name", { length: 255 }).notNull(),
currency: char({ length: 3 }),
}, (table) => [
primaryKey({ columns: [table.model, table.price, table.validFrom, table.tokenType, table.isRegional, table.backendName], name: "costs_pkey"}),
]);
export const costs = pgTable(
"costs",
{
model: varchar({ length: 255 }).notNull(),
price: integer().notNull(),
validFrom: date("valid_from").defaultNow().notNull(),
tokenType: varchar("token_type", { length: 255 }).notNull(),
unitOfMessure: costUnit("unit_of_messure"),
isRegional: boolean("is_regional").notNull(),
backendName: varchar("backend_name", { length: 255 }).notNull(),
currency: char({ length: 3 }),
},
(table) => [
primaryKey({
columns: [
table.model,
table.price,
table.validFrom,
table.tokenType,
table.isRegional,
table.backendName,
],
name: "costs_pkey",
}),
],
);
2 changes: 1 addition & 1 deletion app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./src/env.js";

/** @type {import("next").NextConfig} */
const config = {
output: "standalone",
output: "standalone",
};

export default config;
Loading