Skip to content

Commit 2882caa

Browse files
committed
remove parent software from project
1 parent f8592c8 commit 2882caa

File tree

19 files changed

+50
-229
lines changed

19 files changed

+50
-229
lines changed

api/scripts/load-git-repo-in-pg.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ const insertSoftwares = async (
5959
await trx
6060
.insertInto("softwares")
6161
.values(
62-
softwareRows.map(({ similarSoftwareExternalDataIds: _, addedByAgentEmail, ...row }) => {
63-
// @ts-ignore
64-
const { testUrls: _1, catalogNumeriqueGouvFrId: _2, ...sanitizedRow } = row; // removing fields that have been deleted since
62+
softwareRows.map(originalRow => {
63+
const {
64+
// @ts-ignore
65+
similarSoftwareExternalDataIds,
66+
// @ts-ignore
67+
testUrls,
68+
// @ts-ignore
69+
parentSoftwareWikidataId,
70+
// @ts-ignore
71+
catalogNumeriqueGouvFrId,
72+
addedByAgentEmail,
73+
...row
74+
} = originalRow;
75+
6576
return {
66-
...sanitizedRow,
77+
...row,
6778
addedByAgentId: agentIdByEmail[addedByAgentEmail],
6879
dereferencing: row.dereferencing ? JSON.stringify(row.dereferencing) : null,
6980
softwareType: JSON.stringify(row.softwareType),

api/src/core/adapters/dbApi/kysely/createGetCompiledData.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Kysely } from "kysely";
22
import { CompiledData } from "../../../ports/CompileData";
33
import { Db } from "../../../ports/DbApi";
4-
import { ParentSoftwareExternalData, SoftwareExternalData } from "../../../ports/GetSoftwareExternalData";
4+
import type { SoftwareExternalData } from "../../../ports/GetSoftwareExternalData";
55
import { Database } from "./kysely.database";
66
import { stripNullOrUndefinedValues, isNotNull, jsonBuildObject, jsonStripNulls } from "./kysely.utils";
77

@@ -22,7 +22,6 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
2222
.leftJoin("software_users as users", "s.id", "users.softwareId")
2323
.leftJoin("instances", "s.id", "instances.mainSoftwareSillId")
2424
.leftJoin("software_external_datas as ext", "ext.externalId", "s.externalId")
25-
.leftJoin("software_external_datas as parentExt", "parentExt.externalId", "s.parentSoftwareWikidataId")
2625
.leftJoin(
2726
"softwares__similar_software_external_datas",
2827
"softwares__similar_software_external_datas.softwareId",
@@ -33,7 +32,7 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
3332
"softwares__similar_software_external_datas.similarExternalId",
3433
"similarExt.externalId"
3534
)
36-
.groupBy(["s.id", "csft.softwareId", "parentExt.externalId", "ext.externalId"])
35+
.groupBy(["s.id", "csft.softwareId", "ext.externalId"])
3736
.select([
3837
"s.id",
3938
"s.addedByAgentId",
@@ -61,19 +60,6 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
6160
"csft.comptoirDuLibreSoftware",
6261
"csft.latestVersion",
6362
"csft.serviceProviders",
64-
({ ref, ...qb }) =>
65-
qb
66-
.case()
67-
.when("parentExt.externalId", "is not", null)
68-
.then(
69-
jsonBuildObject({
70-
externalId: ref("parentExt.externalId"),
71-
label: ref("parentExt.label"),
72-
description: ref("parentExt.description")
73-
}).$castTo<ParentSoftwareExternalData>()
74-
)
75-
.end()
76-
.as("parentWikidataSoftware"),
7763
({ ref, ...qb }) =>
7864
qb
7965
.case()
@@ -113,7 +99,6 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
11399
annuaireCnllServiceProviders,
114100
comptoirDuLibreSoftware,
115101
latestVersion,
116-
parentWikidataSoftware,
117102
serviceProviders,
118103
similarExternalSoftwares,
119104
dereferencing,
@@ -136,7 +121,6 @@ export const createGetCompiledData = (db: Kysely<Database>) => async (): Promise
136121
annuaireCnllServiceProviders: annuaireCnllServiceProviders ?? undefined,
137122
comptoirDuLibreSoftware: comptoirDuLibreSoftware ?? undefined,
138123
latestVersion: latestVersion ?? undefined,
139-
parentWikidataSoftware: parentWikidataSoftware ?? undefined,
140124
dereferencing: dereferencing ?? undefined,
141125
serviceProviders: serviceProviders ?? [],
142126
similarExternalSoftwares: (similarExternalSoftwares ?? [])

api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Kysely, sql } from "kysely";
22
import type { Equals } from "tsafe";
33
import { assert } from "tsafe/assert";
44
import { SoftwareRepository } from "../../../ports/DbApiV2";
5-
import { ParentSoftwareExternalData } from "../../../ports/GetSoftwareExternalData";
65
import { Software } from "../../../usecases/readWriteSillData";
76
import { Database } from "./kysely.database";
87
import { stripNullOrUndefinedValues, jsonBuildObject } from "./kysely.utils";
@@ -55,7 +54,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
5554
updateTime: now,
5655
dereferencing: undefined,
5756
isStillInObservation: false,
58-
parentSoftwareWikidataId: undefined,
5957
doRespectRgaa: doRespectRgaa,
6058
isFromFrenchPublicService: isFromFrenchPublicService,
6159
isPresentInSupportContract: isPresentInSupportContract,
@@ -132,7 +130,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
132130
versionMin: softwareMinimalVersion || null,
133131
updateTime: now,
134132
isStillInObservation: false,
135-
parentSoftwareWikidataId: undefined,
136133
doRespectRgaa: doRespectRgaa,
137134
isFromFrenchPublicService: isFromFrenchPublicService,
138135
isPresentInSupportContract: isPresentInSupportContract,
@@ -156,7 +153,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
156153
if (!result) return;
157154
const {
158155
serviceProviders,
159-
parentExternalData,
160156
updateTime,
161157
addedTime,
162158
softwareExternalData,
@@ -184,7 +180,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
184180
software.comptoirDuLibreSoftware?.external_resources.repository,
185181
documentationUrl: softwareExternalData?.documentationUrl,
186182
comptoirDuLibreServiceProviderCount: software.comptoirDuLibreSoftware?.providers.length ?? 0,
187-
parentWikidataSoftware: parentExternalData,
188183
keywords: software?.keywords ?? softwareExternalData?.keywords ?? [],
189184
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
190185
referencePublications: softwareExternalData?.referencePublications,
@@ -200,11 +195,10 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
200195
const software = await getBySoftwareId(softwareId);
201196
if (!software) return;
202197

203-
const { parentSoftwareExternalId, similarSoftwaresExternalIds } = await db
198+
const { similarSoftwaresExternalIds } = await db
204199
.selectFrom("softwares as s")
205200
.leftJoin("softwares__similar_software_external_datas as sim", "sim.softwareId", "s.id")
206201
.select([
207-
"s.parentSoftwareWikidataId as parentSoftwareExternalId",
208202
qb =>
209203
qb.fn
210204
.jsonAgg(qb.ref("sim.similarExternalId"))
@@ -218,8 +212,7 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
218212

219213
return {
220214
software,
221-
similarSoftwaresExternalIds: similarSoftwaresExternalIds ?? [],
222-
parentSoftwareExternalId: parentSoftwareExternalId ?? undefined
215+
similarSoftwaresExternalIds: similarSoftwaresExternalIds ?? []
223216
};
224217
},
225218
getAll: ({ onlyIfUpdatedMoreThan3HoursAgo } = {}): Promise<Software[]> => {
@@ -240,7 +233,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
240233
return softwares.map(
241234
({
242235
serviceProviders,
243-
parentExternalData,
244236
updateTime,
245237
addedTime,
246238
softwareExternalData,
@@ -285,7 +277,6 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
285277
documentationUrl: softwareExternalData?.documentationUrl ?? undefined,
286278
comptoirDuLibreServiceProviderCount:
287279
software.comptoirDuLibreSoftware?.providers.length ?? 0,
288-
parentWikidataSoftware: parentExternalData ?? undefined,
289280
applicationCategories: software.categories.concat(
290281
softwareExternalData?.applicationCategories ?? []
291282
),
@@ -341,7 +332,6 @@ const makeGetSoftwareBuilder = (db: Kysely<Database>) =>
341332
.selectFrom("softwares as s")
342333
.leftJoin("software_external_datas as ext", "ext.externalId", "s.externalId")
343334
.leftJoin("compiled_softwares as cs", "cs.softwareId", "s.id")
344-
.leftJoin("software_external_datas as parentExt", "s.parentSoftwareWikidataId", "parentExt.externalId")
345335
.leftJoin(
346336
"softwares__similar_software_external_datas",
347337
"softwares__similar_software_external_datas.softwareId",
@@ -359,8 +349,7 @@ const makeGetSoftwareBuilder = (db: Kysely<Database>) =>
359349
"cs.comptoirDuLibreSoftware",
360350
"cs.latestVersion",
361351
"cs.serviceProviders",
362-
"ext.externalId",
363-
"parentExt.externalId"
352+
"ext.externalId"
364353
])
365354
.orderBy("s.id", "asc")
366355
.select([
@@ -396,20 +385,6 @@ const makeGetSoftwareBuilder = (db: Kysely<Database>) =>
396385
"s.externalId",
397386
"s.externalDataOrigin",
398387
"s.softwareType",
399-
({ ref, ...qb }) =>
400-
qb
401-
.case()
402-
.when("parentExt.externalId", "is not", null)
403-
.then(
404-
jsonBuildObject({
405-
externalId: ref("parentExt.externalId"),
406-
label: ref("parentExt.label"),
407-
description: ref("parentExt.description")
408-
}).$castTo<ParentSoftwareExternalData>()
409-
)
410-
.else(null)
411-
.end()
412-
.as("parentExternalData"),
413388
"s.keywords",
414389
({ ref }) =>
415390
jsonBuildObject({
@@ -529,7 +504,6 @@ const makeGetSoftwareById =
529504
if (!result) return;
530505
const {
531506
serviceProviders,
532-
parentExternalData,
533507
updateTime,
534508
addedTime,
535509
softwareExternalData,
@@ -557,7 +531,6 @@ const makeGetSoftwareById =
557531
software.comptoirDuLibreSoftware?.external_resources.repository,
558532
documentationUrl: softwareExternalData?.documentationUrl,
559533
comptoirDuLibreServiceProviderCount: software.comptoirDuLibreSoftware?.providers.length ?? 0,
560-
parentWikidataSoftware: parentExternalData,
561534
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
562535
referencePublications: softwareExternalData?.referencePublications,
563536
identifiers: softwareExternalData?.identifiers,

api/src/core/adapters/dbApi/kysely/kysely.database.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ type SoftwaresTable = {
123123
doRespectRgaa: boolean | null;
124124
isFromFrenchPublicService: boolean;
125125
isPresentInSupportContract: boolean;
126-
parentSoftwareWikidataId: string | null;
127126
externalId: string | null;
128127
externalDataOrigin: "wikidata" | "HAL" | null;
129128
comptoirDuLibreId: number | null;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Kysely } from "kysely";
2+
3+
export async function up(db: Kysely<any>): Promise<void> {
4+
await db.schema.dropIndex("softwares__parentExternalId_idx").execute();
5+
await db.schema.alterTable("softwares").dropColumn("parentSoftwareWikidataId").execute();
6+
}
7+
8+
export async function down(db: Kysely<any>): Promise<void> {
9+
await db.schema.alterTable("softwares").addColumn("parentSoftwareWikidataId", "text").execute();
10+
// we don't bother with the index
11+
}

api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ const similarSoftwareExternalData: SoftwareExternalData = {
8686
publicationTime: new Date(1561566581000)
8787
};
8888

89-
const parentSoftwareExternalData: SoftwareExternalData = {
90-
...similarSoftwareExternalData,
91-
externalId: "Q-parent-external-id",
92-
label: "Some parent software label",
93-
description: { en: "Some parent software description" }
94-
};
95-
9689
const insertedAgent = {
9790
email: "test@test.com",
9891
organization: "test-organization",
@@ -147,12 +140,6 @@ describe("pgDbApi", () => {
147140
console.log("------ software scenario ------");
148141
const { softwareId, agentId } = await insertSoftwareExternalDataAndSoftwareAndAgent();
149142

150-
await db
151-
.updateTable("softwares")
152-
.set("parentSoftwareWikidataId", parentSoftwareExternalData.externalId)
153-
.where("id", "=", softwareId)
154-
.execute();
155-
156143
await dbApi.softwareUser.add({
157144
agentId,
158145
softwareId,
@@ -191,11 +178,6 @@ describe("pgDbApi", () => {
191178
license: "MIT",
192179
logoUrl: "https://example.com/logo.png",
193180
officialWebsiteUrl: softwareExternalData.websiteUrl,
194-
parentWikidataSoftware: {
195-
label: parentSoftwareExternalData.label,
196-
description: parentSoftwareExternalData.description,
197-
externalId: parentSoftwareExternalData.externalId
198-
},
199181
prerogatives: {
200182
doRespectRgaa: true,
201183
isFromFrenchPublicServices: false,
@@ -437,7 +419,7 @@ describe("pgDbApi", () => {
437419
await db
438420
.insertInto("software_external_datas")
439421
.values(
440-
[softwareExternalData, similarSoftwareExternalData, parentSoftwareExternalData].map(softExtData => ({
422+
[softwareExternalData, similarSoftwareExternalData].map(softExtData => ({
441423
...softExtData,
442424
developers: JSON.stringify(softExtData.developers),
443425
label: JSON.stringify(softExtData.label),

api/src/core/adapters/fetchExternalData.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ const insertApacheWithCorrectId = async (db: Kysely<Database>, agentId: number)
3939
"comptoirDuLibreId", name, description, license, "versionMin",
4040
"isPresentInSupportContract", "isFromFrenchPublicService", "logoUrl",
4141
keywords, "doRespectRgaa", "isStillInObservation",
42-
"parentSoftwareWikidataId", "workshopUrls", categories, "generalInfoMd", "addedByAgentId",
42+
"workshopUrls", categories, "generalInfoMd", "addedByAgentId",
4343
dereferencing, "referencedSinceTime", "updateTime")
4444
VALUES (${apacheSoftwareId},
4545
'{"os": {"ios": false, "mac": false, "linux": true, "android": false, "windows": false}, "type": "desktop/mobile"}',
4646
'Q11354', 'wikidata', 3737, 'Apache HTTP Server',
4747
'Serveur Web & Reverse Proxy', 'Apache-2.0', '212', true, false,
4848
'https://sill.code.gouv.fr/logo/apache-http.png',
4949
'["serveur", "http", "web", "server", "apache"]', false, false,
50-
null, '[]', '[]', null, ${agentId}, null,
50+
'[]', '[]', null, ${agentId}, null,
5151
1728462232094,
5252
1728462232094);
5353
`.execute(db);
@@ -63,7 +63,6 @@ const insertAcceleroWithCorrectId = async (db: Kysely<Database>, agentId: number
6363
"isFromFrenchPublicService", "logoUrl",
6464
keywords, "doRespectRgaa",
6565
"isStillInObservation",
66-
"parentSoftwareWikidataId",
6766
"workshopUrls", categories,
6867
"generalInfoMd", "addedByAgentId",
6968
dereferencing, "referencedSinceTime",
@@ -73,7 +72,7 @@ const insertAcceleroWithCorrectId = async (db: Kysely<Database>, agentId: number
7372
'Outil et/ou plugin de génération de tout ou partie du code',
7473
'EPL-2.0', '3.7.8', false, false, null,
7574
'["modélisation", "génération", "code", "modeling", "code generation"]',
76-
false, false, null, '[]',
75+
false, false, '[]',
7776
'["Other Development Tools"]', null, ${agentId}, null,
7877
1514764800000,
7978
1514764800000);
@@ -513,6 +512,12 @@ describe("fetches software extra data (from different providers)", () => {
513512
siren: "522588979",
514513
cnllUrl: "https://annuaire.cnll.fr/societes/522588979"
515514
},
515+
{
516+
name: "3CT - Consulting and Conception of Cloud Technologies",
517+
cdlUrl: "https://comptoir-du-libre.org/fr/users/4085",
518+
website: "https://www.3ct.fr"
519+
},
520+
516521
{
517522
name: "AUKFOOD",
518523
cdlUrl: "https://comptoir-du-libre.org/fr/users/3288",

api/src/core/adapters/fetchExternalData.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,14 @@ export const makeFetchAndSaveSoftwareExtraData = ({
3535
const data = await dbApi.software.getByIdWithLinkedSoftwaresExternalIds(softwareId);
3636
if (!data) return;
3737

38-
const { software, similarSoftwaresExternalIds, parentSoftwareExternalId } = data;
38+
const { software, similarSoftwaresExternalIds } = data;
3939
console.log(`🚀${software.softwareName}`);
4040

4141
if (software.externalId) {
4242
console.log(" • Soft: ", software.softwareName, " - Own wiki : ", software.externalId);
4343
await getSoftwareExternalDataAndSaveIt(software.externalId, softwareExternalDataCache);
4444
}
4545

46-
if (parentSoftwareExternalId) {
47-
console.log(" • Parent wiki : ", parentSoftwareExternalId);
48-
await getSoftwareExternalDataAndSaveIt(parentSoftwareExternalId, softwareExternalDataCache);
49-
}
50-
5146
if (similarSoftwaresExternalIds.length > 0) {
5247
for (const similarExternalId of similarSoftwaresExternalIds) {
5348
console.log(" • Similar wiki : ", similarExternalId);

0 commit comments

Comments
 (0)