forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20260324000000-CreateSimplifiedDebtsTable.ts
More file actions
85 lines (80 loc) · 2.38 KB
/
Copy path20260324000000-CreateSimplifiedDebtsTable.ts
File metadata and controls
85 lines (80 loc) · 2.38 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
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';
export class CreateSimplifiedDebtsTable20260324000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'simplified_debts',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
default: 'gen_random_uuid()',
},
{
name: 'groupId',
type: 'uuid',
isNullable: true,
},
{
name: 'calculatedForUserIds',
type: 'jsonb',
isNullable: false,
},
{
name: 'debts',
type: 'jsonb',
isNullable: false,
default: "'[]'",
},
{
name: 'originalTransactionCount',
type: 'int',
default: 0,
},
{
name: 'simplifiedTransactionCount',
type: 'int',
default: 0,
},
{
name: 'savingsPercentage',
type: 'decimal',
precision: 5,
scale: 2,
default: 0,
},
{
name: 'calculatedAt',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
},
{
name: 'expiresAt',
type: 'timestamp',
isNullable: false,
},
],
}),
true,
);
await queryRunner.createIndex(
'simplified_debts',
new TableIndex({ name: 'IDX_simplified_debts_groupId', columnNames: ['groupId'] }),
);
await queryRunner.createIndex(
'simplified_debts',
new TableIndex({ name: 'IDX_simplified_debts_calculatedAt', columnNames: ['calculatedAt'] }),
);
await queryRunner.createIndex(
'simplified_debts',
new TableIndex({ name: 'IDX_simplified_debts_expiresAt', columnNames: ['expiresAt'] }),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropIndex('simplified_debts', 'IDX_simplified_debts_expiresAt');
await queryRunner.dropIndex('simplified_debts', 'IDX_simplified_debts_calculatedAt');
await queryRunner.dropIndex('simplified_debts', 'IDX_simplified_debts_groupId');
await queryRunner.dropTable('simplified_debts', true);
}
}