PrithviGuardian / shared /schema.ts
Varad Bakshi
Fresh upload
e7427b5
Raw
History Blame Contribute Delete
6.69 kB
import { pgTable, text, serial, integer, boolean, timestamp, jsonb } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
export const users = pgTable("users", {
id: serial("id").primaryKey(),
username: text("username").notNull().unique(),
password: text("password").notNull(),
});
export const calculations = pgTable("calculations", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
module: text("module").notNull(),
type: text("type").notNull(),
inputs: jsonb("inputs").notNull(),
results: jsonb("results").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
export const reports = pgTable("reports", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
title: text("title").notNull(),
content: jsonb("content").notNull(),
pdfData: text("pdf_data"),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
export const settings = pgTable("settings", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
key: text("key").notNull(),
value: jsonb("value").notNull(),
});
// Project Management System
export const projects = pgTable("projects", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
name: text("name").notNull(),
description: text("description"),
type: text("type").notNull(), // 'university', 'residential', 'commercial', 'infrastructure'
location: text("location"),
status: text("status").notNull().default("active"), // 'active', 'completed', 'archived'
data: jsonb("data").notNull().default('{}'), // Project-specific data
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Link calculations to projects
export const projectCalculations = pgTable("project_calculations", {
id: serial("id").primaryKey(),
projectId: integer("project_id").notNull(),
calculationId: integer("calculation_id").notNull(),
moduleUsed: text("module_used").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Government Reports
export const governmentReports = pgTable("government_reports", {
id: serial("id").primaryKey(),
projectId: integer("project_id"),
reportType: text("report_type").notNull(), // 'eia', 'cpcb', 'municipal', 'forest_clearance'
title: text("title").notNull(),
content: jsonb("content").notNull(),
status: text("status").notNull().default("draft"), // 'draft', 'ready', 'submitted'
generatedData: jsonb("generated_data").notNull(),
pdfData: text("pdf_data"),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Crop Planning (Fasal Chakra)
export const cropPlans = pgTable("crop_plans", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
projectId: integer("project_id"),
farmName: text("farm_name").notNull(),
location: text("location").notNull(),
soilType: text("soil_type").notNull(),
climate: text("climate").notNull(),
area: integer("area").notNull(), // in acres
cropRotation: jsonb("crop_rotation").notNull(),
waterRequirement: jsonb("water_requirement").notNull(),
fertilizerPlan: jsonb("fertilizer_plan").notNull(),
season: text("season").notNull(), // 'kharif', 'rabi', 'zaid'
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Coastal Management (Samudra Raksha)
export const coastalProjects = pgTable("coastal_projects", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
projectId: integer("project_id"),
siteName: text("site_name").notNull(),
coordinates: text("coordinates").notNull(),
coastlineLength: integer("coastline_length"), // in meters
mangroveData: jsonb("mangrove_data").notNull(),
erosionRisk: jsonb("erosion_risk").notNull(),
crzMapping: jsonb("crz_mapping").notNull(),
protectionMeasures: jsonb("protection_measures").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Community Knowledge Hub
export const communityPosts = pgTable("community_posts", {
id: serial("id").primaryKey(),
userId: integer("user_id"),
title: text("title").notNull(),
description: text("description").notNull(),
category: text("category").notNull(), // 'case_study', 'best_practice', 'design_sharing'
projectData: jsonb("project_data"),
images: jsonb("images").default('[]'),
tags: jsonb("tags").default('[]'),
likes: integer("likes").default(0),
isPublic: boolean("is_public").default(true),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
export const insertUserSchema = createInsertSchema(users).pick({
username: true,
password: true,
});
export const insertCalculationSchema = createInsertSchema(calculations).omit({
id: true,
createdAt: true,
});
export const insertReportSchema = createInsertSchema(reports).omit({
id: true,
createdAt: true,
});
export const insertSettingSchema = createInsertSchema(settings).omit({
id: true,
});
export const insertProjectSchema = createInsertSchema(projects).omit({
id: true,
createdAt: true,
updatedAt: true,
});
export const insertGovernmentReportSchema = createInsertSchema(governmentReports).omit({
id: true,
createdAt: true,
});
export const insertCropPlanSchema = createInsertSchema(cropPlans).omit({
id: true,
createdAt: true,
});
export const insertCoastalProjectSchema = createInsertSchema(coastalProjects).omit({
id: true,
createdAt: true,
});
export const insertCommunityPostSchema = createInsertSchema(communityPosts).omit({
id: true,
createdAt: true,
});
export type InsertUser = z.infer<typeof insertUserSchema>;
export type User = typeof users.$inferSelect;
export type InsertCalculation = z.infer<typeof insertCalculationSchema>;
export type Calculation = typeof calculations.$inferSelect;
export type InsertReport = z.infer<typeof insertReportSchema>;
export type Report = typeof reports.$inferSelect;
export type InsertSetting = z.infer<typeof insertSettingSchema>;
export type Setting = typeof settings.$inferSelect;
export type InsertProject = z.infer<typeof insertProjectSchema>;
export type Project = typeof projects.$inferSelect;
export type InsertGovernmentReport = z.infer<typeof insertGovernmentReportSchema>;
export type GovernmentReport = typeof governmentReports.$inferSelect;
export type InsertCropPlan = z.infer<typeof insertCropPlanSchema>;
export type CropPlan = typeof cropPlans.$inferSelect;
export type InsertCoastalProject = z.infer<typeof insertCoastalProjectSchema>;
export type CoastalProject = typeof coastalProjects.$inferSelect;
export type InsertCommunityPost = z.infer<typeof insertCommunityPostSchema>;
export type CommunityPost = typeof communityPosts.$inferSelect;