Skip to content

Commit 26d0cd7

Browse files
committed
Fixed migrations
1 parent b9e7ad2 commit 26d0cd7

File tree

4 files changed

+126
-86
lines changed

4 files changed

+126
-86
lines changed

backend/src/migrations/dev/1541649474826-seed.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export async function up(connection: Connection, bffLoggerService: LoggerSharedS
1313
await connection.model('IUserModel', UserSchema).collection.insertMany(data.users);
1414
await connection.model('IAuthenticationModel', AuthenticationSchema).collection.insertMany(data.authentications);
1515
await connection.model('IOrganizationModel', OrganizationSchema).collection.insertMany(data.organizations);
16-
await connection.model('IAccessPermissionsModel', AccessPermissionsSchema).collection.insertMany(data.authorizations);
16+
await connection
17+
.model('IAccessPermissionsModel', AccessPermissionsSchema)
18+
.collection.insertMany(data.accesspermissions);
1719

1820
bffLoggerService.info(`UP script completed.`);
1921
}
@@ -36,7 +38,7 @@ export async function down(connection: Connection, bffLoggerService: LoggerShare
3638

3739
await connection
3840
.model('IAuthorizationModel', AccessPermissionsSchema)
39-
.collection.deleteMany({ id: { $in: data.authorizations.map(item => item._id) } });
41+
.collection.deleteMany({ id: { $in: data.accesspermissions.map(item => item._id) } });
4042

4143
bffLoggerService.info(`DOWN script completed.`);
4244
}

backend/src/migrations/dev/data/seed-data.ts

