@trafficgroup/knex-rel 0.1.11 → 0.1.12

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.
Files changed (110) hide show
  1. package/.claude/settings.local.json +2 -5
  2. package/CLAUDE.md +11 -2
  3. package/dist/constants/folder.constants.d.ts +12 -0
  4. package/dist/constants/folder.constants.js +28 -0
  5. package/dist/constants/folder.constants.js.map +1 -0
  6. package/dist/constants/video.constants.d.ts +2 -2
  7. package/dist/constants/video.constants.js +9 -5
  8. package/dist/constants/video.constants.js.map +1 -1
  9. package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
  10. package/dist/dao/VideoMinuteResultDAO.js +29 -23
  11. package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
  12. package/dist/dao/auth/auth.dao.js +4 -1
  13. package/dist/dao/auth/auth.dao.js.map +1 -1
  14. package/dist/dao/batch/batch.dao.js +13 -14
  15. package/dist/dao/batch/batch.dao.js.map +1 -1
  16. package/dist/dao/camera/camera.dao.js +10 -7
  17. package/dist/dao/camera/camera.dao.js.map +1 -1
  18. package/dist/dao/chat/chat.dao.d.ts +1 -1
  19. package/dist/dao/chat/chat.dao.js +27 -40
  20. package/dist/dao/chat/chat.dao.js.map +1 -1
  21. package/dist/dao/folder/folder.dao.d.ts +10 -1
  22. package/dist/dao/folder/folder.dao.js +44 -6
  23. package/dist/dao/folder/folder.dao.js.map +1 -1
  24. package/dist/dao/location/location.dao.js +16 -9
  25. package/dist/dao/location/location.dao.js.map +1 -1
  26. package/dist/dao/message/message.dao.d.ts +1 -1
  27. package/dist/dao/message/message.dao.js +18 -26
  28. package/dist/dao/message/message.dao.js.map +1 -1
  29. package/dist/dao/report-configuration/report-configuration.dao.js +32 -31
  30. package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
  31. package/dist/dao/study/study.dao.js +7 -2
  32. package/dist/dao/study/study.dao.js.map +1 -1
  33. package/dist/dao/user/user.dao.js +4 -1
  34. package/dist/dao/user/user.dao.js.map +1 -1
  35. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
  36. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
  37. package/dist/dao/video/video.dao.js +30 -28
  38. package/dist/dao/video/video.dao.js.map +1 -1
  39. package/dist/index.d.ts +8 -5
  40. package/dist/index.js +5 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
  43. package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
  44. package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
  45. package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
  46. package/dist/interfaces/message/message.interfaces.d.ts +2 -2
  47. package/dist/interfaces/study/study.interfaces.d.ts +2 -2
  48. package/dist/interfaces/user/user.interfaces.d.ts +1 -1
  49. package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
  50. package/dist/interfaces/video/video.interfaces.d.ts +2 -2
  51. package/migrations/20250717160737_migration.ts +1 -1
  52. package/migrations/20250717160908_migration.ts +5 -2
  53. package/migrations/20250717161310_migration.ts +1 -1
  54. package/migrations/20250717161406_migration.ts +3 -3
  55. package/migrations/20250717162431_migration.ts +1 -1
  56. package/migrations/20250717173228_migration.ts +2 -2
  57. package/migrations/20250717204731_migration.ts +1 -1
  58. package/migrations/20250722210109_migration.ts +8 -4
  59. package/migrations/20250722211019_migration.ts +1 -1
  60. package/migrations/20250723153852_migration.ts +13 -10
  61. package/migrations/20250723162257_migration.ts +4 -7
  62. package/migrations/20250723171109_migration.ts +4 -7
  63. package/migrations/20250723205331_migration.ts +6 -9
  64. package/migrations/20250724191345_migration.ts +8 -11
  65. package/migrations/20250730180932_migration.ts +14 -13
  66. package/migrations/20250730213625_migration.ts +8 -11
  67. package/migrations/20250804124509_migration.ts +26 -21
  68. package/migrations/20250804132053_migration.ts +5 -8
  69. package/migrations/20250804164518_migration.ts +7 -7
  70. package/migrations/20250823223016_migration.ts +32 -21
  71. package/migrations/20250910015452_migration.ts +18 -6
  72. package/migrations/20250911000000_migration.ts +18 -4
  73. package/migrations/20250917144153_migration.ts +14 -7
  74. package/migrations/20250930200521_migration.ts +8 -4
  75. package/migrations/20251010143500_migration.ts +27 -6
  76. package/migrations/20251020225758_migration.ts +51 -15
  77. package/migrations/20251112120000_migration.ts +10 -2
  78. package/migrations/20251112120200_migration.ts +19 -7
  79. package/migrations/20251112120300_migration.ts +7 -2
  80. package/package.json +1 -1
  81. package/src/constants/folder.constants.ts +29 -0
  82. package/src/constants/video.constants.ts +11 -7
  83. package/src/d.types.ts +18 -14
  84. package/src/dao/VideoMinuteResultDAO.ts +72 -49
  85. package/src/dao/auth/auth.dao.ts +58 -55
  86. package/src/dao/batch/batch.dao.ts +101 -98
  87. package/src/dao/camera/camera.dao.ts +124 -121
  88. package/src/dao/chat/chat.dao.ts +45 -45
  89. package/src/dao/folder/folder.dao.ts +112 -55
  90. package/src/dao/location/location.dao.ts +109 -87
  91. package/src/dao/message/message.dao.ts +32 -32
  92. package/src/dao/report-configuration/report-configuration.dao.ts +370 -342
  93. package/src/dao/study/study.dao.ts +88 -63
  94. package/src/dao/user/user.dao.ts +52 -50
  95. package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +80 -48
  96. package/src/dao/video/video.dao.ts +385 -334
  97. package/src/entities/BaseEntity.ts +1 -1
  98. package/src/index.ts +42 -17
  99. package/src/interfaces/auth/auth.interfaces.ts +10 -10
  100. package/src/interfaces/batch/batch.interfaces.ts +1 -1
  101. package/src/interfaces/camera/camera.interfaces.ts +9 -9
  102. package/src/interfaces/chat/chat.interfaces.ts +4 -4
  103. package/src/interfaces/folder/folder.interfaces.ts +2 -2
  104. package/src/interfaces/location/location.interfaces.ts +7 -7
  105. package/src/interfaces/message/message.interfaces.ts +3 -3
  106. package/src/interfaces/report-configuration/report-configuration.interfaces.ts +16 -16
  107. package/src/interfaces/study/study.interfaces.ts +3 -3
  108. package/src/interfaces/user/user.interfaces.ts +9 -9
  109. package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
  110. package/src/interfaces/video/video.interfaces.ts +34 -34
