Skip to content

Commit

Permalink
fix: schema check not working because of custom type for blob in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
Meierschlumpf committed Oct 20, 2024
1 parent 4116546 commit 2df3fb1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/db/schema/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const invites = sqliteTable("invite", {
export const medias = sqliteTable("media", {
id: text("id").notNull().primaryKey(),
name: text("name").notNull(),
content: blob("content").$type<Buffer>().notNull(),
content: blob("content", { mode: "buffer" }).$type<Buffer>().notNull(),
contentType: text("content_type").notNull(),
size: int("size").notNull(),
createdAt: integer("created_at", { mode: "timestamp" })
Expand Down
28 changes: 26 additions & 2 deletions packages/db/test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,35 @@ import { objectEntries } from "@homarr/common";
import * as mysqlSchema from "../schema/mysql";
import * as sqliteSchema from "../schema/sqlite";

// We need the following two types as there is currently no support for Buffer in mysql and
// so we use a custom type which results in the config beeing different
type FixedMysqlConfig = {
[key in keyof MysqlConfig]: {
[column in keyof MysqlConfig[key]]: {
[property in Exclude<keyof MysqlConfig[key][column], "dataType" | "data">]: MysqlConfig[key][column][property];
} & {
dataType: MysqlConfig[key][column]["data"] extends Buffer ? "buffer" : MysqlConfig[key][column]["dataType"];
data: MysqlConfig[key][column]["data"] extends Buffer ? Buffer : MysqlConfig[key][column]["data"];
};
};
};

type FixedSqliteConfig = {
[key in keyof SqliteConfig]: {
[column in keyof SqliteConfig[key]]: {
[property in Exclude<keyof SqliteConfig[key][column], "dataType" | "data">]: SqliteConfig[key][column][property];
} & {
dataType: SqliteConfig[key][column]["dataType"] extends Buffer ? "buffer" : SqliteConfig[key][column]["dataType"];
data: SqliteConfig[key][column]["data"] extends Buffer ? Buffer : SqliteConfig[key][column]["data"];
};
};
};

test("schemas should match", () => {
expectTypeOf<SqliteTables>().toEqualTypeOf<MysqlTables>();
expectTypeOf<MysqlTables>().toEqualTypeOf<SqliteTables>();
expectTypeOf<SqliteConfig>().toEqualTypeOf<MysqlConfig>();
expectTypeOf<MysqlConfig>().toEqualTypeOf<SqliteConfig>();
expectTypeOf<FixedSqliteConfig>().toEqualTypeOf<FixedMysqlConfig>();
expectTypeOf<FixedMysqlConfig>().toEqualTypeOf<FixedSqliteConfig>();

objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => {
Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => {
Expand Down

0 comments on commit 2df3fb1

Please sign in to comment.