fix(deps): update dependency drizzle-kit to ^0.21.1 (#462)

* fix(deps): update dependency drizzle-kit to ^0.21.0

* fix(deps): update dependency drizzle-kit to ^0.21.1

* fix: migrate to drizzle kit 0.21

* fix: format issues

* feat: add default env variables for db dialect and driver

* fix: issue with driver seems to be fixed

---------

Co-authored-by: homarr-renovate[bot] <158783068+homarr-renovate[bot]@users.noreply.github.com>
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
homarr-renovate[bot]
2024-05-10 23:46:01 +02:00
committed by GitHub
parent 2434e2e758
commit 1ce6fb0d0f
21 changed files with 367 additions and 2476 deletions

View File

@@ -4,8 +4,8 @@ import type { Config } from "drizzle-kit";
dotenv.config({ path: "../../.env" });
export default {
dialect: "mysql",
schema: "./schema",
driver: "mysql2",
dbCredentials: {
host: process.env.DB_HOST!,
user: process.env.DB_USER!,

View File

@@ -4,8 +4,8 @@ import type { Config } from "drizzle-kit";
dotenv.config({ path: "../../.env" });
export default {
dialect: "sqlite",
schema: "./schema",
driver: "better-sqlite",
dbCredentials: { url: process.env.DB_URL! },
out: "./migrations/sqlite",
} satisfies Config;

View File

@@ -43,11 +43,11 @@ const initBetterSqlite = () => {
};
const initMySQL2 = () => {
if (process.env.DB_URL) {
if (!process.env.DB_HOST) {
connection = mysql.createConnection({ uri: process.env.DB_URL });
} else {
connection = mysql.createConnection({
host: process.env.DB_HOST!,
host: process.env.DB_HOST,
database: process.env.DB_NAME!,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,

View File

@@ -1,8 +1,8 @@
CREATE TABLE `account` (
`userId` varchar(256) NOT NULL,
`userId` varchar(64) NOT NULL,
`type` text NOT NULL,
`provider` varchar(256) NOT NULL,
`providerAccountId` varchar(256) NOT NULL,
`provider` varchar(64) NOT NULL,
`providerAccountId` varchar(64) NOT NULL,
`refresh_token` text,
`access_token` text,
`expires_at` int,
@@ -14,7 +14,7 @@ CREATE TABLE `account` (
);
--> statement-breakpoint
CREATE TABLE `app` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`name` text NOT NULL,
`description` text,
`icon_url` text NOT NULL,
@@ -23,24 +23,24 @@ CREATE TABLE `app` (
);
--> statement-breakpoint
CREATE TABLE `boardGroupPermission` (
`board_id` text NOT NULL,
`group_id` text NOT NULL,
`permission` text NOT NULL,
`board_id` varchar(64) NOT NULL,
`group_id` varchar(64) NOT NULL,
`permission` varchar(128) NOT NULL,
CONSTRAINT `boardGroupPermission_board_id_group_id_permission_pk` PRIMARY KEY(`board_id`,`group_id`,`permission`)
);
--> statement-breakpoint
CREATE TABLE `boardUserPermission` (
`board_id` text NOT NULL,
`user_id` text NOT NULL,
`permission` text NOT NULL,
`board_id` varchar(64) NOT NULL,
`user_id` varchar(64) NOT NULL,
`permission` varchar(128) NOT NULL,
CONSTRAINT `boardUserPermission_board_id_user_id_permission_pk` PRIMARY KEY(`board_id`,`user_id`,`permission`)
);
--> statement-breakpoint
CREATE TABLE `board` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`name` varchar(256) NOT NULL,
`is_public` boolean NOT NULL DEFAULT false,
`creator_id` text,
`creator_id` varchar(64),
`page_title` text,
`meta_title` text,
`logo_image_url` text,
@@ -59,26 +59,41 @@ CREATE TABLE `board` (
);
--> statement-breakpoint
CREATE TABLE `groupMember` (
`groupId` varchar(256) NOT NULL,
`userId` varchar(256) NOT NULL,
`groupId` varchar(64) NOT NULL,
`userId` varchar(64) NOT NULL,
CONSTRAINT `groupMember_groupId_userId_pk` PRIMARY KEY(`groupId`,`userId`)
);
--> statement-breakpoint
CREATE TABLE `groupPermission` (
`groupId` varchar(256) NOT NULL,
`groupId` varchar(64) NOT NULL,
`permission` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `group` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`name` varchar(64) NOT NULL,
`owner_id` varchar(256),
`owner_id` varchar(64),
CONSTRAINT `group_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `iconRepository` (
`iconRepository_id` varchar(64) NOT NULL,
`iconRepository_slug` varchar(150) NOT NULL,
CONSTRAINT `iconRepository_iconRepository_id` PRIMARY KEY(`iconRepository_id`)
);
--> statement-breakpoint
CREATE TABLE `icon` (
`icon_id` varchar(64) NOT NULL,
`icon_name` varchar(250) NOT NULL,
`icon_url` text NOT NULL,
`icon_checksum` text NOT NULL,
`iconRepository_id` varchar(64) NOT NULL,
CONSTRAINT `icon_icon_id` PRIMARY KEY(`icon_id`)
);
--> statement-breakpoint
CREATE TABLE `integration_item` (
`item_id` varchar(256) NOT NULL,
`integration_id` varchar(256) NOT NULL,
`item_id` varchar(64) NOT NULL,
`integration_id` varchar(64) NOT NULL,
CONSTRAINT `integration_item_item_id_integration_id_pk` PRIMARY KEY(`item_id`,`integration_id`)
);
--> statement-breakpoint
@@ -86,12 +101,12 @@ CREATE TABLE `integrationSecret` (
`kind` varchar(16) NOT NULL,
`value` text NOT NULL,
`updated_at` timestamp NOT NULL,
`integration_id` varchar(256) NOT NULL,
`integration_id` varchar(64) NOT NULL,
CONSTRAINT `integrationSecret_integration_id_kind_pk` PRIMARY KEY(`integration_id`,`kind`)
);
--> statement-breakpoint
CREATE TABLE `integration` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`name` text NOT NULL,
`url` text NOT NULL,
`kind` varchar(128) NOT NULL,
@@ -99,17 +114,17 @@ CREATE TABLE `integration` (
);
--> statement-breakpoint
CREATE TABLE `invite` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`token` varchar(512) NOT NULL,
`expiration_date` timestamp NOT NULL,
`creator_id` varchar(256) NOT NULL,
`creator_id` varchar(64) NOT NULL,
CONSTRAINT `invite_id` PRIMARY KEY(`id`),
CONSTRAINT `invite_token_unique` UNIQUE(`token`)
);
--> statement-breakpoint
CREATE TABLE `item` (
`id` varchar(256) NOT NULL,
`section_id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`section_id` varchar(64) NOT NULL,
`kind` text NOT NULL,
`x_offset` int NOT NULL,
`y_offset` int NOT NULL,
@@ -120,8 +135,8 @@ CREATE TABLE `item` (
);
--> statement-breakpoint
CREATE TABLE `section` (
`id` varchar(256) NOT NULL,
`board_id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`board_id` varchar(64) NOT NULL,
`kind` text NOT NULL,
`position` int NOT NULL,
`name` text,
@@ -130,13 +145,13 @@ CREATE TABLE `section` (
--> statement-breakpoint
CREATE TABLE `session` (
`sessionToken` varchar(512) NOT NULL,
`userId` varchar(256) NOT NULL,
`userId` varchar(64) NOT NULL,
`expires` timestamp NOT NULL,
CONSTRAINT `session_sessionToken` PRIMARY KEY(`sessionToken`)
);
--> statement-breakpoint
CREATE TABLE `user` (
`id` varchar(256) NOT NULL,
`id` varchar(64) NOT NULL,
`name` text,
`email` text,
`emailVerified` timestamp,
@@ -147,17 +162,12 @@ CREATE TABLE `user` (
);
--> statement-breakpoint
CREATE TABLE `verificationToken` (
`identifier` varchar(256) NOT NULL,
`identifier` varchar(64) NOT NULL,
`token` varchar(512) NOT NULL,
`expires` timestamp NOT NULL,
CONSTRAINT `verificationToken_identifier_token_pk` PRIMARY KEY(`identifier`,`token`)
);
--> statement-breakpoint
CREATE INDEX `userId_idx` ON `account` (`userId`);--> statement-breakpoint
CREATE INDEX `integration_secret__kind_idx` ON `integrationSecret` (`kind`);--> statement-breakpoint
CREATE INDEX `integration_secret__updated_at_idx` ON `integrationSecret` (`updated_at`);--> statement-breakpoint
CREATE INDEX `integration__kind_idx` ON `integration` (`kind`);--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `session` (`userId`);--> statement-breakpoint
ALTER TABLE `account` ADD CONSTRAINT `account_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `boardGroupPermission` ADD CONSTRAINT `boardGroupPermission_board_id_board_id_fk` FOREIGN KEY (`board_id`) REFERENCES `board`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `boardGroupPermission` ADD CONSTRAINT `boardGroupPermission_group_id_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
@@ -168,10 +178,16 @@ ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_groupId_group_id_fk` FOREI
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `groupPermission` ADD CONSTRAINT `groupPermission_groupId_group_id_fk` FOREIGN KEY (`groupId`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `group` ADD CONSTRAINT `group_owner_id_user_id_fk` FOREIGN KEY (`owner_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `icon` ADD CONSTRAINT `icon_iconRepository_id_iconRepository_iconRepository_id_fk` FOREIGN KEY (`iconRepository_id`) REFERENCES `iconRepository`(`iconRepository_id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `integration_item` ADD CONSTRAINT `integration_item_item_id_item_id_fk` FOREIGN KEY (`item_id`) REFERENCES `item`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `integration_item` ADD CONSTRAINT `integration_item_integration_id_integration_id_fk` FOREIGN KEY (`integration_id`) REFERENCES `integration`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `integrationSecret` ADD CONSTRAINT `integrationSecret_integration_id_integration_id_fk` FOREIGN KEY (`integration_id`) REFERENCES `integration`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `invite` ADD CONSTRAINT `invite_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `item` ADD CONSTRAINT `item_section_id_section_id_fk` FOREIGN KEY (`section_id`) REFERENCES `section`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `section` ADD CONSTRAINT `section_board_id_board_id_fk` FOREIGN KEY (`board_id`) REFERENCES `board`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `session` ADD CONSTRAINT `session_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;
ALTER TABLE `session` ADD CONSTRAINT `session_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX `userId_idx` ON `account` (`userId`);--> statement-breakpoint
CREATE INDEX `integration_secret__kind_idx` ON `integrationSecret` (`kind`);--> statement-breakpoint
CREATE INDEX `integration_secret__updated_at_idx` ON `integrationSecret` (`updated_at`);--> statement-breakpoint
CREATE INDEX `integration__kind_idx` ON `integration` (`kind`);--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `session` (`userId`);

View File

@@ -1,16 +0,0 @@
CREATE TABLE `iconRepository` (
`iconRepository_id` varchar(256) NOT NULL,
`iconRepository_slug` varchar(150) NOT NULL,
CONSTRAINT `iconRepository_iconRepository_id` PRIMARY KEY(`iconRepository_id`)
);
--> statement-breakpoint
CREATE TABLE `icon` (
`icon_id` varchar(256) NOT NULL,
`icon_name` varchar(250) NOT NULL,
`icon_url` text NOT NULL,
`icon_checksum` text NOT NULL,
`iconRepository_id` varchar(256) NOT NULL,
CONSTRAINT `icon_icon_id` PRIMARY KEY(`icon_id`)
);
--> statement-breakpoint
ALTER TABLE `icon` ADD CONSTRAINT `icon_iconRepository_id_iconRepository_iconRepository_id_fk` FOREIGN KEY (`iconRepository_id`) REFERENCES `iconRepository`(`iconRepository_id`) ON DELETE cascade ON UPDATE no action;

View File

@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "mysql",
"id": "47dc6887-a308-480d-8125-183412fe7fa7",
"id": "fdeaf6eb-cd62-4fa5-9b38-d7f80a60db9f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"account": {
@@ -9,7 +9,7 @@
"columns": {
"userId": {
"name": "userId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -23,14 +23,14 @@
},
"provider": {
"name": "provider",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"providerAccountId": {
"name": "providerAccountId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -116,7 +116,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -165,21 +165,21 @@
"columns": {
"board_id": {
"name": "board_id",
"type": "text",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"group_id": {
"name": "group_id",
"type": "text",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"permission": {
"name": "permission",
"type": "text",
"type": "varchar(128)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -219,21 +219,21 @@
"columns": {
"board_id": {
"name": "board_id",
"type": "text",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"permission": {
"name": "permission",
"type": "text",
"type": "varchar(128)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -273,7 +273,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -295,7 +295,7 @@
},
"creator_id": {
"name": "creator_id",
"type": "text",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
@@ -429,14 +429,14 @@
"columns": {
"groupId": {
"name": "groupId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -476,7 +476,7 @@
"columns": {
"groupId": {
"name": "groupId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -509,7 +509,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -523,7 +523,7 @@
},
"owner_id": {
"name": "owner_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
@@ -549,19 +549,106 @@
},
"uniqueConstraints": {}
},
"iconRepository": {
"name": "iconRepository",
"columns": {
"iconRepository_id": {
"name": "iconRepository_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"iconRepository_slug": {
"name": "iconRepository_slug",
"type": "varchar(150)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"iconRepository_iconRepository_id": {
"name": "iconRepository_iconRepository_id",
"columns": ["iconRepository_id"]
}
},
"uniqueConstraints": {}
},
"icon": {
"name": "icon",
"columns": {
"icon_id": {
"name": "icon_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon_name": {
"name": "icon_name",
"type": "varchar(250)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon_checksum": {
"name": "icon_checksum",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"iconRepository_id": {
"name": "iconRepository_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"icon_iconRepository_id_iconRepository_iconRepository_id_fk": {
"name": "icon_iconRepository_id_iconRepository_iconRepository_id_fk",
"tableFrom": "icon",
"tableTo": "iconRepository",
"columnsFrom": ["iconRepository_id"],
"columnsTo": ["iconRepository_id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"icon_icon_id": {
"name": "icon_icon_id",
"columns": ["icon_id"]
}
},
"uniqueConstraints": {}
},
"integration_item": {
"name": "integration_item",
"columns": {
"item_id": {
"name": "item_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"integration_id": {
"name": "integration_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -622,7 +709,7 @@
},
"integration_id": {
"name": "integration_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -664,7 +751,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -712,7 +799,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -733,7 +820,7 @@
},
"creator_id": {
"name": "creator_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -769,14 +856,14 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"section_id": {
"name": "section_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -850,14 +937,14 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"board_id": {
"name": "board_id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -916,7 +1003,7 @@
},
"userId": {
"name": "userId",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -960,7 +1047,7 @@
"columns": {
"id": {
"name": "id",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -1023,7 +1110,7 @@
"columns": {
"identifier": {
"name": "identifier",
"type": "varchar(256)",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
@@ -1054,7 +1141,6 @@
"uniqueConstraints": {}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,12 @@
{
"version": "5",
"version": "6",
"dialect": "mysql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1714817536714,
"tag": "0000_hot_mandrill",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1714854892785,
"tag": "0001_fluffy_overlord",
"when": 1715334452118,
"tag": "0000_harsh_photon",
"breakpoints": true
}
]

View File

@@ -0,0 +1,31 @@
import { drizzle } from "drizzle-orm/mysql2";
import { migrate } from "drizzle-orm/mysql2/migrator";
import mysql from "mysql2";
const migrationsFolder = process.argv[2] ?? ".";
const mysql2 = mysql.createConnection(
process.env.DB_HOST
? {
host: process.env.DB_HOST,
database: process.env.DB_NAME!,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
}
: { uri: process.env.DB_URL },
);
const db = drizzle(mysql2, {
mode: "default",
});
migrate(db, { migrationsFolder })
.then(() => {
console.log("Migration complete");
process.exit(0);
})
.catch((err) => {
console.log("Migration failed", err);
process.exit(1);
});

View File

@@ -82,6 +82,20 @@ CREATE TABLE `group` (
FOREIGN KEY (`owner_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE TABLE `iconRepository` (
`iconRepository_id` text PRIMARY KEY NOT NULL,
`iconRepository_slug` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `icon` (
`icon_id` text PRIMARY KEY NOT NULL,
`icon_name` text NOT NULL,
`icon_url` text NOT NULL,
`icon_checksum` text NOT NULL,
`iconRepository_id` text NOT NULL,
FOREIGN KEY (`iconRepository_id`) REFERENCES `iconRepository`(`iconRepository_id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `integration_item` (
`item_id` text NOT NULL,
`integration_id` text NOT NULL,

View File

@@ -1,13 +0,0 @@
CREATE TABLE `iconRepository` (
`iconRepository_id` text PRIMARY KEY NOT NULL,
`iconRepository_slug` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `icon` (
`icon_id` text PRIMARY KEY NOT NULL,
`icon_name` text NOT NULL,
`icon_url` text NOT NULL,
`icon_checksum` text NOT NULL,
`iconRepository_id` text NOT NULL,
FOREIGN KEY (`iconRepository_id`) REFERENCES `iconRepository`(`iconRepository_id`) ON UPDATE no action ON DELETE cascade
);

View File

@@ -1,7 +1,7 @@
{
"version": "5",
"version": "6",
"dialect": "sqlite",
"id": "116fcd87-09c7-4c7c-b590-0ed5681ffdc5",
"id": "0575873a-9e10-4480-8d7d-c47198622c22",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"account": {
@@ -535,6 +535,83 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"iconRepository": {
"name": "iconRepository",
"columns": {
"iconRepository_id": {
"name": "iconRepository_id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"iconRepository_slug": {
"name": "iconRepository_slug",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"icon": {
"name": "icon",
"columns": {
"icon_id": {
"name": "icon_id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"icon_name": {
"name": "icon_name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon_checksum": {
"name": "icon_checksum",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"iconRepository_id": {
"name": "iconRepository_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"icon_iconRepository_id_iconRepository_iconRepository_id_fk": {
"name": "icon_iconRepository_id_iconRepository_iconRepository_id_fk",
"tableFrom": "icon",
"tableTo": "iconRepository",
"columnsFrom": ["iconRepository_id"],
"columnsTo": ["iconRepository_id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"integration_item": {
"name": "integration_item",
"columns": {

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,12 @@
{
"version": "5",
"version": "6",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1714817544524,
"tag": "0000_premium_forgotten_one",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1714854863811,
"tag": "0001_unusual_rage",
"version": "6",
"when": 1715334238443,
"tag": "0000_talented_ben_parker",
"breakpoints": true
}
]

View File

@@ -2,7 +2,7 @@ import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
const migrationsFolder = process.argv[2] ?? "./migrations/sqlite";
const migrationsFolder = process.argv[2] ?? ".";
const sqlite = new Database(process.env.DB_URL?.replace("file:", ""));

View File

@@ -13,14 +13,18 @@
"types": "./index.ts",
"license": "MIT",
"scripts": {
"build": "esbuild migrate.ts --bundle --platform=node --outfile=migrate.cjs",
"build": "pnpm run build:sqlite && pnpm run build:mysql",
"build:sqlite": "esbuild migrations/sqlite/migrate.ts --bundle --platform=node --outfile=migrations/sqlite/migrate.cjs",
"build:mysql": "esbuild migrations/mysql/migrate.ts --bundle --platform=node --outfile=migrations/mysql/migrate.cjs",
"clean": "rm -rf .turbo node_modules",
"lint": "eslint .",
"format": "prettier --check . --ignore-path ../../.gitignore",
"migration:sqlite:generate": "drizzle-kit generate:sqlite --config ./sqlite.config.ts",
"migration:run": "tsx ./migrate.ts",
"migration:mysql:generate": "drizzle-kit generate:mysql --config ./mysql.config.ts",
"push": "drizzle-kit push:sqlite --config ./sqlite.config.ts",
"migration:sqlite:generate": "drizzle-kit generate --config ./configs/sqlite.config.ts",
"migration:sqlite:run": "drizzle-kit migrate --config ./configs/sqlite.config.ts",
"migration:mysql:generate": "drizzle-kit generate --config ./configs/mysql.config.ts",
"migration:mysql:run": "drizzle-kit migrate --config ./configs/mysql.config.ts",
"push:sqlite": "drizzle-kit push --config ./configs/sqlite.config.ts",
"push:mysql": "drizzle-kit push --config ./configs/mysql.config.ts",
"studio": "drizzle-kit studio",
"typecheck": "tsc --noEmit"
},
@@ -32,7 +36,7 @@
"better-sqlite3": "^9.6.0",
"drizzle-orm": "^0.30.10",
"mysql2": "3.9.7",
"drizzle-kit": "^0.20.18"
"drizzle-kit": "^0.21.1"
},
"devDependencies": {
"@homarr/eslint-config": "workspace:^0.2.0",

View File

@@ -29,7 +29,7 @@ import {
} from "@homarr/definitions";
export const users = mysqlTable("user", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name"),
email: text("email"),
emailVerified: timestamp("emailVerified"),
@@ -41,12 +41,12 @@ export const users = mysqlTable("user", {
export const accounts = mysqlTable(
"account",
{
userId: varchar("userId", { length: 256 })
userId: varchar("userId", { length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
type: text("type").$type<AdapterAccount["type"]>().notNull(),
provider: varchar("provider", { length: 256 }).notNull(),
providerAccountId: varchar("providerAccountId", { length: 256 }).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"),
@@ -69,7 +69,7 @@ export const sessions = mysqlTable(
sessionToken: varchar("sessionToken", { length: 512 })
.notNull()
.primaryKey(),
userId: varchar("userId", { length: 256 })
userId: varchar("userId", { length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
expires: timestamp("expires").notNull(),
@@ -82,7 +82,7 @@ export const sessions = mysqlTable(
export const verificationTokens = mysqlTable(
"verificationToken",
{
identifier: varchar("identifier", { length: 256 }).notNull(),
identifier: varchar("identifier", { length: 64 }).notNull(),
token: varchar("token", { length: 512 }).notNull(),
expires: timestamp("expires").notNull(),
},
@@ -96,10 +96,10 @@ export const verificationTokens = mysqlTable(
export const groupMembers = mysqlTable(
"groupMember",
{
groupId: varchar("groupId", { length: 256 })
groupId: varchar("groupId", { length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
userId: varchar("userId", { length: 256 })
userId: varchar("userId", { length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
},
@@ -111,25 +111,25 @@ export const groupMembers = mysqlTable(
);
export const groups = mysqlTable("group", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: varchar("name", { length: 64 }).notNull(),
ownerId: varchar("owner_id", { length: 256 }).references(() => users.id, {
ownerId: varchar("owner_id", { length: 64 }).references(() => users.id, {
onDelete: "set null",
}),
});
export const groupPermissions = mysqlTable("groupPermission", {
groupId: varchar("groupId", { length: 256 })
groupId: varchar("groupId", { length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<GroupPermissionKey>().notNull(),
});
export const invites = mysqlTable("invite", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
token: varchar("token", { length: 512 }).notNull().unique(),
expirationDate: timestamp("expiration_date").notNull(),
creatorId: varchar("creator_id", { length: 256 })
creatorId: varchar("creator_id", { length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
});
@@ -137,7 +137,7 @@ export const invites = mysqlTable("invite", {
export const integrations = mysqlTable(
"integration",
{
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name").notNull(),
url: text("url").notNull(),
kind: varchar("kind", { length: 128 }).$type<IntegrationKind>().notNull(),
@@ -155,7 +155,7 @@ export const integrationSecrets = mysqlTable(
.notNull(),
value: text("value").$type<`${string}.${string}`>().notNull(),
updatedAt: timestamp("updated_at").notNull(),
integrationId: varchar("integration_id", { length: 256 })
integrationId: varchar("integration_id", { length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -171,10 +171,10 @@ export const integrationSecrets = mysqlTable(
);
export const boards = mysqlTable("board", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: varchar("name", { length: 256 }).unique().notNull(),
isPublic: boolean("is_public").default(false).notNull(),
creatorId: text("creator_id").references(() => users.id, {
creatorId: varchar("creator_id", { length: 64 }).references(() => users.id, {
onDelete: "set null",
}),
pageTitle: text("page_title"),
@@ -204,13 +204,15 @@ export const boards = mysqlTable("board", {
export const boardUserPermissions = mysqlTable(
"boardUserPermission",
{
boardId: text("board_id")
boardId: varchar("board_id", { length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
userId: text("user_id")
userId: varchar("user_id", { length: 64 })
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permission: text("permission").$type<BoardPermission>().notNull(),
permission: varchar("permission", { length: 128 })
.$type<BoardPermission>()
.notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -222,13 +224,15 @@ export const boardUserPermissions = mysqlTable(
export const boardGroupPermissions = mysqlTable(
"boardGroupPermission",
{
boardId: text("board_id")
boardId: varchar("board_id", { length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
groupId: text("group_id")
groupId: varchar("group_id", { length: 64 })
.notNull()
.references(() => groups.id, { onDelete: "cascade" }),
permission: text("permission").$type<BoardPermission>().notNull(),
permission: varchar("permission", { length: 128 })
.$type<BoardPermission>()
.notNull(),
},
(table) => ({
compoundKey: primaryKey({
@@ -238,8 +242,8 @@ export const boardGroupPermissions = mysqlTable(
);
export const sections = mysqlTable("section", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
boardId: varchar("board_id", { length: 256 })
id: varchar("id", { length: 64 }).notNull().primaryKey(),
boardId: varchar("board_id", { length: 64 })
.notNull()
.references(() => boards.id, { onDelete: "cascade" }),
kind: text("kind").$type<SectionKind>().notNull(),
@@ -248,8 +252,8 @@ export const sections = mysqlTable("section", {
});
export const items = mysqlTable("item", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
sectionId: varchar("section_id", { length: 256 })
id: varchar("id", { length: 64 }).notNull().primaryKey(),
sectionId: varchar("section_id", { length: 64 })
.notNull()
.references(() => sections.id, { onDelete: "cascade" }),
kind: text("kind").$type<WidgetKind>().notNull(),
@@ -261,7 +265,7 @@ export const items = mysqlTable("item", {
});
export const apps = mysqlTable("app", {
id: varchar("id", { length: 256 }).notNull().primaryKey(),
id: varchar("id", { length: 64 }).notNull().primaryKey(),
name: text("name").notNull(),
description: text("description"),
iconUrl: text("icon_url").notNull(),
@@ -271,10 +275,10 @@ export const apps = mysqlTable("app", {
export const integrationItems = mysqlTable(
"integration_item",
{
itemId: varchar("item_id", { length: 256 })
itemId: varchar("item_id", { length: 64 })
.notNull()
.references(() => items.id, { onDelete: "cascade" }),
integrationId: varchar("integration_id", { length: 256 })
integrationId: varchar("integration_id", { length: 64 })
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
},
@@ -286,17 +290,17 @@ export const integrationItems = mysqlTable(
);
export const icons = mysqlTable("icon", {
id: varchar("icon_id", { length: 256 }).notNull().primaryKey(),
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: 256 })
iconRepositoryId: varchar("iconRepository_id", { length: 64 })
.notNull()
.references(() => iconRepositories.id, { onDelete: "cascade" }),
});
export const iconRepositories = mysqlTable("iconRepository", {
id: varchar("iconRepository_id", { length: 256 }).notNull().primaryKey(),
id: varchar("iconRepository_id", { length: 64 }).notNull().primaryKey(),
slug: varchar("iconRepository_slug", { length: 150 }).notNull(),
});