-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy path1748589373000-CreateArchiveCheckpoints.ts
More file actions
106 lines (102 loc) · 2.78 KB
/
Copy path1748589373000-CreateArchiveCheckpoints.ts
File metadata and controls
106 lines (102 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";
export class CreateArchiveCheckpoints1748589373000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "archive_checkpoints",
columns: [
{
name: "id",
type: "uuid",
isPrimary: true,
generationStrategy: "uuid",
default: "gen_random_uuid()",
},
{
name: "job_type",
type: "varchar",
length: "64",
isNullable: false,
},
{
name: "last_processed_timestamp",
type: "timestamptz",
isNullable: true,
},
{
name: "last_processed_id",
type: "uuid",
isNullable: true,
},
{
name: "total_archived",
type: "integer",
default: 0,
isNullable: false,
},
{
name: "batch_number",
type: "integer",
default: 0,
isNullable: false,
},
{
name: "status",
type: "varchar",
length: "20",
default: "'in_progress'",
isNullable: false,
},
{
name: "config_snapshot",
type: "jsonb",
isNullable: false,
},
{
name: "started_at",
type: "timestamptz",
default: "CURRENT_TIMESTAMP",
isNullable: false,
},
{
name: "updated_at",
type: "timestamptz",
default: "CURRENT_TIMESTAMP",
isNullable: false,
},
{
name: "completed_at",
type: "timestamptz",
isNullable: true,
},
],
}),
true,
);
// Create index for efficient checkpoint lookup
await queryRunner.createIndex(
"archive_checkpoints",
new TableIndex({
name: "idx_archive_checkpoints_job_type_status",
columnNames: ["job_type", "status"],
}),
);
// Create index for timestamp-based queries
await queryRunner.createIndex(
"archive_checkpoints",
new TableIndex({
name: "idx_archive_checkpoints_started_at",
columnNames: ["started_at"],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX IF EXISTS "idx_archive_checkpoints_started_at"`,
);
await queryRunner.query(
`DROP INDEX IF EXISTS "idx_archive_checkpoints_job_type_status"`,
);
await queryRunner.query(`DROP TABLE IF EXISTS "archive_checkpoints"`);
}
}