synapticpush commited on
Commit
39eada6
·
1 Parent(s): b55355a

db-migrations: Add initial migration schema

Browse files
Backend/database/migrations/final_sql_schema.sql ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- WARNING: This schema is for context only and is not meant to be run.
2
+ -- Table order and constraints may not be valid for execution.
3
+
4
+ CREATE TABLE public.classifications (
5
+ id uuid NOT NULL,
6
+ issue_id uuid NOT NULL UNIQUE,
7
+ primary_category character varying,
8
+ primary_confidence double precision NOT NULL,
9
+ detections_json text,
10
+ inference_time_ms double precision NOT NULL,
11
+ model_version character varying NOT NULL,
12
+ created_at timestamp without time zone NOT NULL,
13
+ CONSTRAINT classifications_pkey PRIMARY KEY (id),
14
+ CONSTRAINT classifications_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES public.issues(id)
15
+ );
16
+ CREATE TABLE public.departments (
17
+ id uuid NOT NULL,
18
+ name character varying NOT NULL UNIQUE,
19
+ code character varying NOT NULL UNIQUE,
20
+ description text,
21
+ categories text,
22
+ default_sla_hours integer NOT NULL,
23
+ escalation_email character varying,
24
+ is_active boolean NOT NULL,
25
+ created_at timestamp without time zone NOT NULL,
26
+ updated_at timestamp without time zone NOT NULL,
27
+ CONSTRAINT departments_pkey PRIMARY KEY (id)
28
+ );
29
+ CREATE TABLE public.escalations (
30
+ id uuid NOT NULL,
31
+ issue_id uuid NOT NULL,
32
+ from_level integer NOT NULL,
33
+ to_level integer NOT NULL,
34
+ reason text NOT NULL,
35
+ escalated_by character varying NOT NULL,
36
+ notified_emails text,
37
+ created_at timestamp without time zone NOT NULL,
38
+ CONSTRAINT escalations_pkey PRIMARY KEY (id),
39
+ CONSTRAINT escalations_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES public.issues(id)
40
+ );
41
+ CREATE TABLE public.issue_events (
42
+ id uuid NOT NULL,
43
+ issue_id uuid NOT NULL,
44
+ event_type character varying NOT NULL,
45
+ agent_name character varying,
46
+ event_data text,
47
+ created_at timestamp without time zone NOT NULL,
48
+ CONSTRAINT issue_events_pkey PRIMARY KEY (id),
49
+ CONSTRAINT issue_events_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES public.issues(id)
50
+ );
51
+ CREATE TABLE public.issue_images (
52
+ id uuid NOT NULL,
53
+ issue_id uuid NOT NULL,
54
+ file_path character varying NOT NULL,
55
+ annotated_path character varying,
56
+ original_filename character varying,
57
+ created_at timestamp without time zone NOT NULL,
58
+ CONSTRAINT issue_images_pkey PRIMARY KEY (id),
59
+ CONSTRAINT issue_images_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES public.issues(id)
60
+ );
61
+ CREATE TABLE public.issues (
62
+ id uuid NOT NULL,
63
+ description text,
64
+ latitude double precision NOT NULL,
65
+ longitude double precision NOT NULL,
66
+ accuracy_meters double precision,
67
+ state character varying NOT NULL,
68
+ priority integer,
69
+ priority_reason text,
70
+ validation_source character varying,
71
+ validation_reason text,
72
+ is_duplicate boolean NOT NULL,
73
+ parent_issue_id uuid,
74
+ geo_cluster_id character varying,
75
+ platform character varying NOT NULL,
76
+ device_model character varying,
77
+ department_id uuid,
78
+ assigned_member_id uuid,
79
+ city character varying,
80
+ locality character varying,
81
+ full_address text,
82
+ sla_deadline timestamp without time zone,
83
+ sla_hours integer,
84
+ escalation_level integer NOT NULL,
85
+ escalated_at timestamp without time zone,
86
+ resolved_at timestamp without time zone,
87
+ resolution_notes text,
88
+ created_at timestamp without time zone NOT NULL,
89
+ updated_at timestamp without time zone NOT NULL,
90
+ user_id character varying,
91
+ proof_image_path character varying,
92
+ completed_at timestamp without time zone,
93
+ CONSTRAINT issues_pkey PRIMARY KEY (id),
94
+ CONSTRAINT issues_parent_issue_id_fkey FOREIGN KEY (parent_issue_id) REFERENCES public.issues(id),
95
+ CONSTRAINT issues_department_id_fkey FOREIGN KEY (department_id) REFERENCES public.departments(id),
96
+ CONSTRAINT issues_assigned_member_id_fkey FOREIGN KEY (assigned_member_id) REFERENCES public.members(id)
97
+ );
98
+ CREATE TABLE public.members (
99
+ id uuid NOT NULL,
100
+ department_id uuid,
101
+ name character varying NOT NULL,
102
+ email character varying NOT NULL UNIQUE,
103
+ phone character varying,
104
+ role character varying NOT NULL,
105
+ city character varying,
106
+ locality character varying,
107
+ is_active boolean NOT NULL,
108
+ current_workload integer NOT NULL,
109
+ max_workload integer NOT NULL,
110
+ created_at timestamp without time zone NOT NULL,
111
+ updated_at timestamp without time zone NOT NULL,
112
+ password_hash character varying,
113
+ CONSTRAINT members_pkey PRIMARY KEY (id),
114
+ CONSTRAINT members_department_id_fkey FOREIGN KEY (department_id) REFERENCES public.departments(id)
115
+ );