Set up core database structure to store user and application data

Initializes PostgreSQL database with tables for users, tasks, sessions, and AI interactions.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ff0be73b-afdd-4747-978b-bb8301fb0a82
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/7930aad1-3044-457e-b465-8c9b7c2af1b9.jpg
This commit is contained in:
ghaddaditw
2025-06-07 23:59:46 +00:00
parent 4ed5b6b687
commit b0b9600cf6
4 changed files with 913 additions and 1 deletions
+115
View File
@@ -0,0 +1,115 @@
CREATE TYPE "public"."appointment_status" AS ENUM('pending', 'confirmed', 'cancelled', 'completed', 'no_show');--> statement-breakpoint
CREATE TYPE "public"."connection_status" AS ENUM('pending', 'accepted', 'blocked');--> statement-breakpoint
CREATE TYPE "public"."day_of_week" AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');--> statement-breakpoint
CREATE TYPE "public"."professional_type" AS ENUM('doctor', 'dentist', 'therapist', 'consultant', 'lawyer', 'accountant', 'coach', 'tutor', 'other');--> statement-breakpoint
CREATE TABLE "ai_interactions" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer,
"type" varchar(20) NOT NULL,
"prompt" text,
"response" text NOT NULL,
"model_used" text,
"processing_time" integer,
"was_spoken" boolean DEFAULT false,
"created_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "financial_records" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"type" varchar(10) NOT NULL,
"amount" numeric(12, 2) NOT NULL,
"category" text NOT NULL,
"description" text,
"date" timestamp NOT NULL,
"created_via_voice" boolean DEFAULT false,
"voice_transcription" text,
"metadata" json,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "sessions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" integer NOT NULL,
"token" text NOT NULL,
"expires_at" timestamp NOT NULL,
"created_at" timestamp DEFAULT now(),
CONSTRAINT "sessions_token_unique" UNIQUE("token")
);
--> statement-breakpoint
CREATE TABLE "tasks" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"title" text NOT NULL,
"description" text,
"priority" varchar(10) DEFAULT 'medium' NOT NULL,
"status" varchar(20) DEFAULT 'pending' NOT NULL,
"due_date" timestamp,
"completed_at" timestamp,
"created_via_voice" boolean DEFAULT false,
"voice_transcription" text,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "user_preferences" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"theme" varchar(10) DEFAULT 'light',
"language" varchar(10) DEFAULT 'en',
"voice_model" text DEFAULT 'base',
"tts_voice" text DEFAULT 'default',
"notifications" json,
"dashboard_layout" json,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
CONSTRAINT "user_preferences_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" serial PRIMARY KEY NOT NULL,
"username" text NOT NULL,
"email" text NOT NULL,
"password" text NOT NULL,
"role" varchar(20) DEFAULT 'standard' NOT NULL,
"first_name" text,
"last_name" text,
"onboarding_complete" boolean DEFAULT false,
"voice_enabled" boolean DEFAULT true,
"tts_enabled" boolean DEFAULT true,
"is_professional" boolean DEFAULT false NOT NULL,
"professional_type" "professional_type",
"business_name" varchar(255),
"bio" text,
"specializations" text,
"phone_number" varchar(20),
"address" text,
"is_public_profile" boolean DEFAULT false NOT NULL,
"allow_appointment_booking" boolean DEFAULT false NOT NULL,
"profile_image_url" varchar(500),
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
CONSTRAINT "users_username_unique" UNIQUE("username"),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "voice_commands" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"command" text NOT NULL,
"transcription" text NOT NULL,
"intent" varchar(50),
"confidence" numeric(5, 4),
"processing_time" integer,
"successful" boolean DEFAULT true,
"error_message" text,
"created_at" timestamp DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "ai_interactions" ADD CONSTRAINT "ai_interactions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "financial_records" ADD CONSTRAINT "financial_records_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_preferences" ADD CONSTRAINT "user_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "voice_commands" ADD CONSTRAINT "voice_commands_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
+784
View File
@@ -0,0 +1,784 @@
{
"id": "a32565e4-aac3-44e2-9920-3d292a9e1002",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.ai_interactions": {
"name": "ai_interactions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"type": {
"name": "type",
"type": "varchar(20)",
"primaryKey": false,
"notNull": true
},
"prompt": {
"name": "prompt",
"type": "text",
"primaryKey": false,
"notNull": false
},
"response": {
"name": "response",
"type": "text",
"primaryKey": false,
"notNull": true
},
"model_used": {
"name": "model_used",
"type": "text",
"primaryKey": false,
"notNull": false
},
"processing_time": {
"name": "processing_time",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"was_spoken": {
"name": "was_spoken",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"ai_interactions_user_id_users_id_fk": {
"name": "ai_interactions_user_id_users_id_fk",
"tableFrom": "ai_interactions",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.financial_records": {
"name": "financial_records",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"type": {
"name": "type",
"type": "varchar(10)",
"primaryKey": false,
"notNull": true
},
"amount": {
"name": "amount",
"type": "numeric(12, 2)",
"primaryKey": false,
"notNull": true
},
"category": {
"name": "category",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"date": {
"name": "date",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_via_voice": {
"name": "created_via_voice",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"voice_transcription": {
"name": "voice_transcription",
"type": "text",
"primaryKey": false,
"notNull": false
},
"metadata": {
"name": "metadata",
"type": "json",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"financial_records_user_id_users_id_fk": {
"name": "financial_records_user_id_users_id_fk",
"tableFrom": "financial_records",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.sessions": {
"name": "sessions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"sessions_user_id_users_id_fk": {
"name": "sessions_user_id_users_id_fk",
"tableFrom": "sessions",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"sessions_token_unique": {
"name": "sessions_token_unique",
"nullsNotDistinct": false,
"columns": [
"token"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.tasks": {
"name": "tasks",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"priority": {
"name": "priority",
"type": "varchar(10)",
"primaryKey": false,
"notNull": true,
"default": "'medium'"
},
"status": {
"name": "status",
"type": "varchar(20)",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"due_date": {
"name": "due_date",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"completed_at": {
"name": "completed_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"created_via_voice": {
"name": "created_via_voice",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"voice_transcription": {
"name": "voice_transcription",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"tasks_user_id_users_id_fk": {
"name": "tasks_user_id_users_id_fk",
"tableFrom": "tasks",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user_preferences": {
"name": "user_preferences",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"theme": {
"name": "theme",
"type": "varchar(10)",
"primaryKey": false,
"notNull": false,
"default": "'light'"
},
"language": {
"name": "language",
"type": "varchar(10)",
"primaryKey": false,
"notNull": false,
"default": "'en'"
},
"voice_model": {
"name": "voice_model",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'base'"
},
"tts_voice": {
"name": "tts_voice",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "'default'"
},
"notifications": {
"name": "notifications",
"type": "json",
"primaryKey": false,
"notNull": false
},
"dashboard_layout": {
"name": "dashboard_layout",
"type": "json",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"user_preferences_user_id_users_id_fk": {
"name": "user_preferences_user_id_users_id_fk",
"tableFrom": "user_preferences",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_preferences_user_id_unique": {
"name": "user_preferences_user_id_unique",
"nullsNotDistinct": false,
"columns": [
"user_id"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": true
},
"role": {
"name": "role",
"type": "varchar(20)",
"primaryKey": false,
"notNull": true,
"default": "'standard'"
},
"first_name": {
"name": "first_name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"last_name": {
"name": "last_name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"onboarding_complete": {
"name": "onboarding_complete",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": false
},
"voice_enabled": {
"name": "voice_enabled",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"tts_enabled": {
"name": "tts_enabled",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"is_professional": {
"name": "is_professional",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"professional_type": {
"name": "professional_type",
"type": "professional_type",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"business_name": {
"name": "business_name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"bio": {
"name": "bio",
"type": "text",
"primaryKey": false,
"notNull": false
},
"specializations": {
"name": "specializations",
"type": "text",
"primaryKey": false,
"notNull": false
},
"phone_number": {
"name": "phone_number",
"type": "varchar(20)",
"primaryKey": false,
"notNull": false
},
"address": {
"name": "address",
"type": "text",
"primaryKey": false,
"notNull": false
},
"is_public_profile": {
"name": "is_public_profile",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"allow_appointment_booking": {
"name": "allow_appointment_booking",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"profile_image_url": {
"name": "profile_image_url",
"type": "varchar(500)",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_username_unique": {
"name": "users_username_unique",
"nullsNotDistinct": false,
"columns": [
"username"
]
},
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.voice_commands": {
"name": "voice_commands",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"command": {
"name": "command",
"type": "text",
"primaryKey": false,
"notNull": true
},
"transcription": {
"name": "transcription",
"type": "text",
"primaryKey": false,
"notNull": true
},
"intent": {
"name": "intent",
"type": "varchar(50)",
"primaryKey": false,
"notNull": false
},
"confidence": {
"name": "confidence",
"type": "numeric(5, 4)",
"primaryKey": false,
"notNull": false
},
"processing_time": {
"name": "processing_time",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"successful": {
"name": "successful",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"error_message": {
"name": "error_message",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"voice_commands_user_id_users_id_fk": {
"name": "voice_commands_user_id_users_id_fk",
"tableFrom": "voice_commands",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {
"public.appointment_status": {
"name": "appointment_status",
"schema": "public",
"values": [
"pending",
"confirmed",
"cancelled",
"completed",
"no_show"
]
},
"public.connection_status": {
"name": "connection_status",
"schema": "public",
"values": [
"pending",
"accepted",
"blocked"
]
},
"public.day_of_week": {
"name": "day_of_week",
"schema": "public",
"values": [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday"
]
},
"public.professional_type": {
"name": "professional_type",
"schema": "public",
"values": [
"doctor",
"dentist",
"therapist",
"consultant",
"lawyer",
"accountant",
"coach",
"tutor",
"other"
]
}
},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
+13
View File
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1749340739411,
"tag": "0000_demonic_vector",
"breakpoints": true
}
]
}