Skip to content

Commit

Permalink
feat: write migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto committed Aug 23, 2024
1 parent cc9d254 commit 81aa25f
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 93 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pnpm-lock.yaml
LICENSE.md
tsconfig.json
tsconfig.*.json
src/main/migrations
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"build:win": "electron-vite build && electron-builder --win",
"build:mac": "electron-vite build && electron-builder --mac",
"build:linux": "electron-vite build && electron-builder --linux",
"prepare": "husky",
"typeorm:migration-create": "yarn typeorm migration:create"
"prepare": "husky"
},
"dependencies": {
"@electron-toolkit/preload": "^3.0.0",
Expand All @@ -43,7 +42,7 @@
"@vanilla-extract/recipes": "^0.5.2",
"auto-launch": "^5.0.6",
"axios": "^1.6.8",
"better-sqlite3": "^9.5.0",
"better-sqlite3": "^11.2.1",
"check-disk-space": "^3.4.0",
"classnames": "^2.5.1",
"color": "^4.2.3",
Expand All @@ -61,6 +60,7 @@
"iso-639-1": "3.1.2",
"jsdom": "^24.0.0",
"jsonwebtoken": "^9.0.2",
"knex": "^3.1.0",
"lodash-es": "^4.17.21",
"lottie-react": "^2.4.0",
"parse-torrent": "^11.0.16",
Expand Down
4 changes: 1 addition & 3 deletions src/main/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "@main/entity";

import { databasePath } from "./constants";
import * as migrations from "./migrations";

export const dataSource = new DataSource({
type: "better-sqlite3",
Expand All @@ -23,7 +22,6 @@ export const dataSource = new DataSource({
DownloadQueue,
UserAuth,
],
synchronize: true,
synchronize: false,
database: databasePath,
migrations,
});
6 changes: 0 additions & 6 deletions src/main/entity/repack.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export class Repack {
@Column("text", { unique: true })
magnet: string;

/**
* @deprecated Direct scraping capability has been removed
*/
@Column("int", { nullable: true })
page: number;

@Column("text")
repacker: string;

Expand Down
17 changes: 16 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { logger, PythonInstance, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
import * as resources from "@locales";
import { userPreferencesRepository } from "@main/repository";
import { knexClient, migrationConfig } from "./knex";

const { autoUpdater } = updater;

Expand Down Expand Up @@ -63,8 +64,22 @@ app.whenReady().then(async () => {
return net.fetch(url.pathToFileURL(decodeURI(filePath)).toString());
});

await knexClient.migrate.list(migrationConfig).then((result) => {
console.log("Migrations to run:", result[1]);
});

await knexClient.migrate
.latest(migrationConfig)
.then(() => {
console.log("Migrations executed successfully");
})
.catch((err) => {
console.log("Migrations failed to run:", err);
});

await knexClient.destroy();

await dataSource.initialize();
await dataSource.runMigrations();

await import("./main");

Expand Down
14 changes: 14 additions & 0 deletions src/main/knex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import knex, { Knex } from "knex";
import { databasePath } from "./constants";
import path from "node:path";

export const knexClient = knex({
client: "better-sqlite3",
connection: {
filename: databasePath,
},
});

export const migrationConfig: Knex.MigratorConfig = {
directory: path.resolve(__dirname, "migrations"),
};
50 changes: 0 additions & 50 deletions src/main/migrations/1724081695967-Hydra_2_0_3.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/migrations/1724081984535-DowloadsRefactor.ts

This file was deleted.

Loading

0 comments on commit 81aa25f

Please sign in to comment.