|
| 1 | +// SPDX-FileCopyrightText: 2021-2025 DINUM <[email protected]> |
| 2 | +// SPDX-FileCopyrightText: 2024-2025 Université Grenoble Alpes |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import { Kysely, sql } from "kysely"; |
| 6 | + |
| 7 | +export async function up(db: Kysely<any>): Promise<void> { |
| 8 | + await db.schema.alterTable("softwares").addColumn("referencedSinceTime_temp", "timestamptz").execute(); |
| 9 | + await sql`UPDATE softwares SET "referencedSinceTime_temp" = to_timestamp("referencedSinceTime" / 1000.0)`.execute( |
| 10 | + db |
| 11 | + ); |
| 12 | + await db.schema |
| 13 | + .alterTable("softwares") |
| 14 | + .alterColumn("referencedSinceTime_temp", col => col.setNotNull()) |
| 15 | + .execute(); |
| 16 | + await db.schema.alterTable("softwares").dropColumn("referencedSinceTime").execute(); |
| 17 | + await db.schema.alterTable("softwares").renameColumn("referencedSinceTime_temp", "referencedSinceTime").execute(); |
| 18 | + |
| 19 | + await db.schema.alterTable("softwares").addColumn("updateTime_temp", "timestamptz").execute(); |
| 20 | + await sql`UPDATE softwares SET "updateTime_temp" = to_timestamp("updateTime" / 1000.0)`.execute(db); |
| 21 | + await db.schema |
| 22 | + .alterTable("softwares") |
| 23 | + .alterColumn("updateTime_temp", col => col.setNotNull()) |
| 24 | + .execute(); |
| 25 | + await db.schema.alterTable("softwares").dropColumn("updateTime").execute(); |
| 26 | + await db.schema.alterTable("softwares").renameColumn("updateTime_temp", "updateTime").execute(); |
| 27 | + |
| 28 | + await db.schema.alterTable("instances").addColumn("referencedSinceTime_temp", "timestamptz").execute(); |
| 29 | + await sql`UPDATE instances SET "referencedSinceTime_temp" = to_timestamp("referencedSinceTime" / 1000.0)`.execute( |
| 30 | + db |
| 31 | + ); |
| 32 | + await db.schema |
| 33 | + .alterTable("instances") |
| 34 | + .alterColumn("referencedSinceTime_temp", col => col.setNotNull()) |
| 35 | + .execute(); |
| 36 | + await db.schema.alterTable("instances").dropColumn("referencedSinceTime").execute(); |
| 37 | + await db.schema.alterTable("instances").renameColumn("referencedSinceTime_temp", "referencedSinceTime").execute(); |
| 38 | + |
| 39 | + await db.schema.alterTable("instances").addColumn("updateTime_temp", "timestamptz").execute(); |
| 40 | + await sql`UPDATE instances SET "updateTime_temp" = to_timestamp("updateTime" / 1000.0)`.execute(db); |
| 41 | + await db.schema |
| 42 | + .alterTable("instances") |
| 43 | + .alterColumn("updateTime_temp", col => col.setNotNull()) |
| 44 | + .execute(); |
| 45 | + await db.schema.alterTable("instances").dropColumn("updateTime").execute(); |
| 46 | + await db.schema.alterTable("instances").renameColumn("updateTime_temp", "updateTime").execute(); |
| 47 | + |
| 48 | + await db.schema.alterTable("software_external_datas").addColumn("lastDataFetchAt_temp", "timestamptz").execute(); |
| 49 | + await sql`UPDATE software_external_datas SET "lastDataFetchAt_temp" = to_timestamp("lastDataFetchAt" / 1000.0) WHERE "lastDataFetchAt" IS NOT NULL`.execute( |
| 50 | + db |
| 51 | + ); |
| 52 | + await db.schema.alterTable("software_external_datas").dropColumn("lastDataFetchAt").execute(); |
| 53 | + await db.schema |
| 54 | + .alterTable("software_external_datas") |
| 55 | + .renameColumn("lastDataFetchAt_temp", "lastDataFetchAt") |
| 56 | + .execute(); |
| 57 | +} |
| 58 | + |
| 59 | +export async function down(db: Kysely<any>): Promise<void> { |
| 60 | + await db.schema.alterTable("softwares").addColumn("referencedSinceTime_temp", "bigint").execute(); |
| 61 | + await sql`UPDATE softwares SET "referencedSinceTime_temp" = EXTRACT(EPOCH FROM "referencedSinceTime")::bigint * 1000`.execute( |
| 62 | + db |
| 63 | + ); |
| 64 | + await db.schema |
| 65 | + .alterTable("softwares") |
| 66 | + .alterColumn("referencedSinceTime_temp", col => col.setNotNull()) |
| 67 | + .execute(); |
| 68 | + await db.schema.alterTable("softwares").dropColumn("referencedSinceTime").execute(); |
| 69 | + await db.schema.alterTable("softwares").renameColumn("referencedSinceTime_temp", "referencedSinceTime").execute(); |
| 70 | + |
| 71 | + await db.schema.alterTable("softwares").addColumn("updateTime_temp", "bigint").execute(); |
| 72 | + await sql`UPDATE softwares SET "updateTime_temp" = EXTRACT(EPOCH FROM "updateTime")::bigint * 1000`.execute(db); |
| 73 | + await db.schema |
| 74 | + .alterTable("softwares") |
| 75 | + .alterColumn("updateTime_temp", col => col.setNotNull()) |
| 76 | + .execute(); |
| 77 | + await db.schema.alterTable("softwares").dropColumn("updateTime").execute(); |
| 78 | + await db.schema.alterTable("softwares").renameColumn("updateTime_temp", "updateTime").execute(); |
| 79 | + |
| 80 | + await db.schema.alterTable("instances").addColumn("referencedSinceTime_temp", "bigint").execute(); |
| 81 | + await sql`UPDATE instances SET "referencedSinceTime_temp" = EXTRACT(EPOCH FROM "referencedSinceTime")::bigint * 1000`.execute( |
| 82 | + db |
| 83 | + ); |
| 84 | + await db.schema |
| 85 | + .alterTable("instances") |
| 86 | + .alterColumn("referencedSinceTime_temp", col => col.setNotNull()) |
| 87 | + .execute(); |
| 88 | + await db.schema.alterTable("instances").dropColumn("referencedSinceTime").execute(); |
| 89 | + await db.schema.alterTable("instances").renameColumn("referencedSinceTime_temp", "referencedSinceTime").execute(); |
| 90 | + |
| 91 | + await db.schema.alterTable("instances").addColumn("updateTime_temp", "bigint").execute(); |
| 92 | + await sql`UPDATE instances SET "updateTime_temp" = EXTRACT(EPOCH FROM "updateTime")::bigint * 1000`.execute(db); |
| 93 | + await db.schema |
| 94 | + .alterTable("instances") |
| 95 | + .alterColumn("updateTime_temp", col => col.setNotNull()) |
| 96 | + .execute(); |
| 97 | + await db.schema.alterTable("instances").dropColumn("updateTime").execute(); |
| 98 | + await db.schema.alterTable("instances").renameColumn("updateTime_temp", "updateTime").execute(); |
| 99 | + |
| 100 | + await db.schema.alterTable("software_external_datas").addColumn("lastDataFetchAt_temp", "bigint").execute(); |
| 101 | + await sql`UPDATE software_external_datas SET "lastDataFetchAt_temp" = EXTRACT(EPOCH FROM "lastDataFetchAt")::bigint * 1000 WHERE "lastDataFetchAt" IS NOT NULL`.execute( |
| 102 | + db |
| 103 | + ); |
| 104 | + await db.schema.alterTable("software_external_datas").dropColumn("lastDataFetchAt").execute(); |
| 105 | + await db.schema |
| 106 | + .alterTable("software_external_datas") |
| 107 | + .renameColumn("lastDataFetchAt_temp", "lastDataFetchAt") |
| 108 | + .execute(); |
| 109 | +} |
0 commit comments