vr-migrations 1.0.2
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/README.md +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +60 -0
- package/dist/create-migration.d.ts +1 -0
- package/dist/create-migration.js +26 -0
- package/dist/create-seeder.d.ts +1 -0
- package/dist/create-seeder.js +26 -0
- package/dist/db.d.ts +12 -0
- package/dist/db.js +54 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +29 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +36 -0
- package/dist/migrations/001-create-security-clearances.js +62 -0
- package/dist/migrations/002-create-users.js +141 -0
- package/dist/migrations/003-create-products.js +52 -0
- package/dist/migrations/004-create-pricing.js +82 -0
- package/dist/migrations/005-create-devices.js +63 -0
- package/dist/migrations/006-create-device-payment-plans.js +115 -0
- package/dist/migrations/007-create-idempotency-records.js +61 -0
- package/dist/migrations/008-create-payments.js +106 -0
- package/dist/migrations/009-create-transactions.js +80 -0
- package/dist/migrations/010-create-eventLogs.js +117 -0
- package/dist/migrations/index.d.ts +0 -0
- package/dist/migrations/index.js +1 -0
- package/dist/migrations/index.ts +1 -0
- package/dist/reset.d.ts +1 -0
- package/dist/reset.js +9 -0
- package/dist/rollback.d.ts +1 -0
- package/dist/rollback.js +40 -0
- package/dist/seed.d.ts +1 -0
- package/dist/seed.js +38 -0
- package/dist/seeders/001-security-clearance-demo.js +116 -0
- package/dist/seeders/002-users-demo.js +94 -0
- package/dist/seeders/index.d.ts +0 -0
- package/dist/seeders/index.js +1 -0
- package/dist/seeders/index.ts +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +2 -0
- package/package.json +56 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/** @type {import('sequelize').QueryInterface} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
async up(queryInterface, Sequelize) {
|
|
6
|
+
await queryInterface.createTable("device_payment_plans", {
|
|
7
|
+
id: {
|
|
8
|
+
type: Sequelize.UUID,
|
|
9
|
+
defaultValue: Sequelize.UUIDV4,
|
|
10
|
+
primaryKey: true,
|
|
11
|
+
allowNull: false
|
|
12
|
+
},
|
|
13
|
+
deviceId: {
|
|
14
|
+
type: Sequelize.UUID,
|
|
15
|
+
allowNull: false,
|
|
16
|
+
unique: true,
|
|
17
|
+
references: {
|
|
18
|
+
model: "devices",
|
|
19
|
+
key: "id"
|
|
20
|
+
},
|
|
21
|
+
onUpdate: "CASCADE",
|
|
22
|
+
onDelete: "CASCADE"
|
|
23
|
+
},
|
|
24
|
+
userId: {
|
|
25
|
+
type: Sequelize.UUID,
|
|
26
|
+
allowNull: false,
|
|
27
|
+
references: {
|
|
28
|
+
model: "users",
|
|
29
|
+
key: "id"
|
|
30
|
+
},
|
|
31
|
+
onUpdate: "CASCADE",
|
|
32
|
+
onDelete: "CASCADE"
|
|
33
|
+
},
|
|
34
|
+
pricingSnapshot: {
|
|
35
|
+
type: Sequelize.JSONB,
|
|
36
|
+
allowNull: false
|
|
37
|
+
},
|
|
38
|
+
totalAmount: {
|
|
39
|
+
type: Sequelize.FLOAT,
|
|
40
|
+
allowNull: false
|
|
41
|
+
},
|
|
42
|
+
downPayment: {
|
|
43
|
+
type: Sequelize.FLOAT,
|
|
44
|
+
allowNull: false
|
|
45
|
+
},
|
|
46
|
+
installmentAmount: {
|
|
47
|
+
type: Sequelize.FLOAT,
|
|
48
|
+
allowNull: false
|
|
49
|
+
},
|
|
50
|
+
installmentFrequency: {
|
|
51
|
+
type: Sequelize.ENUM("DAILY", "WEEKLY", "MONTHLY"),
|
|
52
|
+
allowNull: false,
|
|
53
|
+
defaultValue: "WEEKLY"
|
|
54
|
+
},
|
|
55
|
+
paidAmount: {
|
|
56
|
+
type: Sequelize.FLOAT,
|
|
57
|
+
allowNull: false,
|
|
58
|
+
defaultValue: 0
|
|
59
|
+
},
|
|
60
|
+
outstandingAmount: {
|
|
61
|
+
type: Sequelize.FLOAT,
|
|
62
|
+
allowNull: false
|
|
63
|
+
},
|
|
64
|
+
lastPaymentAt: {
|
|
65
|
+
type: Sequelize.DATE,
|
|
66
|
+
allowNull: true
|
|
67
|
+
},
|
|
68
|
+
nextInstallmentDueAt: {
|
|
69
|
+
type: Sequelize.DATE,
|
|
70
|
+
allowNull: true
|
|
71
|
+
},
|
|
72
|
+
gracePeriodDays: {
|
|
73
|
+
type: Sequelize.INTEGER,
|
|
74
|
+
allowNull: false,
|
|
75
|
+
defaultValue: 2
|
|
76
|
+
},
|
|
77
|
+
autoLockOnMiss: {
|
|
78
|
+
type: Sequelize.BOOLEAN,
|
|
79
|
+
allowNull: false,
|
|
80
|
+
defaultValue: true
|
|
81
|
+
},
|
|
82
|
+
status: {
|
|
83
|
+
type: Sequelize.ENUM("ACTIVE", "COMPLETED", "DEFAULTED", "CANCELLED"),
|
|
84
|
+
allowNull: false,
|
|
85
|
+
defaultValue: "ACTIVE"
|
|
86
|
+
},
|
|
87
|
+
completedAt: {
|
|
88
|
+
type: Sequelize.DATE,
|
|
89
|
+
allowNull: true
|
|
90
|
+
},
|
|
91
|
+
createdAt: {
|
|
92
|
+
type: Sequelize.DATE,
|
|
93
|
+
allowNull: false,
|
|
94
|
+
defaultValue: Sequelize.fn("NOW")
|
|
95
|
+
},
|
|
96
|
+
updatedAt: {
|
|
97
|
+
type: Sequelize.DATE,
|
|
98
|
+
allowNull: false,
|
|
99
|
+
defaultValue: Sequelize.fn("NOW")
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
async down(queryInterface) {
|
|
105
|
+
await queryInterface.dropTable("device_payment_plans");
|
|
106
|
+
|
|
107
|
+
// Remove the enums
|
|
108
|
+
await queryInterface.sequelize.query(
|
|
109
|
+
'DROP TYPE IF EXISTS "enum_device_payment_plans_status"'
|
|
110
|
+
);
|
|
111
|
+
await queryInterface.sequelize.query(
|
|
112
|
+
'DROP TYPE IF EXISTS "enum_device_payment_plans_installmentFrequency"'
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("idempotency_records", {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.UUID,
|
|
8
|
+
defaultValue: Sequelize.UUIDV4,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
allowNull: false
|
|
11
|
+
},
|
|
12
|
+
key: {
|
|
13
|
+
type: Sequelize.STRING(128),
|
|
14
|
+
allowNull: false,
|
|
15
|
+
unique: true
|
|
16
|
+
},
|
|
17
|
+
requestMethod: {
|
|
18
|
+
type: Sequelize.STRING(10),
|
|
19
|
+
allowNull: false
|
|
20
|
+
},
|
|
21
|
+
requestPath: {
|
|
22
|
+
type: Sequelize.STRING(255),
|
|
23
|
+
allowNull: false
|
|
24
|
+
},
|
|
25
|
+
requestParams: {
|
|
26
|
+
type: Sequelize.JSONB,
|
|
27
|
+
allowNull: true
|
|
28
|
+
},
|
|
29
|
+
responseStatusCode: {
|
|
30
|
+
type: Sequelize.INTEGER,
|
|
31
|
+
allowNull: true
|
|
32
|
+
},
|
|
33
|
+
responseBody: {
|
|
34
|
+
type: Sequelize.JSONB,
|
|
35
|
+
allowNull: true
|
|
36
|
+
},
|
|
37
|
+
createdAt: {
|
|
38
|
+
allowNull: false,
|
|
39
|
+
type: Sequelize.DATE,
|
|
40
|
+
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
|
|
41
|
+
},
|
|
42
|
+
expiresAt: {
|
|
43
|
+
allowNull: false,
|
|
44
|
+
type: Sequelize.DATE
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Indexes
|
|
49
|
+
await queryInterface.addIndex("idempotency_records", ["key"], {
|
|
50
|
+
unique: true
|
|
51
|
+
});
|
|
52
|
+
await queryInterface.addIndex("idempotency_records", ["expiresAt"]);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
async down(queryInterface) {
|
|
56
|
+
await queryInterface.dropTable("idempotency_records");
|
|
57
|
+
await queryInterface.sequelize.query(
|
|
58
|
+
"DROP TYPE IF EXISTS enum_idempotency_keys_request_method"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("payments", {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.UUID,
|
|
8
|
+
defaultValue: Sequelize.UUIDV4,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
allowNull: false
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
userId: {
|
|
14
|
+
type: Sequelize.UUID,
|
|
15
|
+
allowNull: false,
|
|
16
|
+
references: {
|
|
17
|
+
model: "users",
|
|
18
|
+
key: "id"
|
|
19
|
+
},
|
|
20
|
+
onUpdate: "CASCADE",
|
|
21
|
+
onDelete: "RESTRICT"
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
devicePaymentPlanId: {
|
|
25
|
+
type: Sequelize.UUID,
|
|
26
|
+
allowNull: false,
|
|
27
|
+
references: {
|
|
28
|
+
model: "device_payment_plans",
|
|
29
|
+
key: "id"
|
|
30
|
+
},
|
|
31
|
+
onUpdate: "CASCADE",
|
|
32
|
+
onDelete: "RESTRICT"
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
transactionId: {
|
|
36
|
+
type: Sequelize.UUID,
|
|
37
|
+
allowNull: true
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
idempotencyKeyId: {
|
|
41
|
+
type: Sequelize.UUID,
|
|
42
|
+
allowNull: true,
|
|
43
|
+
references: {
|
|
44
|
+
model: "idempotency_records",
|
|
45
|
+
key: "id"
|
|
46
|
+
},
|
|
47
|
+
onUpdate: "CASCADE",
|
|
48
|
+
onDelete: "SET NULL"
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
amount: {
|
|
52
|
+
type: Sequelize.FLOAT,
|
|
53
|
+
allowNull: false
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
provider: {
|
|
57
|
+
type: Sequelize.ENUM("mtn_momo", "airtel_money"),
|
|
58
|
+
allowNull: false
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
providerReference: {
|
|
62
|
+
type: Sequelize.STRING,
|
|
63
|
+
allowNull: true
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
status: {
|
|
67
|
+
type: Sequelize.ENUM("pending", "succeeded", "failed"),
|
|
68
|
+
allowNull: false,
|
|
69
|
+
defaultValue: "pending"
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
metadata: {
|
|
73
|
+
type: Sequelize.JSONB,
|
|
74
|
+
allowNull: false,
|
|
75
|
+
defaultValue: {}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
createdAt: {
|
|
79
|
+
type: Sequelize.DATE,
|
|
80
|
+
allowNull: false,
|
|
81
|
+
defaultValue: Sequelize.fn("NOW")
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
updatedAt: {
|
|
85
|
+
type: Sequelize.DATE,
|
|
86
|
+
allowNull: false,
|
|
87
|
+
defaultValue: Sequelize.fn("NOW")
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await queryInterface.addIndex("payments", ["userId"]);
|
|
92
|
+
await queryInterface.addIndex("payments", ["devicePaymentPlanId"]);
|
|
93
|
+
await queryInterface.addIndex("payments", ["status"]);
|
|
94
|
+
await queryInterface.addIndex("payments", ["provider"]);
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
async down(queryInterface) {
|
|
98
|
+
await queryInterface.dropTable("payments");
|
|
99
|
+
await queryInterface.sequelize.query(
|
|
100
|
+
'DROP TYPE IF EXISTS "enum_payments_provider";'
|
|
101
|
+
);
|
|
102
|
+
await queryInterface.sequelize.query(
|
|
103
|
+
'DROP TYPE IF EXISTS "enum_payments_status";'
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("transactions", {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.UUID,
|
|
8
|
+
defaultValue: Sequelize.UUIDV4,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
allowNull: false
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
userId: {
|
|
14
|
+
type: Sequelize.UUID,
|
|
15
|
+
allowNull: false,
|
|
16
|
+
references: {
|
|
17
|
+
model: "users",
|
|
18
|
+
key: "id"
|
|
19
|
+
},
|
|
20
|
+
onUpdate: "CASCADE",
|
|
21
|
+
onDelete: "RESTRICT"
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
paymentId: {
|
|
25
|
+
type: Sequelize.UUID,
|
|
26
|
+
allowNull: false,
|
|
27
|
+
references: {
|
|
28
|
+
model: "payments",
|
|
29
|
+
key: "id"
|
|
30
|
+
},
|
|
31
|
+
onUpdate: "CASCADE",
|
|
32
|
+
onDelete: "RESTRICT"
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
amount: {
|
|
36
|
+
type: Sequelize.FLOAT,
|
|
37
|
+
allowNull: false
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
status: {
|
|
41
|
+
type: Sequelize.ENUM("succeeded", "failed"),
|
|
42
|
+
allowNull: false
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
providerReference: {
|
|
46
|
+
type: Sequelize.STRING,
|
|
47
|
+
allowNull: false
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
metadata: {
|
|
51
|
+
type: Sequelize.JSONB,
|
|
52
|
+
allowNull: false,
|
|
53
|
+
defaultValue: {}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
createdAt: {
|
|
57
|
+
type: Sequelize.DATE,
|
|
58
|
+
allowNull: false,
|
|
59
|
+
defaultValue: Sequelize.fn("NOW")
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
updatedAt: {
|
|
63
|
+
type: Sequelize.DATE,
|
|
64
|
+
allowNull: false,
|
|
65
|
+
defaultValue: Sequelize.fn("NOW")
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await queryInterface.addIndex("transactions", ["userId"]);
|
|
70
|
+
await queryInterface.addIndex("transactions", ["paymentId"]);
|
|
71
|
+
await queryInterface.addIndex("transactions", ["status"]);
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
async down(queryInterface) {
|
|
75
|
+
await queryInterface.dropTable("transactions");
|
|
76
|
+
await queryInterface.sequelize.query(
|
|
77
|
+
'DROP TYPE IF EXISTS "enum_transactions_status";'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("event_logs", {
|
|
6
|
+
id: {
|
|
7
|
+
type: Sequelize.UUID,
|
|
8
|
+
defaultValue: Sequelize.UUIDV4,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
allowNull: false
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
actorType: {
|
|
14
|
+
type: Sequelize.ENUM("USER", "SYSTEM"),
|
|
15
|
+
allowNull: false
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
actorId: {
|
|
19
|
+
type: Sequelize.UUID,
|
|
20
|
+
allowNull: true
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
action: {
|
|
24
|
+
type: Sequelize.ENUM(
|
|
25
|
+
"USER_READ",
|
|
26
|
+
"USER_UPDATED",
|
|
27
|
+
"USERS_LISTED",
|
|
28
|
+
"USER_LOGGED_IN",
|
|
29
|
+
"ADMIN_FORGOT_PASSWORD",
|
|
30
|
+
"ADMIN_LOGGED_IN",
|
|
31
|
+
"ADMIN_LOGGED_OUT",
|
|
32
|
+
"PASSENGER_ACCOUNT_DEACTIVATED",
|
|
33
|
+
"PASSENGER_ACCOUNT_DELETED",
|
|
34
|
+
"AGENT_CREATED_RIDER",
|
|
35
|
+
"AGENT_UPDATED_RIDER",
|
|
36
|
+
"ADMIN_CREATED_USER",
|
|
37
|
+
"ADMIN_UPDATED_USER",
|
|
38
|
+
|
|
39
|
+
"PRODUCT_CREATED",
|
|
40
|
+
"PRODUCT_READ",
|
|
41
|
+
"PRODUCT_UPDATED",
|
|
42
|
+
"PRODUCT_DELETED",
|
|
43
|
+
"PRODUCTS_LISTED",
|
|
44
|
+
|
|
45
|
+
"DEVICE_ASSIGNED",
|
|
46
|
+
"DEVICE_READ",
|
|
47
|
+
"DEVICE_UPDATED",
|
|
48
|
+
"DEVICES_LISTED",
|
|
49
|
+
"DEVICE_REPOSSESSED",
|
|
50
|
+
|
|
51
|
+
"DEVICE_PAYMENT_PLAN_CREATED",
|
|
52
|
+
"DEVICE_PAYMENT_PLAN_READ",
|
|
53
|
+
"DEVICE_PAYMENT_PLAN_UPDATED",
|
|
54
|
+
"DEVICE_PAYMENT_DEFAULT_MARKED",
|
|
55
|
+
|
|
56
|
+
"PAYMENT_CREATED",
|
|
57
|
+
"PAYMENT_READ",
|
|
58
|
+
"PAYMENTS_LISTED",
|
|
59
|
+
|
|
60
|
+
"TRANSACTION_READ",
|
|
61
|
+
"TRANSACTIONS_LISTED",
|
|
62
|
+
|
|
63
|
+
"EVENT_LOG_READ",
|
|
64
|
+
"EVENT_LOGS_LISTED",
|
|
65
|
+
|
|
66
|
+
"SECURITY_CLEARANCE_MANAGED",
|
|
67
|
+
"DEVICE_LOCK_OVERRIDDEN"
|
|
68
|
+
),
|
|
69
|
+
allowNull: false
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
entity: {
|
|
73
|
+
type: Sequelize.STRING(100),
|
|
74
|
+
allowNull: false
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
entityId: {
|
|
78
|
+
type: Sequelize.UUID,
|
|
79
|
+
allowNull: true
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
metadata: {
|
|
83
|
+
type: Sequelize.JSONB,
|
|
84
|
+
allowNull: false,
|
|
85
|
+
defaultValue: {}
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
ipAddress: {
|
|
89
|
+
type: Sequelize.STRING(45),
|
|
90
|
+
allowNull: true
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
userAgent: {
|
|
94
|
+
type: Sequelize.TEXT,
|
|
95
|
+
allowNull: true
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
createdAt: {
|
|
99
|
+
type: Sequelize.DATE,
|
|
100
|
+
allowNull: false,
|
|
101
|
+
defaultValue: Sequelize.literal("NOW()")
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Indexes for performance
|
|
106
|
+
await queryInterface.addIndex("event_logs", ["actorType", "actorId"]);
|
|
107
|
+
await queryInterface.addIndex("event_logs", ["entity", "entityId"]);
|
|
108
|
+
await queryInterface.addIndex("event_logs", ["createdAt"]);
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async down(queryInterface) {
|
|
112
|
+
await queryInterface.dropTable("event_logs");
|
|
113
|
+
await queryInterface.sequelize.query(
|
|
114
|
+
'DROP TYPE IF EXISTS "enum_event_logs_actorType";'
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../migrations/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// This file exists to enable proper exports
|
package/dist/reset.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function reset(): Promise<void>;
|
package/dist/reset.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reset = reset;
|
|
4
|
+
const db_js_1 = require("./db.js");
|
|
5
|
+
async function reset() {
|
|
6
|
+
const sequelize = (0, db_js_1.getSequelize)();
|
|
7
|
+
await sequelize.drop();
|
|
8
|
+
console.log("⚠️ CENTRALIZED database reset completed");
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rollback(steps?: number | "all"): Promise<void>;
|
package/dist/rollback.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rollback = rollback;
|
|
7
|
+
const umzug_1 = require("umzug");
|
|
8
|
+
const db_1 = require("./db");
|
|
9
|
+
const sequelize_1 = require("sequelize");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
// const migrationsPath = path.join(__dirname, "../migrations/[0-9]*-*.js");
|
|
12
|
+
const migrationsPath = path_1.default.join(__dirname, "migrations/[0-9]*-*.js");
|
|
13
|
+
async function rollback(steps = 1) {
|
|
14
|
+
const sequelize = (0, db_1.getSequelize)();
|
|
15
|
+
const migrator = new umzug_1.Umzug({
|
|
16
|
+
migrations: {
|
|
17
|
+
glob: migrationsPath,
|
|
18
|
+
resolve: ({ name, path: filePath }) => ({
|
|
19
|
+
name,
|
|
20
|
+
up: async () => {
|
|
21
|
+
const migration = require(filePath);
|
|
22
|
+
return migration.up(sequelize.getQueryInterface(), sequelize_1.Sequelize);
|
|
23
|
+
},
|
|
24
|
+
down: async () => {
|
|
25
|
+
const migration = require(filePath);
|
|
26
|
+
return migration.down(sequelize.getQueryInterface());
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
storage: new umzug_1.SequelizeStorage({ sequelize }),
|
|
31
|
+
logger: console,
|
|
32
|
+
});
|
|
33
|
+
if (steps === "all") {
|
|
34
|
+
await migrator.down({ to: 0 });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
await migrator.down({ step: steps });
|
|
38
|
+
}
|
|
39
|
+
console.log("✅ Rollback completed");
|
|
40
|
+
}
|
package/dist/seed.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function seed(): Promise<void>;
|
package/dist/seed.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.seed = seed;
|
|
7
|
+
const umzug_1 = require("umzug");
|
|
8
|
+
const db_1 = require("./db");
|
|
9
|
+
const sequelize_1 = require("sequelize");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
// const seedersPath = path.join(__dirname, "../seeders/[0-9]*-*.js");
|
|
12
|
+
const seedersPath = path_1.default.join(__dirname, "seeders/[0-9]*-*.js");
|
|
13
|
+
async function seed() {
|
|
14
|
+
const sequelize = (0, db_1.getSequelize)();
|
|
15
|
+
const seeder = new umzug_1.Umzug({
|
|
16
|
+
migrations: {
|
|
17
|
+
glob: seedersPath,
|
|
18
|
+
resolve: ({ name, path: filePath }) => ({
|
|
19
|
+
name,
|
|
20
|
+
up: async () => {
|
|
21
|
+
const migration = require(filePath);
|
|
22
|
+
return migration.up(sequelize.getQueryInterface(), sequelize_1.Sequelize);
|
|
23
|
+
},
|
|
24
|
+
down: async () => {
|
|
25
|
+
const migration = require(filePath);
|
|
26
|
+
return migration.down(sequelize.getQueryInterface());
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
storage: new umzug_1.SequelizeStorage({
|
|
31
|
+
sequelize,
|
|
32
|
+
modelName: "SequelizeSeedMeta",
|
|
33
|
+
}),
|
|
34
|
+
logger: console,
|
|
35
|
+
});
|
|
36
|
+
await seeder.up();
|
|
37
|
+
console.log("✅ Seeding completed");
|
|
38
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const ALL_PERMISSIONS = [
|
|
4
|
+
// Users
|
|
5
|
+
"READ_USER",
|
|
6
|
+
"UPDATE_USER",
|
|
7
|
+
"LIST_USERS",
|
|
8
|
+
|
|
9
|
+
// Products
|
|
10
|
+
"CREATE_PRODUCT",
|
|
11
|
+
"READ_PRODUCT",
|
|
12
|
+
"UPDATE_PRODUCT",
|
|
13
|
+
"DELETE_PRODUCT",
|
|
14
|
+
"LIST_PRODUCTS",
|
|
15
|
+
|
|
16
|
+
// Devices
|
|
17
|
+
"ASSIGN_DEVICE",
|
|
18
|
+
"READ_DEVICE",
|
|
19
|
+
"UPDATE_DEVICE",
|
|
20
|
+
"LIST_DEVICES",
|
|
21
|
+
"REPOSSESS_DEVICE",
|
|
22
|
+
|
|
23
|
+
// Device Payment Plans
|
|
24
|
+
"CREATE_DEVICE_PAYMENT_PLAN",
|
|
25
|
+
"READ_DEVICE_PAYMENT_PLAN",
|
|
26
|
+
"UPDATE_DEVICE_PAYMENT_PLAN",
|
|
27
|
+
"MARK_PAYMENT_DEFAULT",
|
|
28
|
+
|
|
29
|
+
// Payments
|
|
30
|
+
"CREATE_PAYMENT",
|
|
31
|
+
"READ_PAYMENT",
|
|
32
|
+
"LIST_PAYMENTS",
|
|
33
|
+
|
|
34
|
+
// Transactions
|
|
35
|
+
"READ_TRANSACTION",
|
|
36
|
+
"LIST_TRANSACTIONS",
|
|
37
|
+
|
|
38
|
+
// Logs
|
|
39
|
+
"READ_EVENT_LOG",
|
|
40
|
+
"LIST_EVENT_LOGS",
|
|
41
|
+
|
|
42
|
+
// System / Overrides
|
|
43
|
+
"MANAGE_SECURITY_CLEARANCE",
|
|
44
|
+
"OVERRIDE_DEVICE_LOCK"
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
async up(queryInterface) {
|
|
49
|
+
const now = new Date();
|
|
50
|
+
|
|
51
|
+
await queryInterface.bulkInsert("security_clearances", [
|
|
52
|
+
{
|
|
53
|
+
id: "11111111-1111-1111-1111-111111111111",
|
|
54
|
+
role: "RIDER",
|
|
55
|
+
description: "Default rider clearance",
|
|
56
|
+
level: 1,
|
|
57
|
+
permissions: ALL_PERMISSIONS,
|
|
58
|
+
isDefault: true,
|
|
59
|
+
createdAt: now,
|
|
60
|
+
updatedAt: now
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "22222222-2222-2222-2222-222222222222",
|
|
64
|
+
role: "PASSENGER",
|
|
65
|
+
description: "Default rider clearance",
|
|
66
|
+
level: 1,
|
|
67
|
+
permissions: ALL_PERMISSIONS,
|
|
68
|
+
isDefault: true,
|
|
69
|
+
createdAt: now,
|
|
70
|
+
updatedAt: now
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "33333333-3333-3333-3333-333333333333",
|
|
74
|
+
role: "AGENT",
|
|
75
|
+
description: "Agent clearance",
|
|
76
|
+
level: 3,
|
|
77
|
+
permissions: ALL_PERMISSIONS,
|
|
78
|
+
isDefault: false,
|
|
79
|
+
createdAt: now,
|
|
80
|
+
updatedAt: now
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "44444444-4444-4444-4444-444444444444",
|
|
84
|
+
role: "ADMIN",
|
|
85
|
+
description: "Admin clearance",
|
|
86
|
+
level: 7,
|
|
87
|
+
permissions: ALL_PERMISSIONS,
|
|
88
|
+
isDefault: false,
|
|
89
|
+
createdAt: now,
|
|
90
|
+
updatedAt: now
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: "55555555-5555-5555-5555-555555555555",
|
|
94
|
+
role: "SUPER_ADMIN",
|
|
95
|
+
description: "Super admin clearance",
|
|
96
|
+
level: 10,
|
|
97
|
+
permissions: ALL_PERMISSIONS,
|
|
98
|
+
isDefault: false,
|
|
99
|
+
createdAt: now,
|
|
100
|
+
updatedAt: now
|
|
101
|
+
}
|
|
102
|
+
]);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
async down(queryInterface) {
|
|
106
|
+
await queryInterface.bulkDelete("securityClearances", {
|
|
107
|
+
id: [
|
|
108
|
+
"11111111-1111-1111-1111-111111111111",
|
|
109
|
+
"22222222-2222-2222-2222-222222222222",
|
|
110
|
+
"33333333-3333-3333-3333-333333333333",
|
|
111
|
+
"44444444-4444-4444-4444-444444444444",
|
|
112
|
+
"55555555-5555-5555-5555-555555555555"
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|