@trafficgroup/knex-rel 0.1.9 → 0.1.11-rc0
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 +5 -2
- package/CLAUDE.md +2 -11
- package/dist/constants/video.constants.d.ts +12 -0
- package/dist/constants/video.constants.js +22 -0
- package/dist/constants/video.constants.js.map +1 -0
- package/dist/dao/chat/chat.dao.d.ts +4 -1
- package/dist/dao/chat/chat.dao.js +21 -12
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.d.ts +2 -1
- package/dist/dao/video/video.dao.js +18 -2
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/migrations/20250717160737_migration.ts +1 -1
- package/migrations/20250717160908_migration.ts +2 -5
- 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 +4 -8
- package/migrations/20250722211019_migration.ts +1 -1
- package/migrations/20250723153852_migration.ts +10 -13
- package/migrations/20250723162257_migration.ts +7 -4
- package/migrations/20250723171109_migration.ts +7 -4
- package/migrations/20250723205331_migration.ts +9 -6
- package/migrations/20250724191345_migration.ts +11 -8
- package/migrations/20250730180932_migration.ts +13 -14
- package/migrations/20250730213625_migration.ts +11 -8
- package/migrations/20250804124509_migration.ts +21 -26
- package/migrations/20250804132053_migration.ts +8 -5
- package/migrations/20250804164518_migration.ts +7 -7
- package/migrations/20250823223016_migration.ts +21 -32
- package/migrations/20250910015452_migration.ts +6 -18
- package/migrations/20250911000000_migration.ts +4 -18
- package/migrations/20250917144153_migration.ts +7 -14
- package/migrations/20250930200521_migration.ts +4 -8
- package/migrations/20251010143500_migration.ts +6 -27
- package/migrations/20251020225758_migration.ts +15 -51
- package/migrations/20251112120000_migration.ts +2 -10
- package/migrations/20251112120200_migration.ts +7 -19
- package/migrations/20251112120300_migration.ts +2 -7
- package/package.json +1 -1
- package/src/constants/video.constants.ts +19 -0
- package/src/d.types.ts +14 -18
- package/src/dao/VideoMinuteResultDAO.ts +49 -72
- package/src/dao/auth/auth.dao.ts +55 -58
- package/src/dao/batch/batch.dao.ts +98 -101
- package/src/dao/camera/camera.dao.ts +121 -124
- package/src/dao/chat/chat.dao.ts +60 -42
- package/src/dao/folder/folder.dao.ts +56 -65
- package/src/dao/location/location.dao.ts +87 -109
- package/src/dao/message/message.dao.ts +32 -32
- package/src/dao/report-configuration/report-configuration.dao.ts +342 -370
- package/src/dao/study/study.dao.ts +63 -88
- package/src/dao/user/user.dao.ts +50 -52
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +49 -83
- package/src/dao/video/video.dao.ts +339 -357
- package/src/entities/BaseEntity.ts +1 -1
- package/src/index.ts +23 -27
- 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
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
export async function up(knex: Knex): Promise<void> {
|
|
4
|
-
return knex.schema.createTable(
|
|
5
|
-
table.increments(
|
|
6
|
-
table.integer(
|
|
7
|
-
table.string(
|
|
8
|
-
table.boolean(
|
|
5
|
+
return knex.schema.createTable('user_push_notification_token', (table) => {
|
|
6
|
+
table.increments('id').primary();
|
|
7
|
+
table.integer('userId').unsigned().notNullable();
|
|
8
|
+
table.string('token').notNullable();
|
|
9
|
+
table.boolean('available').defaultTo(true);
|
|
9
10
|
table.timestamps(true, true);
|
|
10
|
-
|
|
11
|
-
table
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.inTable("users")
|
|
15
|
-
.onDelete("CASCADE");
|
|
16
|
-
table.index(["userId"]);
|
|
17
|
-
table.index(["token"]);
|
|
11
|
+
|
|
12
|
+
table.foreign('userId').references('id').inTable('users').onDelete('CASCADE');
|
|
13
|
+
table.index(['userId']);
|
|
14
|
+
table.index(['token']);
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
17
|
|
|
18
|
+
|
|
21
19
|
export async function down(knex: Knex): Promise<void> {
|
|
22
|
-
return knex.schema.dropTable(
|
|
20
|
+
return knex.schema.dropTable('user_push_notification_token');
|
|
23
21
|
}
|
|
22
|
+
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
export async function up(knex: Knex): Promise<void> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
await knex.schema.alterTable('user_push_notification_token', (table) => {
|
|
6
|
+
table.string('token_type').defaultTo('expo').notNullable();
|
|
7
|
+
table.string('device_type');
|
|
8
|
+
});
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
export async function down(knex: Knex): Promise<void> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
await knex.schema.alterTable('user_push_notification_token', (table) => {
|
|
14
|
+
table.dropColumn('token_type');
|
|
15
|
+
table.dropColumn('device_type');
|
|
16
|
+
});
|
|
15
17
|
}
|
|
18
|
+
|
|
@@ -1,48 +1,43 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
export async function up(knex: Knex): Promise<void> {
|
|
4
5
|
// Create chat table
|
|
5
|
-
await knex.schema.createTable(
|
|
6
|
-
table.increments(
|
|
7
|
-
table.integer(
|
|
8
|
-
table.string(
|
|
9
|
-
table.enum(
|
|
6
|
+
await knex.schema.createTable('chat', (table) => {
|
|
7
|
+
table.increments('id').primary();
|
|
8
|
+
table.integer('userId').unsigned().notNullable();
|
|
9
|
+
table.string('title', 255).notNullable();
|
|
10
|
+
table.enum('status', ['active', 'archived']).defaultTo('active');
|
|
10
11
|
table.timestamps(true, true);
|
|
11
12
|
|
|
12
13
|
// Foreign key
|
|
13
|
-
table
|
|
14
|
-
.foreign("userId")
|
|
15
|
-
.references("id")
|
|
16
|
-
.inTable("users")
|
|
17
|
-
.onDelete("CASCADE");
|
|
14
|
+
table.foreign('userId').references('id').inTable('users').onDelete('CASCADE');
|
|
18
15
|
|
|
19
16
|
// Indexes
|
|
20
|
-
table.index(
|
|
21
|
-
table.index(
|
|
17
|
+
table.index('userId');
|
|
18
|
+
table.index('status');
|
|
22
19
|
});
|
|
23
20
|
|
|
24
21
|
// Create message table
|
|
25
|
-
await knex.schema.createTable(
|
|
26
|
-
table.increments(
|
|
27
|
-
table.integer(
|
|
28
|
-
table.enum(
|
|
29
|
-
table.text(
|
|
22
|
+
await knex.schema.createTable('message', (table) => {
|
|
23
|
+
table.increments('id').primary();
|
|
24
|
+
table.integer('chatId').unsigned().notNullable();
|
|
25
|
+
table.enum('role', ['user', 'assistant']).notNullable();
|
|
26
|
+
table.text('content').notNullable();
|
|
30
27
|
table.timestamps(true, true);
|
|
31
28
|
|
|
32
29
|
// Foreign key
|
|
33
|
-
table
|
|
34
|
-
.foreign("chatId")
|
|
35
|
-
.references("id")
|
|
36
|
-
.inTable("chat")
|
|
37
|
-
.onDelete("CASCADE");
|
|
30
|
+
table.foreign('chatId').references('id').inTable('chat').onDelete('CASCADE');
|
|
38
31
|
|
|
39
32
|
// Indexes
|
|
40
|
-
table.index(
|
|
41
|
-
table.index(
|
|
33
|
+
table.index('chatId');
|
|
34
|
+
table.index('created_at');
|
|
42
35
|
});
|
|
43
36
|
}
|
|
44
37
|
|
|
38
|
+
|
|
45
39
|
export async function down(knex: Knex): Promise<void> {
|
|
46
|
-
await knex.schema.dropTableIfExists(
|
|
47
|
-
await knex.schema.dropTableIfExists(
|
|
40
|
+
await knex.schema.dropTableIfExists('message');
|
|
41
|
+
await knex.schema.dropTableIfExists('chat');
|
|
48
42
|
}
|
|
43
|
+
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
export async function up(knex: Knex): Promise<void> {
|
|
4
5
|
// Add uuid column to chat table
|
|
5
|
-
await knex.schema.alterTable(
|
|
6
|
-
table.uuid(
|
|
7
|
-
table.index(
|
|
6
|
+
await knex.schema.alterTable('chat', (table) => {
|
|
7
|
+
table.uuid('uuid').defaultTo(knex.raw('gen_random_uuid()')).notNullable();
|
|
8
|
+
table.index('uuid');
|
|
8
9
|
});
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
|
|
11
13
|
export async function down(knex: Knex): Promise<void> {
|
|
12
|
-
await knex.schema.alterTable(
|
|
13
|
-
table.dropColumn(
|
|
14
|
+
await knex.schema.alterTable('chat', (table) => {
|
|
15
|
+
table.dropColumn('uuid');
|
|
14
16
|
});
|
|
15
17
|
}
|
|
18
|
+
|
|
@@ -2,16 +2,16 @@ import type { Knex } from "knex";
|
|
|
2
2
|
|
|
3
3
|
export async function up(knex: Knex): Promise<void> {
|
|
4
4
|
// Add description and type columns to study table
|
|
5
|
-
await knex.schema.alterTable(
|
|
6
|
-
table.text(
|
|
7
|
-
table.string(
|
|
5
|
+
await knex.schema.alterTable('study', (table) => {
|
|
6
|
+
table.text('description').nullable();
|
|
7
|
+
table.string('type', 50).notNullable().defaultTo('TMC');
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export async function down(knex: Knex): Promise<void> {
|
|
12
12
|
// Remove description and type columns from study table
|
|
13
|
-
await knex.schema.alterTable(
|
|
14
|
-
table.dropColumn(
|
|
15
|
-
table.dropColumn(
|
|
13
|
+
await knex.schema.alterTable('study', (table) => {
|
|
14
|
+
table.dropColumn('description');
|
|
15
|
+
table.dropColumn('type');
|
|
16
16
|
});
|
|
17
|
-
}
|
|
17
|
+
}
|
|
@@ -2,45 +2,34 @@ 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
|
-
|
|
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();
|
|
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();
|
|
21
12
|
table.timestamps(true, true);
|
|
22
|
-
|
|
13
|
+
|
|
23
14
|
// Constraints
|
|
24
|
-
table.unique([
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
table.check("minute_number >= 0", [], "valid_minute_number");
|
|
28
|
-
|
|
15
|
+
table.unique(['video_id', 'minute_number'], { indexName: 'unique_video_minute' });
|
|
16
|
+
table.check('minute_number >= 0', [], 'valid_minute_number');
|
|
17
|
+
|
|
29
18
|
// Indexes
|
|
30
|
-
table.index(
|
|
31
|
-
table.index(
|
|
32
|
-
table.index(
|
|
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');
|
|
33
22
|
});
|
|
34
|
-
|
|
23
|
+
|
|
35
24
|
// Add duration_seconds to video table
|
|
36
|
-
await knex.schema.alterTable(
|
|
37
|
-
table.integer(
|
|
25
|
+
await knex.schema.alterTable('video', (table) => {
|
|
26
|
+
table.integer('duration_seconds').nullable();
|
|
38
27
|
});
|
|
39
28
|
}
|
|
40
29
|
|
|
41
30
|
export async function down(knex: Knex): Promise<void> {
|
|
42
|
-
await knex.schema.dropTableIfExists(
|
|
43
|
-
await knex.schema.alterTable(
|
|
44
|
-
table.dropColumn(
|
|
31
|
+
await knex.schema.dropTableIfExists('video_minute_results');
|
|
32
|
+
await knex.schema.alterTable('video', (table) => {
|
|
33
|
+
table.dropColumn('duration_seconds');
|
|
45
34
|
});
|
|
46
|
-
}
|
|
35
|
+
}
|
|
@@ -2,26 +2,13 @@ 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
|
-
|
|
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");
|
|
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");
|
|
17
8
|
|
|
18
|
-
table
|
|
19
|
-
.json("streamingMetadata")
|
|
20
|
-
.nullable()
|
|
21
|
-
.comment(
|
|
22
|
-
"Additional streaming metadata (quality levels, segment info, etc.)",
|
|
23
|
-
);
|
|
9
|
+
table.json("streamingMetadata").nullable().comment("Additional streaming metadata (quality levels, segment info, etc.)");
|
|
24
10
|
});
|
|
11
|
+
|
|
25
12
|
}
|
|
26
13
|
|
|
27
14
|
export async function down(knex: Knex): Promise<void> {
|
|
@@ -32,3 +19,4 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
32
19
|
table.dropColumn("streamingMetadata");
|
|
33
20
|
});
|
|
34
21
|
}
|
|
22
|
+
|
|
@@ -4,11 +4,7 @@ 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
|
|
8
|
-
.uuid("uuid")
|
|
9
|
-
.defaultTo(knex.raw("uuid_generate_v4()"))
|
|
10
|
-
.notNullable()
|
|
11
|
-
.unique();
|
|
7
|
+
table.uuid("uuid").defaultTo(knex.raw("uuid_generate_v4()")).notNullable().unique();
|
|
12
8
|
table.string("name", 100).notNullable();
|
|
13
9
|
table.decimal("longitude", 10, 7).notNullable();
|
|
14
10
|
table.decimal("latitude", 10, 7).notNullable();
|
|
@@ -20,23 +16,13 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
20
16
|
|
|
21
17
|
// Add cameraId to videos table
|
|
22
18
|
await knex.schema.alterTable("video", (table) => {
|
|
23
|
-
table
|
|
24
|
-
.integer("cameraId")
|
|
25
|
-
.nullable()
|
|
26
|
-
.references("id")
|
|
27
|
-
.inTable("cameras")
|
|
28
|
-
.onDelete("SET NULL");
|
|
19
|
+
table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
|
|
29
20
|
table.index(["cameraId"]);
|
|
30
21
|
});
|
|
31
22
|
|
|
32
23
|
// Add cameraId to folders table
|
|
33
24
|
await knex.schema.alterTable("folders", (table) => {
|
|
34
|
-
table
|
|
35
|
-
.integer("cameraId")
|
|
36
|
-
.nullable()
|
|
37
|
-
.references("id")
|
|
38
|
-
.inTable("cameras")
|
|
39
|
-
.onDelete("SET NULL");
|
|
25
|
+
table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
|
|
40
26
|
table.index(["cameraId"]);
|
|
41
27
|
});
|
|
42
28
|
}
|
|
@@ -58,4 +44,4 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
58
44
|
|
|
59
45
|
// Drop cameras table
|
|
60
46
|
await knex.schema.dropTable("cameras");
|
|
61
|
-
}
|
|
47
|
+
}
|
|
@@ -3,35 +3,28 @@ 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
|
|
7
|
-
.integer("annotationSourceId")
|
|
6
|
+
table.integer("annotationSourceId")
|
|
8
7
|
.nullable()
|
|
9
8
|
.references("id")
|
|
10
9
|
.inTable("video")
|
|
11
10
|
.onDelete("SET NULL");
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
// Add index for performance when querying by annotation source
|
|
14
13
|
table.index(["annotationSourceId"], "idx_video_annotation_source_id");
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
// Add composite index for efficient template lookups
|
|
17
|
-
table.index(
|
|
18
|
-
["folderId", "videoType", "status"],
|
|
19
|
-
"idx_video_template_lookup",
|
|
20
|
-
);
|
|
16
|
+
table.index(["folderId", "videoType", "status"], "idx_video_template_lookup");
|
|
21
17
|
});
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
export async function down(knex: Knex): Promise<void> {
|
|
25
21
|
await knex.schema.alterTable("video", (table) => {
|
|
26
22
|
// Drop indexes first
|
|
27
|
-
table.dropIndex(
|
|
28
|
-
["folderId", "videoType", "status"],
|
|
29
|
-
"idx_video_template_lookup",
|
|
30
|
-
);
|
|
23
|
+
table.dropIndex(["folderId", "videoType", "status"], "idx_video_template_lookup");
|
|
31
24
|
table.dropIndex(["annotationSourceId"], "idx_video_annotation_source_id");
|
|
32
|
-
|
|
25
|
+
|
|
33
26
|
// Drop foreign key and column
|
|
34
27
|
table.dropForeign(["annotationSourceId"]);
|
|
35
28
|
table.dropColumn("annotationSourceId");
|
|
36
29
|
});
|
|
37
|
-
}
|
|
30
|
+
}
|
|
@@ -4,11 +4,7 @@ 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
|
|
8
|
-
.uuid("uuid")
|
|
9
|
-
.notNullable()
|
|
10
|
-
.unique()
|
|
11
|
-
.defaultTo(knex.raw("uuid_generate_v4()"));
|
|
7
|
+
table.uuid("uuid").notNullable().unique().defaultTo(knex.raw("uuid_generate_v4()"));
|
|
12
8
|
table.string("name", 30).notNullable().unique();
|
|
13
9
|
table.text("description");
|
|
14
10
|
table.jsonb("configuration").notNullable();
|
|
@@ -34,9 +30,9 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
34
30
|
customClasses: [
|
|
35
31
|
{ name: "Cars", fhwaClasses: [1, 2, 3] },
|
|
36
32
|
{ name: "Medium Trucks", fhwaClasses: [5] },
|
|
37
|
-
{ name: "Heavy Trucks", fhwaClasses: [4, 6, 7, 8, 9, 10, 11, 12, 13] }
|
|
38
|
-
]
|
|
39
|
-
})
|
|
33
|
+
{ name: "Heavy Trucks", fhwaClasses: [4, 6, 7, 8, 9, 10, 11, 12, 13] }
|
|
34
|
+
]
|
|
35
|
+
})
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
38
|
|
|
@@ -5,12 +5,7 @@ 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
|
|
9
|
-
.integer("cameraId")
|
|
10
|
-
.nullable()
|
|
11
|
-
.references("id")
|
|
12
|
-
.inTable("cameras")
|
|
13
|
-
.onDelete("SET NULL");
|
|
8
|
+
table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
|
|
14
9
|
table.index(["cameraId"]);
|
|
15
10
|
});
|
|
16
11
|
}
|
|
@@ -18,9 +13,7 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
18
13
|
// 2. Remove cameraId from video table
|
|
19
14
|
const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
|
|
20
15
|
if (videoHasCamera) {
|
|
21
|
-
await knex.raw(
|
|
22
|
-
`ALTER TABLE video DROP CONSTRAINT IF EXISTS video_cameraid_foreign`,
|
|
23
|
-
);
|
|
16
|
+
await knex.raw(`ALTER TABLE video DROP CONSTRAINT IF EXISTS video_cameraid_foreign`);
|
|
24
17
|
await knex.raw(`DROP INDEX IF EXISTS video_cameraid_index`);
|
|
25
18
|
await knex.schema.alterTable("video", (table) => {
|
|
26
19
|
table.dropColumn("cameraId");
|
|
@@ -30,9 +23,7 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
30
23
|
// 3. Remove cameraId from folders table
|
|
31
24
|
const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
|
|
32
25
|
if (foldersHasCamera) {
|
|
33
|
-
await knex.raw(
|
|
34
|
-
`ALTER TABLE folders DROP CONSTRAINT IF EXISTS folders_cameraid_foreign`,
|
|
35
|
-
);
|
|
26
|
+
await knex.raw(`ALTER TABLE folders DROP CONSTRAINT IF EXISTS folders_cameraid_foreign`);
|
|
36
27
|
await knex.raw(`DROP INDEX IF EXISTS folders_cameraid_index`);
|
|
37
28
|
await knex.schema.alterTable("folders", (table) => {
|
|
38
29
|
table.dropColumn("cameraId");
|
|
@@ -45,12 +36,7 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
45
36
|
const foldersHasCamera = await knex.schema.hasColumn("folders", "cameraId");
|
|
46
37
|
if (!foldersHasCamera) {
|
|
47
38
|
await knex.schema.alterTable("folders", (table) => {
|
|
48
|
-
table
|
|
49
|
-
.integer("cameraId")
|
|
50
|
-
.nullable()
|
|
51
|
-
.references("id")
|
|
52
|
-
.inTable("cameras")
|
|
53
|
-
.onDelete("SET NULL");
|
|
39
|
+
table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
|
|
54
40
|
table.index(["cameraId"]);
|
|
55
41
|
});
|
|
56
42
|
}
|
|
@@ -59,12 +45,7 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
59
45
|
const videoHasCamera = await knex.schema.hasColumn("video", "cameraId");
|
|
60
46
|
if (!videoHasCamera) {
|
|
61
47
|
await knex.schema.alterTable("video", (table) => {
|
|
62
|
-
table
|
|
63
|
-
.integer("cameraId")
|
|
64
|
-
.nullable()
|
|
65
|
-
.references("id")
|
|
66
|
-
.inTable("cameras")
|
|
67
|
-
.onDelete("SET NULL");
|
|
48
|
+
table.integer("cameraId").nullable().references("id").inTable("cameras").onDelete("SET NULL");
|
|
68
49
|
table.index(["cameraId"]);
|
|
69
50
|
});
|
|
70
51
|
}
|
|
@@ -72,9 +53,7 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
72
53
|
// 3. Remove cameraId from study table
|
|
73
54
|
const studyHasCamera = await knex.schema.hasColumn("study", "cameraId");
|
|
74
55
|
if (studyHasCamera) {
|
|
75
|
-
await knex.raw(
|
|
76
|
-
`ALTER TABLE study DROP CONSTRAINT IF EXISTS study_cameraid_foreign`,
|
|
77
|
-
);
|
|
56
|
+
await knex.raw(`ALTER TABLE study DROP CONSTRAINT IF EXISTS study_cameraid_foreign`);
|
|
78
57
|
await knex.raw(`DROP INDEX IF EXISTS study_cameraid_index`);
|
|
79
58
|
await knex.schema.alterTable("study", (table) => {
|
|
80
59
|
table.dropColumn("cameraId");
|
|
@@ -13,49 +13,28 @@ 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
|
|
17
|
-
.increments("id")
|
|
18
|
-
.primary()
|
|
16
|
+
table.increments("id").primary()
|
|
19
17
|
.comment("Primary key for internal foreign key relationships");
|
|
20
18
|
|
|
21
|
-
table
|
|
22
|
-
.uuid("uuid")
|
|
23
|
-
.notNullable()
|
|
24
|
-
.unique()
|
|
25
|
-
.defaultTo(knex.raw("uuid_generate_v4()"))
|
|
19
|
+
table.uuid("uuid").notNullable().unique().defaultTo(knex.raw('uuid_generate_v4()'))
|
|
26
20
|
.comment("UUID for external API communication");
|
|
27
21
|
|
|
28
|
-
table
|
|
29
|
-
.
|
|
30
|
-
.unsigned()
|
|
31
|
-
.notNullable()
|
|
32
|
-
.references("id")
|
|
33
|
-
.inTable("folders")
|
|
34
|
-
.onDelete("CASCADE")
|
|
22
|
+
table.integer("folderId").unsigned().notNullable()
|
|
23
|
+
.references("id").inTable("folders").onDelete("CASCADE")
|
|
35
24
|
.comment("Foreign key to folders table");
|
|
36
25
|
|
|
37
|
-
table
|
|
38
|
-
.enu("status", ["PENDING", "IN_PROGRESS", "COMPLETED", "FAILED"])
|
|
26
|
+
table.enu("status", ["PENDING", "IN_PROGRESS", "COMPLETED", "FAILED"])
|
|
39
27
|
.notNullable()
|
|
40
28
|
.defaultTo("PENDING")
|
|
41
29
|
.comment("Status of the batch upload");
|
|
42
30
|
|
|
43
|
-
table
|
|
44
|
-
.integer("totalVideos")
|
|
45
|
-
.notNullable()
|
|
46
|
-
.defaultTo(0)
|
|
31
|
+
table.integer("totalVideos").notNullable().defaultTo(0)
|
|
47
32
|
.comment("Total number of videos in batch");
|
|
48
33
|
|
|
49
|
-
table
|
|
50
|
-
.integer("completedVideos")
|
|
51
|
-
.notNullable()
|
|
52
|
-
.defaultTo(0)
|
|
34
|
+
table.integer("completedVideos").notNullable().defaultTo(0)
|
|
53
35
|
.comment("Number of successfully created videos");
|
|
54
36
|
|
|
55
|
-
table
|
|
56
|
-
.integer("failedVideos")
|
|
57
|
-
.notNullable()
|
|
58
|
-
.defaultTo(0)
|
|
37
|
+
table.integer("failedVideos").notNullable().defaultTo(0)
|
|
59
38
|
.comment("Number of failed videos");
|
|
60
39
|
|
|
61
40
|
table.timestamps(true, true);
|
|
@@ -63,32 +42,17 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
63
42
|
|
|
64
43
|
// Step 2: Add recording time, trimming, and batch columns to video table
|
|
65
44
|
await knex.schema.alterTable("video", (table) => {
|
|
66
|
-
table
|
|
67
|
-
.timestamp("recordingStartedAt", { useTz: true })
|
|
68
|
-
.nullable()
|
|
45
|
+
table.timestamp("recordingStartedAt", { useTz: true }).nullable()
|
|
69
46
|
.comment("Recording start time in UTC - null for backward compatibility");
|
|
70
47
|
|
|
71
|
-
table
|
|
72
|
-
.boolean("trimEnabled")
|
|
73
|
-
.notNullable()
|
|
74
|
-
.defaultTo(false)
|
|
48
|
+
table.boolean("trimEnabled").notNullable().defaultTo(false)
|
|
75
49
|
.comment("Whether video trimming is enabled");
|
|
76
50
|
|
|
77
|
-
table
|
|
78
|
-
.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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")
|
|
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")
|
|
92
56
|
.comment("Foreign key to video_batch table (numerical ID, NOT UUID)");
|
|
93
57
|
});
|
|
94
58
|
|
|
@@ -29,11 +29,7 @@ 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
|
|
33
|
-
.foreign("locationId")
|
|
34
|
-
.references("id")
|
|
35
|
-
.inTable("locations")
|
|
36
|
-
.onDelete("SET NULL");
|
|
32
|
+
table.foreign("locationId").references("id").inTable("locations").onDelete("SET NULL");
|
|
37
33
|
});
|
|
38
34
|
|
|
39
35
|
// 6. Drop old index if it exists
|
|
@@ -66,11 +62,7 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
66
62
|
|
|
67
63
|
// 4. Restore original foreign key constraint
|
|
68
64
|
await knex.schema.alterTable("study", (table) => {
|
|
69
|
-
table
|
|
70
|
-
.foreign("cameraId")
|
|
71
|
-
.references("id")
|
|
72
|
-
.inTable("locations")
|
|
73
|
-
.onDelete("SET NULL");
|
|
65
|
+
table.foreign("cameraId").references("id").inTable("locations").onDelete("SET NULL");
|
|
74
66
|
});
|
|
75
67
|
|
|
76
68
|
// 5. Restore original index
|
|
@@ -9,27 +9,15 @@ 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
|
-
.
|
|
15
|
-
.unique()
|
|
16
|
-
.notNullable();
|
|
17
|
-
table
|
|
18
|
-
.integer("locationId")
|
|
19
|
-
.unsigned()
|
|
20
|
-
.notNullable()
|
|
21
|
-
.references("id")
|
|
22
|
-
.inTable("locations")
|
|
23
|
-
.onDelete("CASCADE");
|
|
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");
|
|
24
15
|
table.string("name", 100).notNullable();
|
|
25
16
|
table.text("description").nullable();
|
|
26
|
-
table
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
.defaultTo("ACTIVE")
|
|
32
|
-
.notNullable();
|
|
17
|
+
table.enu("status", ["ACTIVE", "INACTIVE", "MAINTENANCE"], {
|
|
18
|
+
useNative: true,
|
|
19
|
+
enumName: "camera_status_enum"
|
|
20
|
+
}).defaultTo("ACTIVE").notNullable();
|
|
33
21
|
table.jsonb("metadata").defaultTo("{}").notNullable();
|
|
34
22
|
table.timestamps(true, true);
|
|
35
23
|
|
|
@@ -8,13 +8,8 @@ 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
|
-
.
|
|
13
|
-
.unsigned()
|
|
14
|
-
.nullable()
|
|
15
|
-
.references("id")
|
|
16
|
-
.inTable("cameras")
|
|
17
|
-
.onDelete("SET NULL");
|
|
11
|
+
table.integer("cameraId").unsigned().nullable()
|
|
12
|
+
.references("id").inTable("cameras").onDelete("SET NULL");
|
|
18
13
|
table.index(["cameraId"], "video_cameraid_index");
|
|
19
14
|
});
|
|
20
15
|
}
|