Skip to content

Commit

Permalink
feat: re-add the snake_casing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Nov 2, 2024
1 parent 8872d8a commit b6146da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({
schema: "./src/config/db/schema.mts",
out: "./drizzle",
dialect: "postgresql",
casing: "snake_case",
dbCredentials: {
url: DB_URL,
},
Expand Down
36 changes: 18 additions & 18 deletions src/config/db/schema.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const logs = pgTable(
environment: text().notNull(),
ip: text(),
data: jsonb(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" }).defaultNow().notNull(),
serviceId: text("service_id")
createdAt: timestamp({ precision: 3, mode: "string" }).defaultNow().notNull(),
serviceId: text()
.notNull()
.references(() => services.id, { onDelete: "cascade", onUpdate: "cascade" }),
level: text().default("info").notNull(),
lookupFilterValue: text("lookup_filter_value"),
isPersisted: boolean("is_persisted").notNull(),
lookupFilterValue: text(),
isPersisted: boolean().notNull(),
},
(t) => ({
createdAtIdx: index("log_created_at_idx").on(t.createdAt),
Expand All @@ -35,11 +35,11 @@ export const services = pgTable(
{
id: text().primaryKey().notNull(),
name: text().notNull(),
isActive: boolean("is_active").notNull(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" }).defaultNow().notNull(),
isPersisted: boolean("is_persisted").notNull(),
isAdmin: boolean("is_admin").notNull(),
tenantId: text("tenant_id").references(() => tenants.id),
isActive: boolean().notNull(),
createdAt: timestamp({ precision: 3, mode: "string" }).defaultNow().notNull(),
isPersisted: boolean().notNull(),
isAdmin: boolean().notNull(),
tenantId: text().references(() => tenants.id),
},
(t) => ({
createdAtIdx: index("service_created_at_idx").on(t.createdAt),
Expand All @@ -59,8 +59,8 @@ export const tenants = pgTable("tenants", {
id: text().primaryKey().notNull(),
name: text().notNull(),
workspace: text().notNull().unique(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(),
});

export const tenantRelations = relations(tenants, ({ many }) => ({
Expand All @@ -72,8 +72,8 @@ export const users = pgTable("users", {
id: text().primaryKey().notNull(),
username: text().notNull(),
githubId: text("github_id").unique(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(),
});

export const userRelations = relations(users, ({ many }) => ({
Expand All @@ -84,13 +84,13 @@ export const userRelations = relations(users, ({ many }) => ({
export const usersToTenants = pgTable(
"users_to_tenants",
{
userId: text("user_id")
userId: text()
.notNull()
.references(() => users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
tenantId: text("tenant_id")
tenantId: text()
.notNull()
.references(() => tenants.id, {
onDelete: "cascade",
Expand All @@ -115,14 +115,14 @@ export const usersToTenantsRelations = relations(usersToTenants, ({ one }) => ({

export const sessions = pgTable("sessions", {
id: text().primaryKey().notNull(),
userId: text("user_id")
userId: text()
.notNull()
.references(() => users.id, { onDelete: "cascade", onUpdate: "cascade" }),
expiresAt: timestamp("expires_at", {
expiresAt: timestamp({
withTimezone: true,
mode: "date",
}).notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
createdAt: timestamp({ withTimezone: true, mode: "date" }).defaultNow().notNull(),
});

export const sessionRelations = relations(sessions, ({ one }) => ({
Expand Down

0 comments on commit b6146da

Please sign in to comment.