feat: add home board for users (#505)

* feat: add home board for users

* fix: format issues

* fix: deepsource issue

* chore: address pull request feedback

* fix: typecheck issue
This commit is contained in:
Meier Lukas
2024-05-18 16:57:00 +02:00
committed by GitHub
parent dfed804f65
commit 7e339c09c8
36 changed files with 2509 additions and 62 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE `user` ADD `homeBoardId` varchar(64);--> statement-breakpoint
ALTER TABLE `user` ADD CONSTRAINT `user_homeBoardId_board_id_fk` FOREIGN KEY (`homeBoardId`) REFERENCES `board`(`id`) ON DELETE set null ON UPDATE no action;

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,13 @@
"when": 1715334452118,
"tag": "0000_harsh_photon",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1715885855801,
"tag": "0001_wild_alex_wilder",
"breakpoints": true
}
]
}

View File

@@ -0,0 +1,33 @@
COMMIT TRANSACTION;
--> statement-breakpoint
PRAGMA foreign_keys = OFF;
--> statement-breakpoint
BEGIN TRANSACTION;
--> statement-breakpoint
ALTER TABLE `user` RENAME TO `__user_old`;
--> statement-breakpoint
CREATE TABLE `user` (
`id` text PRIMARY KEY NOT NULL,
`name` text,
`email` text,
`emailVerified` integer,
`image` text,
`password` text,
`salt` text,
`homeBoardId` text,
FOREIGN KEY (`homeBoardId`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
INSERT INTO `user` SELECT `id`, `name`, `email`, `emailVerified`, `image`, `password`, `salt`, null FROM `__user_old`;
--> statement-breakpoint
DROP TABLE `__user_old`;
--> statement-breakpoint
ALTER TABLE `user` RENAME TO `__user_old`;
--> statement-breakpoint
ALTER TABLE `__user_old` RENAME TO `user`;
--> statement-breakpoint
COMMIT TRANSACTION;
--> statement-breakpoint
PRAGMA foreign_keys = ON;
--> statement-breakpoint
BEGIN TRANSACTION;

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,13 @@
"when": 1715334238443,
"tag": "0000_talented_ben_parker",
"breakpoints": true
},
{
"idx": 1,
"version": "6",
"when": 1715871797713,
"tag": "0001_mixed_titanium_man",
"breakpoints": true
}
]
}

View File

@@ -1,5 +1,6 @@
import type { AdapterAccount } from "@auth/core/adapters";
import { relations } from "drizzle-orm";
import type { AnyMySqlColumn } from "drizzle-orm/mysql-core";
import {
boolean,
index,
@@ -36,6 +37,12 @@ export const users = mysqlTable("user", {
image: text("image"),
password: text("password"),
salt: text("salt"),
homeBoardId: varchar("homeBoardId", { length: 64 }).references(
(): AnyMySqlColumn => boards.id,
{
onDelete: "set null",
},
),
});
export const accounts = mysqlTable(

View File

@@ -1,6 +1,7 @@
import type { AdapterAccount } from "@auth/core/adapters";
import type { InferSelectModel } from "drizzle-orm";
import { relations } from "drizzle-orm";
import type { AnySQLiteColumn } from "drizzle-orm/sqlite-core";
import {
index,
int,
@@ -35,6 +36,12 @@ export const users = sqliteTable("user", {
image: text("image"),
password: text("password"),
salt: text("salt"),
homeBoardId: text("homeBoardId").references(
(): AnySQLiteColumn => boards.id,
{
onDelete: "set null",
},
),
});
export const accounts = sqliteTable(

View File

@@ -4,11 +4,16 @@ import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { schema } from "..";
export const createDb = () => {
export const createDb = (debug?: boolean) => {
const sqlite = new Database(":memory:");
const db = drizzle(sqlite, { schema });
const db = drizzle(sqlite, { schema, logger: debug });
migrate(db, {
migrationsFolder: "./packages/db/migrations/sqlite",
});
if (debug) {
console.log("Database created");
}
return db;
};