@sphereon/ssi-sdk.data-store 0.24.1-unstable.9 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +1 -1
  2. package/dist/contact/ContactStore.d.ts +3 -0
  3. package/dist/contact/ContactStore.d.ts.map +1 -1
  4. package/dist/contact/ContactStore.js +84 -48
  5. package/dist/contact/ContactStore.js.map +1 -1
  6. package/dist/entities/contact/BaseContactEntity.d.ts +2 -0
  7. package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -1
  8. package/dist/entities/contact/BaseContactEntity.js +12 -3
  9. package/dist/entities/contact/BaseContactEntity.js.map +1 -1
  10. package/dist/entities/contact/ConnectionEntity.d.ts +2 -0
  11. package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
  12. package/dist/entities/contact/ConnectionEntity.js +8 -0
  13. package/dist/entities/contact/ConnectionEntity.js.map +1 -1
  14. package/dist/entities/contact/ContactMetadataItemEntity.d.ts +14 -0
  15. package/dist/entities/contact/ContactMetadataItemEntity.d.ts.map +1 -0
  16. package/dist/entities/contact/ContactMetadataItemEntity.js +88 -0
  17. package/dist/entities/contact/ContactMetadataItemEntity.js.map +1 -0
  18. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -0
  19. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
  20. package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -0
  21. package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
  22. package/dist/entities/contact/DidAuthConfigEntity.d.ts +2 -0
  23. package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
  24. package/dist/entities/contact/DidAuthConfigEntity.js +8 -0
  25. package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
  26. package/dist/entities/contact/ElectronicAddressEntity.d.ts +2 -0
  27. package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
  28. package/dist/entities/contact/ElectronicAddressEntity.js +8 -0
  29. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
  30. package/dist/entities/contact/IMetadataEntity.d.ts +8 -0
  31. package/dist/entities/contact/IMetadataEntity.d.ts.map +1 -0
  32. package/dist/entities/contact/IMetadataEntity.js +2 -0
  33. package/dist/entities/contact/IMetadataEntity.js.map +1 -0
  34. package/dist/entities/contact/IdentityEntity.d.ts +5 -2
  35. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
  36. package/dist/entities/contact/IdentityEntity.js +13 -0
  37. package/dist/entities/contact/IdentityEntity.js.map +1 -1
  38. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +6 -2
  39. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
  40. package/dist/entities/contact/IdentityMetadataItemEntity.js +19 -3
  41. package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
  42. package/dist/entities/contact/NaturalPersonEntity.d.ts +2 -0
  43. package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -1
  44. package/dist/entities/contact/NaturalPersonEntity.js +8 -0
  45. package/dist/entities/contact/NaturalPersonEntity.js.map +1 -1
  46. package/dist/entities/contact/OpenIdConfigEntity.d.ts +2 -0
  47. package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
  48. package/dist/entities/contact/OpenIdConfigEntity.js +8 -0
  49. package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
  50. package/dist/entities/contact/OrganizationEntity.d.ts +2 -0
  51. package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -1
  52. package/dist/entities/contact/OrganizationEntity.js +8 -0
  53. package/dist/entities/contact/OrganizationEntity.js.map +1 -1
  54. package/dist/entities/contact/PartyEntity.d.ts +2 -0
  55. package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
  56. package/dist/entities/contact/PartyEntity.js +8 -0
  57. package/dist/entities/contact/PartyEntity.js.map +1 -1
  58. package/dist/entities/contact/PartyRelationshipEntity.d.ts +2 -0
  59. package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -1
  60. package/dist/entities/contact/PartyRelationshipEntity.js +8 -0
  61. package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -1
  62. package/dist/entities/contact/PartyTypeEntity.js +4 -4
  63. package/dist/entities/contact/PartyTypeEntity.js.map +1 -1
  64. package/dist/entities/contact/PhysicalAddressEntity.d.ts +2 -0
  65. package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -1
  66. package/dist/entities/contact/PhysicalAddressEntity.js +10 -1
  67. package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -1
  68. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.d.ts +14 -0
  69. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.d.ts.map +1 -0
  70. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js +74 -0
  71. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js.map +1 -0
  72. package/dist/index.d.ts +10 -4
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +16 -2
  75. package/dist/index.js.map +1 -1
  76. package/dist/migrations/generic/10-CreatePresentationDefinitions.d.ts +7 -0
  77. package/dist/migrations/generic/10-CreatePresentationDefinitions.d.ts.map +1 -0
  78. package/dist/migrations/generic/10-CreatePresentationDefinitions.js +78 -0
  79. package/dist/migrations/generic/10-CreatePresentationDefinitions.js.map +1 -0
  80. package/dist/migrations/generic/8-CreateContacts.d.ts +7 -0
  81. package/dist/migrations/generic/8-CreateContacts.d.ts.map +1 -0
  82. package/dist/migrations/generic/8-CreateContacts.js +78 -0
  83. package/dist/migrations/generic/8-CreateContacts.js.map +1 -0
  84. package/dist/migrations/generic/9-CreateContacts.d.ts +7 -0
  85. package/dist/migrations/generic/9-CreateContacts.d.ts.map +1 -0
  86. package/dist/migrations/generic/9-CreateContacts.js +78 -0
  87. package/dist/migrations/generic/9-CreateContacts.js.map +1 -0
  88. package/dist/migrations/generic/index.d.ts +2 -0
  89. package/dist/migrations/generic/index.d.ts.map +1 -1
  90. package/dist/migrations/generic/index.js +12 -2
  91. package/dist/migrations/generic/index.js.map +1 -1
  92. package/dist/migrations/index.d.ts +1 -1
  93. package/dist/migrations/index.d.ts.map +1 -1
  94. package/dist/migrations/index.js +2 -1
  95. package/dist/migrations/index.js.map +1 -1
  96. package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -1
  97. package/dist/migrations/postgres/1690925872592-CreateContacts.js +40 -3
  98. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
  99. package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts +7 -0
  100. package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts.map +1 -0
  101. package/dist/migrations/postgres/1710438363001-CreateContacts.js +63 -0
  102. package/dist/migrations/postgres/1710438363001-CreateContacts.js.map +1 -0
  103. package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts +7 -0
  104. package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts.map +1 -0
  105. package/dist/migrations/postgres/1715761125001-CreateContacts.js +74 -0
  106. package/dist/migrations/postgres/1715761125001-CreateContacts.js.map +1 -0
  107. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts +7 -0
  108. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts.map +1 -0
  109. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +41 -0
  110. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js.map +1 -0
  111. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
  112. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +40 -3
  113. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  114. package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts +7 -0
  115. package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts.map +1 -0
  116. package/dist/migrations/sqlite/1710438363002-CreateContacts.js +79 -0
  117. package/dist/migrations/sqlite/1710438363002-CreateContacts.js.map +1 -0
  118. package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts +7 -0
  119. package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts.map +1 -0
  120. package/dist/migrations/sqlite/1715761125002-CreateContacts.js +73 -0
  121. package/dist/migrations/sqlite/1715761125002-CreateContacts.js.map +1 -0
  122. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts +7 -0
  123. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts.map +1 -0
  124. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +38 -0
  125. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js.map +1 -0
  126. package/dist/presentationDefinition/AbstractPDStore.d.ts +12 -0
  127. package/dist/presentationDefinition/AbstractPDStore.d.ts.map +1 -0
  128. package/dist/presentationDefinition/AbstractPDStore.js +7 -0
  129. package/dist/presentationDefinition/AbstractPDStore.js.map +1 -0
  130. package/dist/presentationDefinition/PDStore.d.ts +19 -0
  131. package/dist/presentationDefinition/PDStore.d.ts.map +1 -0
  132. package/dist/presentationDefinition/PDStore.js +152 -0
  133. package/dist/presentationDefinition/PDStore.js.map +1 -0
  134. package/dist/types/contact/contact.d.ts +51 -15
  135. package/dist/types/contact/contact.d.ts.map +1 -1
  136. package/dist/types/contact/contact.js +12 -7
  137. package/dist/types/contact/contact.js.map +1 -1
  138. package/dist/types/index.d.ts +2 -0
  139. package/dist/types/index.d.ts.map +1 -1
  140. package/dist/types/index.js +2 -0
  141. package/dist/types/index.js.map +1 -1
  142. package/dist/types/presentationDefinition/IAbstractPDStore.d.ts +17 -0
  143. package/dist/types/presentationDefinition/IAbstractPDStore.d.ts.map +1 -0
  144. package/dist/types/presentationDefinition/IAbstractPDStore.js +3 -0
  145. package/dist/types/presentationDefinition/IAbstractPDStore.js.map +1 -0
  146. package/dist/types/presentationDefinition/presentationDefinition.d.ts +16 -0
  147. package/dist/types/presentationDefinition/presentationDefinition.d.ts.map +1 -0
  148. package/dist/types/presentationDefinition/presentationDefinition.js +3 -0
  149. package/dist/types/presentationDefinition/presentationDefinition.js.map +1 -0
  150. package/dist/utils/contact/MappingUtils.d.ts +6 -4
  151. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  152. package/dist/utils/contact/MappingUtils.js +122 -18
  153. package/dist/utils/contact/MappingUtils.js.map +1 -1
  154. package/dist/utils/presentationDefinition/MappingUtils.d.ts +6 -0
  155. package/dist/utils/presentationDefinition/MappingUtils.d.ts.map +1 -0
  156. package/dist/utils/presentationDefinition/MappingUtils.js +48 -0
  157. package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -0
  158. package/package.json +7 -4
  159. package/src/__tests__/contact.entities.test.ts +129 -44
  160. package/src/__tests__/contact.store.test.ts +205 -29
  161. package/src/__tests__/eventLogger.entities.test.ts +2 -2
  162. package/src/__tests__/eventLogger.store.test.ts +2 -5
  163. package/src/__tests__/pd-manager.entities.test.ts +71 -0
  164. package/src/__tests__/pd-manager.store.test.ts +191 -0
  165. package/src/contact/ContactStore.ts +74 -30
  166. package/src/entities/contact/BaseContactEntity.ts +11 -0
  167. package/src/entities/contact/ConnectionEntity.ts +6 -0
  168. package/src/entities/contact/ContactMetadataItemEntity.ts +50 -0
  169. package/src/entities/contact/CorrelationIdentifierEntity.ts +6 -0
  170. package/src/entities/contact/DidAuthConfigEntity.ts +6 -0
  171. package/src/entities/contact/ElectronicAddressEntity.ts +6 -0
  172. package/src/entities/contact/IMetadataEntity.ts +8 -0
  173. package/src/entities/contact/IdentityEntity.ts +11 -2
  174. package/src/entities/contact/IdentityMetadataItemEntity.ts +16 -4
  175. package/src/entities/contact/NaturalPersonEntity.ts +6 -0
  176. package/src/entities/contact/OpenIdConfigEntity.ts +6 -0
  177. package/src/entities/contact/OrganizationEntity.ts +6 -0
  178. package/src/entities/contact/PartyEntity.ts +6 -0
  179. package/src/entities/contact/PartyRelationshipEntity.ts +6 -0
  180. package/src/entities/contact/PartyTypeEntity.ts +4 -4
  181. package/src/entities/contact/PhysicalAddressEntity.ts +9 -2
  182. package/src/entities/presentationDefinition/PresentationDefinitionItemEntity.ts +43 -0
  183. package/src/index.ts +13 -0
  184. package/src/migrations/generic/10-CreatePresentationDefinitions.ts +66 -0
  185. package/src/migrations/generic/8-CreateContacts.ts +66 -0
  186. package/src/migrations/generic/9-CreateContacts.ts +66 -0
  187. package/src/migrations/generic/index.ts +11 -1
  188. package/src/migrations/index.ts +1 -0
  189. package/src/migrations/postgres/1690925872592-CreateContacts.ts +57 -3
  190. package/src/migrations/postgres/1710438363001-CreateContacts.ts +63 -0
  191. package/src/migrations/postgres/1715761125001-CreateContacts.ts +60 -0
  192. package/src/migrations/postgres/1716475165345-CreatePresentationDefinitions.ts +25 -0
  193. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +70 -3
  194. package/src/migrations/sqlite/1710438363002-CreateContacts.ts +83 -0
  195. package/src/migrations/sqlite/1715761125002-CreateContacts.ts +59 -0
  196. package/src/migrations/sqlite/1716475165344-CreatePresentationDefinitions.ts +24 -0
  197. package/src/presentationDefinition/AbstractPDStore.ts +20 -0
  198. package/src/presentationDefinition/PDStore.ts +185 -0
  199. package/src/types/contact/contact.ts +56 -15
  200. package/src/types/index.ts +2 -0
  201. package/src/types/presentationDefinition/IAbstractPDStore.ts +25 -0
  202. package/src/types/presentationDefinition/presentationDefinition.ts +17 -0
  203. package/src/utils/contact/MappingUtils.ts +128 -18
  204. package/src/utils/presentationDefinition/MappingUtils.ts +52 -0
