mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
fix: database migration
This commit is contained in:
parent
214e39adda
commit
c21ebe1ce2
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydralauncher",
|
"name": "hydralauncher",
|
||||||
"version": "2.1.2",
|
"version": "2.1.3 ",
|
||||||
"description": "Hydra",
|
"description": "Hydra",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "Los Broxas",
|
"author": "Los Broxas",
|
||||||
|
@ -4,6 +4,7 @@ import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
|
|||||||
import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
||||||
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
|
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
|
||||||
import { EnsureRepackUris } from "./migrations/20240915035339_ensure_repack_uris";
|
import { EnsureRepackUris } from "./migrations/20240915035339_ensure_repack_uris";
|
||||||
|
import { app } from "electron";
|
||||||
|
|
||||||
export type HydraMigration = Knex.Migration & { name: string };
|
export type HydraMigration = Knex.Migration & { name: string };
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const knexClient = knex({
|
export const knexClient = knex({
|
||||||
|
debug: !app.isPackaged,
|
||||||
client: "better-sqlite3",
|
client: "better-sqlite3",
|
||||||
connection: {
|
connection: {
|
||||||
filename: databasePath,
|
filename: databasePath,
|
||||||
|
@ -4,55 +4,15 @@ import type { Knex } from "knex";
|
|||||||
export const RepackUris: HydraMigration = {
|
export const RepackUris: HydraMigration = {
|
||||||
name: "RepackUris",
|
name: "RepackUris",
|
||||||
up: async (knex: Knex) => {
|
up: async (knex: Knex) => {
|
||||||
await knex.schema.createTable("temporary_repack", (table) => {
|
await knex.schema.alterTable("repack", (table) => {
|
||||||
const timestamp = new Date().getTime();
|
|
||||||
table.increments("id").primary();
|
|
||||||
table
|
|
||||||
.text("title")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "repack_title_unique_" + timestamp });
|
|
||||||
table
|
|
||||||
.text("magnet")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "repack_magnet_unique_" + timestamp });
|
|
||||||
table.text("repacker").notNullable();
|
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
table.text("uris").notNullable().defaultTo("[]");
|
table.text("uris").notNullable().defaultTo("[]");
|
||||||
});
|
});
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "temporary_repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("repack");
|
|
||||||
await knex.schema.renameTable("temporary_repack", "repack");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
down: async (knex: Knex) => {
|
down: async (knex: Knex) => {
|
||||||
await knex.schema.renameTable("repack", "temporary_repack");
|
await knex.schema.alterTable("repack", (table) => {
|
||||||
await knex.schema.createTable("repack", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table.text("title").notNullable().unique();
|
|
||||||
table.text("magnet").notNullable().unique();
|
|
||||||
table.integer("page");
|
table.integer("page");
|
||||||
table.text("repacker").notNullable();
|
table.dropColumn("uris");
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
});
|
});
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "temporary_repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("temporary_repack");
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -4,55 +4,14 @@ import type { Knex } from "knex";
|
|||||||
export const EnsureRepackUris: HydraMigration = {
|
export const EnsureRepackUris: HydraMigration = {
|
||||||
name: "EnsureRepackUris",
|
name: "EnsureRepackUris",
|
||||||
up: async (knex: Knex) => {
|
up: async (knex: Knex) => {
|
||||||
await knex.schema.createTable("temporary_repack", (table) => {
|
await knex.schema.hasColumn("repack", "uris").then(async (exists) => {
|
||||||
const timestamp = new Date().getTime();
|
if (!exists) {
|
||||||
table.increments("id").primary();
|
await knex.schema.table("repack", (table) => {
|
||||||
table
|
table.text("uris").notNullable().defaultTo("[]");
|
||||||
.text("title")
|
});
|
||||||
.notNullable()
|
}
|
||||||
.unique({ indexName: "repack_title_unique_" + timestamp });
|
|
||||||
table
|
|
||||||
.text("magnet")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "repack_magnet_unique_" + timestamp });
|
|
||||||
table.text("repacker").notNullable();
|
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
table.text("uris").notNullable().defaultTo("[]");
|
|
||||||
});
|
});
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "temporary_repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("repack");
|
|
||||||
await knex.schema.renameTable("temporary_repack", "repack");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
down: async (knex: Knex) => {
|
down: async (_knex: Knex) => {},
|
||||||
await knex.schema.renameTable("repack", "temporary_repack");
|
|
||||||
await knex.schema.createTable("repack", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table.text("title").notNullable().unique();
|
|
||||||
table.text("magnet").notNullable().unique();
|
|
||||||
table.integer("page");
|
|
||||||
table.text("repacker").notNullable();
|
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
});
|
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "temporary_repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("temporary_repack");
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user