reset-infra 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "reset-infra",
3
+ "version": "1.0.0",
4
+ "description": "ReSet – Database infrastructure, Prisma migrations & Zod schema generation",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "prisma/schema.prisma"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "db:up": "docker compose up -d",
14
+ "db:down": "docker compose down",
15
+ "db:migrate": "npx prisma migrate dev",
16
+ "db:generate": "npx prisma generate",
17
+ "postinstall": "npx prisma generate",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "dependencies": {
24
+ "dotenv": "^17.3.1"
25
+ },
26
+ "peerDependencies": {
27
+ "@prisma/client": "^7.4.0",
28
+ "zod": "^3.22.0 || ^4.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^25.3.0",
32
+ "prisma": "^7.4.1",
33
+ "typescript": "^5.9.3",
34
+ "zod-prisma-types": "^3.3.11"
35
+ }
36
+ }
@@ -0,0 +1,212 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ previewFeatures = ["multiSchema"]
4
+ }
5
+
6
+ generator zod {
7
+ provider = "zod-prisma-types"
8
+ output = "../src/schemas"
9
+ }
10
+
11
+ datasource db {
12
+ provider = "postgresql"
13
+ schemas = ["auth", "tracking", "emergency", "core"]
14
+ }
15
+
16
+ // ==========================================
17
+ // 1. SCHEMA: AUTH
18
+ // ==========================================
19
+ model User {
20
+ id String @id @default(uuid()) @db.Uuid
21
+ name String @db.VarChar(100)
22
+ email String @unique @db.VarChar(150)
23
+ password_hash String @db.Text
24
+ role String? @db.VarChar(20)
25
+ created_at DateTime @default(now())
26
+ updated_at DateTime @default(now()) @updatedAt
27
+
28
+ addictions UserAddiction?
29
+ daily_logs DailyLog[]
30
+ sponsorships_as_sponsor Sponsorship[] @relation("SponsorRelation")
31
+ sponsorships_as_addict Sponsorship[] @relation("AddictRelation")
32
+ contacts SupportContact[]
33
+ alerts EmergencyAlert[]
34
+ streak Streak?
35
+ absences LogAbsence[]
36
+
37
+ @@map("users")
38
+ @@schema("auth")
39
+ }
40
+
41
+ // ==========================================
42
+ // 2. SCHEMA: CORE
43
+ // ==========================================
44
+ model CravingLevel {
45
+ id String @id @default(uuid()) @db.Uuid
46
+ level Int @unique // El valor 1-10
47
+ label String @db.VarChar(50)
48
+ description String? @db.Text
49
+ daily_logs DailyLog[]
50
+
51
+ @@map("craving_levels")
52
+ @@schema("core")
53
+ }
54
+
55
+ model EmotionalState {
56
+ id String @id @default(uuid()) @db.Uuid
57
+ level Int @unique // El valor 1-10
58
+ label String @db.VarChar(50)
59
+ description String? @db.Text
60
+ daily_logs DailyLog[]
61
+
62
+ @@map("emotional_states")
63
+ @@schema("core")
64
+ }
65
+
66
+ model UserAddiction {
67
+ id String @id @default(uuid()) @db.Uuid
68
+ user_id String @unique @db.Uuid
69
+ custom_name String @db.VarChar(100)
70
+ classification String? @db.VarChar(50)
71
+ is_active Boolean @default(true)
72
+ registered_at DateTime @default(now())
73
+ created_at DateTime @default(now())
74
+
75
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
76
+ streak Streak?
77
+ alerts EmergencyAlert[]
78
+
79
+ @@map("user_addictions")
80
+ @@schema("core")
81
+ }
82
+
83
+ model Sponsorship {
84
+ id String @id @default(uuid()) @db.Uuid
85
+ sponsor_id String? @unique @db.Uuid
86
+ addict_id String? @unique @db.Uuid
87
+ started_at DateTime @default(now())
88
+ ended_at DateTime?
89
+ is_active Boolean @default(true)
90
+ termination_reason String? @db.Text
91
+ created_at DateTime @default(now())
92
+
93
+ sponsor User? @relation("SponsorRelation", fields: [sponsor_id], references: [id])
94
+ addict User? @relation("AddictRelation", fields: [addict_id], references: [id])
95
+
96
+ @@map("sponsorships")
97
+ @@schema("core")
98
+ }
99
+
100
+ // ==========================================
101
+ // 3. SCHEMA: TRACKING
102
+ // ==========================================
103
+ model DailyLog {
104
+ id String @id @default(uuid()) @db.Uuid
105
+ user_id String @db.Uuid
106
+ log_date DateTime @db.Date
107
+ consumed Boolean @default(false)
108
+ craving_level_id String? @db.Uuid
109
+ emotional_state_id String? @db.Uuid
110
+ triggers String? @db.Text
111
+ notes String? @db.Text
112
+ created_at DateTime @default(now())
113
+
114
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
115
+ craving_level CravingLevel? @relation(fields: [craving_level_id], references: [id])
116
+ emotional_state EmotionalState? @relation(fields: [emotional_state_id], references: [id])
117
+
118
+ @@unique([user_id, log_date])
119
+ @@map("daily_logs")
120
+ @@schema("tracking")
121
+ }
122
+
123
+ model StreakEvent {
124
+ id String @id @default(uuid()) @db.Uuid
125
+ streak_id String @db.Uuid
126
+ emergency_alert_id String? @db.Uuid
127
+ event_type String? @db.VarChar(20)
128
+ event_date DateTime
129
+ days_achieved Int?
130
+ avg_craving_period Decimal? @db.Decimal(4, 2)
131
+ avg_emotion_period Decimal? @db.Decimal(4, 2)
132
+ created_at DateTime @default(now())
133
+
134
+ streak Streak @relation(fields: [streak_id], references: [id], onDelete: Cascade)
135
+ absences LogAbsence[]
136
+
137
+ @@map("streak_events")
138
+ @@schema("tracking")
139
+ }
140
+
141
+ model LogAbsence {
142
+ id String @id @default(uuid()) @db.Uuid
143
+ user_id String @db.Uuid
144
+ streak_id String @db.Uuid
145
+ last_log_date DateTime? @db.Date
146
+ detected_at DateTime @default(now())
147
+ absence_hours Int?
148
+ event_generated Boolean @default(false)
149
+ streak_event_id String? @db.Uuid
150
+
151
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
152
+ streak_event StreakEvent? @relation(fields: [streak_event_id], references: [id])
153
+
154
+ @@map("log_absences")
155
+ @@schema("tracking")
156
+ }
157
+
158
+ // ==========================================
159
+ // 4. SCHEMA: EMERGENCY
160
+ // ==========================================
161
+ model SupportContact {
162
+ id String @id @default(uuid()) @db.Uuid
163
+ user_id String @db.Uuid
164
+ contact_name String @db.VarChar(100)
165
+ phone String? @db.VarChar(20)
166
+ email String? @db.VarChar(150)
167
+ relationship String? @db.VarChar(50)
168
+ custom_relationship String? @db.Text
169
+ is_active Boolean @default(true)
170
+ priority_order Int?
171
+ created_at DateTime @default(now())
172
+ updated_at DateTime @default(now()) @updatedAt
173
+
174
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
175
+
176
+ @@map("support_contacts")
177
+ @@schema("emergency")
178
+ }
179
+
180
+ model EmergencyAlert {
181
+ id String @id @default(uuid()) @db.Uuid
182
+ user_id String @db.Uuid
183
+ user_addiction_id String @db.Uuid
184
+ activated_at DateTime @default(now())
185
+ resulted_in_relapse Boolean @default(false)
186
+ resolution_notes String? @db.Text
187
+ created_at DateTime @default(now())
188
+
189
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
190
+ addiction UserAddiction @relation(fields: [user_addiction_id], references: [id])
191
+
192
+ @@map("emergency_alerts")
193
+ @@schema("emergency")
194
+ }
195
+
196
+ model Streak {
197
+ id String @id @default(uuid()) @db.Uuid
198
+ user_id String @unique @db.Uuid
199
+ user_addiction_id String @unique @db.Uuid
200
+ status String? @db.VarChar(20)
201
+ started_at DateTime
202
+ day_counter Int @default(0)
203
+ last_log_date DateTime? @db.Date
204
+ updated_at DateTime @default(now()) @updatedAt
205
+
206
+ user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
207
+ addiction UserAddiction @relation(fields: [user_addiction_id], references: [id], onDelete: Cascade)
208
+ events StreakEvent[]
209
+
210
+ @@map("streaks")
211
+ @@schema("core")
212
+ }