refactor: make casing for column names consistent (#1517)

* refactor: make casing for column names consistent

* fix: format issues
This commit is contained in:
Meier Lukas
2024-11-23 17:17:00 +01:00
committed by GitHub
parent 32ee9f3dcc
commit 8fea983c2e
15 changed files with 3678 additions and 275 deletions

View File

@@ -7,6 +7,7 @@ dotenv.config({ path: "../../.env" });
export default {
dialect: "mysql",
schema: "./schema",
casing: "snake_case",
dbCredentials: {
host: process.env.DB_HOST!,
user: process.env.DB_USER!,

View File

@@ -6,6 +6,7 @@ dotenv.config({ path: "../../.env" });
export default {
dialect: "sqlite",
schema: "./schema",
casing: "snake_case",
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dbCredentials: { url: process.env.DB_URL! },
out: "./migrations/sqlite",

View File

@@ -40,6 +40,7 @@ const initBetterSqlite = () => {
database = drizzleSqlite(connection, {
schema: sqliteSchema,
logger: new WinstonDrizzleLogger(),
casing: "snake_case",
}) as unknown as never;
};
@@ -61,6 +62,7 @@ const initMySQL2 = () => {
schema: mysqlSchema,
mode: "default",
logger: new WinstonDrizzleLogger(),
casing: "snake_case",
}) as unknown as HomarrDatabase;
};

View File

@@ -0,0 +1,64 @@
ALTER TABLE `account` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
ALTER TABLE `account` RENAME COLUMN `providerAccountId` TO `provider_account_id`;--> statement-breakpoint
ALTER TABLE `apiKey` RENAME COLUMN `apiKey` TO `api_key`;--> statement-breakpoint
ALTER TABLE `apiKey` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
ALTER TABLE `groupMember` RENAME COLUMN `groupId` TO `group_id`;--> statement-breakpoint
ALTER TABLE `groupMember` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
ALTER TABLE `groupPermission` RENAME COLUMN `groupId` TO `group_id`;--> statement-breakpoint
ALTER TABLE `iconRepository` RENAME COLUMN `iconRepository_id` TO `id`;--> statement-breakpoint
ALTER TABLE `iconRepository` RENAME COLUMN `iconRepository_slug` TO `slug`;--> statement-breakpoint
ALTER TABLE `icon` RENAME COLUMN `icon_id` TO `id`;--> statement-breakpoint
ALTER TABLE `icon` RENAME COLUMN `icon_name` TO `name`;--> statement-breakpoint
ALTER TABLE `icon` RENAME COLUMN `icon_url` TO `url`;--> statement-breakpoint
ALTER TABLE `icon` RENAME COLUMN `icon_checksum` TO `checksum`;--> statement-breakpoint
ALTER TABLE `icon` RENAME COLUMN `iconRepository_id` TO `icon_repository_id`;--> statement-breakpoint
ALTER TABLE `serverSetting` RENAME COLUMN `key` TO `setting_key`;--> statement-breakpoint
ALTER TABLE `session` RENAME COLUMN `sessionToken` TO `session_token`;--> statement-breakpoint
ALTER TABLE `session` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
ALTER TABLE `user` RENAME COLUMN `emailVerified` TO `email_verified`;--> statement-breakpoint
ALTER TABLE `user` RENAME COLUMN `homeBoardId` TO `home_board_id`;--> statement-breakpoint
ALTER TABLE `user` RENAME COLUMN `colorScheme` TO `color_scheme`;--> statement-breakpoint
ALTER TABLE `user` RENAME COLUMN `firstDayOfWeek` TO `first_day_of_week`;--> statement-breakpoint
ALTER TABLE `user` RENAME COLUMN `pingIconsEnabled` TO `ping_icons_enabled`;--> statement-breakpoint
ALTER TABLE `serverSetting` DROP INDEX `serverSetting_key_unique`;--> statement-breakpoint
ALTER TABLE `account` DROP FOREIGN KEY `account_userId_user_id_fk`;
--> statement-breakpoint
ALTER TABLE `apiKey` DROP FOREIGN KEY `apiKey_userId_user_id_fk`;
--> statement-breakpoint
ALTER TABLE `groupMember` DROP FOREIGN KEY `groupMember_groupId_group_id_fk`;
--> statement-breakpoint
ALTER TABLE `groupMember` DROP FOREIGN KEY `groupMember_userId_user_id_fk`;
--> statement-breakpoint
ALTER TABLE `groupPermission` DROP FOREIGN KEY `groupPermission_groupId_group_id_fk`;
--> statement-breakpoint
ALTER TABLE `icon` DROP FOREIGN KEY `icon_iconRepository_id_iconRepository_iconRepository_id_fk`;
--> statement-breakpoint
ALTER TABLE `session` DROP FOREIGN KEY `session_userId_user_id_fk`;
--> statement-breakpoint
ALTER TABLE `user` DROP FOREIGN KEY `user_homeBoardId_board_id_fk`;
--> statement-breakpoint
DROP INDEX `userId_idx` ON `account`;--> statement-breakpoint
DROP INDEX `user_id_idx` ON `session`;--> statement-breakpoint
ALTER TABLE `account` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `groupMember` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `iconRepository` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `icon` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `serverSetting` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `session` DROP PRIMARY KEY;--> statement-breakpoint
ALTER TABLE `account` ADD PRIMARY KEY(`provider`,`provider_account_id`);--> statement-breakpoint
ALTER TABLE `groupMember` ADD PRIMARY KEY(`group_id`,`user_id`);--> statement-breakpoint
ALTER TABLE `iconRepository` ADD PRIMARY KEY(`id`);--> statement-breakpoint
ALTER TABLE `icon` ADD PRIMARY KEY(`id`);--> statement-breakpoint
ALTER TABLE `serverSetting` ADD PRIMARY KEY(`setting_key`);--> statement-breakpoint
ALTER TABLE `session` ADD PRIMARY KEY(`session_token`);--> statement-breakpoint
ALTER TABLE `serverSetting` ADD CONSTRAINT `serverSetting_settingKey_unique` UNIQUE(`setting_key`);--> statement-breakpoint
ALTER TABLE `account` ADD CONSTRAINT `account_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `apiKey` ADD CONSTRAINT `apiKey_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_group_id_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `groupPermission` ADD CONSTRAINT `groupPermission_group_id_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `icon` ADD CONSTRAINT `icon_icon_repository_id_iconRepository_id_fk` FOREIGN KEY (`icon_repository_id`) REFERENCES `iconRepository`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `session` ADD CONSTRAINT `session_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user` ADD CONSTRAINT `user_home_board_id_board_id_fk` FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX `userId_idx` ON `account` (`user_id`);--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `session` (`user_id`);

File diff suppressed because it is too large Load Diff

View File

@@ -113,6 +113,13 @@
"when": 1730653393442,
"tag": "0015_unknown_firedrake",
"breakpoints": true
},
{
"idx": 16,
"version": "5",
"when": 1732212709518,
"tag": "0016_change_all_to_snake_case",
"breakpoints": true
}
]
}

View File

@@ -25,6 +25,7 @@ const migrateAsync = async () => {
const db = drizzle(mysql2, {
mode: "default",
schema: mysqlSchema,
casing: "snake_case",
});
await migrate(db, { migrationsFolder });

View File

@@ -0,0 +1,102 @@
ALTER TABLE `iconRepository` RENAME COLUMN "iconRepository_id" TO "id";--> statement-breakpoint
ALTER TABLE `iconRepository` RENAME COLUMN "iconRepository_slug" TO "slug";--> statement-breakpoint
ALTER TABLE `serverSetting` RENAME COLUMN "key" TO "setting_key";--> statement-breakpoint
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_account` (
`user_id` text NOT NULL,
`type` text NOT NULL,
`provider` text NOT NULL,
`provider_account_id` text NOT NULL,
`refresh_token` text,
`access_token` text,
`expires_at` integer,
`token_type` text,
`scope` text,
`id_token` text,
`session_state` text,
PRIMARY KEY(`provider`, `provider_account_id`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_account`("user_id", "type", "provider", "provider_account_id", "refresh_token", "access_token", "expires_at", "token_type", "scope", "id_token", "session_state") SELECT "userId", "type", "provider", "providerAccountId", "refresh_token", "access_token", "expires_at", "token_type", "scope", "id_token", "session_state" FROM `account`;--> statement-breakpoint
DROP TABLE `account`;--> statement-breakpoint
ALTER TABLE `__new_account` RENAME TO `account`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> statement-breakpoint
CREATE INDEX `userId_idx` ON `account` (`user_id`);--> statement-breakpoint
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_apiKey` (
`id` text PRIMARY KEY NOT NULL,
`api_key` text NOT NULL,
`salt` text NOT NULL,
`user_id` text NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_apiKey`("id", "api_key", "salt", "user_id") SELECT "id", "apiKey", "salt", "userId" FROM `apiKey`;--> statement-breakpoint
DROP TABLE `apiKey`;--> statement-breakpoint
ALTER TABLE `__new_apiKey` RENAME TO `apiKey`;--> statement-breakpoint
CREATE TABLE `__new_groupMember` (
`group_id` text NOT NULL,
`user_id` text NOT NULL,
PRIMARY KEY(`group_id`, `user_id`),
FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_groupMember`("group_id", "user_id") SELECT "groupId", "userId" FROM `groupMember`;--> statement-breakpoint
DROP TABLE `groupMember`;--> statement-breakpoint
ALTER TABLE `__new_groupMember` RENAME TO `groupMember`;--> statement-breakpoint
CREATE TABLE `__new_groupPermission` (
`group_id` text NOT NULL,
`permission` text NOT NULL,
FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_groupPermission`("group_id", "permission") SELECT "groupId", "permission" FROM `groupPermission`;--> statement-breakpoint
DROP TABLE `groupPermission`;--> statement-breakpoint
ALTER TABLE `__new_groupPermission` RENAME TO `groupPermission`;--> statement-breakpoint
CREATE TABLE `__new_icon` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`url` text NOT NULL,
`checksum` text NOT NULL,
`icon_repository_id` text NOT NULL,
FOREIGN KEY (`icon_repository_id`) REFERENCES `iconRepository`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_icon`("id", "name", "url", "checksum", "icon_repository_id") SELECT "icon_id", "icon_name", "icon_url", "icon_checksum", "iconRepository_id" FROM `icon`;--> statement-breakpoint
DROP TABLE `icon`;--> statement-breakpoint
ALTER TABLE `__new_icon` RENAME TO `icon`;--> statement-breakpoint
DROP INDEX IF EXISTS `serverSetting_key_unique`;--> statement-breakpoint
CREATE UNIQUE INDEX `serverSetting_settingKey_unique` ON `serverSetting` (`setting_key`);--> statement-breakpoint
CREATE TABLE `__new_session` (
`session_token` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`expires` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_session`("session_token", "user_id", "expires") SELECT "sessionToken", "userId", "expires" FROM `session`;--> statement-breakpoint
DROP TABLE `session`;--> statement-breakpoint
ALTER TABLE `__new_session` RENAME TO `session`;--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `session` (`user_id`);--> statement-breakpoint
CREATE TABLE `__new_user` (
`id` text PRIMARY KEY NOT NULL,
`name` text,
`email` text,
`email_verified` integer,
`image` text,
`password` text,
`salt` text,
`provider` text DEFAULT 'credentials' NOT NULL,
`home_board_id` text,
`color_scheme` text DEFAULT 'dark' NOT NULL,
`first_day_of_week` integer DEFAULT 1 NOT NULL,
`ping_icons_enabled` integer DEFAULT false NOT NULL,
FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
INSERT INTO `__new_user`("id", "name", "email", "email_verified", "image", "password", "salt", "provider", "home_board_id", "color_scheme", "first_day_of_week", "ping_icons_enabled") SELECT "id", "name", "email", "emailVerified", "image", "password", "salt", "provider", "homeBoardId", "colorScheme", "firstDayOfWeek", "pingIconsEnabled" FROM `user`;--> statement-breakpoint
DROP TABLE `user`;--> statement-breakpoint
ALTER TABLE `__new_user` RENAME TO `user`;--> statement-breakpoint
PRAGMA foreign_keys=ON;

File diff suppressed because it is too large Load Diff

View File

@@ -113,6 +113,13 @@
"when": 1730653336134,
"tag": "0015_superb_psylocke",
"breakpoints": true
},
{
"idx": 16,
"version": "6",
"when": 1732210918783,
"tag": "0016_change_all_to_snake_case",
"breakpoints": true
}
]
}

View File

@@ -10,7 +10,7 @@ const migrationsFolder = process.argv[2] ?? ".";
const migrateAsync = async () => {
const sqlite = new Database(process.env.DB_URL?.replace("file:", ""));
const db = drizzle(sqlite, { schema });
const db = drizzle(sqlite, { schema, casing: "snake_case" });
migrate(db, { migrationsFolder });

View File

@@ -39,10 +39,10 @@ const customBlob = customType<{ data: Buffer }>({
});
export const apiKeys = mysqlTable("apiKey", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
apiKey: text("apiKey").notNull(),
salt: text("salt").notNull(),
userId: varchar("userId", { length: 64 })
id: varchar({ length: 64 }).notNull().primaryKey(),
apiKey: text().notNull(),
salt: text().notNull(),
userId: varchar({ length: 64 })
.notNull()
.references((): AnyMySqlColumn => users.id, {
onDelete: "cascade",
@@ -50,38 +50,38 @@ export const apiKeys = mysqlTable("apiKey", {
});
export const users = mysqlTable("user", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name"),
email: text("email"),
emailVerified: timestamp("emailVerified"),
image: text("image"),
password: text("password"),
salt: text("salt"),
provider: varchar("provider", { length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
homeBoardId: varchar("homeBoardId", { length: 64 }).references((): AnyMySqlColumn => boards.id, {
id: varchar({ length: 64 }).notNull().primaryKey(),
name: text(),
email: text(),
emailVerified: timestamp(),
image: text(),
password: text(),
salt: text(),
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
homeBoardId: varchar({ length: 64 }).references((): AnyMySqlColumn => boards.id, {
onDelete: "set null",
}),
colorScheme: varchar("colorScheme", { length: 5 }).$type<ColorScheme>().default("dark").notNull(),
firstDayOfWeek: tinyint("firstDayOfWeek").$type<DayOfWeek>().default(1).notNull(), // Defaults to Monday
pingIconsEnabled: boolean("pingIconsEnabled").default(false).notNull(),
colorScheme: varchar({ length: 5 }).$type<ColorScheme>().default("dark").notNull(),
firstDayOfWeek: tinyint().$type<DayOfWeek>().default(1).notNull(), // Defaults to Monday
pingIconsEnabled: boolean().default(false).notNull(),
});
export const accounts = mysqlTable(
"account",
{
userId: varchar("userId", { length: 64 })
userId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
type: text("type").$type<AdapterAccount["type"]>().notNull(),
provider: varchar("provider", { length: 64 }).notNull(),
providerAccountId: varchar("providerAccountId", { length: 64 }).notNull(),
refresh_token: text("refresh_token"),
access_token: text("access_token"),
expires_at: int("expires_at"),
token_type: text("token_type"),
scope: text("scope"),
id_token: text("id_token"),
session_state: text("session_state"),
type: text().$type<AdapterAccount["type"]>().notNull(),
provider: varchar({ length: 64 }).notNull(),
providerAccountId: varchar({ length: 64 }).notNull(),
refresh_token: text(),
access_token: text(),
expires_at: int(),
token_type: text(),
scope: text(),
id_token: text(),
session_state: text(),
},
(account) => ({
compoundKey: primaryKey({
@@ -94,11 +94,11 @@ export const accounts = mysqlTable(
export const sessions = mysqlTable(
"session",
{
sessionToken: varchar("sessionToken", { length: 512 }).notNull().primaryKey(),
userId: varchar("userId", { length: 64 })
sessionToken: varchar({ length: 512 }).notNull().primaryKey(),
userId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
expires: timestamp("expires").notNull(),
expires: timestamp().notNull(),
},
(session) => ({
userIdIdx: index("user_id_idx").on(session.userId),
@@ -108,9 +108,9 @@ export const sessions = mysqlTable(
export const verificationTokens = mysqlTable(
"verificationToken",
{
identifier: varchar("identifier", { length: 64 }).notNull(),
token: varchar("token", { length: 512 }).notNull(),
expires: timestamp("expires").notNull(),
identifier: varchar({ length: 64 }).notNull(),
token: varchar({ length: 512 }).notNull(),
expires: timestamp().notNull(),
},
(verificationToken) => ({
compoundKey: primaryKey({
@@ -122,10 +122,10 @@ export const verificationTokens = mysqlTable(
export const groupMembers = mysqlTable(
"groupMember",
{
groupId: varchar("groupId", { length: 64 })
groupId: varchar({ length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
userId: varchar("userId", { length: 64 })
userId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
},
@@ -137,46 +137,46 @@ export const groupMembers = mysqlTable(
);
export const groups = mysqlTable("group", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: varchar("name", { length: 64 }).unique().notNull(),
ownerId: varchar("owner_id", { length: 64 }).references(() => users.id, {
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 64 }).unique().notNull(),
ownerId: varchar({ length: 64 }).references(() => users.id, {
onDelete: "set null",
}),
});
export const groupPermissions = mysqlTable("groupPermission", {
groupId: varchar("groupId", { length: 64 })
groupId: varchar({ length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<GroupPermissionKey>().notNull(),
permission: text().$type<GroupPermissionKey>().notNull(),
});
export const invites = mysqlTable("invite", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
token: varchar("token", { length: 512 }).notNull().unique(),
expirationDate: timestamp("expiration_date").notNull(),
creatorId: varchar("creator_id", { length: 64 })
id: varchar({ length: 64 }).notNull().primaryKey(),
token: varchar({ length: 512 }).notNull().unique(),
expirationDate: timestamp().notNull(),
creatorId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
});
export const medias = mysqlTable("media", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: varchar("name", { length: 512 }).notNull(),
content: customBlob("content").notNull(),
contentType: text("content_type").notNull(),
size: int("size").notNull(),
createdAt: timestamp("created_at", { mode: "date" }).notNull().defaultNow(),
creatorId: varchar("creator_id", { length: 64 }).references(() => users.id, { onDelete: "set null" }),
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 512 }).notNull(),
content: customBlob().notNull(),
contentType: text().notNull(),
size: int().notNull(),
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
creatorId: varchar({ length: 64 }).references(() => users.id, { onDelete: "set null" }),
});
export const integrations = mysqlTable(
"integration",
{
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name").notNull(),
url: text("url").notNull(),
kind: varchar("kind", { length: 128 }).$type<IntegrationKind>().notNull(),
id: varchar({ length: 64 }).notNull().primaryKey(),
name: text().notNull(),
url: text().notNull(),
kind: varchar({ length: 128 }).$type<IntegrationKind>().notNull(),
},
(integrations) => ({
kindIdx: index("integration__kind_idx").on(integrations.kind),
@@ -186,12 +186,12 @@ export const integrations = mysqlTable(
export const integrationSecrets = mysqlTable(
"integrationSecret",
{
kind: varchar("kind", { length: 16 }).$type<IntegrationSecretKind>().notNull(),
value: text("value").$type<`${string}.${string}`>().notNull(),
updatedAt: timestamp("updated_at")
kind: varchar({ length: 16 }).$type<IntegrationSecretKind>().notNull(),
value: text().$type<`${string}.${string}`>().notNull(),
updatedAt: timestamp()
.$onUpdateFn(() => new Date())
.notNull(),
integrationId: varchar("integration_id", { length: 64 })
integrationId: varchar({ length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -207,13 +207,13 @@ export const integrationSecrets = mysqlTable(
export const integrationUserPermissions = mysqlTable(
"integrationUserPermission",
{
integrationId: varchar("integration_id", { length: 64 })
integrationId: varchar({ length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
userId: varchar("user_id", { length: 64 })
userId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permission: varchar("permission", { length: 128 }).$type<IntegrationPermission>().notNull(),
permission: varchar({ length: 128 }).$type<IntegrationPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -225,13 +225,13 @@ export const integrationUserPermissions = mysqlTable(
export const integrationGroupPermissions = mysqlTable(
"integrationGroupPermissions",
{
integrationId: varchar("integration_id", { length: 64 })
integrationId: varchar({ length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
groupId: varchar("group_id", { length: 64 })
groupId: varchar({ length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: varchar("permission", { length: 128 }).$type<IntegrationPermission>().notNull(),
permission: varchar({ length: 128 }).$type<IntegrationPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -242,46 +242,40 @@ export const integrationGroupPermissions = mysqlTable(
);
export const boards = mysqlTable("board", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: varchar("name", { length: 256 }).unique().notNull(),
isPublic: boolean("is_public").default(false).notNull(),
creatorId: varchar("creator_id", { length: 64 }).references(() => users.id, {
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 256 }).unique().notNull(),
isPublic: boolean().default(false).notNull(),
creatorId: varchar({ length: 64 }).references(() => users.id, {
onDelete: "set null",
}),
pageTitle: text("page_title"),
metaTitle: text("meta_title"),
logoImageUrl: text("logo_image_url"),
faviconImageUrl: text("favicon_image_url"),
backgroundImageUrl: text("background_image_url"),
backgroundImageAttachment: text("background_image_attachment")
pageTitle: text(),
metaTitle: text(),
logoImageUrl: text(),
faviconImageUrl: text(),
backgroundImageUrl: text(),
backgroundImageAttachment: text()
.$type<BackgroundImageAttachment>()
.default(backgroundImageAttachments.defaultValue)
.notNull(),
backgroundImageRepeat: text("background_image_repeat")
.$type<BackgroundImageRepeat>()
.default(backgroundImageRepeats.defaultValue)
.notNull(),
backgroundImageSize: text("background_image_size")
.$type<BackgroundImageSize>()
.default(backgroundImageSizes.defaultValue)
.notNull(),
primaryColor: text("primary_color").default("#fa5252").notNull(),
secondaryColor: text("secondary_color").default("#fd7e14").notNull(),
opacity: int("opacity").default(100).notNull(),
customCss: text("custom_css"),
columnCount: int("column_count").default(10).notNull(),
backgroundImageRepeat: text().$type<BackgroundImageRepeat>().default(backgroundImageRepeats.defaultValue).notNull(),
backgroundImageSize: text().$type<BackgroundImageSize>().default(backgroundImageSizes.defaultValue).notNull(),
primaryColor: text().default("#fa5252").notNull(),
secondaryColor: text().default("#fd7e14").notNull(),
opacity: int().default(100).notNull(),
customCss: text(),
columnCount: int().default(10).notNull(),
});
export const boardUserPermissions = mysqlTable(
"boardUserPermission",
{
boardId: varchar("board_id", { length: 64 })
boardId: varchar({ length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
userId: varchar("user_id", { length: 64 })
userId: varchar({ length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permission: varchar("permission", { length: 128 }).$type<BoardPermission>().notNull(),
permission: varchar({ length: 128 }).$type<BoardPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -293,13 +287,13 @@ export const boardUserPermissions = mysqlTable(
export const boardGroupPermissions = mysqlTable(
"boardGroupPermission",
{
boardId: varchar("board_id", { length: 64 })
boardId: varchar({ length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
groupId: varchar("group_id", { length: 64 })
groupId: varchar({ length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: varchar("permission", { length: 128 }).$type<BoardPermission>().notNull(),
permission: varchar({ length: 128 }).$type<BoardPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -309,50 +303,50 @@ export const boardGroupPermissions = mysqlTable(
);
export const sections = mysqlTable("section", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
boardId: varchar("board_id", { length: 64 })
id: varchar({ length: 64 }).notNull().primaryKey(),
boardId: varchar({ length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
kind: text("kind").$type<SectionKind>().notNull(),
xOffset: int("x_offset").notNull(),
yOffset: int("y_offset").notNull(),
width: int("width"),
height: int("height"),
name: text("name"),
parentSectionId: varchar("parent_section_id", { length: 64 }).references((): AnyMySqlColumn => sections.id, {
kind: text().$type<SectionKind>().notNull(),
xOffset: int().notNull(),
yOffset: int().notNull(),
width: int(),
height: int(),
name: text(),
parentSectionId: varchar({ length: 64 }).references((): AnyMySqlColumn => sections.id, {
onDelete: "cascade",
}),
});
export const items = mysqlTable("item", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
sectionId: varchar("section_id", { length: 64 })
id: varchar({ length: 64 }).notNull().primaryKey(),
sectionId: varchar({ length: 64 })
.notNull()
.references(() => sections.id, { onDelete: "cascade" }),
kind: text("kind").$type<WidgetKind>().notNull(),
xOffset: int("x_offset").notNull(),
yOffset: int("y_offset").notNull(),
width: int("width").notNull(),
height: int("height").notNull(),
options: text("options").default('{"json": {}}').notNull(), // empty superjson object
advancedOptions: text("advanced_options").default('{"json": {}}').notNull(), // empty superjson object
kind: text().$type<WidgetKind>().notNull(),
xOffset: int().notNull(),
yOffset: int().notNull(),
width: int().notNull(),
height: int().notNull(),
options: text().default('{"json": {}}').notNull(), // empty superjson object
advancedOptions: text().default('{"json": {}}').notNull(), // empty superjson object
});
export const apps = mysqlTable("app", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name").notNull(),
description: text("description"),
iconUrl: text("icon_url").notNull(),
href: text("href"),
id: varchar({ length: 64 }).notNull().primaryKey(),
name: text().notNull(),
description: text(),
iconUrl: text().notNull(),
href: text(),
});
export const integrationItems = mysqlTable(
"integration_item",
{
itemId: varchar("item_id", { length: 64 })
itemId: varchar({ length: 64 })
.notNull()
.references(() => items.id, { onDelete: "cascade" }),
integrationId: varchar("integration_id", { length: 64 })
integrationId: varchar({ length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -364,23 +358,23 @@ export const integrationItems = mysqlTable(
);
export const icons = mysqlTable("icon", {
id: varchar("icon_id", { length: 64 }).notNull().primaryKey(),
name: varchar("icon_name", { length: 250 }).notNull(),
url: text("icon_url").notNull(),
checksum: text("icon_checksum").notNull(),
iconRepositoryId: varchar("iconRepository_id", { length: 64 })
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 250 }).notNull(),
url: text().notNull(),
checksum: text().notNull(),
iconRepositoryId: varchar({ length: 64 })
.notNull()
.references(() => iconRepositories.id, { onDelete: "cascade" }),
});
export const iconRepositories = mysqlTable("iconRepository", {
id: varchar("iconRepository_id", { length: 64 }).notNull().primaryKey(),
slug: varchar("iconRepository_slug", { length: 150 }).notNull(),
id: varchar({ length: 64 }).notNull().primaryKey(),
slug: varchar({ length: 150 }).notNull(),
});
export const serverSettings = mysqlTable("serverSetting", {
settingKey: varchar("key", { length: 64 }).notNull().unique().primaryKey(),
value: text("value").default('{"json": {}}').notNull(), // empty superjson object
settingKey: varchar({ length: 64 }).notNull().unique().primaryKey(),
value: text().default('{"json": {}}').notNull(), // empty superjson object
});
export const apiKeyRelations = relations(apiKeys, ({ one }) => ({
@@ -391,14 +385,14 @@ export const apiKeyRelations = relations(apiKeys, ({ one }) => ({
}));
export const searchEngines = mysqlTable("search_engine", {
id: varchar("id", { length: 64 }).notNull().primaryKey(),
iconUrl: text("icon_url").notNull(),
name: varchar("name", { length: 64 }).notNull(),
short: varchar("short", { length: 8 }).notNull(),
description: text("description"),
urlTemplate: text("url_template"),
type: varchar("type", { length: 64 }).$type<SearchEngineType>().notNull().default("generic"),
integrationId: varchar("integration_id", { length: 64 }).references(() => integrations.id, { onDelete: "cascade" }),
id: varchar({ length: 64 }).notNull().primaryKey(),
iconUrl: text().notNull(),
name: varchar({ length: 64 }).notNull(),
short: varchar({ length: 8 }).notNull(),
description: text(),
urlTemplate: text(),
type: varchar({ length: 64 }).$type<SearchEngineType>().notNull().default("generic"),
integrationId: varchar({ length: 64 }).references(() => integrations.id, { onDelete: "cascade" }),
});
export const accountRelations = relations(accounts, ({ one }) => ({

View File

@@ -3,7 +3,7 @@ import type { DayOfWeek } from "@mantine/dates";
import type { InferSelectModel } from "drizzle-orm";
import { relations, sql } from "drizzle-orm";
import type { AnySQLiteColumn } from "drizzle-orm/sqlite-core";
import { blob, index, int, integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { blob, index, int, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { backgroundImageAttachments, backgroundImageRepeats, backgroundImageSizes } from "@homarr/definitions";
import type {
@@ -23,10 +23,10 @@ import type {
} from "@homarr/definitions";
export const apiKeys = sqliteTable("apiKey", {
id: text("id").notNull().primaryKey(),
apiKey: text("apiKey").notNull(),
salt: text("salt").notNull(),
userId: text("userId")
id: text().notNull().primaryKey(),
apiKey: text().notNull(),
salt: text().notNull(),
userId: text()
.notNull()
.references((): AnySQLiteColumn => users.id, {
onDelete: "cascade",
@@ -34,38 +34,38 @@ export const apiKeys = sqliteTable("apiKey", {
});
export const users = sqliteTable("user", {
id: text("id").notNull().primaryKey(),
name: text("name"),
email: text("email"),
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
image: text("image"),
password: text("password"),
salt: text("salt"),
provider: text("provider").$type<SupportedAuthProvider>().default("credentials").notNull(),
homeBoardId: text("homeBoardId").references((): AnySQLiteColumn => boards.id, {
id: text().notNull().primaryKey(),
name: text(),
email: text(),
emailVerified: int({ mode: "timestamp_ms" }),
image: text(),
password: text(),
salt: text(),
provider: text().$type<SupportedAuthProvider>().default("credentials").notNull(),
homeBoardId: text().references((): AnySQLiteColumn => boards.id, {
onDelete: "set null",
}),
colorScheme: text("colorScheme").$type<ColorScheme>().default("dark").notNull(),
firstDayOfWeek: int("firstDayOfWeek").$type<DayOfWeek>().default(1).notNull(), // Defaults to Monday
pingIconsEnabled: int("pingIconsEnabled", { mode: "boolean" }).default(false).notNull(),
colorScheme: text().$type<ColorScheme>().default("dark").notNull(),
firstDayOfWeek: int().$type<DayOfWeek>().default(1).notNull(), // Defaults to Monday
pingIconsEnabled: int({ mode: "boolean" }).default(false).notNull(),
});
export const accounts = sqliteTable(
"account",
{
userId: text("userId")
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
type: text("type").$type<AdapterAccount["type"]>().notNull(),
provider: text("provider").notNull(),
providerAccountId: text("providerAccountId").notNull(),
refresh_token: text("refresh_token"),
access_token: text("access_token"),
expires_at: integer("expires_at"),
token_type: text("token_type"),
scope: text("scope"),
id_token: text("id_token"),
session_state: text("session_state"),
type: text().$type<AdapterAccount["type"]>().notNull(),
provider: text().notNull(),
providerAccountId: text().notNull(),
refresh_token: text(),
access_token: text(),
expires_at: int(),
token_type: text(),
scope: text(),
id_token: text(),
session_state: text(),
},
(account) => ({
compoundKey: primaryKey({
@@ -78,11 +78,11 @@ export const accounts = sqliteTable(
export const sessions = sqliteTable(
"session",
{
sessionToken: text("sessionToken").notNull().primaryKey(),
userId: text("userId")
sessionToken: text().notNull().primaryKey(),
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
expires: int({ mode: "timestamp_ms" }).notNull(),
},
(session) => ({
userIdIdx: index("user_id_idx").on(session.userId),
@@ -92,9 +92,9 @@ export const sessions = sqliteTable(
export const verificationTokens = sqliteTable(
"verificationToken",
{
identifier: text("identifier").notNull(),
token: text("token").notNull(),
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
identifier: text().notNull(),
token: text().notNull(),
expires: int({ mode: "timestamp_ms" }).notNull(),
},
(verificationToken) => ({
compoundKey: primaryKey({
@@ -106,10 +106,10 @@ export const verificationTokens = sqliteTable(
export const groupMembers = sqliteTable(
"groupMember",
{
groupId: text("groupId")
groupId: text()
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
userId: text("userId")
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
},
@@ -121,50 +121,50 @@ export const groupMembers = sqliteTable(
);
export const groups = sqliteTable("group", {
id: text("id").notNull().primaryKey(),
name: text("name").unique().notNull(),
ownerId: text("owner_id").references(() => users.id, {
id: text().notNull().primaryKey(),
name: text().unique().notNull(),
ownerId: text().references(() => users.id, {
onDelete: "set null",
}),
});
export const groupPermissions = sqliteTable("groupPermission", {
groupId: text("groupId")
groupId: text()
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<GroupPermissionKey>().notNull(),
permission: text().$type<GroupPermissionKey>().notNull(),
});
export const invites = sqliteTable("invite", {
id: text("id").notNull().primaryKey(),
token: text("token").notNull().unique(),
expirationDate: int("expiration_date", {
id: text().notNull().primaryKey(),
token: text().notNull().unique(),
expirationDate: int({
mode: "timestamp",
}).notNull(),
creatorId: text("creator_id")
creatorId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
});
export const medias = sqliteTable("media", {
id: text("id").notNull().primaryKey(),
name: text("name").notNull(),
content: blob("content", { mode: "buffer" }).$type<Buffer>().notNull(),
contentType: text("content_type").notNull(),
size: int("size").notNull(),
createdAt: integer("created_at", { mode: "timestamp" })
id: text().notNull().primaryKey(),
name: text().notNull(),
content: blob({ mode: "buffer" }).$type<Buffer>().notNull(),
contentType: text().notNull(),
size: int().notNull(),
createdAt: int({ mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
creatorId: text("creator_id").references(() => users.id, { onDelete: "set null" }),
creatorId: text().references(() => users.id, { onDelete: "set null" }),
});
export const integrations = sqliteTable(
"integration",
{
id: text("id").notNull().primaryKey(),
name: text("name").notNull(),
url: text("url").notNull(),
kind: text("kind").$type<IntegrationKind>().notNull(),
id: text().notNull().primaryKey(),
name: text().notNull(),
url: text().notNull(),
kind: text().$type<IntegrationKind>().notNull(),
},
(integrations) => ({
kindIdx: index("integration__kind_idx").on(integrations.kind),
@@ -174,12 +174,12 @@ export const integrations = sqliteTable(
export const integrationSecrets = sqliteTable(
"integrationSecret",
{
kind: text("kind").$type<IntegrationSecretKind>().notNull(),
value: text("value").$type<`${string}.${string}`>().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" })
kind: text().$type<IntegrationSecretKind>().notNull(),
value: text().$type<`${string}.${string}`>().notNull(),
updatedAt: int({ mode: "timestamp" })
.$onUpdateFn(() => new Date())
.notNull(),
integrationId: text("integration_id")
integrationId: text()
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -195,13 +195,13 @@ export const integrationSecrets = sqliteTable(
export const integrationUserPermissions = sqliteTable(
"integrationUserPermission",
{
integrationId: text("integration_id")
integrationId: text()
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
userId: text("user_id")
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permission: text("permission").$type<IntegrationPermission>().notNull(),
permission: text().$type<IntegrationPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -213,13 +213,13 @@ export const integrationUserPermissions = sqliteTable(
export const integrationGroupPermissions = sqliteTable(
"integrationGroupPermissions",
{
integrationId: text("integration_id")
integrationId: text()
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
groupId: text("group_id")
groupId: text()
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<IntegrationPermission>().notNull(),
permission: text().$type<IntegrationPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -229,46 +229,40 @@ export const integrationGroupPermissions = sqliteTable(
);
export const boards = sqliteTable("board", {
id: text("id").notNull().primaryKey(),
name: text("name").unique().notNull(),
isPublic: int("is_public", { mode: "boolean" }).default(false).notNull(),
creatorId: text("creator_id").references(() => users.id, {
id: text().notNull().primaryKey(),
name: text().unique().notNull(),
isPublic: int({ mode: "boolean" }).default(false).notNull(),
creatorId: text().references(() => users.id, {
onDelete: "set null",
}),
pageTitle: text("page_title"),
metaTitle: text("meta_title"),
logoImageUrl: text("logo_image_url"),
faviconImageUrl: text("favicon_image_url"),
backgroundImageUrl: text("background_image_url"),
backgroundImageAttachment: text("background_image_attachment")
pageTitle: text(),
metaTitle: text(),
logoImageUrl: text(),
faviconImageUrl: text(),
backgroundImageUrl: text(),
backgroundImageAttachment: text()
.$type<BackgroundImageAttachment>()
.default(backgroundImageAttachments.defaultValue)
.notNull(),
backgroundImageRepeat: text("background_image_repeat")
.$type<BackgroundImageRepeat>()
.default(backgroundImageRepeats.defaultValue)
.notNull(),
backgroundImageSize: text("background_image_size")
.$type<BackgroundImageSize>()
.default(backgroundImageSizes.defaultValue)
.notNull(),
primaryColor: text("primary_color").default("#fa5252").notNull(),
secondaryColor: text("secondary_color").default("#fd7e14").notNull(),
opacity: int("opacity").default(100).notNull(),
customCss: text("custom_css"),
columnCount: int("column_count").default(10).notNull(),
backgroundImageRepeat: text().$type<BackgroundImageRepeat>().default(backgroundImageRepeats.defaultValue).notNull(),
backgroundImageSize: text().$type<BackgroundImageSize>().default(backgroundImageSizes.defaultValue).notNull(),
primaryColor: text().default("#fa5252").notNull(),
secondaryColor: text().default("#fd7e14").notNull(),
opacity: int().default(100).notNull(),
customCss: text(),
columnCount: int().default(10).notNull(),
});
export const boardUserPermissions = sqliteTable(
"boardUserPermission",
{
boardId: text("board_id")
boardId: text()
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
userId: text("user_id")
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permission: text("permission").$type<BoardPermission>().notNull(),
permission: text().$type<BoardPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -280,13 +274,13 @@ export const boardUserPermissions = sqliteTable(
export const boardGroupPermissions = sqliteTable(
"boardGroupPermission",
{
boardId: text("board_id")
boardId: text()
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
groupId: text("group_id")
groupId: text()
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<BoardPermission>().notNull(),
permission: text().$type<BoardPermission>().notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -296,50 +290,50 @@ export const boardGroupPermissions = sqliteTable(
);
export const sections = sqliteTable("section", {
id: text("id").notNull().primaryKey(),
boardId: text("board_id")
id: text().notNull().primaryKey(),
boardId: text()
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
kind: text("kind").$type<SectionKind>().notNull(),
xOffset: int("x_offset").notNull(),
yOffset: int("y_offset").notNull(),
width: int("width"),
height: int("height"),
name: text("name"),
parentSectionId: text("parent_section_id").references((): AnySQLiteColumn => sections.id, {
kind: text().$type<SectionKind>().notNull(),
xOffset: int().notNull(),
yOffset: int().notNull(),
width: int(),
height: int(),
name: text(),
parentSectionId: text().references((): AnySQLiteColumn => sections.id, {
onDelete: "cascade",
}),
});
export const items = sqliteTable("item", {
id: text("id").notNull().primaryKey(),
sectionId: text("section_id")
id: text().notNull().primaryKey(),
sectionId: text()
.notNull()
.references(() => sections.id, { onDelete: "cascade" }),
kind: text("kind").$type<WidgetKind>().notNull(),
xOffset: int("x_offset").notNull(),
yOffset: int("y_offset").notNull(),
width: int("width").notNull(),
height: int("height").notNull(),
options: text("options").default('{"json": {}}').notNull(), // empty superjson object
advancedOptions: text("advanced_options").default('{"json": {}}').notNull(), // empty superjson object
kind: text().$type<WidgetKind>().notNull(),
xOffset: int().notNull(),
yOffset: int().notNull(),
width: int().notNull(),
height: int().notNull(),
options: text().default('{"json": {}}').notNull(), // empty superjson object
advancedOptions: text().default('{"json": {}}').notNull(), // empty superjson object
});
export const apps = sqliteTable("app", {
id: text("id").notNull().primaryKey(),
name: text("name").notNull(),
description: text("description"),
iconUrl: text("icon_url").notNull(),
href: text("href"),
id: text().notNull().primaryKey(),
name: text().notNull(),
description: text(),
iconUrl: text().notNull(),
href: text(),
});
export const integrationItems = sqliteTable(
"integration_item",
{
itemId: text("item_id")
itemId: text()
.notNull()
.references(() => items.id, { onDelete: "cascade" }),
integrationId: text("integration_id")
integrationId: text()
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -351,23 +345,23 @@ export const integrationItems = sqliteTable(
);
export const icons = sqliteTable("icon", {
id: text("icon_id").notNull().primaryKey(),
name: text("icon_name").notNull(),
url: text("icon_url").notNull(),
checksum: text("icon_checksum").notNull(),
iconRepositoryId: text("iconRepository_id")
id: text().notNull().primaryKey(),
name: text().notNull(),
url: text().notNull(),
checksum: text().notNull(),
iconRepositoryId: text()
.notNull()
.references(() => iconRepositories.id, { onDelete: "cascade" }),
});
export const iconRepositories = sqliteTable("iconRepository", {
id: text("iconRepository_id").notNull().primaryKey(),
slug: text("iconRepository_slug").notNull(),
id: text().notNull().primaryKey(),
slug: text().notNull(),
});
export const serverSettings = sqliteTable("serverSetting", {
settingKey: text("key").notNull().unique().primaryKey(),
value: text("value").default('{"json": {}}').notNull(), // empty superjson object
settingKey: text().notNull().unique().primaryKey(),
value: text().default('{"json": {}}').notNull(), // empty superjson object
});
export const apiKeyRelations = relations(apiKeys, ({ one }) => ({
@@ -378,14 +372,14 @@ export const apiKeyRelations = relations(apiKeys, ({ one }) => ({
}));
export const searchEngines = sqliteTable("search_engine", {
id: text("id").notNull().primaryKey(),
iconUrl: text("icon_url").notNull(),
name: text("name").notNull(),
short: text("short").notNull(),
description: text("description"),
urlTemplate: text("url_template"),
type: text("type").$type<SearchEngineType>().notNull().default("generic"),
integrationId: text("integration_id").references(() => integrations.id, { onDelete: "cascade" }),
id: text().notNull().primaryKey(),
iconUrl: text().notNull(),
name: text().notNull(),
short: text().notNull(),
description: text(),
urlTemplate: text(),
type: text().$type<SearchEngineType>().notNull().default("generic"),
integrationId: text().references(() => integrations.id, { onDelete: "cascade" }),
});
export const accountRelations = relations(accounts, ({ one }) => ({

View File

@@ -6,7 +6,7 @@ import { schema } from "..";
export const createDb = (debug?: boolean) => {
const sqlite = new Database(":memory:");
const db = drizzle(sqlite, { schema, logger: debug });
const db = drizzle(sqlite, { schema, logger: debug, casing: "snake_case" });
migrate(db, {
migrationsFolder: "./packages/db/migrations/sqlite",
});

View File

@@ -22,6 +22,7 @@ describe("Mysql Migration", () => {
const database = drizzle(connection, {
schema: mysqlSchema,
mode: "default",
casing: "snake_case",
});
// Run migrations and check if it works