vr-migrations 1.0.24 → 1.0.26

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.
@@ -18,11 +18,6 @@ module.exports = {
18
18
  type: Sequelize.STRING(100),
19
19
  allowNull: false,
20
20
  },
21
- phoneNumber: {
22
- type: Sequelize.STRING(100),
23
- allowNull: false,
24
- unique: true,
25
- },
26
21
  nationalId: {
27
22
  type: Sequelize.STRING(100),
28
23
  allowNull: true,
@@ -54,6 +49,10 @@ module.exports = {
54
49
  type: Sequelize.STRING(100),
55
50
  allowNull: true,
56
51
  },
52
+ primaryPhoneId: {
53
+ type: Sequelize.UUID,
54
+ allowNull: false,
55
+ },
57
56
  isActive: {
58
57
  type: Sequelize.BOOLEAN,
59
58
  allowNull: false,
@@ -68,23 +67,7 @@ module.exports = {
68
67
  type: Sequelize.BOOLEAN,
69
68
  defaultValue: false,
70
69
  },
71
- verified: {
72
- type: Sequelize.BOOLEAN,
73
- allowNull: false,
74
- defaultValue: false,
75
- },
76
- verifiedAt: {
77
- type: Sequelize.DATE,
78
- allowNull: true,
79
- },
80
- otp: {
81
- type: Sequelize.STRING(50),
82
- allowNull: true,
83
- },
84
- otpExpiresAt: {
85
- type: Sequelize.DATE,
86
- allowNull: true,
87
- },
70
+
88
71
  lastLoginAt: {
89
72
  type: Sequelize.DATE,
90
73
  allowNull: true,
@@ -114,10 +97,11 @@ module.exports = {
114
97
  },
115
98
  });
116
99
 
117
- // Optional: explicit indexes (Postgres already enforces uniques, but this is clarity)
118
- await queryInterface.addIndex("users", ["phoneNumber"]);
100
+ // Add indexes
119
101
  await queryInterface.addIndex("users", ["jacketId"]);
120
102
  await queryInterface.addIndex("users", ["nationalId"]);
103
+ await queryInterface.addIndex("users", ["primaryPhoneId"]);
104
+ await queryInterface.addIndex("users", ["securityClearanceId"]);
121
105
  },
122
106
 
