@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.
- package/.claude/settings.local.json +2 -5
- package/CLAUDE.md +11 -2
- package/dist/constants/folder.constants.d.ts +12 -0
- package/dist/constants/folder.constants.js +28 -0
- package/dist/constants/folder.constants.js.map +1 -0
- package/dist/constants/video.constants.d.ts +2 -2
- package/dist/constants/video.constants.js +9 -5
- package/dist/constants/video.constants.js.map +1 -1
- package/dist/dao/VideoMinuteResultDAO.d.ts +1 -1
- package/dist/dao/VideoMinuteResultDAO.js +29 -23
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -1
- package/dist/dao/auth/auth.dao.js +4 -1
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/batch/batch.dao.js +13 -14
- package/dist/dao/batch/batch.dao.js.map +1 -1
- package/dist/dao/camera/camera.dao.js +10 -7
- package/dist/dao/camera/camera.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +1 -1
- package/dist/dao/chat/chat.dao.js +27 -40
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.d.ts +10 -1
- package/dist/dao/folder/folder.dao.js +44 -6
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/location/location.dao.js +16 -9
- package/dist/dao/location/location.dao.js.map +1 -1
- package/dist/dao/message/message.dao.d.ts +1 -1
- package/dist/dao/message/message.dao.js +18 -26
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/report-configuration/report-configuration.dao.js +32 -31
- package/dist/dao/report-configuration/report-configuration.dao.js.map +1 -1
- package/dist/dao/study/study.dao.js +7 -2
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/user/user.dao.js +4 -1
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.js +30 -28
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/batch/batch.interfaces.d.ts +1 -1
- package/dist/interfaces/camera/camera.interfaces.d.ts +1 -1
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/study/study.interfaces.d.ts +2 -2
- package/dist/interfaces/user/user.interfaces.d.ts +1 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
- package/dist/interfaces/video/video.interfaces.d.ts +2 -2
- package/migrations/20250717160737_migration.ts +1 -1
- package/migrations/20250717160908_migration.ts +5 -2
- package/migrations/20250717161310_migration.ts +1 -1
- package/migrations/20250717161406_migration.ts +3 -3
- package/migrations/20250717162431_migration.ts +1 -1
- package/migrations/20250717173228_migration.ts +2 -2
- package/migrations/20250717204731_migration.ts +1 -1
- package/migrations/20250722210109_migration.ts +8 -4
- package/migrations/20250722211019_migration.ts +1 -1
- package/migrations/20250723153852_migration.ts +13 -10
- package/migrations/20250723162257_migration.ts +4 -7
- package/migrations/20250723171109_migration.ts +4 -7
- package/migrations/20250723205331_migration.ts +6 -9
- package/migrations/20250724191345_migration.ts +8 -11
- package/migrations/20250730180932_migration.ts +14 -13
- package/migrations/20250730213625_migration.ts +8 -11
- package/migrations/20250804124509_migration.ts +26 -21
- package/migrations/20250804132053_migration.ts +5 -8
- package/migrations/20250804164518_migration.ts +7 -7
- package/migrations/20250823223016_migration.ts +32 -21
- package/migrations/20250910015452_migration.ts +18 -6
- package/migrations/20250911000000_migration.ts +18 -4
- package/migrations/20250917144153_migration.ts +14 -7
- package/migrations/20250930200521_migration.ts +8 -4
- package/migrations/20251010143500_migration.ts +27 -6
- package/migrations/20251020225758_migration.ts +51 -15
- package/migrations/20251112120000_migration.ts +10 -2
- package/migrations/20251112120200_migration.ts +19 -7
- package/migrations/20251112120300_migration.ts +7 -2
- package/package.json +1 -1
- package/src/constants/folder.constants.ts +29 -0
- package/src/constants/video.constants.ts +11 -7
- package/src/d.types.ts +18 -14
- package/src/dao/VideoMinuteResultDAO.ts +72 -49
- package/src/dao/auth/auth.dao.ts +58 -55
- package/src/dao/batch/batch.dao.ts +101 -98
- package/src/dao/camera/camera.dao.ts +124 -121
- package/src/dao/chat/chat.dao.ts +45 -45
- package/src/dao/folder/folder.dao.ts +112 -55
- package/src/dao/location/location.dao.ts +109 -87
- package/src/dao/message/message.dao.ts +32 -32
- package/src/dao/report-configuration/report-configuration.dao.ts +370 -342
- package/src/dao/study/study.dao.ts +88 -63
- package/src/dao/user/user.dao.ts +52 -50
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +80 -48
- package/src/dao/video/video.dao.ts +385 -334
- package/src/entities/BaseEntity.ts +1 -1
- package/src/index.ts +42 -17
- package/src/interfaces/auth/auth.interfaces.ts +10 -10
- package/src/interfaces/batch/batch.interfaces.ts +1 -1
- package/src/interfaces/camera/camera.interfaces.ts +9 -9
- package/src/interfaces/chat/chat.interfaces.ts +4 -4
- package/src/interfaces/folder/folder.interfaces.ts +2 -2
- package/src/interfaces/location/location.interfaces.ts +7 -7
- package/src/interfaces/message/message.interfaces.ts +3 -3
- package/src/interfaces/report-configuration/report-configuration.interfaces.ts +16 -16
- package/src/interfaces/study/study.interfaces.ts +3 -3
- package/src/interfaces/user/user.interfaces.ts +9 -9
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
- 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(
|
|
6
|
-
table.bigIncrements(
|
|
7
|
-
table
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
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([
|
|
16
|
-
|
|
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(
|
|
20
|
-
table.index(
|
|
21
|
-
table.index(
|
|
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(
|
|
26
|
-
table.integer(
|
|
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(
|
|
32
|
-
await knex.schema.alterTable(
|
|
33
|
-
table.dropColumn(
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
16
|
+
table
|
|
17
|
+
.increments("id")
|
|
18
|
+
.primary()
|
|
17
19
|
.comment("Primary key for internal foreign key relationships");
|
|
18
20
|
|
|
19
|
-
table
|
|
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
|
|
23
|
-
.
|
|
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
|
|
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
|
|
43
|
+
table
|
|
44
|
+
.integer("totalVideos")
|
|
45
|
+
.notNullable()
|
|
46
|
+
.defaultTo(0)
|
|
32
47
|
.comment("Total number of videos in batch");
|
|
33
48
|
|
|
34
|
-
table
|
|
49
|
+
table
|
|
50
|
+
.integer("completedVideos")
|
|
51
|
+
.notNullable()
|
|
52
|
+
.defaultTo(0)
|
|
35
53
|
.comment("Number of successfully created videos");
|
|
36
54
|
|
|
37
|
-
table
|
|
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
|
|
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
|
|
71
|
+
table
|
|
72
|
+
.boolean("trimEnabled")
|
|
73
|
+
.notNullable()
|
|
74
|
+
.defaultTo(false)
|
|
49
75
|
.comment("Whether video trimming is enabled");
|
|
50
76
|
|
|
51
|
-
table
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
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
|
|
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
|
|
13
|
-
|
|
14
|
-
.
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
12
|
-
.
|
|
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
|
@@ -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 = [
|
|
7
|
-
|
|
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 = [
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|