vr-migrations 1.0.26 → 1.0.28

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.
@@ -51,7 +51,7 @@ module.exports = {
51
51
  },
52
52
  primaryPhoneId: {
53
53
  type: Sequelize.UUID,
54
- allowNull: false,
54
+ allowNull: true,
55
55
  },
56
56
  isActive: {
57
57
  type: Sequelize.BOOLEAN,
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  const bcrypt = require("bcryptjs");
3
+ const { Sequelize } = require("sequelize");
3
4
 
4
5
  module.exports = {
5
6
  async up(queryInterface) {
@@ -10,71 +11,7 @@ module.exports = {
10
11
  const nid_3 = await bcrypt.hash("1199900000000003", 10);
11
12
  const nid_4 = await bcrypt.hash("1199900000000004", 10);
12
13
 
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
14
+ // STEP 1: Create users FIRST (without primaryPhoneId initially)
78
15
  await queryInterface.bulkInsert("users", [
79
16
  {
80
17
  id: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
@@ -84,7 +21,7 @@ module.exports = {
84
21
  jacketId: "JACKET-R-001",
85
22
  plateNumber: "RAD101A",
86
23
  securityClearanceId: "11111111-1111-1111-1111-111111111111", // RIDER
87
- primaryPhoneId: "11111111-1111-1111-1111-111111111111",
24
+ primaryPhoneId: null, // Will update after phone_contacts are created
88
25
  isActive: true,
89
26
  lastLoginAt: null,
90
27
  createdAt: now,
@@ -96,7 +33,7 @@ module.exports = {
96
33
  email: "jane@passenger.com",
97
34
  password: passwordHash,
98
35
  securityClearanceId: "22222222-2222-2222-2222-222222222222", // PASSENGER
99
- primaryPhoneId: "22222222-2222-2222-2222-222222222222",
36
+ primaryPhoneId: null,
100
37
  isActive: true,
101
38
  lastLoginAt: null,
102
39
  createdAt: now,
@@ -109,7 +46,7 @@ module.exports = {
109
46
  email: "alice@agent.com",
110
47
  password: passwordHash,
111
48
  securityClearanceId: "33333333-3333-3333-3333-333333333333", // AGENT
112
- primaryPhoneId: "33333333-3333-3333-3333-333333333333",
49
+ primaryPhoneId: null,
113
50
  isActive: true,
114
51
  lastLoginAt: null,
115
52
  createdAt: now,
@@ -122,7 +59,7 @@ module.exports = {
122
59
  email: "eric@admin.com",
123
60
  password: passwordHash,
124
61
  securityClearanceId: "44444444-4444-4444-4444-444444444444", // ADMIN
125
- primaryPhoneId: "44444444-4444-4444-4444-444444444444",
62
+ primaryPhoneId: null,
126
63
  isActive: true,
127
64
  lastLoginAt: null,
128
65
  createdAt: now,
@@ -135,12 +72,103 @@ module.exports = {
135
72
  password: passwordHash,
136
73
  nationalId: nid_4,
137
74
  securityClearanceId: "55555555-5555-5555-5555-555555555555", // SUPER_ADMIN
138
- primaryPhoneId: "55555555-5555-5555-5555-555555555555",
75
+ primaryPhoneId: null,
139
76
  isActive: true,
140
77
  lastLoginAt: null,
141
78
  createdAt: now,
142
79
  },
143
80
  ]);
81
+
82
+ // STEP 2: Create phone contacts (now users exist)
83
+ await queryInterface.bulkInsert("phone_contacts", [
84
+ {
85
+ id: "11111111-1111-1111-1111-111111111111",
86
+ phoneNumber: "+250788000001",
87
+ userId: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
88
+ isVerified: true,
89
+ verifiedAt: now,
90
+ isPrimary: true,
91
+ isActive: true,
92
+ metadata: Sequelize.literal("'{}'::jsonb"),
93
+ createdAt: now,
94
+ updatedAt: now,
95
+ },
96
+ {
97
+ id: "22222222-2222-2222-2222-222222222222",
98
+ phoneNumber: "+250788000002",
99
+ userId: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa2",
100
+ isVerified: true,
101
+ verifiedAt: now,
102
+ isPrimary: true,
103
+ isActive: true,
104
+ metadata: Sequelize.literal("'{}'::jsonb"),
105
+ createdAt: now,
106
+ updatedAt: now,
107
+ },
108
+ {
109
+ id: "33333333-3333-3333-3333-333333333333",
110
+ phoneNumber: "+250788000003",
111
+ userId: "aaaaaaa2-aaaa-aaaa-aaaa-aaaaaaaaaaa3",
112
+ isVerified: true,
113
+ verifiedAt: now,
114
+ isPrimary: true,
115
+ isActive: true,
116
+ metadata: Sequelize.literal("'{}'::jsonb"),
117
+ createdAt: now,
118
+ updatedAt: now,
119
+ },
120
+ {
121
+ id: "44444444-4444-4444-4444-444444444444",
122
+ phoneNumber: "+250788000004",
123
+ userId: "aaaaaaa3-aaaa-aaaa-aaaa-aaaaaaaaaaa4",
124
+ isVerified: true,
125
+ verifiedAt: now,
126
+ isPrimary: true,
127
+ isActive: true,
128
+ metadata: Sequelize.literal("'{}'::jsonb"),
129
+ createdAt: now,
130
+ updatedAt: now,
131
+ },
132
+ {
133
+ id: "55555555-5555-5555-5555-555555555555",
134
+ phoneNumber: "+250788000005",
135
+ userId: "aaaaaaa4-aaaa-aaaa-aaaa-aaaaaaaaaaa5",
136
+ isVerified: true,
137
+ verifiedAt: now,
138
+ isPrimary: true,
139
+ isActive: true,
140
+ metadata: Sequelize.literal("'{}'::jsonb"),
141
+ createdAt: now,
142
+ updatedAt: now,
143
+ },
144
+ ]);
145
+
146
+ // STEP 3: Update users with their primaryPhoneId
147
+ await queryInterface.bulkUpdate(
148
+ "users",
149
+ { primaryPhoneId: "11111111-1111-1111-1111-111111111111" },
150
+ { id: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1" }
151
+ );
152
+ await queryInterface.bulkUpdate(
153
+ "users",
154
+ { primaryPhoneId: "22222222-2222-2222-2222-222222222222" },
155
+ { id: "aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa2" }
156
+ );
157
+ await queryInterface.bulkUpdate(
158
+ "users",
159
+ { primaryPhoneId: "33333333-3333-3333-3333-333333333333" },
160
+ { id: "aaaaaaa2-aaaa-aaaa-aaaa-aaaaaaaaaaa3" }
161
+ );
162
+ await queryInterface.bulkUpdate(
163
+ "users",
164
+ { primaryPhoneId: "44444444-4444-4444-4444-444444444444" },
165
+ { id: "aaaaaaa3-aaaa-aaaa-aaaa-aaaaaaaaaaa4" }
166
+ );
167
+ await queryInterface.bulkUpdate(
168
+ "users",
169
+ { primaryPhoneId: "55555555-5555-5555-5555-555555555555" },
170
+ { id: "aaaaaaa4-aaaa-aaaa-aaaa-aaaaaaaaaaa5" }
171
+ );
144
172
  },
145
173
 
146
174
  async down(queryInterface) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Database migration and seeding package for VR applications",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",