create new communities table and entity

This commit is contained in:
Claus-Peter Hübner 2022-11-25 17:52:56 +01:00
parent 89283fa3da
commit e3fa8012ab
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
@Entity('community')
export class Community extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ name: 'public_key', type: 'binary', length: 32, default: null, nullable: true })
publicKey: Buffer
@Column({ name: 'api_version', length: 10, nullable: false })
apiVersion: string
@Column({ name: 'endpoint', length: 255, nullable: false })
endPoint: string
@Column({ name: 'last_announced_at', type: 'datetime', nullable: false })
lastAnnouncedAt: Date
@Column({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP', nullable: false })
createdAt: Date
@Column({ name: 'updated_at', type: 'datetime', nullable: true, default: null })
updatedAt: Date | null
}

View File

@ -0,0 +1 @@
export { Community } from './0054-add_communities_table/Community'

View File

@ -0,0 +1,28 @@
/* MIGRATION TO CREATE THE FEDERATION COMMUNITY TABLES
*
* This migration creates the `community` and 'communityfederation' tables in the `apollo` database (`gradido_community`).
*/
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(`
CREATE TABLE IF NOT EXISTS communities (
id int unsigned NOT NULL AUTO_INCREMENT,
public_key binary(32),
api_version varchar(10) NOT NULL,
endpoint varchar(255) NOT NULL,
last_announced_at datetime(3) NOT NULL,
created_at datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at datetime(3),
PRIMARY KEY (id),
UNIQUE KEY public_api_key (public_key, api_version)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
`)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// write downgrade logic as parameter of queryFn
await queryFn(`DROP TABLE IF EXISTS communities;`)
}