fix: foreign key reference default search engine (#2211)
* fix: foreign key reference default search engine * fix: add sqlite migration to fix on delete action --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -195,6 +195,12 @@ export const searchEngineRouter = createTRPCRouter({
|
|||||||
.requiresPermission("search-engine-full-all")
|
.requiresPermission("search-engine-full-all")
|
||||||
.input(validation.common.byId)
|
.input(validation.common.byId)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
await ctx.db
|
||||||
|
.update(users)
|
||||||
|
.set({
|
||||||
|
defaultSearchEngineId: null,
|
||||||
|
})
|
||||||
|
.where(eq(users.defaultSearchEngineId, input.id));
|
||||||
await ctx.db.delete(searchEngines).where(eq(searchEngines.id, input.id));
|
await ctx.db.delete(searchEngines).where(eq(searchEngines.id, input.id));
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- Custom SQL migration file, put your code below! --
|
||||||
|
-- This file is empty as there was a bug in the migration script of sqlite, missing on delete actions. See https://github.com/homarr-labs/homarr/pull/2211 --
|
||||||
1764
packages/db/migrations/mysql/meta/0023_snapshot.json
Normal file
1764
packages/db/migrations/mysql/meta/0023_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -162,6 +162,13 @@
|
|||||||
"when": 1737927618711,
|
"when": 1737927618711,
|
||||||
"tag": "0022_famous_otto_octavius",
|
"tag": "0022_famous_otto_octavius",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 23,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1738687012272,
|
||||||
|
"tag": "0023_fix_on_delete_actions",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
39
packages/db/migrations/sqlite/0023_fix_on_delete_actions.sql
Normal file
39
packages/db/migrations/sqlite/0023_fix_on_delete_actions.sql
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
-- Custom SQL migration file, put your code below! --
|
||||||
|
COMMIT TRANSACTION;
|
||||||
|
--> statement-breakpoint
|
||||||
|
PRAGMA foreign_keys = OFF;
|
||||||
|
--> statement-breakpoint
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
--> 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,
|
||||||
|
`mobile_home_board_id` text,
|
||||||
|
`default_search_engine_id` text,
|
||||||
|
`open_search_in_new_tab` integer DEFAULT true NOT NULL,
|
||||||
|
`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,
|
||||||
|
FOREIGN KEY (`mobile_home_board_id`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null,
|
||||||
|
FOREIGN KEY (`default_search_engine_id`) REFERENCES `search_engine`(`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", "mobile_home_board_id", "default_search_engine_id", "open_search_in_new_tab", "color_scheme", "first_day_of_week", "ping_icons_enabled") SELECT "id", "name", "email", "email_verified", "image", "password", "salt", "provider", "home_board_id", "mobile_home_board_id", "default_search_engine_id", "open_search_in_new_tab", "color_scheme", "first_day_of_week", "ping_icons_enabled" FROM `user`;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP TABLE `user`;
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE `__new_user` RENAME TO `user`;
|
||||||
|
--> statement-breakpoint
|
||||||
|
COMMIT TRANSACTION;
|
||||||
|
--> statement-breakpoint
|
||||||
|
PRAGMA foreign_keys = ON;
|
||||||
|
--> statement-breakpoint
|
||||||
|
BEGIN TRANSACTION;
|
||||||
1689
packages/db/migrations/sqlite/meta/0023_snapshot.json
Normal file
1689
packages/db/migrations/sqlite/meta/0023_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -162,6 +162,13 @@
|
|||||||
"when": 1737927609085,
|
"when": 1737927609085,
|
||||||
"tag": "0022_modern_sunfire",
|
"tag": "0022_modern_sunfire",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 23,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1738686324915,
|
||||||
|
"tag": "0023_fix_on_delete_actions",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user