mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
create new communities table and entity
This commit is contained in:
parent
89283fa3da
commit
e3fa8012ab
25
database/entity/0054-add_communities_table/Community.ts
Normal file
25
database/entity/0054-add_communities_table/Community.ts
Normal 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
|
||||
}
|
||||
1
database/entity/Community.ts
Normal file
1
database/entity/Community.ts
Normal file
@ -0,0 +1 @@
|
||||
export { Community } from './0054-add_communities_table/Community'
|
||||
28
database/migrations/0054-add_communities_table.ts
Normal file
28
database/migrations/0054-add_communities_table.ts
Normal 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;`)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user