mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: refactor
This commit is contained in:
parent
89399a6da4
commit
567d9f540d
@ -2,3 +2,4 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
out
|
out
|
||||||
.gitignore
|
.gitignore
|
||||||
|
migration.stub
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
"build:win": "electron-vite build && electron-builder --win",
|
"build:win": "electron-vite build && electron-builder --win",
|
||||||
"build:mac": "electron-vite build && electron-builder --mac",
|
"build:mac": "electron-vite build && electron-builder --mac",
|
||||||
"build:linux": "electron-vite build && electron-builder --linux",
|
"build:linux": "electron-vite build && electron-builder --linux",
|
||||||
"prepare": "husky"
|
"prepare": "husky",
|
||||||
|
"knex:migrate:make": "knex --knexfile src/main/knexfile.ts migrate:make --esm"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.0",
|
"@electron-toolkit/preload": "^3.0.0",
|
||||||
@ -106,6 +107,7 @@
|
|||||||
"prettier": "^3.2.4",
|
"prettier": "^3.2.4",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.0.12",
|
"vite": "^5.0.12",
|
||||||
"vite-plugin-svgr": "^4.2.0"
|
"vite-plugin-svgr": "^4.2.0"
|
||||||
|
BIN
src/main/hydra.dev.db
Normal file
BIN
src/main/hydra.dev.db
Normal file
Binary file not shown.
@ -1,19 +1,18 @@
|
|||||||
import knex, { Knex } from "knex";
|
import knex, { Knex } from "knex";
|
||||||
import { databasePath } from "./constants";
|
import { databasePath } from "./constants";
|
||||||
import * as migrations from "./migrations";
|
import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
|
||||||
|
import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
||||||
|
|
||||||
type Migration = Knex.Migration & { name: string };
|
export type HydraMigration = Knex.Migration & { name: string };
|
||||||
|
|
||||||
class MigrationSource implements Knex.MigrationSource<Migration> {
|
class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
||||||
getMigrations(): Promise<Migration[]> {
|
getMigrations(): Promise<HydraMigration[]> {
|
||||||
return Promise.resolve(
|
return Promise.resolve([Hydra2_0_3, RepackUris]);
|
||||||
Object.values(migrations).sort((a, b) => a.name.localeCompare(b.name))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
getMigrationName(migration: Migration): string {
|
getMigrationName(migration: HydraMigration): string {
|
||||||
return migration.name;
|
return migration.name;
|
||||||
}
|
}
|
||||||
getMigration(migration: Migration): Promise<Migration> {
|
getMigration(migration: HydraMigration): Promise<Knex.Migration> {
|
||||||
return Promise.resolve(migration);
|
return Promise.resolve(migration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/main/knexfile.ts
Normal file
10
src/main/knexfile.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const config = {
|
||||||
|
development: {
|
||||||
|
migrations: {
|
||||||
|
extension: "ts",
|
||||||
|
stub: "migrations/migration.stub",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
@ -1,169 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
export const name = "001_Hydra_2_0_3";
|
|
||||||
|
|
||||||
export const up = async (knex: Knex) => {
|
|
||||||
const timestamp = new Date().getTime();
|
|
||||||
|
|
||||||
await knex.schema.hasTable("migrations").then(async (exists) => {
|
|
||||||
if (exists) {
|
|
||||||
await knex.schema.dropTable("migrations");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("download_source").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("download_source", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table
|
|
||||||
.text("url")
|
|
||||||
.unique({ indexName: "download_source_url_unique_" + timestamp });
|
|
||||||
table.text("name").notNullable();
|
|
||||||
table.text("etag");
|
|
||||||
table.integer("downloadCount").notNullable().defaultTo(0);
|
|
||||||
table.text("status").notNullable().defaultTo(0);
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("repack").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("repack", (table) => {
|
|
||||||
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.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.schema.hasTable("game").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("game", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table
|
|
||||||
.text("objectID")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "game_objectID_unique_" + timestamp });
|
|
||||||
table
|
|
||||||
.text("remoteId")
|
|
||||||
.unique({ indexName: "game_remoteId_unique_" + timestamp });
|
|
||||||
table.text("title").notNullable();
|
|
||||||
table.text("iconUrl");
|
|
||||||
table.text("folderName");
|
|
||||||
table.text("downloadPath");
|
|
||||||
table.text("executablePath");
|
|
||||||
table.integer("playTimeInMilliseconds").notNullable().defaultTo(0);
|
|
||||||
table.text("shop").notNullable();
|
|
||||||
table.text("status");
|
|
||||||
table.integer("downloader").notNullable().defaultTo(1);
|
|
||||||
table.float("progress").notNullable().defaultTo(0);
|
|
||||||
table.integer("bytesDownloaded").notNullable().defaultTo(0);
|
|
||||||
table.datetime("lastTimePlayed");
|
|
||||||
table.float("fileSize").notNullable().defaultTo(0);
|
|
||||||
table.text("uri");
|
|
||||||
table.boolean("isDeleted").notNullable().defaultTo(0);
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("repackId")
|
|
||||||
.references("repack.id")
|
|
||||||
.unique("repack_repackId_unique_" + timestamp);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("user_preferences").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("user_preferences", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table.text("downloadsPath");
|
|
||||||
table.text("language").notNullable().defaultTo("en");
|
|
||||||
table.text("realDebridApiToken");
|
|
||||||
table
|
|
||||||
.boolean("downloadNotificationsEnabled")
|
|
||||||
.notNullable()
|
|
||||||
.defaultTo(0);
|
|
||||||
table
|
|
||||||
.boolean("repackUpdatesNotificationsEnabled")
|
|
||||||
.notNullable()
|
|
||||||
.defaultTo(0);
|
|
||||||
table.boolean("preferQuitInsteadOfHiding").notNullable().defaultTo(0);
|
|
||||||
table.boolean("runAtStartup").notNullable().defaultTo(0);
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("game_shop_cache").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("game_shop_cache", (table) => {
|
|
||||||
table.text("objectID").primary().notNullable();
|
|
||||||
table.text("shop").notNullable();
|
|
||||||
table.text("serializedData");
|
|
||||||
table.text("howLongToBeatSerializedData");
|
|
||||||
table.text("language");
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("download_queue").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("download_queue", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table
|
|
||||||
.integer("gameId")
|
|
||||||
.references("game.id")
|
|
||||||
.unique("download_queue_gameId_unique_" + timestamp);
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.hasTable("user_auth").then(async (exists) => {
|
|
||||||
if (!exists) {
|
|
||||||
await knex.schema.createTable("user_auth", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table.text("userId").notNullable().defaultTo("");
|
|
||||||
table.text("displayName").notNullable().defaultTo("");
|
|
||||||
table.text("profileImageUrl");
|
|
||||||
table.text("accessToken").notNullable().defaultTo("");
|
|
||||||
table.text("refreshToken").notNullable().defaultTo("");
|
|
||||||
table.integer("tokenExpirationTimestamp").notNullable().defaultTo(0);
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const down = async (knex: Knex) => {
|
|
||||||
await knex.schema.dropTableIfExists("game");
|
|
||||||
await knex.schema.dropTableIfExists("repack");
|
|
||||||
await knex.schema.dropTableIfExists("download_queue");
|
|
||||||
await knex.schema.dropTableIfExists("user_auth");
|
|
||||||
await knex.schema.dropTableIfExists("game_shop_cache");
|
|
||||||
await knex.schema.dropTableIfExists("user_preferences");
|
|
||||||
await knex.schema.dropTableIfExists("download_source");
|
|
||||||
};
|
|
@ -1,56 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
export const name = "002_RepackUris";
|
|
||||||
|
|
||||||
export const up = async (knex: Knex) => {
|
|
||||||
await knex.schema.createTable("temporary_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("[]");
|
|
||||||
});
|
|
||||||
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");
|
|
||||||
};
|
|
||||||
|
|
||||||
export const 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");
|
|
||||||
};
|
|
171
src/main/migrations/20240830143811_Hydra_2_0_3.ts
Normal file
171
src/main/migrations/20240830143811_Hydra_2_0_3.ts
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
import type { HydraMigration } from "@main/knex-client";
|
||||||
|
import type { Knex } from "knex";
|
||||||
|
|
||||||
|
export const Hydra2_0_3: HydraMigration = {
|
||||||
|
name: "Hydra_2_0_3",
|
||||||
|
up: async (knex: Knex) => {
|
||||||
|
const timestamp = new Date().getTime();
|
||||||
|
|
||||||
|
await knex.schema.hasTable("migrations").then(async (exists) => {
|
||||||
|
if (exists) {
|
||||||
|
await knex.schema.dropTable("migrations");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("download_source").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("download_source", (table) => {
|
||||||
|
table.increments("id").primary();
|
||||||
|
table
|
||||||
|
.text("url")
|
||||||
|
.unique({ indexName: "download_source_url_unique_" + timestamp });
|
||||||
|
table.text("name").notNullable();
|
||||||
|
table.text("etag");
|
||||||
|
table.integer("downloadCount").notNullable().defaultTo(0);
|
||||||
|
table.text("status").notNullable().defaultTo(0);
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("repack").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("repack", (table) => {
|
||||||
|
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.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.schema.hasTable("game").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("game", (table) => {
|
||||||
|
table.increments("id").primary();
|
||||||
|
table
|
||||||
|
.text("objectID")
|
||||||
|
.notNullable()
|
||||||
|
.unique({ indexName: "game_objectID_unique_" + timestamp });
|
||||||
|
table
|
||||||
|
.text("remoteId")
|
||||||
|
.unique({ indexName: "game_remoteId_unique_" + timestamp });
|
||||||
|
table.text("title").notNullable();
|
||||||
|
table.text("iconUrl");
|
||||||
|
table.text("folderName");
|
||||||
|
table.text("downloadPath");
|
||||||
|
table.text("executablePath");
|
||||||
|
table.integer("playTimeInMilliseconds").notNullable().defaultTo(0);
|
||||||
|
table.text("shop").notNullable();
|
||||||
|
table.text("status");
|
||||||
|
table.integer("downloader").notNullable().defaultTo(1);
|
||||||
|
table.float("progress").notNullable().defaultTo(0);
|
||||||
|
table.integer("bytesDownloaded").notNullable().defaultTo(0);
|
||||||
|
table.datetime("lastTimePlayed");
|
||||||
|
table.float("fileSize").notNullable().defaultTo(0);
|
||||||
|
table.text("uri");
|
||||||
|
table.boolean("isDeleted").notNullable().defaultTo(0);
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table
|
||||||
|
.integer("repackId")
|
||||||
|
.references("repack.id")
|
||||||
|
.unique("repack_repackId_unique_" + timestamp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("user_preferences").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("user_preferences", (table) => {
|
||||||
|
table.increments("id").primary();
|
||||||
|
table.text("downloadsPath");
|
||||||
|
table.text("language").notNullable().defaultTo("en");
|
||||||
|
table.text("realDebridApiToken");
|
||||||
|
table
|
||||||
|
.boolean("downloadNotificationsEnabled")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(0);
|
||||||
|
table
|
||||||
|
.boolean("repackUpdatesNotificationsEnabled")
|
||||||
|
.notNullable()
|
||||||
|
.defaultTo(0);
|
||||||
|
table.boolean("preferQuitInsteadOfHiding").notNullable().defaultTo(0);
|
||||||
|
table.boolean("runAtStartup").notNullable().defaultTo(0);
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("game_shop_cache").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("game_shop_cache", (table) => {
|
||||||
|
table.text("objectID").primary().notNullable();
|
||||||
|
table.text("shop").notNullable();
|
||||||
|
table.text("serializedData");
|
||||||
|
table.text("howLongToBeatSerializedData");
|
||||||
|
table.text("language");
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("download_queue").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("download_queue", (table) => {
|
||||||
|
table.increments("id").primary();
|
||||||
|
table
|
||||||
|
.integer("gameId")
|
||||||
|
.references("game.id")
|
||||||
|
.unique("download_queue_gameId_unique_" + timestamp);
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.hasTable("user_auth").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.createTable("user_auth", (table) => {
|
||||||
|
table.increments("id").primary();
|
||||||
|
table.text("userId").notNullable().defaultTo("");
|
||||||
|
table.text("displayName").notNullable().defaultTo("");
|
||||||
|
table.text("profileImageUrl");
|
||||||
|
table.text("accessToken").notNullable().defaultTo("");
|
||||||
|
table.text("refreshToken").notNullable().defaultTo("");
|
||||||
|
table.integer("tokenExpirationTimestamp").notNullable().defaultTo(0);
|
||||||
|
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (knex: Knex) => {
|
||||||
|
await knex.schema.dropTableIfExists("game");
|
||||||
|
await knex.schema.dropTableIfExists("repack");
|
||||||
|
await knex.schema.dropTableIfExists("download_queue");
|
||||||
|
await knex.schema.dropTableIfExists("user_auth");
|
||||||
|
await knex.schema.dropTableIfExists("game_shop_cache");
|
||||||
|
await knex.schema.dropTableIfExists("user_preferences");
|
||||||
|
await knex.schema.dropTableIfExists("download_source");
|
||||||
|
},
|
||||||
|
};
|
58
src/main/migrations/20240830143906_RepackUris.ts
Normal file
58
src/main/migrations/20240830143906_RepackUris.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import type { HydraMigration } from "@main/knex-client";
|
||||||
|
import type { Knex } from "knex";
|
||||||
|
|
||||||
|
export const RepackUris: HydraMigration = {
|
||||||
|
name: "RepackUris",
|
||||||
|
up: async (knex: Knex) => {
|
||||||
|
await knex.schema.createTable("temporary_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("[]");
|
||||||
|
});
|
||||||
|
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) => {
|
||||||
|
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");
|
||||||
|
},
|
||||||
|
};
|
@ -1,2 +0,0 @@
|
|||||||
export * as hydra from "./001_Hydra_2_0_3";
|
|
||||||
export * as downloadRefactor from "./002_RepackUris";
|
|
11
src/main/migrations/migration.stub
Normal file
11
src/main/migrations/migration.stub
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import type { HydraMigration } from "@main/knex-client";
|
||||||
|
import type { Knex } from "knex";
|
||||||
|
|
||||||
|
export const MigrationName: HydraMigration = {
|
||||||
|
name: "MigrationName",
|
||||||
|
up: async (knex: Knex) => {
|
||||||
|
await knex.schema.createTable("table_name", (table) => {});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (knex: Knex) => {},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user