Skip to content

Commit 80b2fbf

Browse files
authored
Merge pull request #1144 from dm3-org/develop
Release 1.6
2 parents bf70292 + 730297e commit 80b2fbf

File tree

162 files changed

+5041
-3211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+5041
-3211
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
run: |
157157
ssh -i ./ssh-key root@${{ vars.HOST_DOMAIN }} "\
158158
ufw allow from 172.18.0.1/16 proto tcp to ${{ vars.HOST_IP}} port 80;
159-
ufw allow from 172.18.0.1/16 proto tcp to ${{ secrets.IP_ADDRESS }} port 443;
159+
ufw allow from 172.18.0.1/16 proto tcp to ${{ vars.HOST_IP }} port 443;
160160
ufw enable"
161161
- name: Start docker on server
162162
run: |

packages/backend/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
cd ../../ && yarn build
99
```
1010

11+
#### Contributing
12+
13+
Whenever the prisma schema is updated, run the following command to generate the types:
14+
15+
1. `prisma-create-migrations`: this will add a new migration to the migrations folder, which will be committed to the repository. Our server environments do not generate the migrations on the fly, so we need to commit the migration to the repository. This requires a running database, so make sure to have the database running before running this command.
16+
2. `prisma-generate`: this will generate the types for the prisma schema (and the client). This step is executed automatically when running on the server.
17+
18+
Fogetting step #1 will result in the server not being able to start, as the types will be missing.
19+
1120
### Usage
1221

1322
yarn
1423

1524
```
1625
yarn start
1726
```
18-
19-
npm
20-
21-
```
22-
npm start
23-
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Input file
4+
input_file="dump.txt"
5+
6+
DB_NAME="dm3"
7+
DB_USER="prisma"
8+
9+
10+
# Read the input file line by line
11+
while IFS= read -r line
12+
do
13+
# Extract the ID (first part of the line) and timestamp (after "createdAt")
14+
id=$(echo "$line" | cut -d ':' -f 2)
15+
timestamp=$(echo "$line" | grep -oP '(?<="createdAt":)[0-9]+')
16+
17+
# Convert the timestamp from milliseconds to seconds
18+
timestamp_seconds=$(echo $timestamp | sed 's/...$//')
19+
20+
# Insert the extracted values into the PostgreSQL table
21+
psql -U $DB_USER -d $DB_NAME -c "INSERT INTO \"Account\" (id, \"createdAt\") \
22+
VALUES ('$id', to_timestamp($timestamp_seconds))\
23+
ON CONFLICT (id) \
24+
DO UPDATE SET \"createdAt\" = excluded.\"createdAt\";"
25+
26+
done < "$input_file"
27+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Process:
2+
3+
check data
4+
`docker exec -it dm3-db-1 redis-cli --scan --pattern 'session*addr.dm3.eth'`
5+
6+
`docker exec -it dm3-storage psql -U prisma -d dm3 -c 'SELECT * FROM "Account";'`
7+
8+
go into the redis container
9+
docker exec -it dm3-db-1 bash
10+
11+
dump all relevant sessions
12+
for key in `redis-cli --scan --pattern 'session*addr.dm3.eth'`; do echo $key: `redis-cli GET $key` >> dump.txt; echo $key; done
13+
14+
copy the dump to the host
15+
docker cp dm3-db-1:/data/dump.txt .
16+
17+
copy the dump to the postgres container
18+
docker cp dump.txt dm3-storage:/
19+
20+
paste script onto server
21+
vi insertWithinDocker.sh
22+
-> paste, close
23+
24+
copy the script to the postgres container
25+
docker cp insertWithinDocker.sh dm3-storage:/
26+
27+
go into the postgres container
28+
docker exec -it dm3-storage bash
29+
30+
make script executable
31+
chmod a+x insertWithinDocker.sh
32+
33+
run the script
34+
./insertWithinDocker.sh
35+
36+
check the data from outside the container
37+
docker exec -it dm3-storage psql -U prisma -d dm3 -c 'SELECT \* FROM "Account";'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Account" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Conversation" ADD COLUMN "encryptedProfileLocation" TEXT NOT NULL DEFAULT '';

