mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: write migrations
This commit is contained in:
parent
52069f7036
commit
89399a6da4
12 changed files with 358 additions and 92 deletions
30
src/main/knex-client.ts
Normal file
30
src/main/knex-client.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import knex, { Knex } from "knex";
|
||||
import { databasePath } from "./constants";
|
||||
import * as migrations from "./migrations";
|
||||
|
||||
type Migration = Knex.Migration & { name: string };
|
||||
|
||||
class MigrationSource implements Knex.MigrationSource<Migration> {
|
||||
getMigrations(): Promise<Migration[]> {
|
||||
return Promise.resolve(
|
||||
Object.values(migrations).sort((a, b) => a.name.localeCompare(b.name))
|
||||
);
|
||||
}
|
||||
getMigrationName(migration: Migration): string {
|
||||
return migration.name;
|
||||
}
|
||||
getMigration(migration: Migration): Promise<Migration> {
|
||||
return Promise.resolve(migration);
|
||||
}
|
||||
}
|
||||
|
||||
export const knexClient = knex({
|
||||
client: "better-sqlite3",
|
||||
connection: {
|
||||
filename: databasePath,
|
||||
},
|
||||
});
|
||||
|
||||
export const migrationConfig: Knex.MigratorConfig = {
|
||||
migrationSource: new MigrationSource(),
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue