forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1674316800000-CreateRecurringSplitsTable.ts
More file actions
141 lines (134 loc) · 3.42 KB
/
Copy path1674316800000-CreateRecurringSplitsTable.ts
File metadata and controls
141 lines (134 loc) · 3.42 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import {
MigrationInterface,
QueryRunner,
Table,
TableIndex,
TableForeignKey,
} from "typeorm";
export class CreateRecurringSplitsTable1674316800000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "recurring_splits",
columns: [
{
name: "id",
type: "uuid",
isPrimary: true,
default: "gen_random_uuid()",
},
{
name: "creator_id",
type: "varchar",
isNullable: false,
},
{
name: "template_split_id",
type: "uuid",
isNullable: false,
},
{
name: "frequency",
type: "varchar",
isNullable: false,
default: "'monthly'",
},
{
name: "next_occurrence",
type: "timestamp",
isNullable: false,
},
{
name: "end_date",
type: "timestamp",
isNullable: true,
},
{
name: "is_active",
type: "boolean",
default: true,
isNullable: false,
},
{
name: "auto_remind",
type: "boolean",
default: true,
isNullable: false,
},
{
name: "reminder_days_before",
type: "int",
default: 1,
isNullable: false,
},
{
name: "description",
type: "text",
isNullable: true,
},
{
name: "created_at",
type: "timestamp",
default: "CURRENT_TIMESTAMP",
isNullable: false,
},
{
name: "updated_at",
type: "timestamp",
default: "CURRENT_TIMESTAMP",
onUpdate: "CURRENT_TIMESTAMP",
isNullable: false,
},
],
foreignKeys: [
new TableForeignKey({
columnNames: ["template_split_id"],
referencedTableName: "splits",
referencedColumnNames: ["id"],
onDelete: "CASCADE",
}),
],
}),
true,
);
// Create indexes for performance
await queryRunner.createIndex(
"recurring_splits",
new TableIndex({
name: "idx_recurring_splits_creator_id",
columnNames: ["creator_id"],
}),
);
await queryRunner.createIndex(
"recurring_splits",
new TableIndex({
name: "idx_recurring_splits_template_split_id",
columnNames: ["template_split_id"],
}),
);
await queryRunner.createIndex(
"recurring_splits",
new TableIndex({
name: "idx_recurring_splits_is_active",
columnNames: ["is_active"],
}),
);
await queryRunner.createIndex(
"recurring_splits",
new TableIndex({
name: "idx_recurring_splits_next_occurrence",
columnNames: ["next_occurrence"],
}),
);
await queryRunner.createIndex(
"recurring_splits",
new TableIndex({
name: "idx_recurring_splits_active_next_occurrence",
columnNames: ["is_active", "next_occurrence"],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable("recurring_splits", true);
}
}