Skip to content

Commit

Permalink
refactor: deprecated pgtable schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonardoD committed Dec 23, 2024
1 parent 8ff9522 commit 7ecd595
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
12 changes: 5 additions & 7 deletions backend/src/db/schema/oauth-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export const oauthAccountsTable = pgTable(
.references(() => usersTable.id, { onDelete: 'cascade' }),
createdAt: timestamp().defaultNow().notNull(),
},
(table) => {
return {
pk: primaryKey({
columns: [table.providerId, table.providerUserId],
}),
};
},
(table) => [
primaryKey({
columns: [table.providerId, table.providerUserId],
}),
],
);
7 changes: 1 addition & 6 deletions backend/src/db/schema/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ export const organizationsTable = pgTable(
modifiedAt: timestamp(),
modifiedBy: varchar().references(() => usersTable.id, { onDelete: 'set null' }),
},
(table) => {
return {
nameIndex: index('organizations_name_index').on(table.name.desc()),
createdAtIndex: index('organizations_created_at_index').on(table.createdAt.desc()),
};
},
(table) => [index('organizations_name_index').on(table.name.desc()), index('organizations_created_at_index').on(table.createdAt.desc())],
);

export type OrganizationModel = typeof organizationsTable.$inferSelect;
Expand Down
7 changes: 1 addition & 6 deletions backend/src/db/schema/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export const requestsTable = pgTable(
type: varchar({ enum: requestTypeEnum }).notNull(),
createdAt: timestamp().defaultNow().notNull(),
},
(table) => {
return {
emailIndex: index('requests_emails').on(table.email.desc()),
createdAtIndex: index('requests_created_at').on(table.createdAt.desc()),
};
},
(table) => [index('requests_emails').on(table.email.desc()), index('requests_created_at').on(table.createdAt.desc())],
);

export type RequestsModel = typeof requestsTable.$inferSelect;
Expand Down
6 changes: 1 addition & 5 deletions backend/src/db/schema/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export const sessionsTable = pgTable(
expiresAt: timestamp({ withTimezone: true, mode: 'date' }).notNull(),
adminUserId: varchar().references(() => usersTable.id, { onDelete: 'cascade' }),
},
(table) => {
return {
adminUserIdIndex: index('idx_admin_id').on(table.adminUserId),
};
},
(table) => [index('idx_admin_id').on(table.adminUserId)],
);

export type SessionModel = typeof sessionsTable.$inferSelect;
Expand Down
22 changes: 10 additions & 12 deletions backend/src/db/schema/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ export const usersTable = pgTable(
modifiedBy: varchar(),
role: varchar({ enum: roleEnum }).notNull().default('user'),
},
(table) => {
return {
nameIndex: index('users_name_index').on(table.name.desc()),
unsubscribeTokenIndex: index('users_token_index').on(table.unsubscribeToken),
emailIndex: index('users_email_index').on(table.email.desc()),
createdAtIndex: index('users_created_at_index').on(table.createdAt.desc()),
modifiedByReference: foreignKey({
columns: [table.modifiedBy],
foreignColumns: [table.id],
}),
};
},
(table) => [
index('users_name_index').on(table.name.desc()),
index('users_token_index').on(table.unsubscribeToken),
index('users_email_index').on(table.email.desc()),
index('users_created_at_index').on(table.createdAt.desc()),
foreignKey({
columns: [table.modifiedBy],
foreignColumns: [table.id],
}),
],
);

export const safeUserSelect = omitKeys(usersTable, config.sensitiveFields);
Expand Down

0 comments on commit 7ecd595

Please sign in to comment.