Skip to content

Commit

Permalink
Merge pull request #1061 from dm3-org/fix/prismaMigrateDeploy2
Browse files Browse the repository at this point in the history
use prisma migrate deploy instead of dev
  • Loading branch information
malteish authored Jul 15, 2024
2 parents 667dc66 + 20cc981 commit 53be4dd
Show file tree
Hide file tree
Showing 31 changed files with 58 additions and 518 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:

jobs:
messenger-web-deploy:
environment: ${{ github.ref_name == 'main' && 'prod' || (github.ref == 'develop' && 'staging' || 'testing') }}
environment: ${{ github.ref_name == 'main' && 'prod' || (github.ref_name == 'develop' && 'staging' || 'testing') }}
runs-on: ubuntu-latest
env:
environment_name: ${{ github.ref_name == 'main' && 'prod' || (github.ref == 'develop' && 'staging' || 'testing') }}
environment_name: ${{ github.ref_name == 'main' && 'prod' || (github.ref_name == 'develop' && 'staging' || 'testing') }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"docker:up": "docker-compose up -d",
"prisma-init": "prisma generate && prisma migrate dev ",
"prisma-init": "prisma generate && prisma migrate deploy ",
"start": "yarn prisma-init && node ./dist/index.js",
"start-inspect": "node --inspect=0.0.0.0:9229 ./dist/index.js",
"test": "yarn run before:tests && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn jest --coverage --runInBand --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'",
Expand Down
9 changes: 0 additions & 9 deletions packages/backend/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ISessionDatabase } from '@dm3-org/dm3-lib-server-side';
import { UserStorage } from '@dm3-org/dm3-lib-storage';
import { PrismaClient } from '@prisma/client';
import { createClient } from 'redis';
import Pending from './pending';
import Session from './session';
import Storage from './storage';
import { ConversationRecord } from './storage/postgres/dto/ConversationRecord';
Expand All @@ -15,7 +14,6 @@ export enum RedisPrefix {
Sync = 'sync:',
Session = 'session:',
UserStorage = 'user.storage:',
Pending = 'pending:',
NotificationChannel = 'notificationChannel:',
GlobalNotification = 'globalNotification:',
Otp = 'otp:',
Expand Down Expand Up @@ -69,10 +67,6 @@ export async function getDatabase(
//Legacy remove after storage has been merged
getUserStorage: Storage.getUserStorageOld(redis),
setUserStorage: Storage.setUserStorageOld(redis),
//Pending
addPending: Pending.addPending(redis),
getPending: Pending.getPending(redis),
deletePending: Pending.deletePending(redis),
//Storage AddConversation
addConversation: Storage.addConversation(prisma),
getConversationList: Storage.getConversationList(prisma),
Expand Down Expand Up @@ -110,9 +104,6 @@ export interface IDatabase extends ISessionDatabase {
//Legacy remove after storage has been merged
getUserStorage: (ensName: string) => Promise<UserStorage | null>;
setUserStorage: (ensName: string, data: string) => Promise<void>;
addPending: (ensName: string, contactEnsName: string) => Promise<void>;
getPending: (ensName: string) => Promise<string[]>;
deletePending: (ensName: string) => Promise<void>;

addConversation: (
ensName: string,
Expand Down
11 changes: 0 additions & 11 deletions packages/backend/src/persistence/pending/addPending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/backend/src/persistence/pending/deletePending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/backend/src/persistence/pending/getPending.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/backend/src/persistence/pending/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const clearHaltedMessage =
const message = await db.encryptedMessage.findFirst({
where: {
id: messageId,
ownerId: account.id,
},
});

Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ describe('Profile', () => {
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};

Expand Down
13 changes: 2 additions & 11 deletions packages/backend/src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ describe('Storage', () => {
})
.send();

console.log(body);

expect(body.length).toBe(1);
expect(body[0].contact).toEqual(sha256(receiver.account.ensName));
expect(JSON.parse(body[0].previewMessage)).toEqual(envelop3);
Expand All @@ -508,8 +506,6 @@ describe('Storage', () => {
})
.send();

console.log(body);

expect(status).toBe(400);
});

Expand All @@ -522,8 +518,6 @@ describe('Storage', () => {
})
.send();

console.log(body);

expect(status).toBe(400);
});
});
Expand Down Expand Up @@ -980,7 +974,7 @@ describe('Storage', () => {
.send({
encryptedEnvelopContainer: JSON.stringify(envelop1),
encryptedContactName: sha256(receiver.account.ensName),
messageId: '123',
messageId: envelop1.metadata.encryptedMessageHash,
createdAt: 1,
isHalted: true,
});
Expand All @@ -1007,7 +1001,7 @@ describe('Storage', () => {
authorization: 'Bearer ' + token,
})
.send({
messageId: 123,
messageId: messages[0].messageId,
});

expect(deleteStatus).toBe(200);
Expand Down Expand Up @@ -1162,9 +1156,6 @@ describe('Storage', () => {
isHalted: false,
});

console.log('xxxx', x.status);
console.log('xxxx', x.body);

await request(app)
.post(`/new/bob.eth/addMessage`)
.set({
Expand Down
12 changes: 1 addition & 11 deletions packages/backend/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,12 @@ export default (
}

const ensName = normalizeEnsName(req.params.ensName);
//Since the message is fully encrypted, we cannot use the messageHash as an identifier.
//Instead we use the hash of the ensName and the messageId to have a unique identifier
const uniqueMessageId = sha256(ensName + messageId);

console.log(
'clearHaltedMessage uniqueMessageId ',
uniqueMessageId,
ensName,
messageId,
);

const success = await db.clearHaltedMessage(
ensName,
//If the aliasName is not provided, we use the ensName as the client has no intention to use an alias
aliasName,
uniqueMessageId,
messageId,
);

if (success) {
Expand Down
43 changes: 0 additions & 43 deletions packages/delivery-service/src/delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,6 @@ describe('Delivery', () => {
});
});

describe('getPendingMessages', () => {
it('Returns 200 if schema is valid', async () => {
const web3Provider = {
resolveName: async () =>
'0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870',
};

const token = await createAuthToken(
'0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870',
);

const db = {
getSession: async (ensName: string) => ({
challenge: 'deprecated challenge',
token: 'deprecated token that is not used anymore',
}),
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
deletePending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};
const app = express();
app.use(bodyParser.json());
app.use(
delivery(web3Provider as any, db as any, keysA, serverSecret),
);

const { status } = await request(app)
.post(
'/messages/0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870/pending',
)
.set({
authorization: `Bearer ${token}`,
})

.send();

expect(status).toBe(200);
});
});

describe('syncAcknoledgment', () => {
it('Returns 200 if schema is valid', async () => {
const web3Provider = {
Expand Down
14 changes: 1 addition & 13 deletions packages/delivery-service/src/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default (
req.params.ensName,
//Fetch the last 10 messages per conversation
//If we decide to add pagination for that endpoint we can pass this value as a param
10,
1000,
);
res.json(incomingMessages);
} catch (e) {
Expand All @@ -97,18 +97,6 @@ export default (
},
);

router.post('/messages/:ensName/pending', async (req, res, next) => {
try {
const account = await db.getIdEnsName(req.params.ensName);
const pending = await db.getPending(account);
await db.deletePending(account);

res.json(pending);
} catch (e) {
next(e);
}
});

//TODO remove after storage refactoring
router.post(
'/messages/:ensName/syncAcknoledgment/:last_message_pull',
Expand Down
33 changes: 0 additions & 33 deletions packages/delivery-service/src/messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,37 +249,4 @@ describe('Messaging', () => {
)(getSocketMock());
});
});

describe('pendingMessage', () => {
it('returns error if schema is invalid', async () => {
const data = {
accountAddress: '',
contactAddress: '',
};
const callback = jest.fn((e: any) => {
if (e.error !== 'invalid schema') {
throw Error(e);
}
expect(e.error).toBe('invalid schema');
});
const getSocketMock = jest.fn(() => {
return {
on: async (name: string, onPendingMessage: any) => {
//We just want to test the submitMessage callback fn
if (name === 'pendingMessage') {
await onPendingMessage(data, callback);
}
},
} as unknown as Socket;
});
onConnection(
io as any,
web3Provider as any,
db as any,
keysA,
serverSecret,
mockWsManager,
)(getSocketMock());
});
});
});
Loading

0 comments on commit 53be4dd

Please sign in to comment.