danylokhodus commited on
Commit
4a2c1e9
·
1 Parent(s): 452ab3c

fix: resolve SQLite disk I/O error by enabling WAL mode and increasing field limits

Browse files
FlowAPI.Infrastructure/Data/AppDbContext.cs CHANGED
@@ -68,7 +68,7 @@ namespace FlowAPI.Infrastructure.Data
68
  modelBuilder.Entity<Edge>(entity =>
69
  {
70
  entity.HasKey(e => e.Id);
71
- entity.Property(e => e.Condition).HasMaxLength(50);
72
 
73
  entity.HasOne(e => e.Graph)
74
  .WithMany(g => g.Edges)
 
68
  modelBuilder.Entity<Edge>(entity =>
69
  {
70
  entity.HasKey(e => e.Id);
71
+ entity.Property(e => e.Condition).HasMaxLength(500);
72
 
73
  entity.HasOne(e => e.Graph)
74
  .WithMany(g => g.Edges)
FlowAPI.Infrastructure/Migrations/20260521163957_IncreaseEdgeConditionLimit.Designer.cs ADDED
@@ -0,0 +1,448 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // <auto-generated />
2
+ using System;
3
+ using FlowAPI.Infrastructure.Data;
4
+ using Microsoft.EntityFrameworkCore;
5
+ using Microsoft.EntityFrameworkCore.Infrastructure;
6
+ using Microsoft.EntityFrameworkCore.Migrations;
7
+ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8
+
9
+ #nullable disable
10
+
11
+ namespace FlowAPI.Infrastructure.Migrations
12
+ {
13
+ [DbContext(typeof(AppDbContext))]
14
+ [Migration("20260521163957_IncreaseEdgeConditionLimit")]
15
+ partial class IncreaseEdgeConditionLimit
16
+ {
17
+ /// <inheritdoc />
18
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
19
+ {
20
+ #pragma warning disable 612, 618
21
+ modelBuilder.HasAnnotation("ProductVersion", "10.0.8");
22
+
23
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Achievement", b =>
24
+ {
25
+ b.Property<Guid>("Id")
26
+ .ValueGeneratedOnAdd()
27
+ .HasColumnType("TEXT");
28
+
29
+ b.Property<string>("Category")
30
+ .IsRequired()
31
+ .HasMaxLength(100)
32
+ .HasColumnType("TEXT");
33
+
34
+ b.Property<string>("Description")
35
+ .IsRequired()
36
+ .HasColumnType("TEXT");
37
+
38
+ b.Property<string>("IconUrl")
39
+ .IsRequired()
40
+ .HasColumnType("TEXT");
41
+
42
+ b.Property<int>("RewardPoints")
43
+ .HasColumnType("INTEGER");
44
+
45
+ b.Property<int>("TargetValue")
46
+ .HasColumnType("INTEGER");
47
+
48
+ b.Property<string>("Title")
49
+ .IsRequired()
50
+ .HasMaxLength(200)
51
+ .HasColumnType("TEXT");
52
+
53
+ b.Property<string>("TriggerEventName")
54
+ .IsRequired()
55
+ .HasMaxLength(100)
56
+ .HasColumnType("TEXT");
57
+
58
+ b.Property<int>("Type")
59
+ .HasColumnType("INTEGER");
60
+
61
+ b.HasKey("Id");
62
+
63
+ b.ToTable("Achievements");
64
+ });
65
+
66
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Edge", b =>
67
+ {
68
+ b.Property<Guid>("Id")
69
+ .ValueGeneratedOnAdd()
70
+ .HasColumnType("TEXT");
71
+
72
+ b.Property<string>("Condition")
73
+ .IsRequired()
74
+ .HasMaxLength(500)
75
+ .HasColumnType("TEXT");
76
+
77
+ b.Property<Guid>("FromNodeId")
78
+ .HasColumnType("TEXT");
79
+
80
+ b.Property<Guid>("GraphId")
81
+ .HasColumnType("TEXT");
82
+
83
+ b.Property<Guid>("ToNodeId")
84
+ .HasColumnType("TEXT");
85
+
86
+ b.HasKey("Id");
87
+
88
+ b.HasIndex("FromNodeId");
89
+
90
+ b.HasIndex("GraphId");
91
+
92
+ b.HasIndex("ToNodeId");
93
+
94
+ b.ToTable("Edges");
95
+ });
96
+
97
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Graph", b =>
98
+ {
99
+ b.Property<Guid>("Id")
100
+ .ValueGeneratedOnAdd()
101
+ .HasColumnType("TEXT");
102
+
103
+ b.Property<DateTime>("CreatedAt")
104
+ .HasColumnType("TEXT");
105
+
106
+ b.Property<string>("Description")
107
+ .HasMaxLength(1000)
108
+ .HasColumnType("TEXT");
109
+
110
+ b.Property<string>("Title")
111
+ .IsRequired()
112
+ .HasMaxLength(200)
113
+ .HasColumnType("TEXT");
114
+
115
+ b.Property<DateTime>("UpdatedAt")
116
+ .HasColumnType("TEXT");
117
+
118
+ b.Property<Guid>("UserId")
119
+ .HasColumnType("TEXT");
120
+
121
+ b.HasKey("Id");
122
+
123
+ b.HasIndex("UserId");
124
+
125
+ b.ToTable("Graphs");
126
+ });
127
+
128
+ modelBuilder.Entity("FlowAPI.Domain.Entities.HabitRecord", b =>
129
+ {
130
+ b.Property<Guid>("Id")
131
+ .ValueGeneratedOnAdd()
132
+ .HasColumnType("TEXT");
133
+
134
+ b.Property<DateTime>("CheckedDate")
135
+ .HasColumnType("TEXT");
136
+
137
+ b.Property<string>("HabitName")
138
+ .IsRequired()
139
+ .HasMaxLength(100)
140
+ .HasColumnType("TEXT");
141
+
142
+ b.Property<int>("StreakCount")
143
+ .HasColumnType("INTEGER");
144
+
145
+ b.Property<Guid>("UserId")
146
+ .HasColumnType("TEXT");
147
+
148
+ b.HasKey("Id");
149
+
150
+ b.HasIndex("UserId");
151
+
152
+ b.ToTable("HabitRecords");
153
+ });
154
+
155
+ modelBuilder.Entity("FlowAPI.Domain.Entities.SharedGraph", b =>
156
+ {
157
+ b.Property<Guid>("Id")
158
+ .ValueGeneratedOnAdd()
159
+ .HasColumnType("TEXT");
160
+
161
+ b.Property<DateTime>("CreatedAt")
162
+ .HasColumnType("TEXT");
163
+
164
+ b.Property<Guid>("GraphId")
165
+ .HasColumnType("TEXT");
166
+
167
+ b.Property<string>("Permission")
168
+ .IsRequired()
169
+ .ValueGeneratedOnAdd()
170
+ .HasMaxLength(50)
171
+ .HasColumnType("TEXT")
172
+ .HasDefaultValue("Read");
173
+
174
+ b.Property<Guid>("SharedWithUserId")
175
+ .HasColumnType("TEXT");
176
+
177
+ b.HasKey("Id");
178
+
179
+ b.HasIndex("SharedWithUserId");
180
+
181
+ b.HasIndex("GraphId", "SharedWithUserId")
182
+ .IsUnique();
183
+
184
+ b.ToTable("SharedGraphs");
185
+ });
186
+
187
+ modelBuilder.Entity("FlowAPI.Domain.Entities.TaskNode", b =>
188
+ {
189
+ b.Property<Guid>("Id")
190
+ .ValueGeneratedOnAdd()
191
+ .HasColumnType("TEXT");
192
+
193
+ b.Property<string>("Color")
194
+ .HasMaxLength(100)
195
+ .HasColumnType("TEXT");
196
+
197
+ b.Property<DateTime>("CreatedAt")
198
+ .HasColumnType("TEXT");
199
+
200
+ b.Property<string>("Data")
201
+ .HasColumnType("TEXT");
202
+
203
+ b.Property<string>("Decision")
204
+ .HasMaxLength(10000)
205
+ .HasColumnType("TEXT");
206
+
207
+ b.Property<string>("Description")
208
+ .HasMaxLength(5000)
209
+ .HasColumnType("TEXT");
210
+
211
+ b.Property<Guid>("GraphId")
212
+ .HasColumnType("TEXT");
213
+
214
+ b.Property<double?>("Height")
215
+ .HasColumnType("REAL");
216
+
217
+ b.Property<bool>("IsPinned")
218
+ .HasColumnType("INTEGER");
219
+
220
+ b.Property<string>("Label")
221
+ .IsRequired()
222
+ .HasMaxLength(500)
223
+ .HasColumnType("TEXT");
224
+
225
+ b.Property<double>("PosX")
226
+ .HasColumnType("REAL");
227
+
228
+ b.Property<double>("PosY")
229
+ .HasColumnType("REAL");
230
+
231
+ b.Property<string>("State")
232
+ .IsRequired()
233
+ .ValueGeneratedOnAdd()
234
+ .HasColumnType("TEXT")
235
+ .HasDefaultValue("Pending");
236
+
237
+ b.Property<string>("Type")
238
+ .IsRequired()
239
+ .ValueGeneratedOnAdd()
240
+ .HasMaxLength(100)
241
+ .HasColumnType("TEXT")
242
+ .HasDefaultValue("sketch");
243
+
244
+ b.Property<double?>("Width")
245
+ .HasColumnType("REAL");
246
+
247
+ b.HasKey("Id");
248
+
249
+ b.HasIndex("GraphId");
250
+
251
+ b.ToTable("TaskNodes");
252
+ });
253
+
254
+ modelBuilder.Entity("FlowAPI.Domain.Entities.User", b =>
255
+ {
256
+ b.Property<Guid>("Id")
257
+ .ValueGeneratedOnAdd()
258
+ .HasColumnType("TEXT");
259
+
260
+ b.Property<string>("AvatarUrl")
261
+ .HasColumnType("TEXT");
262
+
263
+ b.Property<DateTime>("CreatedAt")
264
+ .HasColumnType("TEXT");
265
+
266
+ b.Property<string>("DisplayName")
267
+ .IsRequired()
268
+ .HasMaxLength(100)
269
+ .HasColumnType("TEXT");
270
+
271
+ b.Property<string>("Email")
272
+ .IsRequired()
273
+ .HasMaxLength(256)
274
+ .HasColumnType("TEXT");
275
+
276
+ b.Property<bool>("IsPremium")
277
+ .HasColumnType("INTEGER");
278
+
279
+ b.Property<string>("PasswordHash")
280
+ .IsRequired()
281
+ .HasColumnType("TEXT");
282
+
283
+ b.HasKey("Id");
284
+
285
+ b.HasIndex("Email")
286
+ .IsUnique();
287
+
288
+ b.ToTable("Users");
289
+ });
290
+
291
+ modelBuilder.Entity("FlowAPI.Domain.Entities.UserAchievement", b =>
292
+ {
293
+ b.Property<Guid>("Id")
294
+ .ValueGeneratedOnAdd()
295
+ .HasColumnType("TEXT");
296
+
297
+ b.Property<Guid>("AchievementId")
298
+ .HasColumnType("TEXT");
299
+
300
+ b.Property<int>("CurrentValue")
301
+ .HasColumnType("INTEGER");
302
+
303
+ b.Property<bool>("IsUnlocked")
304
+ .HasColumnType("INTEGER");
305
+
306
+ b.Property<DateTime?>("UnlockedAt")
307
+ .HasColumnType("TEXT");
308
+
309
+ b.Property<Guid>("UserId")
310
+ .HasColumnType("TEXT");
311
+
312
+ b.HasKey("Id");
313
+
314
+ b.HasIndex("AchievementId");
315
+
316
+ b.HasIndex("UserId");
317
+
318
+ b.ToTable("UserAchievements");
319
+ });
320
+
321
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Edge", b =>
322
+ {
323
+ b.HasOne("FlowAPI.Domain.Entities.TaskNode", "FromNode")
324
+ .WithMany("OutgoingEdges")
325
+ .HasForeignKey("FromNodeId")
326
+ .OnDelete(DeleteBehavior.Cascade)
327
+ .IsRequired();
328
+
329
+ b.HasOne("FlowAPI.Domain.Entities.Graph", "Graph")
330
+ .WithMany("Edges")
331
+ .HasForeignKey("GraphId")
332
+ .OnDelete(DeleteBehavior.Cascade)
333
+ .IsRequired();
334
+
335
+ b.HasOne("FlowAPI.Domain.Entities.TaskNode", "ToNode")
336
+ .WithMany("IncomingEdges")
337
+ .HasForeignKey("ToNodeId")
338
+ .OnDelete(DeleteBehavior.Cascade)
339
+ .IsRequired();
340
+
341
+ b.Navigation("FromNode");
342
+
343
+ b.Navigation("Graph");
344
+
345
+ b.Navigation("ToNode");
346
+ });
347
+
348
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Graph", b =>
349
+ {
350
+ b.HasOne("FlowAPI.Domain.Entities.User", "User")
351
+ .WithMany("Graphs")
352
+ .HasForeignKey("UserId")
353
+ .OnDelete(DeleteBehavior.Cascade)
354
+ .IsRequired();
355
+
356
+ b.Navigation("User");
357
+ });
358
+
359
+ modelBuilder.Entity("FlowAPI.Domain.Entities.HabitRecord", b =>
360
+ {
361
+ b.HasOne("FlowAPI.Domain.Entities.User", "User")
362
+ .WithMany("HabitRecords")
363
+ .HasForeignKey("UserId")
364
+ .OnDelete(DeleteBehavior.Cascade)
365
+ .IsRequired();
366
+
367
+ b.Navigation("User");
368
+ });
369
+
370
+ modelBuilder.Entity("FlowAPI.Domain.Entities.SharedGraph", b =>
371
+ {
372
+ b.HasOne("FlowAPI.Domain.Entities.Graph", "Graph")
373
+ .WithMany("SharedGraphs")
374
+ .HasForeignKey("GraphId")
375
+ .OnDelete(DeleteBehavior.Cascade)
376
+ .IsRequired();
377
+
378
+ b.HasOne("FlowAPI.Domain.Entities.User", "SharedWithUser")
379
+ .WithMany("SharedGraphs")
380
+ .HasForeignKey("SharedWithUserId")
381
+ .OnDelete(DeleteBehavior.Cascade)
382
+ .IsRequired();
383
+
384
+ b.Navigation("Graph");
385
+
386
+ b.Navigation("SharedWithUser");
387
+ });
388
+
389
+ modelBuilder.Entity("FlowAPI.Domain.Entities.TaskNode", b =>
390
+ {
391
+ b.HasOne("FlowAPI.Domain.Entities.Graph", "Graph")
392
+ .WithMany("Nodes")
393
+ .HasForeignKey("GraphId")
394
+ .OnDelete(DeleteBehavior.Cascade)
395
+ .IsRequired();
396
+
397
+ b.Navigation("Graph");
398
+ });
399
+
400
+ modelBuilder.Entity("FlowAPI.Domain.Entities.UserAchievement", b =>
401
+ {
402
+ b.HasOne("FlowAPI.Domain.Entities.Achievement", "Achievement")
403
+ .WithMany()
404
+ .HasForeignKey("AchievementId")
405
+ .OnDelete(DeleteBehavior.Cascade)
406
+ .IsRequired();
407
+
408
+ b.HasOne("FlowAPI.Domain.Entities.User", "User")
409
+ .WithMany("UserAchievements")
410
+ .HasForeignKey("UserId")
411
+ .OnDelete(DeleteBehavior.Cascade)
412
+ .IsRequired();
413
+
414
+ b.Navigation("Achievement");
415
+
416
+ b.Navigation("User");
417
+ });
418
+
419
+ modelBuilder.Entity("FlowAPI.Domain.Entities.Graph", b =>
420
+ {
421
+ b.Navigation("Edges");
422
+
423
+ b.Navigation("Nodes");
424
+
425
+ b.Navigation("SharedGraphs");
426
+ });
427
+
428
+ modelBuilder.Entity("FlowAPI.Domain.Entities.TaskNode", b =>
429
+ {
430
+ b.Navigation("IncomingEdges");
431
+
432
+ b.Navigation("OutgoingEdges");
433
+ });
434
+
435
+ modelBuilder.Entity("FlowAPI.Domain.Entities.User", b =>
436
+ {
437
+ b.Navigation("Graphs");
438
+
439
+ b.Navigation("HabitRecords");
440
+
441
+ b.Navigation("SharedGraphs");
442
+
443
+ b.Navigation("UserAchievements");
444
+ });
445
+ #pragma warning restore 612, 618
446
+ }
447
+ }
448
+ }
FlowAPI.Infrastructure/Migrations/20260521163957_IncreaseEdgeConditionLimit.cs ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+ #nullable disable
4
+
5
+ namespace FlowAPI.Infrastructure.Migrations
6
+ {
7
+ /// <inheritdoc />
8
+ public partial class IncreaseEdgeConditionLimit : Migration
9
+ {
10
+ /// <inheritdoc />
11
+ protected override void Up(MigrationBuilder migrationBuilder)
12
+ {
13
+
14
+ }
15
+
16
+ /// <inheritdoc />
17
+ protected override void Down(MigrationBuilder migrationBuilder)
18
+ {
19
+
20
+ }
21
+ }
22
+ }
FlowAPI.Infrastructure/Migrations/AppDbContextModelSnapshot.cs CHANGED
@@ -68,7 +68,7 @@ namespace FlowAPI.Infrastructure.Migrations
68
 
69
  b.Property<string>("Condition")
70
  .IsRequired()
71
- .HasMaxLength(50)
72
  .HasColumnType("TEXT");
73
 
74
  b.Property<Guid>("FromNodeId")
 
68
 
69
  b.Property<string>("Condition")
70
  .IsRequired()
71
+ .HasMaxLength(500)
72
  .HasColumnType("TEXT");
73
 
74
  b.Property<Guid>("FromNodeId")
FlowAPI/Program.cs CHANGED
@@ -14,7 +14,10 @@ namespace FlowAPI
14
 
15
  // --- Database ---
16
  builder.Services.AddDbContext<AppDbContext>(options =>
17
- options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
 
 
 
18
 
19
  // --- Repositories (Infrastructure) ---
20
  builder.Services.AddScoped<IUserRepository, UserRepository>();
@@ -133,6 +136,14 @@ namespace FlowAPI
133
 
134
  db.Database.Migrate();
135
 
 
 
 
 
 
 
 
 
136
  // Auto-seed achievements
137
  var achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();
138
  achievementService.SeedAchievementsAsync().Wait();
 
14
 
15
  // --- Database ---
16
  builder.Services.AddDbContext<AppDbContext>(options =>
17
+ {
18
+ var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
19
+ options.UseSqlite(connectionString);
20
+ });
21
 
22
  // --- Repositories (Infrastructure) ---
23
  builder.Services.AddScoped<IUserRepository, UserRepository>();
 
136
 
137
  db.Database.Migrate();
138
 
139
+ // Enable WAL mode for SQLite to improve performance and reliability in Docker/Cloud
140
+ using (var command = db.Database.GetDbConnection().CreateCommand())
141
+ {
142
+ db.Database.OpenConnection();
143
+ command.CommandText = "PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;";
144
+ command.ExecuteNonQuery();
145
+ }
146
+
147
  // Auto-seed achievements
148
  var achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();
149
  achievementService.SeedAchievementsAsync().Wait();