arocapi 2.1.0 → 4.0.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.
- package/README.md +70 -26
- package/dist/app.d.ts +3 -9
- package/dist/app.js +20 -34
- package/dist/app.js.map +1 -1
- package/dist/app.test.js +5 -40
- package/dist/app.test.js.map +1 -1
- package/dist/index.dev.d.ts +1 -8
- package/dist/index.dev.js +12 -2
- package/dist/index.dev.js.map +1 -1
- package/dist/routes/crate.d.ts +2 -0
- package/dist/routes/crate.js +8 -27
- package/dist/routes/crate.js.map +1 -1
- package/dist/routes/crate.test.js +21 -23
- package/dist/routes/crate.test.js.map +1 -1
- package/dist/routes/entities.d.ts +2 -0
- package/dist/routes/entities.js +16 -20
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/entities.test.js +20 -19
- package/dist/routes/entities.test.js.map +1 -1
- package/dist/routes/entity.d.ts +2 -0
- package/dist/routes/entity.js +7 -14
- package/dist/routes/entity.js.map +1 -1
- package/dist/routes/entity.test.js +13 -17
- package/dist/routes/entity.test.js.map +1 -1
- package/dist/routes/file.d.ts +2 -0
- package/dist/routes/file.js +8 -27
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/file.test.js +19 -23
- package/dist/routes/file.test.js.map +1 -1
- package/dist/routes/files.d.ts +2 -0
- package/dist/routes/files.js +15 -20
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/files.test.js +13 -35
- package/dist/routes/files.test.js.map +1 -1
- package/dist/routes/search.d.ts +4 -0
- package/dist/routes/search.js +21 -24
- package/dist/routes/search.js.map +1 -1
- package/dist/routes/search.test.js +56 -24
- package/dist/routes/search.test.js.map +1 -1
- package/dist/test/helpers/fastify.js +0 -6
- package/dist/test/helpers/fastify.js.map +1 -1
- package/dist/test/integration.setup.d.ts +2 -4
- package/dist/test/integration.setup.js +41 -21
- package/dist/test/integration.setup.js.map +1 -1
- package/dist/test/integration.test.js +59 -0
- package/dist/test/integration.test.js.map +1 -1
- package/dist/transformers/default.d.ts +11 -18
- package/dist/transformers/default.js +5 -18
- package/dist/transformers/default.js.map +1 -1
- package/dist/transformers/default.test.js +6 -15
- package/dist/transformers/default.test.js.map +1 -1
- package/dist/transformers/transformer.test.js +2 -6
- package/dist/transformers/transformer.test.js.map +1 -1
- package/dist/utils/errors.d.ts +7 -1
- package/dist/utils/errors.js +2 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/headers.d.ts +7 -0
- package/dist/utils/headers.js +11 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/queryBuilder.d.ts +2 -2
- package/dist/utils/queryBuilder.js +2 -3
- package/dist/utils/queryBuilder.js.map +1 -1
- package/package.json +24 -24
- package/prisma/models/entity.prisma +17 -13
- package/prisma/models/file.prisma +9 -13
- package/prisma.config.ts +0 -2
- package/src/app.test.ts +5 -44
- package/src/app.ts +25 -47
- package/src/index.dev.ts +13 -9
- package/src/routes/__snapshots__/search.test.ts.snap +2 -2
- package/src/routes/crate.test.ts +21 -23
- package/src/routes/crate.ts +11 -33
- package/src/routes/entities.test.ts +23 -19
- package/src/routes/entities.ts +19 -23
- package/src/routes/entity.test.ts +15 -17
- package/src/routes/entity.ts +9 -14
- package/src/routes/file.test.ts +19 -23
- package/src/routes/file.ts +11 -33
- package/src/routes/files.test.ts +14 -39
- package/src/routes/files.ts +18 -23
- package/src/routes/search.test.ts +65 -26
- package/src/routes/search.ts +30 -23
- package/src/test/helpers/fastify.ts +0 -12
- package/src/test/integration.setup.ts +44 -21
- package/src/test/integration.test.ts +72 -1
- package/src/transformers/default.test.ts +10 -20
- package/src/transformers/default.ts +14 -27
- package/src/transformers/transformer.test.ts +4 -6
- package/src/utils/errors.ts +10 -6
- package/src/utils/headers.ts +16 -0
- package/src/utils/queryBuilder.ts +3 -5
- package/prisma/migrations/20250515034400_entities/migration.sql +0 -14
- package/prisma/migrations/20250515050009_extend_entity_fields/migration.sql +0 -7
- package/prisma/migrations/20250804225438_add_record_type/migration.sql +0 -8
- package/prisma/migrations/20250805040110_add_rocrate_field/migration.sql +0 -2
- package/prisma/migrations/20250827033956_record_type_scalar/migration.sql +0 -10
- package/prisma/migrations/20250923032753_api_refactor/migration.sql +0 -39
- package/prisma/migrations/20250923223119_entity_type_to_string/migration.sql +0 -8
- package/prisma/migrations/20251020140329_add_meta_column/migration.sql +0 -2
- package/prisma/migrations/20251027010713_add_file_table/migration.sql +0 -17
- package/prisma/migrations/20251027221138_add_file_id_to_entity/migration.sql +0 -2
- package/prisma/migrations/20251211025510_remove_rocrate_column/migration.sql +0 -8
- package/prisma/migrations/migration_lock.toml +0 -3
- package/prisma/schema.prisma +0 -17
- package/src/__snapshots__/app.test.ts.snap +0 -8
|
@@ -4,13 +4,11 @@ import { AllPublicAccessTransformer, baseEntityTransformer } from './default.js'
|
|
|
4
4
|
|
|
5
5
|
describe('baseEntityTransformer', () => {
|
|
6
6
|
it('should transform entity to standard entity shape', () => {
|
|
7
|
-
const entity: Entity = {
|
|
8
|
-
id:
|
|
9
|
-
rocrateId: 'http://example.com/entity/123',
|
|
7
|
+
const entity: Entity & { file?: { id: string } | null } = {
|
|
8
|
+
id: 'http://example.com/entity/123',
|
|
10
9
|
name: 'Test Entity',
|
|
11
10
|
description: 'A test entity description',
|
|
12
11
|
entityType: 'http://pcdm.org/models#Collection',
|
|
13
|
-
fileId: null,
|
|
14
12
|
memberOf: 'http://example.com/parent',
|
|
15
13
|
rootCollection: 'http://example.com/root',
|
|
16
14
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -35,13 +33,11 @@ describe('baseEntityTransformer', () => {
|
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
it('should handle null memberOf and rootCollection', () => {
|
|
38
|
-
const entity: Entity = {
|
|
39
|
-
id:
|
|
40
|
-
rocrateId: 'http://example.com/collection',
|
|
36
|
+
const entity: Entity & { file?: { id: string } | null } = {
|
|
37
|
+
id: 'http://example.com/collection',
|
|
41
38
|
name: 'Top Collection',
|
|
42
39
|
description: 'A top-level collection',
|
|
43
40
|
entityType: 'http://pcdm.org/models#Collection',
|
|
44
|
-
fileId: null,
|
|
45
41
|
memberOf: null,
|
|
46
42
|
rootCollection: null,
|
|
47
43
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -58,13 +54,11 @@ describe('baseEntityTransformer', () => {
|
|
|
58
54
|
});
|
|
59
55
|
|
|
60
56
|
it('should exclude database-specific fields', () => {
|
|
61
|
-
const entity: Entity = {
|
|
62
|
-
id:
|
|
63
|
-
rocrateId: 'http://example.com/entity/456',
|
|
57
|
+
const entity: Entity & { file?: { id: string } | null } = {
|
|
58
|
+
id: 'http://example.com/entity/456',
|
|
64
59
|
name: 'Test',
|
|
65
60
|
description: 'Test',
|
|
66
61
|
entityType: 'http://pcdm.org/models#Object',
|
|
67
|
-
fileId: null,
|
|
68
62
|
memberOf: null,
|
|
69
63
|
rootCollection: null,
|
|
70
64
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -76,7 +70,6 @@ describe('baseEntityTransformer', () => {
|
|
|
76
70
|
|
|
77
71
|
const result = baseEntityTransformer(entity);
|
|
78
72
|
|
|
79
|
-
// Result should have 'id' (mapped from rocrateId), but not the numeric database id
|
|
80
73
|
expect(result.id).toBe('http://example.com/entity/456');
|
|
81
74
|
expect(result).not.toHaveProperty('createdAt');
|
|
82
75
|
expect(result).not.toHaveProperty('updatedAt');
|
|
@@ -93,14 +86,12 @@ describe('baseEntityTransformer', () => {
|
|
|
93
86
|
]);
|
|
94
87
|
});
|
|
95
88
|
|
|
96
|
-
it('should handle File entity (MediaObject) with
|
|
97
|
-
const entity: Entity = {
|
|
98
|
-
id:
|
|
99
|
-
rocrateId: 'http://example.com/file/audio.wav',
|
|
89
|
+
it('should handle File entity (MediaObject) with file relation', () => {
|
|
90
|
+
const entity: Entity & { file?: { id: string } | null } = {
|
|
91
|
+
id: 'http://example.com/file/audio.wav',
|
|
100
92
|
name: 'Audio File',
|
|
101
93
|
description: 'An audio recording',
|
|
102
94
|
entityType: 'http://schema.org/MediaObject',
|
|
103
|
-
fileId: 'http://example.com/files/audio.wav',
|
|
104
95
|
memberOf: 'http://example.com/collection',
|
|
105
96
|
rootCollection: 'http://example.com/collection',
|
|
106
97
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -108,6 +99,7 @@ describe('baseEntityTransformer', () => {
|
|
|
108
99
|
createdAt: new Date(),
|
|
109
100
|
updatedAt: new Date(),
|
|
110
101
|
meta: null,
|
|
102
|
+
file: { id: 'http://example.com/files/audio.wav' },
|
|
111
103
|
};
|
|
112
104
|
|
|
113
105
|
const result = baseEntityTransformer(entity);
|
|
@@ -117,13 +109,11 @@ describe('baseEntityTransformer', () => {
|
|
|
117
109
|
name: 'Audio File',
|
|
118
110
|
description: 'An audio recording',
|
|
119
111
|
entityType: 'http://schema.org/MediaObject',
|
|
120
|
-
fileId: 'http://example.com/files/audio.wav',
|
|
121
112
|
memberOf: 'http://example.com/collection',
|
|
122
113
|
rootCollection: 'http://example.com/collection',
|
|
123
114
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
124
115
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
125
116
|
});
|
|
126
|
-
expect(result.fileId).toBe('http://example.com/files/audio.wav');
|
|
127
117
|
});
|
|
128
118
|
});
|
|
129
119
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Entity, File, PrismaClient } from '../generated/prisma/client.js';
|
|
2
2
|
|
|
3
|
+
type EntityWithFile = Entity & { file?: { id: string } | null };
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Entity reference - used for memberOf and rootCollection
|
|
5
7
|
*/
|
|
@@ -14,13 +16,14 @@ type EntityReference = {
|
|
|
14
16
|
*/
|
|
15
17
|
export type BaseEntity = {
|
|
16
18
|
id: string;
|
|
19
|
+
entityType: string;
|
|
17
20
|
name: string;
|
|
18
21
|
description: string;
|
|
19
22
|
memberOf: string | null;
|
|
20
23
|
rootCollection: string | null;
|
|
21
24
|
metadataLicenseId: string;
|
|
22
25
|
contentLicenseId: string;
|
|
23
|
-
}
|
|
26
|
+
};
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Standard entity shape - with resolved references
|
|
@@ -28,13 +31,14 @@ export type BaseEntity = {
|
|
|
28
31
|
*/
|
|
29
32
|
export type StandardEntity = {
|
|
30
33
|
id: string;
|
|
34
|
+
entityType: string;
|
|
31
35
|
name: string;
|
|
32
36
|
description: string;
|
|
33
37
|
memberOf: EntityReference | null;
|
|
34
38
|
rootCollection: EntityReference | null;
|
|
35
39
|
metadataLicenseId: string;
|
|
36
40
|
contentLicenseId: string;
|
|
37
|
-
}
|
|
41
|
+
};
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Access information for an entity
|
|
@@ -42,6 +46,7 @@ export type StandardEntity = {
|
|
|
42
46
|
type AccessInfo = {
|
|
43
47
|
metadata: boolean;
|
|
44
48
|
content: boolean;
|
|
49
|
+
metadataAuthorizationUrl?: string;
|
|
45
50
|
contentAuthorizationUrl?: string;
|
|
46
51
|
};
|
|
47
52
|
|
|
@@ -65,16 +70,12 @@ type FileAccessInfo = {
|
|
|
65
70
|
/**
|
|
66
71
|
* Standard file shape - output of base file transformation
|
|
67
72
|
* Does not include access information
|
|
68
|
-
* Files only have contentLicenseId (no metadataLicenseId)
|
|
69
73
|
*/
|
|
70
74
|
export type StandardFile = {
|
|
71
75
|
id: string;
|
|
72
76
|
filename: string;
|
|
73
77
|
mediaType: string;
|
|
74
78
|
size: number;
|
|
75
|
-
memberOf: string;
|
|
76
|
-
rootCollection: string;
|
|
77
|
-
contentLicenseId: string;
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -89,10 +90,11 @@ export type AuthorisedFile = StandardFile & {
|
|
|
89
90
|
/**
|
|
90
91
|
* Base entity transformer - always applied first
|
|
91
92
|
* Transforms raw database entity to base entity shape with unresolved references
|
|
93
|
+
* Accepts Entity with optional file relation included
|
|
92
94
|
*/
|
|
93
|
-
export const baseEntityTransformer = (entity:
|
|
95
|
+
export const baseEntityTransformer = (entity: EntityWithFile): BaseEntity => {
|
|
94
96
|
const base: BaseEntity = {
|
|
95
|
-
id: entity.
|
|
97
|
+
id: entity.id,
|
|
96
98
|
name: entity.name,
|
|
97
99
|
description: entity.description,
|
|
98
100
|
entityType: entity.entityType,
|
|
@@ -102,18 +104,6 @@ export const baseEntityTransformer = (entity: Entity): BaseEntity => {
|
|
|
102
104
|
contentLicenseId: entity.contentLicenseId,
|
|
103
105
|
};
|
|
104
106
|
|
|
105
|
-
if (base.entityType === ('http://schema.org/MediaObject' as const)) {
|
|
106
|
-
if (!entity.fileId) {
|
|
107
|
-
return base;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
...base,
|
|
112
|
-
entityType: base.entityType,
|
|
113
|
-
fileId: entity.fileId,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
107
|
return base;
|
|
118
108
|
};
|
|
119
109
|
|
|
@@ -148,13 +138,10 @@ export const AllPublicAccessTransformer = (entity: StandardEntity): AuthorisedEn
|
|
|
148
138
|
* Transforms raw database file to standard file shape (without access)
|
|
149
139
|
*/
|
|
150
140
|
export const baseFileTransformer = (file: File): StandardFile => ({
|
|
151
|
-
id: file.
|
|
141
|
+
id: file.id,
|
|
152
142
|
filename: file.filename,
|
|
153
143
|
mediaType: file.mediaType,
|
|
154
144
|
size: Number(file.size),
|
|
155
|
-
memberOf: file.memberOf,
|
|
156
|
-
rootCollection: file.rootCollection,
|
|
157
|
-
contentLicenseId: file.contentLicenseId,
|
|
158
145
|
});
|
|
159
146
|
|
|
160
147
|
/**
|
|
@@ -215,9 +202,9 @@ export const resolveEntityReferences = async (
|
|
|
215
202
|
}
|
|
216
203
|
|
|
217
204
|
const refs = await prisma.entity.findMany({
|
|
218
|
-
where: {
|
|
219
|
-
select: {
|
|
205
|
+
where: { id: { in: [...refIds] } },
|
|
206
|
+
select: { id: true, name: true },
|
|
220
207
|
});
|
|
221
208
|
|
|
222
|
-
return new Map(refs.map((r) => [r.
|
|
209
|
+
return new Map(refs.map((r) => [r.id, { id: r.id, name: r.name }]));
|
|
223
210
|
};
|
|
@@ -37,12 +37,11 @@ describe('Entity Transformers', () => {
|
|
|
37
37
|
describe('baseEntityTransformer', () => {
|
|
38
38
|
it('should transform raw entity to base shape with unresolved references', () => {
|
|
39
39
|
const rawEntity = {
|
|
40
|
-
id:
|
|
41
|
-
rocrateId: 'http://example.com/entity/123',
|
|
40
|
+
id: 'http://example.com/entity/123',
|
|
42
41
|
name: 'Test Entity',
|
|
43
42
|
description: 'A test entity',
|
|
44
43
|
entityType: 'http://schema.org/Person',
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
memberOf: 'http://example.com/collection',
|
|
47
46
|
rootCollection: 'http://example.com/root',
|
|
48
47
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -195,12 +194,11 @@ describe('Entity Transformers', () => {
|
|
|
195
194
|
|
|
196
195
|
it('should demonstrate full pipeline: base -> resolve -> access -> custom', async () => {
|
|
197
196
|
const rawEntity = {
|
|
198
|
-
id:
|
|
199
|
-
rocrateId: 'http://example.com/entity/123',
|
|
197
|
+
id: 'http://example.com/entity/123',
|
|
200
198
|
name: 'Test Entity',
|
|
201
199
|
description: 'A test entity',
|
|
202
200
|
entityType: 'http://schema.org/Person',
|
|
203
|
-
|
|
201
|
+
|
|
204
202
|
memberOf: 'http://example.com/collection',
|
|
205
203
|
rootCollection: 'http://example.com/root',
|
|
206
204
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
package/src/utils/errors.ts
CHANGED
|
@@ -29,16 +29,20 @@ const createErrorResponse = (code: ErrorCode, message: string, details?: ErrorDe
|
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
type ValidationViolation = {
|
|
33
|
+
field: string;
|
|
34
|
+
message: string;
|
|
35
|
+
value?: unknown;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const createValidationError = (message: string, violations: ValidationViolation[]): StandardErrorResponse =>
|
|
39
|
+
createErrorResponse(ERROR_CODES.VALIDATION_ERROR, message, { violations });
|
|
34
40
|
|
|
35
41
|
export const createNotFoundError = (message: string, entityId?: string): StandardErrorResponse =>
|
|
36
42
|
createErrorResponse(ERROR_CODES.NOT_FOUND, message, entityId ? { entityId } : undefined);
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// retryAfter,
|
|
41
|
-
// });
|
|
44
|
+
export const createInvalidRequestError = (message: string): StandardErrorResponse =>
|
|
45
|
+
createErrorResponse(ERROR_CODES.INVALID_REQUEST, message);
|
|
42
46
|
|
|
43
47
|
export const createInternalError = (message = 'Internal server error'): StandardErrorResponse => {
|
|
44
48
|
return createErrorResponse(ERROR_CODES.INTERNAL_ERROR, message);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FastifyReply } from 'fastify';
|
|
2
|
+
|
|
3
|
+
export const setFileHeaders = (
|
|
4
|
+
reply: FastifyReply,
|
|
5
|
+
metadata: { contentType: string; contentLength: number; etag?: string; lastModified?: Date },
|
|
6
|
+
) => {
|
|
7
|
+
reply.header('Content-Type', metadata.contentType);
|
|
8
|
+
reply.header('Content-Length', metadata.contentLength.toString());
|
|
9
|
+
|
|
10
|
+
if (metadata.etag) {
|
|
11
|
+
reply.header('ETag', metadata.etag);
|
|
12
|
+
}
|
|
13
|
+
if (metadata.lastModified) {
|
|
14
|
+
reply.header('Last-Modified', metadata.lastModified.toUTCString());
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -92,7 +92,7 @@ export class OpensearchQueryBuilder {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
buildAggregations(geohashPrecision
|
|
95
|
+
buildAggregations(geohashPrecision?: number, boundingBox?: BoundingBox) {
|
|
96
96
|
const aggs = { ...this.aggregations };
|
|
97
97
|
|
|
98
98
|
// Add geohash aggregation if precision is specified
|
|
@@ -123,12 +123,10 @@ export class OpensearchQueryBuilder {
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (sortField === 'name') {
|
|
126
|
+
if (sort === 'name') {
|
|
129
127
|
return [{ 'name.keyword': order }];
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
return [{ [
|
|
130
|
+
return [{ [sort]: order }];
|
|
133
131
|
}
|
|
134
132
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE `Entity` (
|
|
3
|
-
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
4
|
-
`rocrateId` VARCHAR(191) NOT NULL,
|
|
5
|
-
`name` VARCHAR(191) NOT NULL,
|
|
6
|
-
`description` VARCHAR(191) NOT NULL,
|
|
7
|
-
`conformsTo` VARCHAR(191) NOT NULL,
|
|
8
|
-
`memberOf` VARCHAR(191) NULL,
|
|
9
|
-
`root` VARCHAR(191) NULL,
|
|
10
|
-
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
11
|
-
`updatedAt` DATETIME(3) NOT NULL,
|
|
12
|
-
|
|
13
|
-
PRIMARY KEY (`id`)
|
|
14
|
-
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
-- AlterTable
|
|
2
|
-
ALTER TABLE `Entity` MODIFY `rocrateId` VARCHAR(2048) NOT NULL,
|
|
3
|
-
MODIFY `name` VARCHAR(1024) NOT NULL,
|
|
4
|
-
MODIFY `description` TEXT NOT NULL,
|
|
5
|
-
MODIFY `conformsTo` VARCHAR(2048) NOT NULL,
|
|
6
|
-
MODIFY `memberOf` VARCHAR(2048) NULL,
|
|
7
|
-
MODIFY `root` VARCHAR(2048) NULL;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- You are about to alter the column `recordType` on the `Entity` table. The data in that column could be lost. The data in that column will be cast from `Json` to `Enum(EnumId(0))`.
|
|
5
|
-
- Made the column `rocrate` on table `Entity` required. This step will fail if there are existing NULL values in that column.
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
-- AlterTable
|
|
9
|
-
ALTER TABLE `Entity` MODIFY `recordType` ENUM('RepositoryCollection', 'RepositoryObject') NOT NULL,
|
|
10
|
-
MODIFY `rocrate` JSON NOT NULL;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Phased migration to preserve data while renaming and remapping fields:
|
|
3
|
-
1. Add new columns with defaults
|
|
4
|
-
2. Copy and transform data from old columns to new ones
|
|
5
|
-
3. Drop old columns
|
|
6
|
-
4. Remove defaults from new columns where appropriate
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
-- Step 1: Add new columns with temporary defaults
|
|
10
|
-
ALTER TABLE `Entity`
|
|
11
|
-
ADD COLUMN `entityType` ENUM('http://pcdm.org/models#Collection', 'http://pcdm.org/models#Object', 'http://schema.org/MediaObject', 'http://schema.org/Person') NOT NULL DEFAULT 'http://pcdm.org/models#Collection',
|
|
12
|
-
ADD COLUMN `rootCollection` VARCHAR(2048) NULL,
|
|
13
|
-
ADD COLUMN `metadataLicenseId` VARCHAR(2048) NOT NULL DEFAULT 'FIXME',
|
|
14
|
-
ADD COLUMN `contentLicenseId` VARCHAR(2048) NOT NULL DEFAULT 'FIXME';
|
|
15
|
-
|
|
16
|
-
-- Step 2: Copy and transform data from old columns
|
|
17
|
-
-- Map conformsTo URLs to new entityType enum values
|
|
18
|
-
UPDATE `Entity` SET `entityType` =
|
|
19
|
-
CASE
|
|
20
|
-
WHEN `conformsTo` LIKE '%Collection%' THEN 'http://pcdm.org/models#Collection'
|
|
21
|
-
WHEN `conformsTo` LIKE '%Object%' THEN 'http://pcdm.org/models#Object'
|
|
22
|
-
WHEN `conformsTo` LIKE '%File%' THEN 'http://schema.org/MediaObject'
|
|
23
|
-
ELSE 'http://pcdm.org/models#Person' -- Default fallback
|
|
24
|
-
END;
|
|
25
|
-
|
|
26
|
-
-- Copy root to rootCollection
|
|
27
|
-
UPDATE `Entity` SET `rootCollection` = `root`;
|
|
28
|
-
|
|
29
|
-
-- Step 3: Drop old columns
|
|
30
|
-
ALTER TABLE `Entity`
|
|
31
|
-
DROP COLUMN `conformsTo`,
|
|
32
|
-
DROP COLUMN `recordType`,
|
|
33
|
-
DROP COLUMN `root`;
|
|
34
|
-
|
|
35
|
-
-- Step 4: Remove temporary default from entityType (keep defaults for license fields)
|
|
36
|
-
ALTER TABLE `Entity`
|
|
37
|
-
ALTER COLUMN `entityType` DROP DEFAULT,
|
|
38
|
-
ALTER COLUMN `metadataLicenseId` DROP DEFAULT,
|
|
39
|
-
ALTER COLUMN `contentLicenseId` DROP DEFAULT;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Warnings:
|
|
3
|
-
|
|
4
|
-
- You are about to alter the column `entityType` on the `Entity` table. The data in that column could be lost. The data in that column will be cast from `Enum(EnumId(0))` to `VarChar(1024)`.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
-- AlterTable
|
|
8
|
-
ALTER TABLE `Entity` MODIFY `entityType` VARCHAR(1024) NOT NULL;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE `File` (
|
|
3
|
-
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
4
|
-
`fileId` VARCHAR(2048) NOT NULL,
|
|
5
|
-
`filename` VARCHAR(255) NOT NULL,
|
|
6
|
-
`mediaType` VARCHAR(127) NOT NULL,
|
|
7
|
-
`size` BIGINT NOT NULL,
|
|
8
|
-
`memberOf` VARCHAR(2048) NOT NULL,
|
|
9
|
-
`rootCollection` VARCHAR(2048) NOT NULL,
|
|
10
|
-
`contentLicenseId` VARCHAR(2048) NOT NULL,
|
|
11
|
-
`meta` JSON NULL,
|
|
12
|
-
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
13
|
-
`updatedAt` DATETIME(3) NOT NULL,
|
|
14
|
-
|
|
15
|
-
UNIQUE INDEX `File_fileId_key`(`fileId`(768)),
|
|
16
|
-
PRIMARY KEY (`id`)
|
|
17
|
-
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
package/prisma/schema.prisma
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// This is your Prisma schema file,
|
|
2
|
-
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
3
|
-
|
|
4
|
-
generator client {
|
|
5
|
-
provider = "prisma-client"
|
|
6
|
-
output = "../src/generated/prisma"
|
|
7
|
-
importFileExtension = "js"
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
generator json {
|
|
11
|
-
provider = "prisma-json-types-generator"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
datasource db {
|
|
15
|
-
provider = "mysql"
|
|
16
|
-
url = env("DATABASE_URL")
|
|
17
|
-
}
|