@@ -1,4 +1,4 @@
1
- import { IsNotEmpty, validate, ValidationError } from 'class-validator'
1
+ import { IsNotEmpty, Validate, validate, ValidationError } from 'class-validator'
2
2
  import {
3
3
  BaseEntity,
4
4
  BeforeInsert,
@@ -13,6 +13,7 @@ import {
13
13
  import { getConstraint } from '../../utils/ValidatorUtils'
14
14
  import { PhysicalAddressType, ValidationConstraint } from '../../types'
15
15
  import { PartyEntity } from './PartyEntity'
16
+ import { IsNonEmptyStringConstraint } from '../validators'
16
17
 
17
18
  @Entity('PhysicalAddress')
18
19
  export class PhysicalAddressEntity extends BaseEntity {
@@ -48,9 +49,15 @@ export class PhysicalAddressEntity extends BaseEntity {
48
49
  countryCode!: string
49
50
 
50
51
  @Column({ name: 'building_name', length: 255, nullable: true })
51
- @IsNotEmpty({ message: 'Blank building names are not allowed' })
52
+ @Validate(IsNonEmptyStringConstraint, { message: 'Blank building names are not allowed' })
52
53
  buildingName?: string
53
54
 
55
+ @Column({ name: 'owner_id', nullable: true })
56
+ ownerId?: string
57
+
58
+ @Column({ name: 'tenant_id', nullable: true })
59
+ tenantId?: string
60
+
54
61
  @ManyToOne(() => PartyEntity, (party: PartyEntity) => party.physicalAddresses, {
55
62
  onDelete: 'CASCADE',
56
63
  })
@@ -0,0 +1,43 @@
1
+ import { BaseEntity, BeforeInsert, BeforeUpdate, Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
2
+ import { IsNotEmpty } from 'class-validator'
3
+
4
+ @Entity('PresentationDefinitionItem')
5
+ @Index(['version'], { unique: false })
6
+ export class PresentationDefinitionItemEntity extends BaseEntity {
7
+ @PrimaryGeneratedColumn('uuid')
8
+ id!: string
9
+
10
+ @Column({ name: 'definition_id', length: 255, nullable: false, unique: false })
11
+ @IsNotEmpty({ message: 'A blank definition id field is not allowed' })
12
+ definitionId!: string
13
+
14
+ @Column({ name: 'version', length: 255, nullable: false, unique: false })
15
+ @IsNotEmpty({ message: 'A blank version field is not allowed' })
16
+ version!: string
17
+
18
+ @Column({ name: 'tenant_id', length: 255, nullable: true, unique: false })
19
+ tenantId?: string
20
+
21
+ @Column({ name: 'purpose', length: 255, nullable: true, unique: false })
22
+ purpose?: string
23
+
24
+ @Column({ name: 'name', length: 255, nullable: true, unique: false })
25
+ name?: string
26
+
27
+ @Column({ name: 'definition_payload', type: 'text', nullable: false, unique: false })
28
+ @IsNotEmpty({ message: 'A blank definition payload field is not allowed' })
29
+ definitionPayload!: string
30
+
31
+ @CreateDateColumn({ name: 'created_at', nullable: false })
32
+ createdAt!: Date
33
+
34
+ @UpdateDateColumn({ name: 'last_updated_at', nullable: false })
35
+ lastUpdatedAt!: Date
36
+
37
+ // By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
38
+ @BeforeInsert()
39
+ @BeforeUpdate()
40
+ updateUpdatedDate(): void {
41
+ this.lastUpdatedAt = new Date()
42
+ }
43
+ }
package/src/index.ts CHANGED
@@ -34,10 +34,15 @@ export { StatusListStore } from './statusList/StatusListStore'
34
34
  import { AuditEventEntity, auditEventEntityFrom } from './entities/eventLogger/AuditEventEntity'
35
35
  import { DigitalCredentialEntity } from './entities/digitalCredential/DigitalCredentialEntity'
36
36
  import { digitalCredentialFrom, digitalCredentialsFrom, nonPersistedDigitalCredentialEntityFromAddArgs } from './utils/digitalCredential/MappingUtils'
37
+ import { isPresentationDefinitionEqual } from './utils/presentationDefinition/MappingUtils'
38
+ import { PresentationDefinitionItemEntity } from './entities/presentationDefinition/PresentationDefinitionItemEntity'
39
+ import { ContactMetadataItemEntity } from './entities/contact/ContactMetadataItemEntity'
37
40
  export { AbstractEventLoggerStore } from './eventLogger/AbstractEventLoggerStore'
38
41
  export { EventLoggerStore } from './eventLogger/EventLoggerStore'
39
42
  export { IAbstractMachineStateStore } from './machineState/IAbstractMachineStateStore'
40
43
  export { MachineStateStore } from './machineState/MachineStateStore'
44
+ export { AbstractPDStore } from './presentationDefinition/AbstractPDStore'
45
+ export { PDStore } from './presentationDefinition/PDStore'
41
46
 
42
47
  export {
43
48
  DataStoreMigrations,
@@ -46,6 +51,7 @@ export {
46
51
  DataStoreIssuanceBrandingMigrations,
47
52
  DataStoreStatusListMigrations,
48
53
  DataStoreMachineStateMigrations,
54
+ DataStorePresentationDefinitionMigrations,
49
55
  } from './migrations'
50
56
  export * from './types'
51
57
  export * from './utils/contact/MappingUtils'
@@ -66,6 +72,7 @@ export const DataStoreContactEntities = [
66
72
  NaturalPersonEntity,
67
73
  ElectronicAddressEntity,
68
74
  PhysicalAddressEntity,
75
+ ContactMetadataItemEntity,
69
76
  ]
70
77
 
71
78
  export const DataStoreIssuanceBrandingEntities = [
@@ -80,6 +87,8 @@ export const DataStoreIssuanceBrandingEntities = [
80
87
  IssuerLocaleBrandingEntity,
81
88
  ]
82
89
 
90
+ export const DataStorePresentationDefinitionEntities = [PresentationDefinitionItemEntity]
91
+
83
92
  export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEntity]
84
93
 
85
94
  export const DataStoreEventLoggerEntities = [AuditEventEntity]
@@ -96,6 +105,7 @@ export const DataStoreEntities = [
96
105
  ...DataStoreEventLoggerEntities,
97
106
  ...DataStoreDigitalCredentialEntities,
98
107
  ...DataStoreMachineStateEntities,
108
+ ...DataStorePresentationDefinitionEntities,
99
109
  ]
100
110
 
101
111
  export {
@@ -138,4 +148,7 @@ export {
138
148
  digitalCredentialsFrom,
139
149
  nonPersistedDigitalCredentialEntityFromAddArgs,
140
150
  MachineStateInfoEntity,
151
+ PresentationDefinitionItemEntity,
152
+ isPresentationDefinitionEqual,
153
+ ContactMetadataItemEntity,
141
154
  }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug from 'debug'
3
+ import { CreatePresentationDefinitions1716475165345 } from '../postgres/1716475165345-CreatePresentationDefinitions'
4
+ import { CreatePresentationDefinitions1716475165344 } from '../sqlite/1716475165344-CreatePresentationDefinitions'
5
+
6
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreatePresentationDefinitions1716533767523 implements MigrationInterface {
9
+ name = 'CreatePresentationDefinitionItems1716533767523'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: creating machine state tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreatePresentationDefinitions1716475165345 = new CreatePresentationDefinitions1716475165345()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreatePresentationDefinitions1716475165344 = new CreatePresentationDefinitions1716475165344()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting machine state tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreatePresentationDefinitions1716475165345 = new CreatePresentationDefinitions1716475165345()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreatePresentationDefinitions1716475165344 = new CreatePresentationDefinitions1716475165344()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
63
+ )
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug from 'debug'
3
+ import { CreateContacts1710438363001 } from '../postgres/1710438363001-CreateContacts'
4
+ import { CreateContacts1710438363002 } from '../sqlite/1710438363002-CreateContacts'
5
+
6
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreateContacts1708525189000 implements MigrationInterface {
9
+ name = 'CreateContacts1708525189000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: updating contact tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreateContacts1710438363001 = new CreateContacts1710438363001()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreateContacts1710438363002 = new CreateContacts1710438363002()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting machine state tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreateContacts1710438363001 = new CreateContacts1710438363001()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreateContacts1710438363002 = new CreateContacts1710438363002()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
63
+ )
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug from 'debug'
3
+ import { CreateContacts1715761125001 } from '../postgres/1715761125001-CreateContacts'
4
+ import { CreateContacts1715761125002 } from '../sqlite/1715761125002-CreateContacts'
5
+
6
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreateContacts1715761125000 implements MigrationInterface {
9
+ name = 'CreateContacts1715761125000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: updating contact tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreateContacts1715761125001 = new CreateContacts1715761125001()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreateContacts1715761125002 = new CreateContacts1715761125002()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting machine state tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreateContacts1715761125001 = new CreateContacts1715761125001()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreateContacts1715761125002 = new CreateContacts1715761125002()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
63
+ )
64
+ }
65
+ }
66
+ }
@@ -5,6 +5,9 @@ import { CreateStatusList1693866470000 } from './4-CreateStatusList'
5
5
  import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents'
6
6
  import { CreateDigitalCredential1708525189000 } from './6-CreateDigitalCredential'
7
7
  import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStore'
8
+ import { CreateContacts1708525189000 } from './8-CreateContacts'
9
+ import { CreateContacts1715761125000 } from './9-CreateContacts'
10
+ import { CreatePresentationDefinitions1716533767523 } from './10-CreatePresentationDefinitions'
8
11
 
9
12
  /**
10
13
  * The migrations array that SHOULD be used when initializing a TypeORM database connection.
@@ -15,12 +18,18 @@ import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStor
15
18
  */
16
19
 
17
20
  // Individual migrations per purpose. Allows parties to not run migrations and thus create/update tables if they are not using a particular feature (yet)
18
- export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318]
21
+ export const DataStoreContactMigrations = [
22
+ CreateContacts1659463079429,
23
+ CreateContacts1690925872318,
24
+ CreateContacts1708525189000,
25
+ CreateContacts1715761125000,
26
+ ]
19
27
  export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429]
20
28
  export const DataStoreStatusListMigrations = [CreateStatusList1693866470000]
21
29
  export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330]
22
30
  export const DataStoreDigitalCredentialMigrations = [CreateDigitalCredential1708525189000]
23
31
  export const DataStoreMachineStateMigrations = [CreateMachineStateStore1708098041262]
32
+ export const DataStorePresentationDefinitionMigrations = [CreatePresentationDefinitions1716533767523]
24
33
 
25
34
  // All migrations together
26
35
  export const DataStoreMigrations = [
@@ -30,4 +39,5 @@ export const DataStoreMigrations = [
30
39
  ...DataStoreEventLoggerMigrations,
31
40
  ...DataStoreDigitalCredentialMigrations,
32
41
  ...DataStoreMachineStateMigrations,
42
+ ...DataStorePresentationDefinitionMigrations,
33
43
  ]
@@ -6,4 +6,5 @@ export {
6
6
  DataStoreStatusListMigrations,
7
7
  DataStoreDigitalCredentialMigrations,
8
8
  DataStoreMachineStateMigrations,
9
+ DataStorePresentationDefinitionMigrations,
9
10
  } from './generic'
@@ -15,7 +15,7 @@ export class CreateContacts1690925872592 implements MigrationInterface {
15
15
  await queryRunner.query(`CREATE TYPE "public"."PartyType_type_enum" AS ENUM('naturalPerson', 'organization')`)
16
16
  await queryRunner.query(`CREATE TYPE "public"."PartyOrigin_type_enum" AS ENUM('INTERNAL', 'EXTERNAL')`)
17
17
  await queryRunner.query(
18
- `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "origin" "public"."PartyOrigin_type_enum" NOT NULL DEFAULT 'EXTERNAL', "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`,
18
+ `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "origin" "public"."PartyOrigin_type_enum" NOT NULL, "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`,
19
19
  )
20
20
  await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`)
21
21
  await queryRunner.query(
@@ -41,6 +41,10 @@ export class CreateContacts1690925872592 implements MigrationInterface {
41
41
  await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
42
42
  await queryRunner.query(`ALTER TABLE "Identity" RENAME COLUMN "contactId" TO "partyId"`)
43
43
  await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "roles" SET NOT NULL`)
44
+ await queryRunner.query(`CREATE TYPE "public"."IdentityOrigin_type_enum" AS ENUM('INTERNAL', 'EXTERNAL')`)
45
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "origin" "public"."IdentityOrigin_type_enum" DEFAULT 'EXTERNAL' NOT NULL`)
46
+ await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "origin" DROP DEFAULT`)
47
+
44
48
  await queryRunner.query(
45
49
  `ALTER TABLE "CorrelationIdentifier" ADD CONSTRAINT "FK_CorrelationIdentifier_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
46
50
  )
@@ -98,7 +102,57 @@ export class CreateContacts1690925872592 implements MigrationInterface {
98
102
  }
99
103
 
100
104
  public async down(queryRunner: QueryRunner): Promise<void> {
101
- // TODO DPP-27 implement downgrade
102
- return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`))
105
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP CONSTRAINT "FK_BaseConfig_connection_id"`)
106
+ await queryRunner.query(`ALTER TABLE "Connection" DROP CONSTRAINT "FK_Connection_identity_id"`)
107
+ await queryRunner.query(`ALTER TABLE "Identity" DROP CONSTRAINT "FK_Identity_partyId"`)
108
+ await queryRunner.query(`ALTER TABLE "Party" DROP CONSTRAINT "FK_Party_party_type_id"`)
109
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP CONSTRAINT "FK_PhysicalAddress_partyId"`)
110
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP CONSTRAINT "FK_ElectronicAddress_partyId"`)
111
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP CONSTRAINT "FK_PartyRelationship_right_id"`)
112
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP CONSTRAINT "FK_PartyRelationship_left_id"`)
113
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP CONSTRAINT "FK_BaseContact_party_id"`)
114
+ await queryRunner.query(`ALTER TABLE "IdentityMetadata" DROP CONSTRAINT "FK_IdentityMetadata_identityId"`)
115
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP CONSTRAINT "FK_CorrelationIdentifier_identity_id"`)
116
+
117
+ await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "roles" DROP NOT NULL`)
118
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "origin"`)
119
+ await queryRunner.query(`DROP TYPE "public"."IdentityOrigin_type_enum"`)
120
+ await queryRunner.query(`ALTER TABLE "Identity" RENAME COLUMN "partyId" TO "contactId"`)
121
+ await queryRunner.query(`ALTER TABLE "Connection" RENAME COLUMN "identity_id" TO "identityId"`)
122
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" RENAME COLUMN "identity_id" TO "identityId"`)
123
+
124
+ await queryRunner.query(`DROP INDEX "IDX_BaseConfig_type"`)
125
+ await queryRunner.query(`DROP TABLE "BaseConfig"`)
126
+ await queryRunner.query(`DROP TABLE "Party"`)
127
+ await queryRunner.query(`DROP INDEX "IDX_PartyRelationship_left_right"`)
128
+ await queryRunner.query(`DROP TABLE "PartyRelationship"`)
129
+ await queryRunner.query(`DROP INDEX "IDX_BaseContact_type"`)
130
+ await queryRunner.query(`DROP TABLE "BaseContact"`)
131
+ await queryRunner.query(`DROP TABLE "ElectronicAddress"`)
132
+ await queryRunner.query(`DROP TABLE "PhysicalAddress"`)
133
+ await queryRunner.query(`DROP INDEX "IDX_PartyType_type_tenant_id"`)
134
+ await queryRunner.query(`DROP TABLE "PartyType"`)
135
+ await queryRunner.query(`DROP TYPE "public"."PartyOrigin_type_enum"`)
136
+ await queryRunner.query(`DROP TYPE "public"."PartyType_type_enum"`)
137
+
138
+ await queryRunner.query(
139
+ `ALTER TABLE "Connection" ADD CONSTRAINT "FK_Connection_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
140
+ )
141
+ await queryRunner.query(
142
+ `ALTER TABLE "Identity" ADD CONSTRAINT "FK_Identity_contactId" FOREIGN KEY ("contactId") REFERENCES "Contact"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
143
+ )
144
+ await queryRunner.query(
145
+ `ALTER TABLE "IdentityMetadata" ADD CONSTRAINT "FK_IdentityMetadata_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
146
+ )
147
+ await queryRunner.query(
148
+ `ALTER TABLE "CorrelationIdentifier" ADD CONSTRAINT "FK_CorrelationIdentifier_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
149
+ )
150
+
151
+ await queryRunner.query(
152
+ `CREATE TABLE "Contact" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying(255), "alias" character varying(255), CONSTRAINT "PK_Contact_id" PRIMARY KEY ("id"))`,
153
+ )
154
+ await queryRunner.query(
155
+ `INSERT INTO "Contact"(id, uri, created_at, last_updated_at, name, alias) SELECT id, uri, created_at, last_updated_at, (SELECT legal_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id"), (SELECT display_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id") FROM "Party" WHERE party_type_id = '3875c12e-fdaa-4ef6-a340-c936e054b627'`,
156
+ )
103
157
  }
