import { pgTable, text, serial, integer, boolean, timestamp, jsonb } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { z } from "zod"; export const species = pgTable("species", { id: serial("id").primaryKey(), scientificName: text("scientific_name").notNull(), commonName: text("common_name"), rank: text("rank"), kingdom: text("kingdom"), phylum: text("phylum"), class: text("class"), order: text("order"), family: text("family"), genus: text("genus"), citesListings: jsonb("cites_listings"), citesId: integer("cites_id"), iucnStatus: text("iucn_status"), iucnId: text("iucn_id"), iucnData: jsonb("iucn_data"), apiData: jsonb("api_data"), searchedAt: timestamp("searched_at").defaultNow(), }); export const insertSpeciesSchema = createInsertSchema(species).pick({ scientificName: true, commonName: true, rank: true, kingdom: true, phylum: true, class: true, order: true, family: true, genus: true, citesListings: true, citesId: true, iucnStatus: true, iucnId: true, iucnData: true, apiData: true, }); export type InsertSpecies = z.infer; export type Species = typeof species.$inferSelect; export const searches = pgTable("searches", { id: serial("id").primaryKey(), query: text("query").notNull(), timestamp: timestamp("timestamp").defaultNow(), }); export const insertSearchSchema = createInsertSchema(searches).pick({ query: true, }); export type InsertSearch = z.infer; export type Search = typeof searches.$inferSelect; export const apiTokens = pgTable("api_tokens", { id: serial("id").primaryKey(), token: text("token").notNull(), // CITES API token iucnToken: text("iucn_token"), // IUCN API v4 token isActive: boolean("is_active").default(true), createdAt: timestamp("created_at").defaultNow(), }); export const insertApiTokenSchema = createInsertSchema(apiTokens).pick({ token: true, iucnToken: true, isActive: true, }); export type InsertApiToken = z.infer; export type ApiToken = typeof apiTokens.$inferSelect;