mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-14 20:22:10 +00:00
feat: add migration to add missing columns from installations before 2.0
This commit is contained in:
parent
b76441a763
commit
aa2ecfad96
2 changed files with 43 additions and 0 deletions
|
@ -5,6 +5,7 @@ import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
|||
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
|
||||
import { EnsureRepackUris } from "./migrations/20240915035339_ensure_repack_uris";
|
||||
import { app } from "electron";
|
||||
import { FixMissingColumns } from "./migrations/20240918001920_FixMissingColumns";
|
||||
|
||||
export type HydraMigration = Knex.Migration & { name: string };
|
||||
|
||||
|
@ -15,6 +16,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
|||
RepackUris,
|
||||
UpdateUserLanguage,
|
||||
EnsureRepackUris,
|
||||
FixMissingColumns,
|
||||
]);
|
||||
}
|
||||
getMigrationName(migration: HydraMigration): string {
|
||||
|
|
41
src/main/migrations/20240918001920_FixMissingColumns.ts
Normal file
41
src/main/migrations/20240918001920_FixMissingColumns.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import type { HydraMigration } from "@main/knex-client";
|
||||
import type { Knex } from "knex";
|
||||
|
||||
export const FixMissingColumns: HydraMigration = {
|
||||
name: "FixMissingColumns",
|
||||
up: async (knex: Knex) => {
|
||||
const timestamp = new Date().getTime();
|
||||
await knex.schema
|
||||
.hasColumn("repack", "downloadSourceId")
|
||||
.then(async (exists) => {
|
||||
if (!exists) {
|
||||
await knex.schema.table("repack", (table) => {
|
||||
table
|
||||
.integer("downloadSourceId")
|
||||
.references("download_source.id")
|
||||
.onDelete("CASCADE");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await knex.schema.hasColumn("game", "remoteId").then(async (exists) => {
|
||||
if (!exists) {
|
||||
await knex.schema.table("game", (table) => {
|
||||
table
|
||||
.text("remoteId")
|
||||
.unique({ indexName: "game_remoteId_unique_" + timestamp });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await knex.schema.hasColumn("game", "uri").then(async (exists) => {
|
||||
if (!exists) {
|
||||
await knex.schema.table("game", (table) => {
|
||||
table.text("uri");
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
down: async (_knex: Knex) => {},
|
||||
};
|
Loading…
Reference in a new issue