mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
start db setup for dlt-connector
This commit is contained in:
parent
355b02536b
commit
2aee853f7a
73
dlt-database/entity/0001-init_db/Account.ts
Normal file
73
dlt-database/entity/0001-init_db/Account.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
} from 'typeorm'
|
||||
import { User } from './User'
|
||||
import { Community } from './Community'
|
||||
import { TransactionDraft } from './TransactionDraft'
|
||||
import { ConfirmedTransaction } from './ConfirmedTransaction'
|
||||
|
||||
@Entity('accounts')
|
||||
export class Account {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@ManyToOne(() => User, (user) => user.accounts) // Assuming you have a User entity with 'accounts' relation
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
user: User
|
||||
|
||||
// if user id is null, account belongs to community gmw or auf
|
||||
@Column({ name: 'user_id', type: 'int', unsigned: true, nullable: true })
|
||||
userId?: number
|
||||
|
||||
@Column({ name: 'account_nr', type: 'int', unsigned: true, default: 0 })
|
||||
accountNr: number
|
||||
|
||||
@Column({ type: 'binary', length: 32, unique: true })
|
||||
pubkey: Buffer
|
||||
|
||||
@Column({ type: 'tinyint', unsigned: true })
|
||||
type: number
|
||||
|
||||
@CreateDateColumn({
|
||||
name: 'created_at',
|
||||
type: 'datetime',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
nullable: false,
|
||||
})
|
||||
createdAt: Date
|
||||
|
||||
@Column({ name: 'confirmed_at', type: 'datetime', nullable: true })
|
||||
confirmedAt?: Date
|
||||
|
||||
@OneToOne(() => Community, (community) => community.gmwAccount)
|
||||
gmwCommunity?: Community
|
||||
|
||||
@OneToOne(() => Community, (community) => community.aufAccount)
|
||||
aufCommunity?: Community
|
||||
|
||||
@ManyToMany(() => Community, (community) => community.communityAccounts)
|
||||
@JoinTable({
|
||||
name: 'accounts_communities',
|
||||
joinColumn: { name: 'account_id', referencedColumnName: 'id' },
|
||||
inverseJoinColumn: { name: 'community_id', referencedColumnName: 'id' },
|
||||
})
|
||||
accountCommunities: Community[]
|
||||
|
||||
@OneToMany(() => TransactionDraft, (draft) => draft.signingAccount)
|
||||
transactionDraftsSigning?: TransactionDraft[]
|
||||
|
||||
@OneToMany(() => TransactionDraft, (draft) => draft.recipientAccount)
|
||||
transactionDraftsRecipient?: TransactionDraft[]
|
||||
|
||||
@OneToMany(() => ConfirmedTransaction, (transaction) => transaction.account)
|
||||
confirmedTransactions?: ConfirmedTransaction[]
|
||||
}
|
||||
30
dlt-database/entity/0001-init_db/AccountCommunity.ts
Normal file
30
dlt-database/entity/0001-init_db/AccountCommunity.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm'
|
||||
|
||||
import { Account } from './Account'
|
||||
import { Community } from './Community'
|
||||
|
||||
@Entity('accounts_communities')
|
||||
export class AccountCommunity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.accountCommunities)
|
||||
@JoinColumn({ name: 'account_id' })
|
||||
account: Account
|
||||
|
||||
@Column({ name: 'account_id', type: 'int', unsigned: true })
|
||||
accountId: number
|
||||
|
||||
@ManyToOne(() => Community, (community) => community.communityAccounts)
|
||||
@JoinColumn({ name: 'community_id' })
|
||||
community: Community
|
||||
|
||||
@Column({ name: 'community_id', type: 'int', unsigned: true })
|
||||
communityId: number
|
||||
|
||||
@Column({ name: 'valid_from', type: 'datetime' })
|
||||
validFrom: Date
|
||||
|
||||
@Column({ name: 'valid_to', type: 'datetime', nullable: true })
|
||||
validTo?: Date
|
||||
}
|
||||
68
dlt-database/entity/0001-init_db/Community.ts
Normal file
68
dlt-database/entity/0001-init_db/Community.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
JoinColumn,
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
} from 'typeorm'
|
||||
import { Account } from './Account'
|
||||
import { TransactionDraft } from './TransactionDraft'
|
||||
|
||||
@Entity('communities')
|
||||
export class Community {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'iota_topic', collation: 'utf8mb4_unicode_ci' })
|
||||
iotaTopic: string
|
||||
|
||||
@Column({ type: 'binary', length: 32, unique: true })
|
||||
pubkey: Buffer
|
||||
|
||||
@Column({ type: 'binary', length: 32, nullable: true })
|
||||
privkey?: Buffer
|
||||
|
||||
@Column({ type: 'binary', length: 32, nullable: true })
|
||||
chaincode?: Buffer
|
||||
|
||||
@Column({ type: 'tinyint', default: true })
|
||||
foreign: boolean
|
||||
|
||||
@Column({ name: 'gmw_account_id', type: 'int', unsigned: true, nullable: true })
|
||||
gmwAccountId?: number
|
||||
|
||||
@OneToOne(() => Account, (account) => account.gmwCommunity)
|
||||
@JoinColumn({ name: 'gmw_account_id' })
|
||||
gmwAccount?: Account
|
||||
|
||||
@Column({ name: 'auf_account_id', type: 'int', unsigned: true, nullable: true })
|
||||
aufAccountId?: number
|
||||
|
||||
@OneToOne(() => Account, (account) => account.aufCommunity)
|
||||
@JoinColumn({ name: 'auf_account_id' })
|
||||
aufAccount?: Account
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
createdAt: Date
|
||||
|
||||
@Column({ name: 'confirmed_at', type: 'datetime', nullable: true })
|
||||
confirmedAt?: Date
|
||||
|
||||
@ManyToMany(() => Account, (account) => account.accountCommunities)
|
||||
@JoinTable({
|
||||
name: 'accounts_communities',
|
||||
joinColumn: { name: 'community_id', referencedColumnName: 'id' },
|
||||
inverseJoinColumn: { name: 'account_id', referencedColumnName: 'id' },
|
||||
})
|
||||
communityAccounts: Account[]
|
||||
|
||||
@OneToMany(() => TransactionDraft, (draft) => draft.senderCommunity)
|
||||
transactionDraftsSender?: TransactionDraft[]
|
||||
|
||||
@OneToMany(() => TransactionDraft, (draft) => draft.recipientCommunity)
|
||||
transactionDraftsRecipient?: TransactionDraft[]
|
||||
}
|
||||
53
dlt-database/entity/0001-init_db/ConfirmedTransaction.ts
Normal file
53
dlt-database/entity/0001-init_db/ConfirmedTransaction.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
import { Account } from './Account'
|
||||
import { TransactionDraft } from './TransactionDraft'
|
||||
|
||||
@Entity('confirmed_transactions')
|
||||
export class ConfirmedTransaction {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true, type: 'bigint' })
|
||||
id: number
|
||||
|
||||
@ManyToOne(() => TransactionDraft, (draft) => draft.confirmedTransactions)
|
||||
@JoinColumn({ name: 'transaction_draft_id' })
|
||||
transactionDraft: TransactionDraft
|
||||
|
||||
@Column({ name: 'transaction_draft_id', type: 'int', unsigned: true })
|
||||
transactionDraftId: number
|
||||
|
||||
@Column({ type: 'bigint' })
|
||||
nr: number
|
||||
|
||||
@Column({ type: 'binary', length: 48 })
|
||||
runningHash: Buffer
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.confirmedTransactions)
|
||||
@JoinColumn({ name: 'account_id' })
|
||||
account: Account
|
||||
|
||||
@Column({
|
||||
name: 'account_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: false,
|
||||
default: 0,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
accountBalance: Decimal
|
||||
|
||||
@Column({ name: 'iota_milestone', type: 'bigint' })
|
||||
iotaMilestone: number
|
||||
|
||||
@CreateDateColumn({ name: 'confirmed_at', type: 'datetime' })
|
||||
confirmedAt: Date
|
||||
}
|
||||
79
dlt-database/entity/0001-init_db/TransactionDraft.ts
Normal file
79
dlt-database/entity/0001-init_db/TransactionDraft.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
} from 'typeorm'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
import { Account } from './Account'
|
||||
import { Community } from './Community'
|
||||
import { ConfirmedTransaction } from './ConfirmedTransaction'
|
||||
|
||||
@Entity('transaction_drafts')
|
||||
export class TransactionDraft {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true, type: 'bigint' })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'iota_message_id', type: 'binary', length: 32, nullable: true })
|
||||
iotaMessageId?: Buffer
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.transactionDraftsSigning)
|
||||
@JoinColumn({ name: 'signing_account_id' })
|
||||
signingAccount: Account
|
||||
|
||||
@Column({ name: 'signing_account_id', type: 'int', unsigned: true })
|
||||
signingAccountId: number
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.transactionDraftsRecipient)
|
||||
@JoinColumn({ name: 'recipient_account_id' })
|
||||
recipientAccount?: Account
|
||||
|
||||
@Column({ name: 'recipient_account_id', type: 'int', unsigned: true, nullable: true })
|
||||
recipientAccountId?: number
|
||||
|
||||
@ManyToOne(() => Community, (community) => community.transactionDraftsSender)
|
||||
@JoinColumn({ name: 'sender_community_id' })
|
||||
senderCommunity: Community
|
||||
|
||||
@Column({ name: 'sender_community_id', type: 'int', unsigned: true })
|
||||
senderCommunityId: number
|
||||
|
||||
@ManyToOne(() => Community, (community) => community.transactionDraftsRecipient)
|
||||
@JoinColumn({ name: 'recipient_community_id' })
|
||||
recipientCommunity?: Community
|
||||
|
||||
@Column({ name: 'sender_community_id', type: 'int', unsigned: true, nullable: true })
|
||||
recipientCommunityId?: number
|
||||
|
||||
@Column({
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
amount?: Decimal
|
||||
|
||||
@Column({ type: 'tinyint' })
|
||||
type: number
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'datetime' })
|
||||
createdAt: Date
|
||||
|
||||
@Column({ name: 'body_bytes', type: 'blob' })
|
||||
bodyBytes: Buffer
|
||||
|
||||
@Column({ type: 'binary', length: 64 })
|
||||
signature: Buffer
|
||||
|
||||
@Column({ name: 'protocol_version', type: 'int', default: 1 })
|
||||
protocolVersion: number
|
||||
|
||||
@OneToMany(() => ConfirmedTransaction, (transaction) => transaction.transactionDraft)
|
||||
confirmedTransactions?: ConfirmedTransaction[]
|
||||
}
|
||||
39
dlt-database/entity/0001-init_db/User.ts
Normal file
39
dlt-database/entity/0001-init_db/User.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany, JoinColumn } from 'typeorm'
|
||||
|
||||
import { Account } from './Account'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({
|
||||
name: 'gradido_id',
|
||||
length: 36,
|
||||
nullable: true,
|
||||
unique: true,
|
||||
collation: 'utf8mb4_unicode_ci',
|
||||
})
|
||||
gradidoID?: string
|
||||
|
||||
@Column({ type: 'binary', length: 32, unique: true })
|
||||
pubkey: Buffer
|
||||
|
||||
@Column({
|
||||
name: 'created_at',
|
||||
type: 'datetime',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
createdAt: Date
|
||||
|
||||
@Column({
|
||||
name: 'confirmed_at',
|
||||
type: 'datetime',
|
||||
nullable: true,
|
||||
})
|
||||
confirmedAt?: Date
|
||||
|
||||
@OneToMany(() => Account, (account) => account.user)
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
accounts?: Account[]
|
||||
}
|
||||
1
dlt-database/entity/Account.ts
Normal file
1
dlt-database/entity/Account.ts
Normal file
@ -0,0 +1 @@
|
||||
export { Account } from './0001-init_db/Account'
|
||||
1
dlt-database/entity/AccountCommunity.ts
Normal file
1
dlt-database/entity/AccountCommunity.ts
Normal file
@ -0,0 +1 @@
|
||||
export { AccountCommunity } from './0001-init_db/AccountCommunity'
|
||||
1
dlt-database/entity/Community.ts
Normal file
1
dlt-database/entity/Community.ts
Normal file
@ -0,0 +1 @@
|
||||
export { Community } from './0001-init_db/Community'
|
||||
1
dlt-database/entity/ConfirmedTransaction.ts
Normal file
1
dlt-database/entity/ConfirmedTransaction.ts
Normal file
@ -0,0 +1 @@
|
||||
export { ConfirmedTransaction } from './0001-init_db/ConfirmedTransaction'
|
||||
1
dlt-database/entity/TransactionDraft.ts
Normal file
1
dlt-database/entity/TransactionDraft.ts
Normal file
@ -0,0 +1 @@
|
||||
export { TransactionDraft } from './0001-init_db/TransactionDraft'
|
||||
1
dlt-database/entity/User.ts
Normal file
1
dlt-database/entity/User.ts
Normal file
@ -0,0 +1 @@
|
||||
export { User } from './0001-init_db/User'
|
||||
@ -54,6 +54,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
\`created_at\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`confirmed_at\` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE KEY \`pubkey\` (\`pubkey\`),
|
||||
FOREIGN KEY (\`gmw_account_id\`) REFERENCES accounts(id),
|
||||
FOREIGN KEY (\`auf_account_id\`) REFERENCES accounts(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`)
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"build": "mkdir -p build/src/config/ && cp src/config/*.txt build/src/config/ && tsc --build",
|
||||
"build": "mkdir -p build/src/config/ && tsc --build",
|
||||
"clean": "tsc --build --clean",
|
||||
"up": "cross-env TZ=UTC node build/src/index.js up",
|
||||
"down": "cross-env TZ=UTC node build/src/index.js down",
|
||||
|
||||
@ -225,4 +225,6 @@ volumes:
|
||||
federation_database_node_modules:
|
||||
federation_database_build:
|
||||
database_node_modules:
|
||||
database_build:
|
||||
database_build:
|
||||
dlt-database_node_modules:
|
||||
dlt-database_build:
|
||||
Loading…
x
Reference in New Issue
Block a user