feat: setup workspaces members
This commit is contained in:
@@ -61,7 +61,7 @@ export default function BoardPage() {
|
||||
const [selectedPublicListId, setSelectedPublicListId] =
|
||||
useState<PublicListId>("");
|
||||
|
||||
const boardId = params?.id?.length ? params.id[0] : null;
|
||||
const boardId = params?.boardId?.length ? params.boardId[0] : null;
|
||||
|
||||
const updateBoard = api.board.update.useMutation();
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { WorkspaceProvider } from "~/app/providers/workspace";
|
||||
import Dashboard from "~/app/components/dashboard";
|
||||
|
||||
export default function Layout(props: { children: React.ReactNode }) {
|
||||
return <Dashboard>{props.children}</Dashboard>;
|
||||
return (
|
||||
<WorkspaceProvider>
|
||||
<Dashboard>{props.children}</Dashboard>;
|
||||
</WorkspaceProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import { BoardsList } from "./components/BoardsList";
|
||||
import { useModal } from "~/app/providers/modal";
|
||||
import Modal from "~/app/components/modal";
|
||||
|
||||
import { ImportBoardsForm } from "~/app/boards/components/ImportBoardsForm";
|
||||
import { NewBoardForm } from "~/app/boards/components/NewBoardForm";
|
||||
import { ImportBoardsForm } from "./components/ImportBoardsForm";
|
||||
import { NewBoardForm } from "./components/NewBoardForm";
|
||||
|
||||
export default function BoardsPage() {
|
||||
const { openModal, modalContentType } = useModal();
|
||||
|
||||
@@ -27,7 +27,9 @@ export default function CardPage() {
|
||||
const params = useParams();
|
||||
const { modalContentType } = useModal();
|
||||
|
||||
const cardId = params?.id?.length ? params.id[0] : null;
|
||||
const cardId = Array.isArray(params?.cardId)
|
||||
? params.cardId[0]
|
||||
: params?.cardId;
|
||||
|
||||
const { data } = api.card.byId.useQuery({ id: cardId ?? "" });
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { WorkspaceProvider } from "~/app/providers/workspace";
|
||||
import Dashboard from "~/app/components/dashboard";
|
||||
|
||||
export default function Layout(props: { children: React.ReactNode }) {
|
||||
return <Dashboard>{props.children}</Dashboard>;
|
||||
return (
|
||||
<WorkspaceProvider>
|
||||
<Dashboard>{props.children}</Dashboard>;
|
||||
</WorkspaceProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,7 @@ import settingsIcon from "~/app/assets/settings.json";
|
||||
import ReactiveButton from "~/app/components/ReactiveButton";
|
||||
import UserMenu from "~/app/components/UserMenu";
|
||||
|
||||
const navigation = [
|
||||
{ name: "Boards", href: "/boards", icon: boardsIcon },
|
||||
{ name: "Members", href: "/members", icon: membersIcon },
|
||||
{ name: "Settings", href: "/settings", icon: settingsIcon },
|
||||
];
|
||||
import { useWorkspace } from "~/app/providers/workspace";
|
||||
|
||||
interface SideNavigationProps {
|
||||
user: UserType;
|
||||
@@ -28,10 +24,17 @@ interface UserType {
|
||||
|
||||
export default function SideNavigation({ user }: SideNavigationProps) {
|
||||
const pathname = usePathname();
|
||||
const { workspace } = useWorkspace();
|
||||
|
||||
const { data } = api.workspace.all.useQuery();
|
||||
|
||||
const workspace = data?.[0];
|
||||
const navigation = [
|
||||
{ name: "Boards", href: "/boards", icon: boardsIcon },
|
||||
{
|
||||
name: "Members",
|
||||
href: "/members",
|
||||
icon: membersIcon,
|
||||
},
|
||||
{ name: "Settings", href: "/settings", icon: settingsIcon },
|
||||
];
|
||||
|
||||
return (
|
||||
<nav className="flex w-72 flex-col justify-between border-r border-dark-600 px-5 py-5">
|
||||
|
||||
10
src/app/members/layout.tsx
Normal file
10
src/app/members/layout.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { WorkspaceProvider } from "~/app/providers/workspace";
|
||||
import Dashboard from "~/app/components/dashboard";
|
||||
|
||||
export default function Layout(props: { children: React.ReactNode }) {
|
||||
return (
|
||||
<WorkspaceProvider>
|
||||
<Dashboard>{props.children}</Dashboard>;
|
||||
</WorkspaceProvider>
|
||||
);
|
||||
}
|
||||
81
src/app/providers/workspace.tsx
Normal file
81
src/app/providers/workspace.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
"use client";
|
||||
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
|
||||
import { api } from "~/trpc/react";
|
||||
|
||||
interface WorkspaceContextProps {
|
||||
workspace: Workspace;
|
||||
setWorkspace: React.Dispatch<React.SetStateAction<Workspace>>;
|
||||
}
|
||||
|
||||
interface Workspace {
|
||||
name: string;
|
||||
publicId: string;
|
||||
}
|
||||
|
||||
const initialBoardData: Workspace = {
|
||||
name: "",
|
||||
publicId: "",
|
||||
};
|
||||
|
||||
const WorkspaceContext = createContext<WorkspaceContextProps | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [workspace, setWorkspace] = useState<Workspace>(initialBoardData);
|
||||
|
||||
const { data } = api.workspace.all.useQuery();
|
||||
|
||||
useEffect(() => {
|
||||
const storedWorkspaceId: string | null =
|
||||
localStorage.getItem("workspacePublicId");
|
||||
|
||||
if (storedWorkspaceId !== null) {
|
||||
const selectedWorkspace = data?.find(
|
||||
({ workspace }) => (workspace.publicId = storedWorkspaceId),
|
||||
);
|
||||
|
||||
if (!selectedWorkspace) return;
|
||||
|
||||
setWorkspace({
|
||||
publicId: selectedWorkspace.workspace.publicId,
|
||||
name: selectedWorkspace.workspace.name,
|
||||
});
|
||||
} else {
|
||||
const primaryWorkspace = data?.[0]?.workspace;
|
||||
|
||||
if (!primaryWorkspace) return;
|
||||
|
||||
localStorage.setItem("workspacePublicId", primaryWorkspace?.publicId);
|
||||
|
||||
setWorkspace({
|
||||
publicId: primaryWorkspace?.publicId,
|
||||
name: primaryWorkspace?.name,
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<WorkspaceContext.Provider value={{ workspace, setWorkspace }}>
|
||||
{children}
|
||||
</WorkspaceContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useWorkspace = (): WorkspaceContextProps => {
|
||||
const context = useContext(WorkspaceContext);
|
||||
if (!context) {
|
||||
throw new Error("useWorkspace must be used within a WorkspaceProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import Dashboard from "~/app/components/dashboard";
|
||||
|
||||
export default function Layout(props: { children: React.ReactNode }) {
|
||||
return <Dashboard>{props.children}</Dashboard>;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
|
||||
import { workspaces } from "~/server/db/schema";
|
||||
import { workspaceMembers } from "~/server/db/schema";
|
||||
|
||||
import {
|
||||
createTRPCRouter,
|
||||
@@ -13,12 +13,19 @@ export const workspaceRouter = createTRPCRouter({
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
return ctx.db.query.workspaces.findMany({
|
||||
where: and(eq(workspaces.createdBy, userId), isNull(workspaces.deletedAt)),
|
||||
return ctx.db.query.workspaceMembers.findMany({
|
||||
where: and(eq(workspaceMembers.userId, userId), isNull(workspaceMembers.deletedAt)),
|
||||
columns: {
|
||||
publicId: true,
|
||||
name: true,
|
||||
role: true,
|
||||
},
|
||||
with: {
|
||||
workspace: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}),
|
||||
});
|
||||
@@ -63,7 +63,7 @@ export const {
|
||||
options: {},
|
||||
async sendVerificationRequest({ identifier: email, url }) {
|
||||
const magicLinkEmail = MagicLinkEmail({ loginUrl: url });
|
||||
await fetch(process.env.EMAIL_URL ?? '', {
|
||||
const response = await fetch(process.env.EMAIL_URL ?? '', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -77,10 +77,9 @@ export const {
|
||||
}),
|
||||
})
|
||||
|
||||
// if (!response.ok) {
|
||||
// const { errors } = await response.json()
|
||||
// throw new Error(JSON.stringify(errors))
|
||||
// }
|
||||
if (response.status !== 200) {
|
||||
throw new Error('Error sending magic login')
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
|
||||
16
src/server/db/migrations/0010_jittery_zzzax.sql
Normal file
16
src/server/db/migrations/0010_jittery_zzzax.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE `workspace_members` (
|
||||
`id` bigint AUTO_INCREMENT NOT NULL,
|
||||
`publicId` varchar(12) NOT NULL,
|
||||
`userId` varchar(256) NOT NULL,
|
||||
`workspaceId` bigint NOT NULL,
|
||||
`createdBy` varchar(256) NOT NULL,
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updatedAt` timestamp ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deletedAt` timestamp,
|
||||
`role` enum('admin','member','guest') NOT NULL,
|
||||
CONSTRAINT `workspace_members_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `workspace_members_publicId_unique` UNIQUE(`publicId`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
-- ALTER TABLE `workspace_members` ADD CONSTRAINT `workspace_members_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
-- ALTER TABLE `workspace_members` ADD CONSTRAINT `workspace_members_workspaceId_workspace_id_fk` FOREIGN KEY (`workspaceId`) REFERENCES `workspace`(`id`) ON DELETE no action ON UPDATE no action;
|
||||
992
src/server/db/migrations/meta/0010_snapshot.json
Normal file
992
src/server/db/migrations/meta/0010_snapshot.json
Normal file
@@ -0,0 +1,992 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "mysql",
|
||||
"id": "bb0a54cb-844f-4bf2-9cc8-0600d09cccdc",
|
||||
"prevId": "29b7ae44-dce5-4353-ba56-ff398fa3e542",
|
||||
"tables": {
|
||||
"account": {
|
||||
"name": "account",
|
||||
"columns": {
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"provider": {
|
||||
"name": "provider",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"providerAccountId": {
|
||||
"name": "providerAccountId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"refresh_token": {
|
||||
"name": "refresh_token",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"access_token": {
|
||||
"name": "access_token",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token_type": {
|
||||
"name": "token_type",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"scope": {
|
||||
"name": "scope",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"id_token": {
|
||||
"name": "id_token",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"session_state": {
|
||||
"name": "session_state",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"userId_idx": {
|
||||
"name": "userId_idx",
|
||||
"columns": [
|
||||
"userId"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"account_provider_providerAccountId": {
|
||||
"name": "account_provider_providerAccountId",
|
||||
"columns": [
|
||||
"provider",
|
||||
"providerAccountId"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"board": {
|
||||
"name": "board",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"deletedAt": {
|
||||
"name": "deletedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedBy": {
|
||||
"name": "deletedBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"importId": {
|
||||
"name": "importId",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"workspaceId": {
|
||||
"name": "workspaceId",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"board_id": {
|
||||
"name": "board_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"board_publicId_unique": {
|
||||
"name": "board_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"card": {
|
||||
"name": "card",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"listId": {
|
||||
"name": "listId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"index": {
|
||||
"name": "index",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedAt": {
|
||||
"name": "deletedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedBy": {
|
||||
"name": "deletedBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"importId": {
|
||||
"name": "importId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"card_id": {
|
||||
"name": "card_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"card_publicId_unique": {
|
||||
"name": "card_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"card_label": {
|
||||
"name": "card_label",
|
||||
"columns": {
|
||||
"cardId": {
|
||||
"name": "cardId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"labelId": {
|
||||
"name": "labelId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"card_label_cardId_card_id_fk": {
|
||||
"name": "card_label_cardId_card_id_fk",
|
||||
"tableFrom": "card_label",
|
||||
"tableTo": "card",
|
||||
"columnsFrom": [
|
||||
"cardId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"card_label_labelId_label_id_fk": {
|
||||
"name": "card_label_labelId_label_id_fk",
|
||||
"tableFrom": "card_label",
|
||||
"tableTo": "label",
|
||||
"columnsFrom": [
|
||||
"labelId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {
|
||||
"card_label_cardId_labelId": {
|
||||
"name": "card_label_cardId_labelId",
|
||||
"columns": [
|
||||
"cardId",
|
||||
"labelId"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"import": {
|
||||
"name": "import",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"source": {
|
||||
"name": "source",
|
||||
"type": "enum('trello')",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"status": {
|
||||
"name": "status",
|
||||
"type": "enum('started','success','failed')",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"import_id": {
|
||||
"name": "import_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"import_publicId_unique": {
|
||||
"name": "import_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"name": "label",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"colourCode": {
|
||||
"name": "colourCode",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"boardId": {
|
||||
"name": "boardId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"importId": {
|
||||
"name": "importId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"label_id": {
|
||||
"name": "label_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"label_publicId_unique": {
|
||||
"name": "label_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"list": {
|
||||
"name": "list",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"boardId": {
|
||||
"name": "boardId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"index": {
|
||||
"name": "index",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedAt": {
|
||||
"name": "deletedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedBy": {
|
||||
"name": "deletedBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"importId": {
|
||||
"name": "importId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"list_id": {
|
||||
"name": "list_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"list_publicId_unique": {
|
||||
"name": "list_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"session": {
|
||||
"name": "session",
|
||||
"columns": {
|
||||
"sessionToken": {
|
||||
"name": "sessionToken",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expires": {
|
||||
"name": "expires",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"userId_idx": {
|
||||
"name": "userId_idx",
|
||||
"columns": [
|
||||
"userId"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"session_sessionToken": {
|
||||
"name": "session_sessionToken",
|
||||
"columns": [
|
||||
"sessionToken"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"user": {
|
||||
"name": "user",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"emailVerified": {
|
||||
"name": "emailVerified",
|
||||
"type": "timestamp(3)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP(3)"
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"user_email_unique": {
|
||||
"name": "user_email_unique",
|
||||
"columns": [
|
||||
"email"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"verificationToken": {
|
||||
"name": "verificationToken",
|
||||
"columns": {
|
||||
"identifier": {
|
||||
"name": "identifier",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token": {
|
||||
"name": "token",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expires": {
|
||||
"name": "expires",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"verificationToken_identifier_token": {
|
||||
"name": "verificationToken_identifier_token",
|
||||
"columns": [
|
||||
"identifier",
|
||||
"token"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"workspace_members": {
|
||||
"name": "workspace_members",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"workspaceId": {
|
||||
"name": "workspaceId",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"deletedAt": {
|
||||
"name": "deletedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "enum('admin','member','guest')",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"workspace_members_userId_user_id_fk": {
|
||||
"name": "workspace_members_userId_user_id_fk",
|
||||
"tableFrom": "workspace_members",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"userId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"workspace_members_workspaceId_workspace_id_fk": {
|
||||
"name": "workspace_members_workspaceId_workspace_id_fk",
|
||||
"tableFrom": "workspace_members",
|
||||
"tableTo": "workspace",
|
||||
"columnsFrom": [
|
||||
"workspaceId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {
|
||||
"workspace_members_id": {
|
||||
"name": "workspace_members_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"workspace_members_userId_workspaceId": {
|
||||
"name": "workspace_members_userId_workspaceId",
|
||||
"columns": [
|
||||
"userId",
|
||||
"workspaceId"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"workspace_members_publicId_unique": {
|
||||
"name": "workspace_members_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"workspace": {
|
||||
"name": "workspace",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"publicId": {
|
||||
"name": "publicId",
|
||||
"type": "varchar(12)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdBy": {
|
||||
"name": "createdBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updatedAt": {
|
||||
"name": "updatedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true
|
||||
},
|
||||
"deletedAt": {
|
||||
"name": "deletedAt",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"deletedBy": {
|
||||
"name": "deletedBy",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"workspace_id": {
|
||||
"name": "workspace_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {
|
||||
"workspace_publicId_unique": {
|
||||
"name": "workspace_publicId_unique",
|
||||
"columns": [
|
||||
"publicId"
|
||||
]
|
||||
},
|
||||
"workspace_slug_unique": {
|
||||
"name": "workspace_slug_unique",
|
||||
"columns": [
|
||||
"slug"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,13 @@
|
||||
"when": 1709314236852,
|
||||
"tag": "0009_massive_peter_parker",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"version": "5",
|
||||
"when": 1709465628179,
|
||||
"tag": "0010_jittery_zzzax",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -128,7 +128,7 @@ export const cardsToLabels = mySqlTable(
|
||||
}),
|
||||
);
|
||||
|
||||
export const cardOnLabelsRelations = relations(cardsToLabels, ({ one }) => ({
|
||||
export const cardToLabelsRelations = relations(cardsToLabels, ({ one }) => ({
|
||||
card: one(cards, {
|
||||
fields: [cardsToLabels.cardId],
|
||||
references: [cards.id],
|
||||
@@ -315,3 +315,36 @@ export const workspaces = mySqlTable(
|
||||
export const workspaceRelations = relations(workspaces, ({ one }) => ({
|
||||
user: one(users, { fields: [workspaces.createdBy], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const workspaceMembers = mySqlTable(
|
||||
"workspace_members",
|
||||
{
|
||||
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
userId: varchar("userId", { length: 256 }).notNull().references(() => users.id),
|
||||
workspaceId: bigint("workspaceId", { mode: "number" }).notNull().references(() => workspaces.id),
|
||||
createdBy: varchar("createdBy", { length: 256 }).notNull(),
|
||||
createdAt: timestamp("createdAt")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updatedAt").onUpdateNow(),
|
||||
deletedAt: timestamp("deletedAt"),
|
||||
role: mysqlEnum('role', ['admin', 'member', 'guest']).notNull(),
|
||||
}, (t) => ({
|
||||
pk: primaryKey(t.userId, t.workspaceId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const usersToWorkspacesRelations = relations(workspaceMembers, ({ one }) => ({
|
||||
addedBy: one(users, { fields: [workspaceMembers.createdBy], references: [users.id] }),
|
||||
user: one(users, {
|
||||
fields: [workspaceMembers.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
workspace: one(workspaces, {
|
||||
fields: [workspaceMembers.workspaceId],
|
||||
references: [workspaces.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user