-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to kysely for real (probably) (#68)
Unfortunately I don't know the precise cause of why the last attempt to roll this out didn't work. The bot didn't respond at all and it seemed potentially like it had created a new, empty database. In digging in to try again, I learned: - migration tables had not been accounted for in the transition from Knex -> Kysely - migrations were not being run on startup - past migrations were not able to be re-run Fingers crossed this works this time 🤞
- Loading branch information
Showing
29 changed files
with
2,034 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module.exports = { | ||
"**/*.[tj]s?(x)": ["eslint --fix --max-warnings=0", "prettier --check"], | ||
"migrations/*.[tj]s": [ | ||
"npm run start:migrate", | ||
"npm run generate:db-types", | ||
"git add app/db.d.ts", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { ColumnType } from "kysely"; | ||
|
||
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U> | ||
? ColumnType<S, I | undefined, U> | ||
: ColumnType<T, T | undefined, T>; | ||
|
||
export interface Guilds { | ||
id: string | null; | ||
settings: string | null; | ||
} | ||
|
||
export interface Sessions { | ||
data: string | null; | ||
expires: string | null; | ||
id: string | null; | ||
} | ||
|
||
export interface Users { | ||
authProvider: Generated<string | null>; | ||
email: string | null; | ||
externalId: string; | ||
id: string; | ||
} | ||
|
||
export interface DB { | ||
guilds: Guilds; | ||
sessions: Sessions; | ||
users: Users; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import knex from "knex"; | ||
import knexfile from "~/../knexfile"; | ||
import SQLite from "better-sqlite3"; | ||
import { Kysely, SqliteDialect } from "kysely"; | ||
import type { DB } from "./db"; | ||
import { databaseUrl } from "./helpers/env"; | ||
|
||
export { SqliteError } from "better-sqlite3"; | ||
|
||
const environment = process.env.NODE_ENV || ("development" as const); | ||
// @ts-nocheck | ||
const config: { | ||
client: string; | ||
connection: { | ||
filename: string; | ||
}; | ||
useNullAsDefault: boolean; | ||
} = (knexfile as any)[environment]; | ||
|
||
export default knex(config); | ||
console.log(`Connecting to database at ${databaseUrl}`); | ||
|
||
export const dialect = new SqliteDialect({ | ||
database: new SQLite(databaseUrl), | ||
}); | ||
|
||
const db = new Kysely<DB>({ | ||
dialect, | ||
}); | ||
|
||
export default db; | ||
export type { DB }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.