stiba
Explore posts from serversDTDrizzle Team
•Created by stiba on 6/26/2024 in #help
Migrations complain about missing relations
Here are my schema definitions:
import { relations } from "drizzle-orm";
import {
integer,
json,
pgEnum,
pgTable,
serial,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";
export const users = pgTable(
"users",
{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
email: varchar("email", { length: 256 }).notNull(),
avatarUrl: text("avatar_url"),
},
(users) => {
return {
emailIndex: uniqueIndex("email_idx").on(users.email),
};
},
);
export const accountTypeEnum = pgEnum("account_type", ["discord"]);
export const accounts = pgTable("accounts", {
id: text("account_id").primaryKey(),
type: accountTypeEnum("account_type").notNull(),
accessToken: text("access_token").notNull(),
refreshToken: text("refresh_token").notNull(),
userId: integer("user_id")
.references(() => users.id)
.notNull(),
});
export const session = pgTable("session", {
id: text("id").primaryKey(),
data: json("data").notNull(),
expiresAt: timestamp("expires_at").notNull(),
});
export const userRelations = relations(users, ({ many }) => ({
accounts: many(accounts),
}));
export const accountsRelations = relations(accounts, ({ one }) => ({
user: one(users, {
fields: [accounts.userId],
references: [users.id],
}),
}));
import { relations } from "drizzle-orm";
import {
integer,
json,
pgEnum,
pgTable,
serial,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";
export const users = pgTable(
"users",
{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
email: varchar("email", { length: 256 }).notNull(),
avatarUrl: text("avatar_url"),
},
(users) => {
return {
emailIndex: uniqueIndex("email_idx").on(users.email),
};
},
);
export const accountTypeEnum = pgEnum("account_type", ["discord"]);
export const accounts = pgTable("accounts", {
id: text("account_id").primaryKey(),
type: accountTypeEnum("account_type").notNull(),
accessToken: text("access_token").notNull(),
refreshToken: text("refresh_token").notNull(),
userId: integer("user_id")
.references(() => users.id)
.notNull(),
});
export const session = pgTable("session", {
id: text("id").primaryKey(),
data: json("data").notNull(),
expiresAt: timestamp("expires_at").notNull(),
});
export const userRelations = relations(users, ({ many }) => ({
accounts: many(accounts),
}));
export const accountsRelations = relations(accounts, ({ one }) => ({
user: one(users, {
fields: [accounts.userId],
references: [users.id],
}),
}));
2 replies
DTDrizzle Team
•Created by stiba on 3/18/2023 in #help
Applying migrations with drizzle-orm/pg-core
Perfect, thanks! I was just looking at the generic docs, not the ones for PG.
4 replies