@@ -2,34 +2,45 @@ import type { Knex } from "knex";
2
2
 
3
3
  export async function up(knex: Knex): Promise<void> {
4
4
  // Create video_minute_results table
5
- await knex.schema.createTable('video_minute_results', (table) => {
6
- table.bigIncrements('id').primary();
7
- table.uuid('uuid').defaultTo(knex.raw('gen_random_uuid()')).notNullable().unique();
8
- table.integer('video_id').unsigned().notNullable()
9
- .references('id').inTable('video').onDelete('CASCADE');
10
- table.integer('minute_number').notNullable();
11
- table.jsonb('results').notNullable();
5
+ await knex.schema.createTable("video_minute_results", (table) => {
6
+ table.bigIncrements("id").primary();
7
+ table
8
+ .uuid("uuid")
9
+ .defaultTo(knex.raw("gen_random_uuid()"))
10
+ .notNullable()
11
+ .unique();
12
+ table
13
+ .integer("video_id")
14
+ .unsigned()
15
+ .notNullable()
16
+ .references("id")
17
+ .inTable("video")
18
+ .onDelete("CASCADE");
19
+ table.integer("minute_number").notNullable();
20
+ table.jsonb("results").notNullable();
12
21
  table.timestamps(true, true);
13
-
22
+
14
23
  // Constraints
15
- table.unique(['video_id', 'minute_number'], { indexName: 'unique_video_minute' });
16
- table.check('minute_number >= 0', [], 'valid_minute_number');
17
-
24
+ table.unique(["video_id", "minute_number"], {
25
+ indexName: "unique_video_minute",
26
+ });
27
+ table.check("minute_number >= 0", [], "valid_minute_number");
28
+
18
29
  // Indexes
19
- table.index('video_id', 'idx_video_minute_results_video_id');
20
- table.index('uuid', 'idx_video_minute_results_uuid');
21
- table.index('minute_number', 'idx_video_minute_results_minute_number');
30
+ table.index("video_id", "idx_video_minute_results_video_id");
31
+ table.index("uuid", "idx_video_minute_results_uuid");
32
+ table.index("minute_number", "idx_video_minute_results_minute_number");
22
33
  });
23
-
34
+
24
35
  // Add duration_seconds to video table
25
- await knex.schema.alterTable('video', (table) => {
26
- table.integer('duration_seconds').nullable();
36
+ await knex.schema.alterTable("video", (table) => {
37
+ table.integer("duration_seconds").nullable();
27
38
  });
28
39
  }
29
40
 
30
41
  export async function down(knex: Knex): Promise<void> {
31
- await knex.schema.dropTableIfExists('video_minute_results');
32
- await knex.schema.alterTable('video', (table) => {
33
- table.dropColumn('duration_seconds');
42
+ await knex.schema.dropTableIfExists("video_minute_results");
43
+ await knex.schema.alterTable("video", (table) => {
44
+ table.dropColumn("duration_seconds");
34
45
  });
35
- }
46
+ }
@@ -2,13 +2,26 @@ import type { Knex } from "knex";
2
2
 
3
3
  export async function up(knex: Knex): Promise<void> {
4
4
  await knex.schema.alterTable("video", (table) => {
5
- table.boolean("isHlsEnabled").defaultTo(false).comment("Whether HLS streaming is enabled for this video");
6
- table.text("hlsPlaylist").nullable().comment("S3 path to the HLS master playlist file");
7
- table.decimal("videoSizeMB", 12, 2).nullable().comment("Final processed video size in MB");
5
+ table
6
+ .boolean("isHlsEnabled")
7
+ .defaultTo(false)
8
+ .comment("Whether HLS streaming is enabled for this video");
9
+ table
10
+ .text("hlsPlaylist")
11
+ .nullable()
12
+ .comment("S3 path to the HLS master playlist file");
13
+ table
14
+ .decimal("videoSizeMB", 12, 2)
15
+ .nullable()
16
+ .comment("Final processed video size in MB");
8
17
 
9
- table.json("streamingMetadata").nullable().comment("Additional streaming metadata (quality levels, segment info, etc.)");
18
+ table
19
+ .json("streamingMetadata")
20
+ .nullable()
21
+ .comment(
22
+ "Additional streaming metadata (quality levels, segment info, etc.)",
23
+ );
10
24
  });
11
-
12
25
  }
13
26
 
14
27
  export async function down(knex: Knex): Promise<void> {
@@ -19,4 +32,3 @@ export async function down(knex: Knex): Promise<void> {
19
32
  table.dropColumn("streamingMetadata");
20
33
  });
21
34
  }
22
-
@@ -4,7 +4,11 @@ export async function up(knex: Knex): Promise<void> {
4
4
  // Create cameras table
5
5
  await knex.schema.createTable("cameras", (table) => {
6
6
  table.increments("id").primary();
7
- table.uuid("uuid").defaultTo(knex.raw("uuid_generate_v4()")).notNullable().unique();
7
+ table
8
+ .uuid("uuid")
9
+ .defaultTo(knex.raw("uuid_generate_v4()"))
10
+ .notNullable()
11
+ .unique();
8
12
  table.string("name", 100).notNullable();
9
13
  table.decimal("longitude", 10, 7).notNullable();
10
14
  table.decimal("latitude", 10, 7).notNullable();
@@ -16,13 +20,23 @@ export async function up(knex: Knex): Promise<void> {
16
20
 
17
21
  // Add cameraId to videos table
18
22
  await knex.schema.alterTable("video", (table) => {
19
- table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
23
+ table
24
+ .integer("cameraId")
25
+ .nullable()
26
+ .references("id")
27
+ .inTable("cameras")
28
+ .onDelete("SET NULL");
20
29
  table.index(["cameraId"]);
21
30
  });
22
31
 
23
32
  // Add cameraId to folders table
24
33
  await knex.schema.alterTable("folders", (table) => {
25
- table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
34
+ table
35
+ .integer("cameraId")
36
+ .nullable()
37
+ .references("id")
38
+ .inTable("cameras")
39
+ .onDelete("SET NULL");
26
40
  table.index(["cameraId"]);
27
41
  });
28
42
  }
@@ -44,4 +58,4 @@ export async function down(knex: Knex): Promise<void> {
44
58
 
45
59
  // Drop cameras table
46
60
  await knex.schema.dropTable("cameras");
47
- }
61
+ }
@@ -3,28 +3,35 @@ import type { Knex } from "knex";
3
3
  export async function up(knex: Knex): Promise<void> {
4
4
  await knex.schema.alterTable("video", (table) => {
5
5
  // Add annotationSourceId column with foreign key to video table
6
- table.integer("annotationSourceId")
6
+ table
7
+ .integer("annotationSourceId")
7
8
  .nullable()
8
9
  .references("id")
9
10
  .inTable("video")
10
11
  .onDelete("SET NULL");
11
-
12
+
12
13
  // Add index for performance when querying by annotation source
13
14
  table.index(["annotationSourceId"], "idx_video_annotation_source_id");
14
-
15
+
15
16
  // Add composite index for efficient template lookups
16
- table.index(["folderId", "videoType", "status"], "idx_video_template_lookup");
17
+ table.index(
18
+ ["folderId", "videoType", "status"],
19
+ "idx_video_template_lookup",
20
+ );
17
21
  });
18
22
  }
19
23
 
20
24
  export async function down(knex: Knex): Promise<void> {
21
25
  await knex.schema.alterTable("video", (table) => {
22
26
  // Drop indexes first
23
- table.dropIndex(["folderId", "videoType", "status"], "idx_video_template_lookup");
27
+ table.dropIndex(
28
+ ["folderId", "videoType", "status"],
29
+ "idx_video_template_lookup",
30
+ );
24
31
  table.dropIndex(["annotationSourceId"], "idx_video_annotation_source_id");
25
-
32
+
26
33
  // Drop foreign key and column
27
34
  table.dropForeign(["annotationSourceId"]);
28
35
  table.dropColumn("annotationSourceId");
29
36
  });
30
- }
37
+ }
@@ -4,7 +4,11 @@ export async function up(knex: Knex): Promise<void> {
4
4
  // Create report_configurations table
5
5
  await knex.schema.createTable("report_configurations", (table) => {
6
6
  table.increments("id").primary();
7
- table.uuid("uuid").notNullable().unique().defaultTo(knex.raw("uuid_generate_v4()"));
7
+ table
8
+ .uuid("uuid")
9
+ .notNullable()
10
+ .unique()
11
+ .defaultTo(knex.raw("uuid_generate_v4()"));
8
12
  table.string("name", 30).notNullable().unique();
9
13
  table.text("description");
10
14
  table.jsonb("configuration").notNullable();
@@ -30,9 +34,9 @@ export async function up(knex: Knex): Promise<void> {
30
34
  customClasses: [
31
35
  { name: "Cars", fhwaClasses: [1, 2, 3] },
32
36
  { name: "Medium Trucks", fhwaClasses: [5] },
33
- { name: "Heavy Trucks", fhwaClasses: [4, 6, 7, 8, 9, 10, 11, 12, 13] }
34
- ]
35
- })
37
+ { name: "Heavy Trucks", fhwaClasses: [4, 6, 7, 8, 9, 10, 11, 12, 13] },
38
+ ],
39
+ }),
36
40
  });
37
41
  }
38
42
 
@@ -5,7 +5,12 @@ export async function up(knex: Knex): Promise<void> {
5
5
  const studyHasCamera = await knex.schema.hasColumn("study", "cameraId");
6
6
  if (!studyHasCamera) {
7
7
  await knex.schema.alterTable("study", (table) => {
8
- table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
8
+ table
9
+ .integer("cameraId")
10
+ .nullable()
11
+ .references("id")
12
+ .inTable("cameras")
13
+ .onDelete("SET NULL");
9
14
  table.index(["cameraId"]);
10
15
  });
11
16
  }
@@ -13,7 +18,9 @@ export async function up(knex: Knex): Promise<void> {
13
18
  // 2. Remove cameraId from video table
14
19
  const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
15
20
  if (videoHasCamera) {
16
- await knex.raw(`ALTER TABLE video DROP CONSTRAINT IF EXISTS video_cameraid_foreign`);
21
+ await knex.raw(
22
+ `ALTER TABLE video DROP CONSTRAINT IF EXISTS video_cameraid_foreign`,
23
+ );
17
24
  await knex.raw(`DROP INDEX IF EXISTS video_cameraid_index`);
18
25
  await knex.schema.alterTable("video", (table) => {
19
26
  table.dropColumn("cameraId");
@@ -23,7 +30,9 @@ export async function up(knex: Knex): Promise<void> {
23
30
  // 3. Remove cameraId from folders table
24
31
  const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
25
32
  if (foldersHasCamera) {
26
- await knex.raw(`ALTER TABLE folders DROP CONSTRAINT IF EXISTS folders_cameraid_foreign`);
33
+ await knex.raw(
34
+ `ALTER TABLE folders DROP CONSTRAINT IF EXISTS folders_cameraid_foreign`,
35
+ );
27
36
  await knex.raw(`DROP INDEX IF EXISTS folders_cameraid_index`);
28
37
  await knex.schema.alterTable("folders", (table) => {
29
38
  table.dropColumn("cameraId");
@@ -36,7 +45,12 @@ export async function down(knex: Knex): Promise<void> {
36
45
  const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
37
46
  if (!foldersHasCamera) {
38
47
  await knex.schema.alterTable("folders", (table) => {
39
- table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
48
+ table
49
+ .integer("cameraId")
50
+ .nullable()
51
+ .references("id")
52
+ .inTable("cameras")
53
+ .onDelete("SET NULL");
40
54
  table.index(["cameraId"]);
41
55
  });
42
56
  }
@@ -45,7 +59,12 @@ export async function down(knex: Knex): Promise<void> {
45
59
  const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
46
60
  if (!videoHasCamera) {
47
61
  await knex.schema.alterTable("video", (table) => {
48
- table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
62
+ table
63
+ .integer("cameraId")
64
+ .nullable()
65
+ .references("id")
66
+ .inTable("cameras")
67
+ .onDelete("SET NULL");
49
68
  table.index(["cameraId"]);
50
69
  });
51
70
  }
@@ -53,7 +72,9 @@ export async function down(knex: Knex): Promise<void> {
53
72
  // 3. Remove cameraId from study table
54
73
  const studyHasCamera = await knex.schema.hasColumn("study", "cameraId");
55
74
  if (studyHasCamera) {
56
- await knex.raw(`ALTER TABLE study DROP CONSTRAINT IF EXISTS study_cameraid_foreign`);
75
+ await knex.raw(
76
+ `ALTER TABLE study DROP CONSTRAINT IF EXISTS study_cameraid_foreign`,
77
+ );
57
78
  await knex.raw(`DROP INDEX IF EXISTS study_cameraid_index`);
58
79
  await knex.schema.alterTable("study", (table) => {
59
80
  table.dropColumn("cameraId");
@@ -13,28 +13,49 @@ import type { Knex } from "knex";
13
13
  export async function up(knex: Knex): Promise<void> {
14
14
  // Step 1: Create video_batch table with proper id/uuid pattern
15
15
  await knex.schema.createTable("video_batch", (table) => {
16
- table.increments("id").primary()
16
+ table
17
+ .increments("id")
18
+ .primary()
17
19
  .comment("Primary key for internal foreign key relationships");
18
20
 
19
- table.uuid("uuid").notNullable().unique().defaultTo(knex.raw('uuid_generate_v4()'))
21
+ table
22
+ .uuid("uuid")
23
+ .notNullable()
24
+ .unique()
25
+ .defaultTo(knex.raw("uuid_generate_v4()"))
20
26
  .comment("UUID for external API communication");
21
27
 
22
- table.integer("folderId").unsigned().notNullable()
23
- .references("id").inTable("folders").onDelete("CASCADE")
28
+ table
29
+ .integer("folderId")
30
+ .unsigned()
31
+ .notNullable()
32
+ .references("id")
33
+ .inTable("folders")
34
+ .onDelete("CASCADE")
24
35
  .comment("Foreign key to folders table");
25
36
 
26
- table.enu("status", ["PENDING", "IN_PROGRESS", "COMPLETED", "FAILED"])
37
+ table
38
+ .enu("status", ["PENDING", "IN_PROGRESS", "COMPLETED", "FAILED"])
27
39
  .notNullable()
28
40
  .defaultTo("PENDING")
29
41
  .comment("Status of the batch upload");
30
42
 
31
- table.integer("totalVideos").notNullable().defaultTo(0)
43
+ table
44
+ .integer("totalVideos")
45
+ .notNullable()
46
+ .defaultTo(0)
32
47
  .comment("Total number of videos in batch");
33
48
 
34
- table.integer("completedVideos").notNullable().defaultTo(0)
49
+ table
50
+ .integer("completedVideos")
51
+ .notNullable()
52
+ .defaultTo(0)
35
53
  .comment("Number of successfully created videos");
36
54
 
37
- table.integer("failedVideos").notNullable().defaultTo(0)
55
+ table
56
+ .integer("failedVideos")
57
+ .notNullable()
58
+ .defaultTo(0)
38
59
  .comment("Number of failed videos");
39
60
 
40
61
  table.timestamps(true, true);
@@ -42,17 +63,32 @@ export async function up(knex: Knex): Promise<void> {
42
63
 
43
64
  // Step 2: Add recording time, trimming, and batch columns to video table
44
65
  await knex.schema.alterTable("video", (table) => {
45
- table.timestamp("recordingStartedAt", { useTz: true }).nullable()
66
+ table
67
+ .timestamp("recordingStartedAt", { useTz: true })
68
+ .nullable()
46
69
  .comment("Recording start time in UTC - null for backward compatibility");
47
70
 
48
- table.boolean("trimEnabled").notNullable().defaultTo(false)
71
+ table
72
+ .boolean("trimEnabled")
73
+ .notNullable()
74
+ .defaultTo(false)
49
75
  .comment("Whether video trimming is enabled");
50
76
 
51
- table.jsonb("trimPeriods").nullable()
52
- .comment("Array of trim periods with startTime and endTime in ISO 8601 format");
53
-
54
- table.integer("batchId").unsigned().nullable()
55
- .references("id").inTable("video_batch").withKeyName("fk_video_batch").onDelete("SET NULL")
77
+ table
78
+ .jsonb("trimPeriods")
79
+ .nullable()
80
+ .comment(
81
+ "Array of trim periods with startTime and endTime in ISO 8601 format",
82
+ );
83
+
84
+ table
85
+ .integer("batchId")
86
+ .unsigned()
87
+ .nullable()
88
+ .references("id")
89
+ .inTable("video_batch")
90
+ .withKeyName("fk_video_batch")
91
+ .onDelete("SET NULL")
56
92
  .comment("Foreign key to video_batch table (numerical ID, NOT UUID)");
57
93
  });
58
94
 
@@ -29,7 +29,11 @@ export async function up(knex: Knex): Promise<void> {
29
29
 
30
30
  // 5. Add new foreign key constraint with updated name
31
31
  await knex.schema.alterTable("study", (table) => {
32
- table.foreign("locationId").references("id").inTable("locations").onDelete("SET NULL");
32
+ table
33
+ .foreign("locationId")
34
+ .references("id")
35
+ .inTable("locations")
36
+ .onDelete("SET NULL");
33
37
  });
34
38
 
35
39
  // 6. Drop old index if it exists
@@ -62,7 +66,11 @@ export async function down(knex: Knex): Promise<void> {
62
66
 
63
67
  // 4. Restore original foreign key constraint
64
68
  await knex.schema.alterTable("study", (table) => {
65
- table.foreign("cameraId").references("id").inTable("locations").onDelete("SET NULL");
69
+ table
70
+ .foreign("cameraId")
71
+ .references("id")
72
+ .inTable("locations")
73
+ .onDelete("SET NULL");
66
74
  });
67
75
 
68
76
  // 5. Restore original index
@@ -9,15 +9,27 @@ import { Knex } from "knex";
9
9
  export async function up(knex: Knex): Promise<void> {
10
10
  await knex.schema.createTable("cameras", (table) => {
11
11
  table.increments("id").primary();
12
- table.uuid("uuid").defaultTo(knex.raw("uuid_generate_v4()")).unique().notNullable();
13
- table.integer("locationId").unsigned().notNullable()
14
- .references("id").inTable("locations").onDelete("CASCADE");
12
+ table
13
+ .uuid("uuid")
14
+ .defaultTo(knex.raw("uuid_generate_v4()"))
15
+ .unique()
16
+ .notNullable();
17
+ table
18
+ .integer("locationId")
19
+ .unsigned()
20
+ .notNullable()
21
+ .references("id")
22
+ .inTable("locations")
23
+ .onDelete("CASCADE");
15
24
  table.string("name", 100).notNullable();
16
25
  table.text("description").nullable();
17
- table.enu("status", ["ACTIVE", "INACTIVE", "MAINTENANCE"], {
18
- useNative: true,
19
- enumName: "camera_status_enum"
20
- }).defaultTo("ACTIVE").notNullable();
26
+ table
27
+ .enu("status", ["ACTIVE", "INACTIVE", "MAINTENANCE"], {
28
+ useNative: true,
29
+ enumName: "camera_status_enum",
30
+ })
31
+ .defaultTo("ACTIVE")
32
+ .notNullable();
21
33
  table.jsonb("metadata").defaultTo("{}").notNullable();
22
34
  table.timestamps(true, true);
23
35
 
@@ -8,8 +8,13 @@ import { Knex } from "knex";
8
8
  */
9
9
  export async function up(knex: Knex): Promise<void> {
10
10
  await knex.schema.alterTable("video", (table) => {
11
- table.integer("cameraId").unsigned().nullable()
12
- .references("id").inTable("cameras").onDelete("SET NULL");
11
+ table
12
+ .integer("cameraId")
13
+ .unsigned()
14
+ .nullable()
15
+ .references("id")
16
+ .inTable("cameras")
17
+ .onDelete("SET NULL");
13
18
  table.index(["cameraId"], "video_cameraid_index");
14
19
  });
15
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trafficgroup/knex-rel",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Knex Module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Folder sorting and filtering constants
3
+ * Shared between DAO and API controller to ensure validation consistency
4
+ */
5
+
6
+ export const VALID_FOLDER_SORT_FIELDS = [
7
+ "created_at",
8
+ "name",
9
+ "status",
10
+ "updated_at",
11
+ ] as const;
12
+ export type FolderSortField = (typeof VALID_FOLDER_SORT_FIELDS)[number];
13
+
14
+ export const VALID_FOLDER_STATUSES = [
15
+ "UPLOADING",
16
+ "COMPLETED",
17
+ "FAILED",
18
+ ] as const;
19
+ export type FolderStatus = (typeof VALID_FOLDER_STATUSES)[number];
20
+
21
+ /**
22
+ * Maps API sort field names to database column names with table aliases
23
+ */
24
+ export const FOLDER_SORT_COLUMN_MAP: Record<FolderSortField, string> = {
25
+ created_at: "f.created_at",
26
+ name: "f.name",
27
+ status: "f.status",
28
+ updated_at: "f.updated_at",
29
+ };
@@ -3,17 +3,21 @@
3
3
  * Shared between DAO and API controller to ensure validation consistency
4
4
  */
5
5
 
6
- export const VALID_VIDEO_SORT_FIELDS = ['created_at', 'name', 'status'] as const;
7
- export type VideoSortField = typeof VALID_VIDEO_SORT_FIELDS[number];
6
+ export const VALID_VIDEO_SORT_FIELDS = [
7
+ "created_at",
8
+ "name",
9
+ "status",
10
+ ] as const;
11
+ export type VideoSortField = (typeof VALID_VIDEO_SORT_FIELDS)[number];
8
12
 
9
- export const VALID_SORT_ORDERS = ['ASC', 'DESC'] as const;
10
- export type SortOrder = typeof VALID_SORT_ORDERS[number];
13
+ export const VALID_SORT_ORDERS = ["ASC", "DESC"] as const;
14
+ export type SortOrder = (typeof VALID_SORT_ORDERS)[number];
11
15
 
12
16
  /**
13
17
  * Maps API sort field names to database column names with table aliases
14
18
  */
15
19
  export const VIDEO_SORT_COLUMN_MAP: Record<VideoSortField, string> = {
16
- 'created_at': 'v.created_at',
17
- 'name': 'v.name',
18
- 'status': 'v.status'
20
+ created_at: "v.created_at",
21
+ name: "v.name",
22
+ status: "v.status",
19
23
  };
package/src/d.types.ts CHANGED
@@ -1,18 +1,22 @@
1
1
  export interface IDataPaginator<T> {
2
- success: boolean;
3
- data: T[];
4
- page: number;
5
- limit: number;
6
- count: number;
7
- totalCount: number;
8
- totalPages: number;
2
+ success: boolean;
3
+ data: T[];
4
+ page: number;
5
+ limit: number;
6
+ count: number;
7
+ totalCount: number;
8
+ totalPages: number;
9
9
  }
10
10
 
11
11
  export interface IBaseDAO<T> {
12
- create(item: T): Promise<T>;
13
- getById(id: number): Promise<T | null>;
14
- getByUuid(uuid: string): Promise<T | null>;
15
- getAll(page: number, limit: number, entityId?: any | null): Promise<IDataPaginator<T>>;
16
- update(id: number, item: T): Promise<T | null>;
17
- delete(id: number): Promise<boolean>;
18
- }
12
+ create(item: T): Promise<T>;
13
+ getById(id: number): Promise<T | null>;
14
+ getByUuid(uuid: string): Promise<T | null>;
15
+ getAll(
16
+ page: number,
17
+ limit: number,
18
+ entityId?: any | null,
19
+ ): Promise<IDataPaginator<T>>;
20
+ update(id: number, item: T): Promise<T | null>;
21
+ delete(id: number): Promise<boolean>;
22
+ }