mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
add community handshake states table and enum
This commit is contained in:
parent
905388f1a0
commit
d6d626c848
@ -0,0 +1,19 @@
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE community_handshake_states (
|
||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||
handshake_id int unsigned NOT NULL,
|
||||
one_time_code int unsigned NOT NULL,
|
||||
public_key binary(32) NOT NULL,
|
||||
status varchar(255) NOT NULL DEFAULT 'OPEN_CONNECTION',
|
||||
last_error text,
|
||||
created_at datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_public_key (public_key),
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`DROP TABLE community_handshake_states;`)
|
||||
}
|
||||
39
database/src/entity/CommunityHandshakeState.ts
Normal file
39
database/src/entity/CommunityHandshakeState.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { CommunityHandshakeStateType } from '../enum'
|
||||
import { BaseEntity, Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
|
||||
import { FederatedCommunity } from './FederatedCommunity'
|
||||
|
||||
@Entity('community_handshake_states')
|
||||
export class CommunityHandshakeState extends BaseEntity {
|
||||
@PrimaryGeneratedColumn({ unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'handshake_id', type: 'int', unsigned: true })
|
||||
handshakeId: number
|
||||
|
||||
@Column({ name: 'one_time_code', type: 'int', unsigned: true })
|
||||
oneTimeCode: number
|
||||
|
||||
@Column({ name: 'public_key', type: 'binary', length: 32 })
|
||||
publicKey: Buffer
|
||||
|
||||
@Column({
|
||||
type: 'varchar',
|
||||
length: 255,
|
||||
default: CommunityHandshakeStateType.OPEN_CONNECTION,
|
||||
nullable: false,
|
||||
})
|
||||
status: CommunityHandshakeStateType
|
||||
|
||||
@Column({ name: 'last_error', type: 'text', nullable: true })
|
||||
lastError?: string
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'datetime', precision: 3 })
|
||||
createdAt: Date
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'datetime', precision: 3 })
|
||||
updatedAt: Date
|
||||
|
||||
@ManyToOne(() => FederatedCommunity, (federatedCommunity) => federatedCommunity.communityHandshakeStates)
|
||||
@JoinColumn({ name: 'public_key', referencedColumnName: 'publicKey' })
|
||||
federatedCommunity: FederatedCommunity
|
||||
}
|
||||
@ -5,10 +5,12 @@ import {
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
import { Community } from './Community'
|
||||
import { CommunityHandshakeState } from './CommunityHandshakeState'
|
||||
|
||||
@Entity('federated_communities')
|
||||
export class FederatedCommunity extends BaseEntity {
|
||||
@ -60,4 +62,8 @@ export class FederatedCommunity extends BaseEntity {
|
||||
)
|
||||
@JoinColumn({ name: 'public_key', referencedColumnName: 'publicKey' })
|
||||
community?: Community
|
||||
|
||||
@OneToMany(() => CommunityHandshakeState, (communityHandshakeState) => communityHandshakeState.federatedCommunity)
|
||||
@JoinColumn({ name: 'public_key', referencedColumnName: 'publicKey' })
|
||||
communityHandshakeStates: CommunityHandshakeState[]
|
||||
}
|
||||
|
||||
8
database/src/enum/CommunityHandshakeStateType.ts
Normal file
8
database/src/enum/CommunityHandshakeStateType.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export enum CommunityHandshakeStateType {
|
||||
OPEN_CONNECTION = 'OPEN_CONNECTION',
|
||||
OPEN_CONNECTION_CALLBACK = 'OPEN_CONNECTION_CALLBACK',
|
||||
|
||||
SUCCESS = 'SUCCESS',
|
||||
FAILED = 'FAILED',
|
||||
EXPIRED = 'EXPIRED'
|
||||
}
|
||||
1
database/src/enum/index.ts
Normal file
1
database/src/enum/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './CommunityHandshakeStateType'
|
||||
Loading…
x
Reference in New Issue
Block a user