104
158
  }
@@ -0,0 +1,63 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+
3
+ export class CreateContacts1710438363001 implements MigrationInterface {
4
+ name = 'CreateContacts1710438363001'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "owner_id" uuid`)
8
+ await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "tenant_id" uuid`)
9
+
10
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "owner_id" uuid`)
11
+ await queryRunner.query(`ALTER TABLE "Identity" ADD COLUMN "tenant_id" uuid`)
12
+
13
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "owner_id" uuid`)
14
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "tenant_id" uuid`)
15
+
16
+ await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "owner_id" uuid`)
17
+ await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "tenant_id" uuid`)
18
+
19
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "owner_id" uuid`)
20
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "tenant_id" uuid`)
21
+
22
+ await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "owner_id" uuid`)
23
+ await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "tenant_id" uuid`)
24
+
25
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "owner_id" uuid`)
26
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "tenant_id" uuid`)
27
+
28
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "owner_id" uuid`)
29
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "tenant_id" uuid`)
30
+
31
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "owner_id" uuid`)
32
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "tenant_id" uuid`)
33
+ }
34
+
35
+ public async down(queryRunner: QueryRunner): Promise<void> {
36
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "tenant_id"`)
37
+ await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "owner_id"`)
38
+
39
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "tenant_id"`)
40
+ await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "owner_id"`)
41
+
42
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "tenant_id"`)
43
+ await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "owner_id"`)
44
+
45
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "tenant_id"`)
46
+ await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "owner_id"`)
47
+
48
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "tenant_id"`)
49
+ await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "owner_id"`)
50
+
51
+ await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "tenant_id"`)
52
+ await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "owner_id"`)
53
+
54
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "tenant_id"`)
55
+ await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "owner_id"`)
56
+
57
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "tenant_id"`)
58
+ await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "owner_id"`)
59
+
60
+ await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "tenant_id"`)
61
+ await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "owner_id"`)
62
+ }
63
+ }
@@ -0,0 +1,60 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+
3
+ export class CreateContacts1715761125001 implements MigrationInterface {
4
+ name = 'CreateContacts1715761125001'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ // Upgrade IdentityMetadata table
8
+ await queryRunner.query(`ALTER TABLE "IdentityMetadata" RENAME TO "temporary_IdentityMetadata"`)
9
+ await queryRunner.query(`CREATE TABLE "IdentityMetadata"
10
+ (
11
+ "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
12
+ "label" character varying(255) NOT NULL,
13
+ "valueType" character varying NOT NULL,
14
+ "stringValue" text,
15
+ "numberValue" double precision,
16
+ "dateValue" TIMESTAMP,
17
+ "boolValue" boolean,
18
+ "identityId" uuid,
19
+ CONSTRAINT "FK_Identity_IdentityMetadata" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE
20
+ )`)
21
+ await queryRunner.query(`INSERT INTO "IdentityMetadata" ("id", "label", "valueType", "stringValue", "identityId")
22
+ SELECT "id", "label", 'string', "value", "identityId"
23
+ FROM "temporary_IdentityMetadata"`)
24
+ await queryRunner.query(`DROP TABLE "temporary_IdentityMetadata"`)
25
+
26
+ // Create new ContactMetadata table
27
+ await queryRunner.query(`CREATE TABLE "ContactMetadata"
28
+ (
29
+ "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
30
+ "label" character varying(255) NOT NULL,
31
+ "valueType" character varying NOT NULL,
32
+ "stringValue" text,
33
+ "numberValue" double precision,
34
+ "dateValue" TIMESTAMP,
35
+ "boolValue" boolean,
36
+ "contactId" uuid,
37
+ CONSTRAINT "FK_BaseContact_ContactMetadata" FOREIGN KEY ("contactId") REFERENCES "BaseContact" ("id") ON DELETE CASCADE
38
+ )`)
39
+ }
40
+
41
+ public async down(queryRunner: QueryRunner): Promise<void> {
42
+ // Drop the ContactMetadata table
43
+ await queryRunner.query(`DROP TABLE "ContactMetadata"`)
44
+
45
+ // Restore the IdentityMetadata table
46
+ await queryRunner.query(`ALTER TABLE "IdentityMetadata" RENAME TO "temporary_IdentityMetadata"`)
47
+ await queryRunner.query(`CREATE TABLE "IdentityMetadata"
48
+ (
49
+ "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
50
+ "label" character varying(255) NOT NULL,
51
+ "value" character varying(255) NOT NULL,
52
+ "identityId" uuid,
53
+ CONSTRAINT "FK_Identity_IdentityMetadata" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE
54
+ )`)
55
+ await queryRunner.query(`INSERT INTO "IdentityMetadata" ("id", "label", "value", "identityId")
56
+ SELECT "id", "label", "stringValue", "identityId"
57
+ FROM "temporary_IdentityMetadata"`)
58
+ await queryRunner.query(`DROP TABLE "temporary_IdentityMetadata"`)
59
+ }
60
+ }
@@ -0,0 +1,25 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+
3
+ export class CreatePresentationDefinitions1716475165345 implements MigrationInterface {
4
+ name = 'CreatePresentationDefinitions1716475165345'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`
8
+ CREATE TABLE "PresentationDefinitionItem" (
9
+ "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
10
+ "tenant_id" TEXT,
11
+ "definition_id" TEXT NOT NULL,
12
+ "name" TEXT,
13
+ "version" TEXT NOT NULL,
14
+ "purpose" TEXT,
15
+ "definition_payload" TEXT NOT NULL,
16
+ "created_at" TIMESTAMP NOT NULL DEFAULT now(),
17
+ "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(),
18
+ CONSTRAINT "PK_PresentationDefinitionItem_id" PRIMARY KEY ("id"))
19
+ `)
20
+ }
21
+
22
+ public async down(queryRunner: QueryRunner): Promise<void> {
23
+ await queryRunner.query(`DROP TABLE "PresentationDefinitionItem"`)
24
+ }
25
+ }