packages/backend/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dm3-org/dm3-backend",
33
"license": "BSD-2-Clause",
4-
"version": "1.5.0",
4+
"version": "1.6.0",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"dependencies": {
@@ -27,15 +27,16 @@
2727
"yaml": "^2.1.3"
2828
},
2929
"scripts": {
30-
"docker:up": "docker-compose up -d",
30+
"docker:up": "docker compose up -d",
3131
"prisma-init": "prisma generate && prisma migrate deploy ",
32+
"prisma-create-migrations": "prisma generate && prisma migrate dev",
3233
"start": "yarn prisma-init && node ./dist/index.js",
3334
"start-inspect": "node --inspect=0.0.0.0:9229 ./dist/index.js",
3435
"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*)/)'",
35-
"build": "yarn tsc && cp ./config.yml ./dist/config.yml | true",
36+
"build": "yarn prisma generate && yarn tsc && cp ./config.yml ./dist/config.yml | true",
3637
"build:schema": "sh ./schemas.sh",
3738
"createDeliveryServiceProfile": "node --no-warnings ./cli.js",
38-
"before:tests": "docker-compose -f docker-compose.test.yml up -d && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn prisma-init"
39+
"before:tests": "docker compose -f docker-compose.test.yml up -d && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn prisma-init"
3940
},
4041
"devDependencies": {
4142
"@babel/core": "^7.19.6",

packages/backend/schema.prisma

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ model EncryptedMessage {
2222
}
2323

2424
model Conversation {
25-
id String @id @default(uuid())
26-
updatedAt DateTime @default(now())
27-
encryptedContactName String
28-
Message EncryptedMessage[]
29-
Account Account @relation(fields: [accountId], references: [id])
30-
accountId String
31-
isHidden Boolean @default(false)
25+
id String @id @default(uuid())
26+
updatedAt DateTime @default(now())
27+
encryptedContactName String
28+
encryptedProfileLocation String @default("")
29+
Message EncryptedMessage[]
30+
Account Account @relation(fields: [accountId], references: [id])
31+
accountId String
32+
isHidden Boolean @default(false)
3233
}
3334

3435
model Account {
3536
id String @id
37+
createdAt DateTime @default(now())
3638
conversations Conversation[]
3739
EncryptedMessage EncryptedMessage[]
3840
}

packages/backend/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import express from 'express';
1414
import http from 'http';
1515
import path from 'path';
1616
import { getDatabase } from './persistence/getDatabase';
17-
import Profile from './profile';
1817
import Storage from './storage';
18+
import Profile from './profile/profile';
1919

2020
const app = express();
2121
app.use(express.json({ limit: '50mb' }));
@@ -35,11 +35,11 @@ app.use(bodyParser.json());
3535
app.use(logRequest);
3636

3737
app.get('/hello', (req, res) => {
38-
return res.send('Hello DM3');
38+
return res.status(200).send('Hello DM3');
3939
});
4040
app.use('/profile', Profile(db, web3Provider, serverSecret));
4141
app.use('/storage', Storage(db, web3Provider, serverSecret));
42-
app.use('/auth', Auth(db.getAccount as any, serverSecret));
42+
app.use('/auth', Auth(db, serverSecret, web3Provider));
4343
app.use(logError);
4444
app.use(errorHandler);
4545
})();

packages/backend/src/persistence/session/getAccount.ts renamed to packages/backend/src/persistence/account/getAccount.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export function getAccount(redis: Redis) {
88
RedisPrefix.Account + (await getIdEnsName(redis)(ensName)),
99
);
1010

11+
console.debug('get account ', ensName, session);
12+
1113
return session
1214
? (JSON.parse(session) as Session & {
1315
spamFilterRules: spamFilter.SpamFilterRules;

0 commit comments

Comments
 (0)