Lines changed: 114 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,173 +3,211 @@ import { ObjectId } from 'mongodb';
33
export const data = {
44
users: [
55
{
6-
_id: new ObjectId('5be02a02be151604dc7e8b68'),
6+
_id: ObjectId('a00000000000000000000001'),
77
username: '[email protected]',
88
displayName: 'first-name last-name',
9-
createdAt: new Date('2018-11-05T11:31:14.823+0000'),
10-
updatedAt: new Date('2018-11-05T11:31:14.823+0000'),
9+
createdAt: new Date('2019-01-22T03:39:22.756+0000'),
10+
updatedAt: new Date('2019-01-22T03:39:22.756+0000'),
1111
__v: 0,
1212
},
1313
{
14-
_id: new ObjectId('5be02a02be151604dc7e8b6d'),
14+
_id: ObjectId('a00000000000000000000002'),
1515
username: '[email protected]',
1616
displayName: 'first-name last-name',
17-
createdAt: new Date('2018-11-05T11:31:14.916+0000'),
18-
updatedAt: new Date('2018-11-05T11:31:14.916+0000'),
17+
createdAt: new Date('2019-01-22T03:39:23.149+0000'),
18+
updatedAt: new Date('2019-01-22T03:39:23.149+0000'),
1919
__v: 0,
2020
},
2121
{
22-
_id: new ObjectId('5be02a03be151604dc7e8b71'),
22+
_id: ObjectId('b00000000000000000000001'),
2323
username: '[email protected]',
2424
displayName: 'regular user',
25-
createdAt: new Date('2018-11-05T11:31:15.002+0000'),
26-
updatedAt: new Date('2018-11-05T11:31:15.002+0000'),
25+
createdAt: new Date('2019-01-22T03:39:23.234+0000'),
26+
updatedAt: new Date('2019-01-22T03:39:23.234+0000'),
2727
__v: 0,
2828
},
2929
{
30-
_id: new ObjectId('5be02a03be151604dc7e8b76'),
30+
_id: ObjectId('c00000000000000000000001'),
3131
username: '[email protected]',
3232
displayName: 'first-name last-name',
33-
createdAt: new Date('2018-11-05T11:31:15.057+0000'),
34-
updatedAt: new Date('2018-11-05T11:31:15.057+0000'),
33+
createdAt: new Date('2019-01-22T03:39:23.306+0000'),
34+
updatedAt: new Date('2019-01-22T03:39:23.306+0000'),
35+
__v: 0,
36+
},
37+
{
38+
_id: ObjectId('f00000000000000000000001'),
39+
username: '[email protected]',
40+
displayName: 'first-name last-name',
41+
createdAt: new Date('2019-01-22T03:39:23.391+0000'),
42+
updatedAt: new Date('2019-01-22T03:39:23.391+0000'),
3543
__v: 0,
3644
},
3745
],
3846
authentications: [
3947
{
40-
_id: new ObjectId('5be02a02be151604dc7e8b69'),
48+
_id: ObjectId('5c46906ac07baa98e0ce4a32'),
4149
local: {
4250
43-
hashedPassword: '$2a$08$q9rfQYDBcIghPXMT3oeLIeCbB5l5SNbUnynDsKhqrCjWEEbrlQDfW',
51+
hashedPassword: '$2a$08$fkDiwuscJSWmDqEYo86xpejj7hVPGUkVeOMdRQC/dJhXFSjqPPqky',
4452
},
45-
userId: new ObjectId('5be02a02be151604dc7e8b68'),
46-
createdAt: new Date('2018-11-05T11:31:14.834+0000'),
47-
updatedAt: new Date('2018-11-05T11:31:14.834+0000'),
53+
userId: ObjectId('a00000000000000000000001'),
54+
createdAt: new Date('2019-01-22T03:39:22.958+0000'),
55+
updatedAt: new Date('2019-01-22T03:39:22.958+0000'),
4856
__v: 0,
4957
},
5058
{
51-
_id: new ObjectId('5be02a02be151604dc7e8b6e'),
59+
_id: ObjectId('5c46906bc07baa98e0ce4a36'),
5260
local: {
53-
54-
hashedPassword: '$2a$08$PlLJMrM/LtfoW8JdCyT3zemEybdaHLh/ErimQffxoE4LiLDw0CUkq',
61+
email: '() => testdata.orga.users.regularuser.userentity.username',
62+
hashedPassword: '() => encryption_util_1.generateHashedPassword(testData.orgA.users.regularUser.password)',
5563
},
56-
userId: new ObjectId('5be02a02be151604dc7e8b6d'),
57-
createdAt: new Date('2018-11-05T11:31:14.920+0000'),
58-
updatedAt: new Date('2018-11-05T11:31:14.920+0000'),
64+
userId: ObjectId('a00000000000000000000002'),
65+
createdAt: new Date('2019-01-22T03:39:23.167+0000'),
66+
updatedAt: new Date('2019-01-22T03:39:23.167+0000'),
5967
__v: 0,
6068
},
6169
{
62-
_id: new ObjectId('5be02a03be151604dc7e8b72'),
70+
_id: ObjectId('5c46906bc07baa98e0ce4a3b'),
6371
local: {
64-
65-
hashedPassword: '$2a$08$6Xzzgp6JxWjxe5HXl/a4VOtZvFDTmtZ2dSUPrYMzOnvl1N0I05k9y',
72+
email: '() => testdata.orgb.users.adminuser.userentity.username',
73+
hashedPassword: '() => encryption_util_1.generateHashedPassword(testData.orgB.users.adminUser.password)',
6674
},
67-
userId: new ObjectId('5be02a03be151604dc7e8b71'),
68-
createdAt: new Date('2018-11-05T11:31:15.005+0000'),
69-
updatedAt: new Date('2018-11-05T11:31:15.005+0000'),
75+
userId: ObjectId('b00000000000000000000001'),
76+
createdAt: new Date('2019-01-22T03:39:23.251+0000'),
77+
updatedAt: new Date('2019-01-22T03:39:23.251+0000'),
7078
__v: 0,
7179
},
7280
{
73-
_id: new ObjectId('5be02a03be151604dc7e8b77'),
81+
_id: ObjectId('5c46906bc07baa98e0ce4a40'),
7482
local: {
75-
76-
hashedPassword: '$2a$08$7CxALbFD/RewHkDxVmkXb.ejT.x.The5BAMi9OVv/Wzyfp3IUTYsC',
83+
email: '() => testdata.orgc.users.groupadminuser.userentity.username',
84+
hashedPassword: '() => encryption_util_1.generateHashedPassword(testData.orgC.users.groupAdminUser.password)',
7785
},
78-
userId: new ObjectId('5be02a03be151604dc7e8b76'),
79-
createdAt: new Date('2018-11-05T11:31:15.060+0000'),
80-
updatedAt: new Date('2018-11-05T11:31:15.060+0000'),
86+
userId: ObjectId('c00000000000000000000001'),
87+
createdAt: new Date('2019-01-22T03:39:23.325+0000'),
88+
updatedAt: new Date('2019-01-22T03:39:23.325+0000'),
8189
__v: 0,
8290
},
8391
],
8492
organizations: [
8593
{
86-
_id: new ObjectId('5be02a02be151604dc7e8b6a'),
87-
94+
_id: ObjectId('a00000000000000000000000'),
95+
name: 'Org A',
8896
89-
createdAt: new Date('2018-11-05T11:31:14.834+0000'),
90-
updatedAt: new Date('2018-11-05T11:31:14.834+0000'),
97+
createdAt: new Date('2019-01-22T03:39:22.663+0000'),
98+
updatedAt: new Date('2019-01-22T03:39:22.663+0000'),
9199
__v: 0,
92100
},
93101
{
94-
_id: new ObjectId('5be02a03be151604dc7e8b73'),
95-
102+
_id: ObjectId('b00000000000000000000000'),
103+
name: 'Org B',
96104
97-
createdAt: new Date('2018-11-05T11:31:15.005+0000'),
98-
updatedAt: new Date('2018-11-05T11:31:15.005+0000'),
105+
createdAt: new Date('2019-01-22T03:39:23.215+0000'),
106+
updatedAt: new Date('2019-01-22T03:39:23.215+0000'),
99107
__v: 0,
100108
},
101109
{
102-
_id: new ObjectId('5be02a03be151604dc7e8b78'),
103-
110+
_id: ObjectId('c00000000000000000000000'),
111+
name: 'Org C',
104112
105-
createdAt: new Date('2018-11-05T11:31:15.060+0000'),
106-
updatedAt: new Date('2018-11-05T11:31:15.060+0000'),
113+
createdAt: new Date('2019-01-22T03:39:23.292+0000'),
114+
updatedAt: new Date('2019-01-22T03:39:23.292+0000'),
115+
__v: 0,
116+
},
117+
{
118+
_id: ObjectId('f00000000000000000000000'),
119+
name: 'Org Z',
120+
121+
createdAt: new Date('2019-01-22T03:39:23.373+0000'),
122+
updatedAt: new Date('2019-01-22T03:39:23.373+0000'),
107123
__v: 0,
108124
},
109125
],
110-
authorizations: [
126+
accesspermissions: [
111127
{
112-
_id: new ObjectId('5be02a02be151604dc7e8b6b'),
128+
_id: ObjectId('a00000000000000000000011'),
113129
roles: ['user'],
114130
organizations: [
115131
{
116-
organizationRoles: ['member', 'admin'],
117-
_id: new ObjectId('5be02a02be151604dc7e8b6c'),
132+
organizationRoles: ['admin'],
133+
_id: ObjectId('5c46906bc07baa98e0ce4a34'),
118134
primary: true,
119-
orgId: new ObjectId('5be02a02be151604dc7e8b6a'),
135+
orgId: ObjectId('a00000000000000000000000'),
120136
},
121137
],
122-
userId: new ObjectId('5be02a02be151604dc7e8b68'),
123-
createdAt: new Date('2018-11-05T11:31:14.849+0000'),
124-
updatedAt: new Date('2018-11-05T11:31:14.849+0000'),
138+
userId: ObjectId('a00000000000000000000001'),
139+
createdAt: new Date('2019-01-22T03:39:23.058+0000'),
140+
updatedAt: new Date('2019-01-22T03:39:23.058+0000'),
125141
__v: 0,
126142
},
127143
{
128-
_id: new ObjectId('5be02a02be151604dc7e8b6f'),
144+
_id: ObjectId('a00000000000000000000022'),
129145
roles: ['user'],
130146
organizations: [
131147
{
132148
organizationRoles: ['member'],
133-
_id: new ObjectId('5be02a02be151604dc7e8b70'),
149+
_id: ObjectId('5c46906bc07baa98e0ce4a38'),
134150
primary: true,
135-
orgId: new ObjectId('5be02a02be151604dc7e8b6a'),
151+
orgId: ObjectId('a00000000000000000000000'),
136152
},
137153
],
138-
userId: new ObjectId('5be02a02be151604dc7e8b6d'),
139-
createdAt: new Date('2018-11-05T11:31:14.920+0000'),
140-
updatedAt: new Date('2018-11-05T11:31:14.920+0000'),
154+
userId: ObjectId('a00000000000000000000002'),
155+
createdAt: new Date('2019-01-22T03:39:23.195+0000'),
156+
updatedAt: new Date('2019-01-22T03:39:23.195+0000'),
141157
__v: 0,
142158
},
143159
{
144-
_id: new ObjectId('5be02a03be151604dc7e8b74'),
160+
_id: ObjectId('b00000000000000000000011'),
145161
roles: ['user'],
146162
organizations: [
147163
{
148-
organizationRoles: ['member', 'admin'],
149-
_id: new ObjectId('5be02a03be151604dc7e8b75'),
164+
organizationRoles: ['admin'],
165+
_id: ObjectId('5c46906bc07baa98e0ce4a3d'),
150166
primary: true,
151-
orgId: new ObjectId('5be02a03be151604dc7e8b73'),
167+
orgId: ObjectId('b00000000000000000000000'),
168+
},
169+
],
170+
userId: ObjectId('b00000000000000000000001'),
171+
createdAt: new Date('2019-01-22T03:39:23.274+0000'),
172+
updatedAt: new Date('2019-01-22T03:39:23.274+0000'),
173+
__v: 0,
174+
},
175+
{
176+
_id: ObjectId('c00000000000000000000011'),
177+
roles: ['groupAdmin'],
178+
organizations: [
179+
{
180+
organizationRoles: ['admin'],
181+
_id: ObjectId('5c46906bc07baa98e0ce4a43'),
182+
primary: true,
183+
orgId: ObjectId('c00000000000000000000000'),
184+
},
185+
{
186+
organizationRoles: ['facilitator'],
187+
_id: ObjectId('5c46906bc07baa98e0ce4a42'),
188+
primary: false,
189+
orgId: ObjectId('a00000000000000000000000'),
152190
},
153191
],
154-
userId: new ObjectId('5be02a03be151604dc7e8b71'),
155-
createdAt: new Date('2018-11-05T11:31:15.009+0000'),
156-
updatedAt: new Date('2018-11-05T11:31:15.009+0000'),
192+
userId: ObjectId('c00000000000000000000001'),
193+
createdAt: new Date('2019-01-22T03:39:23.354+0000'),
194+
updatedAt: new Date('2019-01-22T03:39:23.354+0000'),
157195
__v: 0,
158196
},
159197
{
160-
_id: new ObjectId('5be02a03be151604dc7e8b79'),
161-
roles: ['user', 'groupAdmin'],
198+
_id: ObjectId('f00000000000000000000011'),
199+
roles: ['systemAdmin'],
162200
organizations: [
163201
{
164-
organizationRoles: ['member', 'admin'],
165-
_id: new ObjectId('5be02a03be151604dc7e8b7a'),
202+
organizationRoles: ['admin'],
203+
_id: ObjectId('5c46906bc07baa98e0ce4a47'),
166204
primary: true,
167-
orgId: new ObjectId('5be02a03be151604dc7e8b78'),
205+
orgId: ObjectId('f00000000000000000000000'),
168206
},
169207
],
170-
userId: new ObjectId('5be02a03be151604dc7e8b76'),
171-
createdAt: new Date('2018-11-05T11:31:15.063+0000'),
172-
updatedAt: new Date('2018-11-05T11:31:15.075+0000'),
208+
userId: ObjectId('f00000000000000000000001'),
209+
createdAt: new Date('2019-01-22T03:39:23.412+0000'),
210+
updatedAt: new Date('2019-01-22T03:39:23.412+0000'),
173211
__v: 0,
174212
},
175213
],

packages/pkg-backend/src/application/user-auth/user-auth.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ export class UserAuthService {
3434
public async signInWithLocal(cmd: LocalAuthenticateCommand): Promise<AccessPermissionsEntity> {
3535
const authenticationEntity = await this.authenticationRepo.findOne({ 'local.email': cmd.username }, { skipAuthorization: true });
3636

37-
if (!authenticationEntity) throw new ValidationError(['Your login accessPermissions were not correct']);
37+
if (!authenticationEntity) throw new ValidationError(['Your login credentials were not correct']);
3838
if (!authenticationEntity.local)
39-
throw new ValidationError(['Your login accessPermissions were not correct or you do not have an account. Perhaps you registered with social login?']);
39+
throw new ValidationError(['Your login credentials were not correct or you do not have an account. Perhaps you registered with social login?']);
4040
if (!authenticationEntity.userId) throw new AppError('UserId can not be null');
4141

42-
if (!validPassword(cmd.password, authenticationEntity.local.hashedPassword)) throw new ValidationError(['Your login accessPermissions were not correct']);
42+
if (!validPassword(cmd.password, authenticationEntity.local.hashedPassword)) throw new ValidationError(['Your login credentials were not correct']);
4343

4444
const accessPermissionsEntity = await this.accessPermissionsRepo.findOne({ userId: authenticationEntity.userId }, { skipAuthorization: true });
4545

46-
if (!accessPermissionsEntity) throw new AppError('Could not find authorization information for signIn');
46+
if (!accessPermissionsEntity) throw new AppError('Could not find access permission information for signIn');
4747

4848
return accessPermissionsEntity;
4949
}

packages/pkg-backend/src/shared/migrations/migrations.shared.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class MigrationsSharedService {
187187
}
188188

189189
/**
190-
* Looks at the file system migrations and imports any migrations that are
190+
* Looks at the file system migrations and import any migrations that are
191191
* on the file system but missing in the database into the database
192192
*
193193
* This functionality is opposite of prune()
@@ -312,7 +312,7 @@ export class MigrationsSharedService {
312312

313313
if (migrationsInDatabase.length > 0) {
314314
this.bffLoggerService.log('\n');
315-
this.bffLoggerService.log(`The following migrations are in the database:`);
315+
this.bffLoggerService.log(`The following migrations were detected:`);
316316
migrationsInDatabase.map(m => {
317317
this.bffLoggerService.log(`${m.filename} (${m.state === MigrationState.Up ? 'UP:' : 'DOWN'})`);
318318
});
@@ -347,7 +347,7 @@ export class MigrationsSharedService {
347347

348348
const migrationsInDatabase = await this.migrationModel.find({}).sort({ createdAt: 1 });
349349

350-
this.bffLoggerService.debug('compareFileSystemWithDB.migrationsInDatabase', migrationsInDatabase);
350+
// this.bffLoggerService.debug('compareFileSystemWithDB.migrationsInDatabase', migrationsInDatabase);
351351

352352
const migrationsInFolder = filesInMigrationFolder
353353
.filter(file => /\d{13,}\-.+.(ts)$/.test(file))
@@ -357,7 +357,7 @@ export class MigrationsSharedService {
357357
return { createdAt: fileCreatedAt, filename, existsInDatabase };
358358
});
359359

360-
this.bffLoggerService.debug('compareFileSystemWithDB.migrationsInFolder', filesInMigrationFolder, migrationsInFolder);
360+
// this.bffLoggerService.debug('compareFileSystemWithDB.migrationsInFolder', filesInMigrationFolder, migrationsInFolder);
361361

362362
const filesNotInDb = migrationsInFolder.filter(migrationInFolder => migrationInFolder.existsInDatabase === false).map(f => f.filename);
363363
const dbMigrationsNotOnFs = migrationsInDatabase.filter(migrationInDB => {

0 commit comments

Comments
 (0)