Skip to content

Commit 96dd573

Browse files
committed
refactor: flatten all migrations, to clean migration unrelated to open source project catalogi
1 parent d5cb1e5 commit 96dd573

24 files changed

+294
-1056
lines changed

api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"db:seed": "yarn build && dotenv -e ../.env -- node dist/scripts/seed.js",
2727
"typecheck": "tsc --noEmit",
2828
"migrate": "dotenv -e ../.env -- kysely migrate",
29-
"db:up": "yarn migrate latest",
29+
"migrate:cleanup": "dotenv -e ../.env -- node scripts/cleanup-migrations.js",
30+
"db:up": "yarn migrate:cleanup && yarn migrate latest",
3031
"dev:db:up": "docker compose -f ../docker-compose.resources.yml up -d",
3132
"dev:db:down": "docker compose -f ../docker-compose.resources.yml down",
3233
"dev:db:flush": "rm -rf ../docker-data",

api/scripts/cleanup-migrations.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-FileCopyrightText: 2021-2025 DINUM <floss@numerique.gouv.fr>
2+
// SPDX-FileCopyrightText: 2024-2025 Université Grenoble Alpes
3+
// SPDX-License-Identifier: MIT
4+
5+
/**
6+
* TEMPORARY SCRIPT: Clean up old migration records before running migrations.
7+
*
8+
* This script removes old migration records from kysely_migration table
9+
* to allow the flattened migration (1760000000000_create-base-tables) to run.
10+
*
11+
* DELETE THIS FILE after the migration has been deployed to production.
12+
*/
13+
14+
const { Kysely, PostgresDialect, sql } = require("kysely");
15+
const { Pool } = require("pg");
16+
17+
async function cleanupMigrations() {
18+
const pool = new Pool({
19+
connectionString: process.env.DATABASE_URL
20+
});
21+
22+
const db = new Kysely({
23+
dialect: new PostgresDialect({ pool })
24+
});
25+
26+
try {
27+
// Check if kysely_migration table exists
28+
const { rows } = await sql`
29+
SELECT EXISTS (
30+
SELECT FROM information_schema.tables
31+
WHERE table_schema = 'public'
32+
AND table_name = 'kysely_migration'
33+
) as exists
34+
`.execute(db);
35+
36+
if (!rows[0]?.exists) {
37+
console.log("No kysely_migration table found. Skipping cleanup.");
38+
return;
39+
}
40+
41+
// Delete all old migration records except the flattened one
42+
const result = await db
43+
.deleteFrom("kysely_migration")
44+
.where("name", "!=", "1760000000000_create-base-tables")
45+
.executeTakeFirst();
46+
47+
const numDeleted = Number(result.numDeletedRows || 0);
48+
49+
if (numDeleted > 0) {
50+
console.log(`✓ Cleaned up ${numDeleted} old migration record(s)`);
51+
} else {
52+
console.log("No old migration records to clean up");
53+
}
54+
} catch (error) {
55+
console.error("Error cleaning up migrations:", error);
56+
throw error;
57+
} finally {
58+
await db.destroy();
59+
}
60+
}
61+
62+
cleanupMigrations().catch(err => {
63+
console.error("Fatal error:", err);
64+
process.exit(1);
65+
});

api/src/core/adapters/dbApi/kysely/migrations/1717162141365_create-initial-tables.ts

Lines changed: 0 additions & 115 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1719576701920_add-compiled-tables.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1720187269028_add-indexes.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1731574107668_make_version_min_nullable_in_softwares_and_add_columns_on_software_external_datas.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1733923587668_make-organization-nullable-for-agent.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1737023616811_add-referencePublication.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1738152406578_add-identifiers.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

api/src/core/adapters/dbApi/kysely/migrations/1740045549729_move-framalibreid.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)