Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update notification branch with master #220

Merged
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.1.0
This release adds notifications to the orion infrastructure...

# 3.0.2
### Bug Fixes:
- Store membership handles both as utf-8 string and raw bytes - [#4950](https://github.com/Joystream/joystream/pull/4950)
# 3.0.1
### Misc
- add migration for the `Account` id field
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions docs/operator-guide/tutorials/backups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Backing up Orion database
It is recommended to schedule daily backups for the `orion-db` service.
This will ensure that a copy of the whole database is saved daily to be used for emergencies
This guide shows a simple method in order to back up `orion-db` using the [cron](https://en.wikipedia.org/wiki/Cron) utility.

Suppose you want to back up orion a daily cron job at 9:00 AM CET. Provided that the `orion-db` service is being run in a docker container, you can follow these steps:

1. Open your crontab file for editing. You can do this by running the following command:

```bash
crontab -e
```

2. Add the following line to your crontab file. This line schedules the job to run every day at 9:00 AM CET:

```bash
0 9 * * * TZ='Europe/Paris' docker exec orion-db pg_dumpall -U postgres > "/path/to/backup/directory/orion-production-$(date '+\%Y-\%m-\%d').bak"
```

Make sure to replace `/path/to/backup/directory` with the actual path where you want to store the backup files.

Here's what each field in the cron expression means:

- `0`: Minutes field, specifying 0 minutes past the hour.
- `9`: Hours field, specifying 9 AM.
- `*`: Wildcard for days of the month, meaning it will run every day.
- `*`: Wildcard for months, meaning it will run every month.
- `*`: Wildcard for days of the week, meaning it will run every day of the week.
- `TZ='Europe/Paris'`: Sets the timezone to CET (Central European Time) to ensure it runs at 9:00 AM CET.

3. Save and exit the crontab file. The cron job is now scheduled to run daily at 9:00 AM CET and will dump the PostgreSQL database to the specified backup file with the current date in the filename.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions schema/membership.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ type Membership @entity {
"Timestamp of the block the membership was created at"
createdAt: DateTime!

"The unique handle chosen by member"
handle: String! @unique
"The handle coming from decoded handleRaw if possible"
handle: String!

"The handle chosen by member coming from event deposit"
handleRaw: String! @unique

"Member's metadata"
metadata: MemberMetadata @derivedFrom(field: "member")
Expand Down
2 changes: 2 additions & 0 deletions src/auth-server/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ export async function signedAction<T extends components['schemas']['ActionExecut

async function insertFakeMember(controllerAccount: string) {
const em = await globalEm
const handle = uniqueId()
return em.getRepository(Membership).save({
createdAt: new Date(),
id: uniqueId(),
controllerAccount,
handle: uniqueId(),
handleRaw: '0x' + Buffer.from(handle).toString('hex'),
totalChannelsCreated: 0,
})
}
Expand Down
1 change: 1 addition & 0 deletions src/mail-scheduler/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function populateDbWithSeedData() {
bannedFromChannels: [],
totalChannelsCreated: 0,
handle: `handle-${i}`,
handleRaw: '0x' + Buffer.from(`handle-${i}`).toString('hex'),
controllerAccount: `j4${i}7rVcUCxi2crhhjRq46fNDRbVHTjJrz6bKxZwehEMQxZeSf`,
channels: [],
})
Expand Down
14 changes: 11 additions & 3 deletions src/mappings/membership/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { u8aToHex } from '@polkadot/util'
import {
Event,
Membership,
Expand All @@ -20,16 +21,18 @@ export async function processNewMember({
| 'Members.MembershipGifted'
>) {
const [memberId, params] = 'isV2001' in event && event.isV2001 ? event.asV2001 : event.asV1000
const { controllerAccount, handle, metadata: metadataBytes } = params
const { controllerAccount, handle: handleBytes, metadata: metadataBytes } = params
const metadata = deserializeMetadata(MembershipMetadata, metadataBytes)

const member = overlay.getRepository(Membership).new({
createdAt: new Date(block.timestamp),
id: memberId.toString(),
controllerAccount: toAddress(controllerAccount),
handle: handle && bytesToString(handle),
totalChannelsCreated: 0,
})
if (handleBytes) {
updateMemberHandle(member as Membership, handleBytes)
}

if (metadata) {
await processMembershipMetadata(overlay, member.id, metadata)
Expand Down Expand Up @@ -57,7 +60,7 @@ export async function processMemberProfileUpdatedEvent({
const member = await overlay.getRepository(Membership).getByIdOrFail(memberId.toString())

if (newHandle) {
member.handle = newHandle.toString()
updateMemberHandle(member as Membership, newHandle)
}

if (newMetadata) {
Expand All @@ -68,6 +71,11 @@ export async function processMemberProfileUpdatedEvent({
}
}

function updateMemberHandle(member: Membership, newHandle: Uint8Array) {
member.handleRaw = u8aToHex(newHandle)
member.handle = bytesToString(newHandle)
}

export async function processMemberRemarkedEvent({
overlay,
block,
Expand Down
2 changes: 1 addition & 1 deletion src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { Event } from './types/support'
import { assertAssignable } from './utils/misc'
import { EntityManagerOverlay } from './utils/overlay'
import { EventNames, EventHandler, eventConstructors, EventInstance } from './utils/events'
import { commentCountersManager, videoRelevanceManager, migrateCounters } from './mappings/utils'
import { commentCountersManager, migrateCounters, videoRelevanceManager } from './mappings/utils'
import { EntityManager } from 'typeorm'
import { OffchainState } from './utils/offchainState'

Expand Down
Loading
Loading