Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relations aren't showing in drizzle-kit studio after push. #379

Open
TrevorMayo13 opened this issue Apr 24, 2024 · 0 comments
Open

Relations aren't showing in drizzle-kit studio after push. #379

TrevorMayo13 opened this issue Apr 24, 2024 · 0 comments

Comments

@TrevorMayo13
Copy link

TrevorMayo13 commented Apr 24, 2024

When running npx drizzle-kit push:pg, my relations aren't pushed to the database. I can't see relations between forms, questions, and fieldOptions (doing a tutorial to learn drizzle). The relations between the user, session, and accounts all work and show correctly on the database within drizzle-kit studio.

Here's my schema.ts

import {
    timestamp,
    pgTable,
    text,
    primaryKey,
    integer,
    serial,
    boolean,
    pgEnum,
    jsonb
} from "drizzle-orm/pg-core";
import type { AdapterAccount } from "next-auth/adapters";
import { relations } from "drizzle-orm";
import { randomUUID } from "crypto";

export const formElements = pgEnum("field_type", [
    "RadioGroup",
    "Select",
    "Input",
    "Textarea",
    "Switch",
]);

export const users = pgTable("user", {
    id: text("id")
        .primaryKey()
        .$defaultFn(() => randomUUID()),
    name: text("name"),
    email: text("email").notNull().unique(),
    emailVerified: timestamp("emailVerified", { mode: "date" }),
    image: text("image"),
});

export const accounts = pgTable(
    "account",
    {
        userId: text("userId")
            .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"),
    },
    (account) => ({
        compoundKey: primaryKey({
            columns: [account.provider, account.providerAccountId],
        }),
    })
);

export const sessions = pgTable("session", {
    id: text("id")
        .primaryKey()
        .$defaultFn(() => randomUUID()),
    sessionToken: text("sessionToken").notNull().unique(),
    userId: text("userId")
        .notNull()
        .references(() => users.id, { onDelete: "cascade" }),
    expires: timestamp("expires", { mode: "date" }).notNull(),
});

export const verificationTokens = pgTable(
    "verificationToken",
    {
        identifier: text("identifier").notNull(),
        token: text("token").notNull(),
        expires: timestamp("expires", { mode: "date" }).notNull(),
    },
    (vt) => ({
        compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
    })
);

export const forms = pgTable("forms", {
    id: serial("id").primaryKey(),
    name: text("name"),
    description: text("description"),
    userId: text("user_id"),
    published: boolean("published"),
});

export const formsRelations = relations(forms, ({ many, one }) => ({
    questions: many(questions),
    user: one(users, {
        fields: [forms.userId],
        references: [users.id],
    }),
}));

export const questions = pgTable("questions", {
    id: serial("id").primaryKey(),
    text: text("text"),
    fieldType: formElements("field_type"),
    formId: integer("form_id"),
});

export const questionsRelations = relations(questions, ({ one, many }) => ({
    form: one(forms, {
        fields: [questions.formId],
        references: [forms.id],
    }),
    fieldOptions: many(fieldOptions),
}));

export const fieldOptions = pgTable("field_options", {
    id: serial("id").primaryKey(),
    text: text("text"),
    value: text("value"),
    questionId: integer("question_id"),
});

export const fieldOptionsRelations = relations(fieldOptions, ({ one }) => ({
    question: one(questions, {
        fields: [fieldOptions.questionId],
        references: [questions.id],
    }),
}));
@TrevorMayo13 TrevorMayo13 changed the title Relations aren't show in drizzle-kit studio after push. Relations aren't showing in drizzle-kit studio after push. Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant