fitaiProto/packages/database/drizzle/0000_classy_jigsaw.sql
echo 24ed0b6190 pedometar
problem with expogo, should be sorted before build
2025-11-28 18:08:52 +01:00

136 lines
4.3 KiB
SQL

CREATE TABLE `activity_logs` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`date` text NOT NULL,
`steps` integer DEFAULT 0 NOT NULL,
`calories` real DEFAULT 0,
`duration` integer DEFAULT 0,
`distance` real DEFAULT 0,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `attendance` (
`id` text PRIMARY KEY NOT NULL,
`client_id` text NOT NULL,
`check_in_time` integer NOT NULL,
`check_out_time` integer,
`type` text DEFAULT 'gym' NOT NULL,
`notes` text,
`created_at` integer NOT NULL,
FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `clients` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`membership_type` text DEFAULT 'basic' NOT NULL,
`membership_status` text DEFAULT 'active' NOT NULL,
`join_date` integer NOT NULL,
`last_visit` integer,
`emergency_contact_name` text,
`emergency_contact_phone` text,
`emergency_contact_relationship` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `fitness_goals` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`fitness_profile_id` text,
`goal_type` text NOT NULL,
`title` text NOT NULL,
`description` text,
`target_value` real,
`current_value` real,
`unit` text,
`start_date` integer NOT NULL,
`target_date` integer,
`completed_date` integer,
`status` text DEFAULT 'active' NOT NULL,
`progress` real DEFAULT 0,
`priority` text DEFAULT 'medium',
`notes` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`fitness_profile_id`) REFERENCES `fitness_profiles`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `fitness_profiles` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`height` real,
`weight` real,
`age` integer,
`gender` text,
`fitness_goal` text,
`activity_level` text,
`medical_conditions` text,
`allergies` text,
`injuries` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `fitness_profiles_user_id_unique` ON `fitness_profiles` (`user_id`);--> statement-breakpoint
CREATE TABLE `notifications` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`title` text NOT NULL,
`message` text NOT NULL,
`type` text NOT NULL,
`read` integer DEFAULT false NOT NULL,
`created_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `payments` (
`id` text PRIMARY KEY NOT NULL,
`client_id` text NOT NULL,
`amount` real NOT NULL,
`currency` text DEFAULT 'USD' NOT NULL,
`status` text DEFAULT 'pending' NOT NULL,
`payment_method` text NOT NULL,
`due_date` integer NOT NULL,
`paid_at` integer,
`description` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `recommendations` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`fitness_profile_id` text NOT NULL,
`recommendation_text` text NOT NULL,
`activity_plan` text NOT NULL,
`diet_plan` text NOT NULL,
`status` text DEFAULT 'pending' NOT NULL,
`generated_at` integer NOT NULL,
`approved_at` integer,
`approved_by` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`fitness_profile_id`) REFERENCES `fitness_profiles`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`first_name` text NOT NULL,
`last_name` text NOT NULL,
`password` text,
`role` text DEFAULT 'client' NOT NULL,
`phone` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);