123
107
  async down(queryInterface) {
@@ -0,0 +1,95 @@
1
+ // migrations/XXXXXXXXXXXXXX-create-phone-contacts.js
2
+ "use strict";
3
+
4
+ module.exports = {
5
+ async up(queryInterface, Sequelize) {
6
+ await queryInterface.createTable("phone_contacts", {
7
+ id: {
8
+ type: Sequelize.UUID,
9
+ defaultValue: Sequelize.UUIDV4,
10
+ primaryKey: true,
11
+ allowNull: false,
12
+ },
13
+ phoneNumber: {
14
+ type: Sequelize.STRING(20),
15
+ allowNull: false,
16
+ unique: true,
17
+ },
18
+ userId: {
19
+ type: Sequelize.UUID,
20
+ allowNull: true,
21
+ references: {
22
+ model: "users",
23
+ key: "id",
24
+ },
25
+ onUpdate: "CASCADE",
26
+ onDelete: "SET NULL",
27
+ },
28
+ isVerified: {
29
+ type: Sequelize.BOOLEAN,
30
+ allowNull: false,
31
+ defaultValue: false,
32
+ },
33
+ verifiedAt: {
34
+ type: Sequelize.DATE,
35
+ allowNull: true,
36
+ },
37
+ isPrimary: {
38
+ type: Sequelize.BOOLEAN,
39
+ allowNull: false,
40
+ defaultValue: false,
41
+ },
42
+ isActive: {
43
+ type: Sequelize.BOOLEAN,
44
+ allowNull: false,
45
+ defaultValue: true,
46
+ },
47
+ otp: {
48
+ type: Sequelize.STRING(10),
49
+ allowNull: true,
50
+ },
51
+ otpExpiresAt: {
52
+ type: Sequelize.DATE,
53
+ allowNull: true,
54
+ },
55
+ metadata: {
56
+ type: Sequelize.JSONB,
57
+ allowNull: false,
58
+ defaultValue: {},
59
+ },
60
+ createdAt: {
61
+ type: Sequelize.DATE,
62
+ allowNull: false,
63
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
64
+ },
65
+ updatedAt: {
66
+ type: Sequelize.DATE,
67
+ allowNull: false,
68
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
69
+ },
70
+ });
71
+
72
+ // Add indexes
73
+ await queryInterface.addIndex("phone_contacts", ["phoneNumber"], {
74
+ unique: true,
75
+ name: "phone_contacts_phone_number_unique",
76
+ });
77
+ await queryInterface.addIndex("phone_contacts", ["userId"], {
78
+ name: "phone_contacts_user_id_idx",
79
+ });
80
+ await queryInterface.addIndex(
81
+ "phone_contacts",
82
+ ["isVerified", "isPrimary"],
83
+ {
84
+ name: "phone_contacts_verified_primary_idx",
85
+ }
86
+ );
87
+ await queryInterface.addIndex("phone_contacts", ["otpExpiresAt"], {
88
+ name: "phone_contacts_otp_expiry_idx",
89
+ });
90
+ },
91
+
92
+ async down(queryInterface) {
93
+ await queryInterface.dropTable("phone_contacts");
94
+ },
95
+ };
@@ -10,16 +10,81 @@ module.exports = {
10
10
  const nid_3 = await bcrypt.hash("1199900000000003", 10);
11
11
  const nid_4 = await bcrypt.hash("1199900000000004", 10);
12
12
 
13
+ // First create phone contacts
14
+ await queryInterface.bulkInsert("phone_contacts", [
15
+ {
16
+ id: "11111111-1111-1111-1111-111111111111",
17
+ phoneNumber: "+250788000001",
18
+ userId: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
19
+ isVerified: true,
20
+ verifiedAt: now,
21
+ isPrimary: true,
22
+ isActive: true,
23
+ metadata: {},
24
+ createdAt: now,
25
+ updatedAt: now,
26
+ },
27
+ {
28
+ id: "22222222-2222-2222-2222-222222222222",
29
+ phoneNumber: "+250788000002",
30
+ userId: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa2",
31
+ isVerified: true,
32
+ verifiedAt: now,
33
+ isPrimary: true,
34
+ isActive: true,
35
+ metadata: {},
36
+ createdAt: now,
37
+ updatedAt: now,
38
+ },
39
+ {
40
+ id: "33333333-3333-3333-3333-333333333333",
41
+ phoneNumber: "+250788000003",
42
+ userId: "aaaaaaa2-aaaa-aaaa-aaaa-aaaaaaaaaaa3",
43
+ isVerified: true,
44
+ verifiedAt: now,
45
+ isPrimary: true,
46
+ isActive: true,
47
+ metadata: {},
48
+ createdAt: now,
49
+ updatedAt: now,
50
+ },
51
+ {
52
+ id: "44444444-4444-4444-4444-444444444444",
53
+ phoneNumber: "+250788000004",
54
+ userId: "aaaaaaa3-aaaa-aaaa-aaaa-aaaaaaaaaaa4",
55
+ isVerified: true,
56
+ verifiedAt: now,
57
+ isPrimary: true,
58
+ isActive: true,
59
+ metadata: {},
60
+ createdAt: now,
61
+ updatedAt: now,
62
+ },
63
+ {
64
+ id: "55555555-5555-5555-5555-555555555555",
65
+ phoneNumber: "+250788000005",
66
+ userId: "aaaaaaa4-aaaa-aaaa-aaaa-aaaaaaaaaaa5",
67
+ isVerified: true,
68
+ verifiedAt: now,
69
+ isPrimary: true,
70
+ isActive: true,
71
+ metadata: {},
72
+ createdAt: now,
73
+ updatedAt: now,
74
+ },
75
+ ]);
76
+
77
+ // Then create users with primaryPhoneId reference
13
78
  await queryInterface.bulkInsert("users", [
14
79
  {
15
80
  id: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
16
81
  firstName: "Jean",
17
82
  lastName: "Rider",
18
- phoneNumber: "0788000000",
19
83
  nationalId: nid_1,
20
84
  jacketId: "JACKET-R-001",
21
85
  plateNumber: "RAD101A",
22
86
  securityClearanceId: "11111111-1111-1111-1111-111111111111", // RIDER
87
+ primaryPhoneId: "11111111-1111-1111-1111-111111111111",
23
88
  isActive: true,
24
89
  lastLoginAt: null,
25
90
  createdAt: now,
@@ -28,10 +93,10 @@ module.exports = {
28
93
  id: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa2",
29
94
  firstName: "Jane",
30
95
  lastName: "Passenger",
31
- phoneNumber: "0788000001",
32
96
  email: "jane@passenger.com",
33
97
  password: passwordHash,
34
- securityClearanceId: "22222222-2222-2222-2222-222222222222", // RIDER
98
+ securityClearanceId: "22222222-2222-2222-2222-222222222222", // PASSENGER
99
+ primaryPhoneId: "22222222-2222-2222-2222-222222222222",
35
100
  isActive: true,
36
101
  lastLoginAt: null,
37
102
  createdAt: now,
@@ -40,11 +105,11 @@ module.exports = {
40
105
  id: "aaaaaaa2-aaaa-aaaa-aaaa-aaaaaaaaaaa3",
41
106
  firstName: "Alice",
42
107
  lastName: "Agent",
43
- phoneNumber: "0788000002",
44
108
  nationalId: nid_2,
45
109
  email: "alice@agent.com",
46
110
  password: passwordHash,
47
111
  securityClearanceId: "33333333-3333-3333-3333-333333333333", // AGENT
112
+ primaryPhoneId: "33333333-3333-3333-3333-333333333333",
48
113
  isActive: true,
49
114
  lastLoginAt: null,
50
115
  createdAt: now,
@@ -53,11 +118,11 @@ module.exports = {
53
118
  id: "aaaaaaa3-aaaa-aaaa-aaaa-aaaaaaaaaaa4",
54
119
  firstName: "Eric",
55
120
  lastName: "Admin",
56
- phoneNumber: "0788000003",
57
121
  nationalId: nid_3,
58
122
  email: "eric@admin.com",
59
123
  password: passwordHash,
60
124
  securityClearanceId: "44444444-4444-4444-4444-444444444444", // ADMIN
125
+ primaryPhoneId: "44444444-4444-4444-4444-444444444444",
61
126
  isActive: true,
62
127
  lastLoginAt: null,
63
128
  createdAt: now,
@@ -66,12 +131,11 @@ module.exports = {
66
131
  id: "aaaaaaa4-aaaa-aaaa-aaaa-aaaaaaaaaaa5",
67
132
  firstName: "Super",
68
133
  lastName: "Admin",
69
- phoneNumber: "0788123456",
70
134
  email: "super@admin.com",
71
135
  password: passwordHash,
72
136
  nationalId: nid_4,
73
- plateNumber: null,
74
137
  securityClearanceId: "55555555-5555-5555-5555-555555555555", // SUPER_ADMIN
138
+ primaryPhoneId: "55555555-5555-5555-5555-555555555555",
75
139
  isActive: true,
76
140
  lastLoginAt: null,
77
141
  createdAt: now,
@@ -80,13 +144,7 @@ module.exports = {
80
144
  },
81
145
 
82
146
  async down(queryInterface) {
83
- await queryInterface.bulkDelete("users", {
84
- id: [
85
- "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
86
- "aaaaaaa2-aaaa-aaaa-aaaa-aaaaaaaaaaa2",
87
- "aaaaaaa3-aaaa-aaaa-aaaa-aaaaaaaaaaa3",
88
- "aaaaaaa4-aaaa-aaaa-aaaa-aaaaaaaaaaa4",
89
- ],
90
- });
147
+ await queryInterface.bulkDelete("phone_contacts", null, {});
148
+ await queryInterface.bulkDelete("users", null, {});
91
149
  },
92
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Database migration and seeding package for VR applications",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",