mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
working authentication
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
import { relations } from "drizzle-orm/relations";
|
||||
import { } from "./schema";
|
||||
import { users, userBuilds, userFavorites, userActivityLog } from "./schema";
|
||||
|
||||
export const userBuildsRelations = relations(userBuilds, ({one}) => ({
|
||||
user: one(users, {
|
||||
fields: [userBuilds.userId],
|
||||
references: [users.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const usersRelations = relations(users, ({many}) => ({
|
||||
userBuilds: many(userBuilds),
|
||||
userFavorites: many(userFavorites),
|
||||
userActivityLogs: many(userActivityLog),
|
||||
}));
|
||||
|
||||
export const userFavoritesRelations = relations(userFavorites, ({one}) => ({
|
||||
user: one(users, {
|
||||
fields: [userFavorites.userId],
|
||||
references: [users.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const userActivityLogRelations = relations(userActivityLog, ({one}) => ({
|
||||
user: one(users, {
|
||||
fields: [userActivityLog.userId],
|
||||
references: [users.id]
|
||||
}),
|
||||
}));
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pgTable, integer, varchar, text, numeric, timestamp, uuid, unique, index, real, doublePrecision, pgView } from "drizzle-orm/pg-core"
|
||||
import { pgTable, integer, varchar, text, numeric, timestamp, uuid, unique, check, bigserial, date, boolean, foreignKey, bigint, index, real, doublePrecision, pgView } from "drizzle-orm/pg-core"
|
||||
import { sql } from "drizzle-orm"
|
||||
|
||||
|
||||
@@ -41,6 +41,66 @@ export const productFeeds = pgTable("product_feeds", {
|
||||
}
|
||||
});
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||
username: varchar({ length: 50 }).notNull(),
|
||||
email: varchar({ length: 255 }).notNull(),
|
||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
firstName: varchar("first_name", { length: 50 }),
|
||||
lastName: varchar("last_name", { length: 50 }),
|
||||
profilePicture: varchar("profile_picture", { length: 255 }),
|
||||
dateOfBirth: date("date_of_birth"),
|
||||
phoneNumber: varchar("phone_number", { length: 20 }),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
isAdmin: boolean("is_admin").default(false),
|
||||
lastLogin: timestamp("last_login", { mode: 'string' }),
|
||||
emailVerified: boolean("email_verified").default(false),
|
||||
buildPrivacySetting: text("build_privacy_setting").default('public'),
|
||||
}, (table) => {
|
||||
return {
|
||||
usersUsernameKey: unique("users_username_key").on(table.username),
|
||||
usersEmailKey: unique("users_email_key").on(table.email),
|
||||
usersBuildPrivacySettingCheck: check("users_build_privacy_setting_check", sql`build_privacy_setting = ANY (ARRAY['private'::text, 'public'::text])`),
|
||||
}
|
||||
});
|
||||
|
||||
export const userBuilds = pgTable("user_builds", {
|
||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||
buildName: varchar("build_name", { length: 255 }).notNull(),
|
||||
buildDescription: text("build_description"),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
isShared: boolean("is_shared").default(false),
|
||||
}, (table) => {
|
||||
return {
|
||||
userBuildsUserIdFkey: foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
name: "user_builds_user_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
}
|
||||
});
|
||||
|
||||
export const userFavorites = pgTable("user_favorites", {
|
||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
itemId: bigint("item_id", { mode: "number" }).notNull(),
|
||||
addedAt: timestamp("added_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => {
|
||||
return {
|
||||
userFavoritesUserIdFkey: foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
name: "user_favorites_user_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
}
|
||||
});
|
||||
|
||||
export const brands = pgTable("brands", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "brands_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
name: varchar({ length: 100 }).notNull(),
|
||||
@@ -67,6 +127,22 @@ export const manufacturer = pgTable("manufacturer", {
|
||||
}
|
||||
});
|
||||
|
||||
export const userActivityLog = pgTable("user_activity_log", {
|
||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||
activity: text().notNull(),
|
||||
timestamp: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => {
|
||||
return {
|
||||
userActivityLogUserIdFkey: foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
name: "user_activity_log_user_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
}
|
||||
});
|
||||
|
||||
export const states = pgTable("states", {
|
||||
id: integer().primaryKey().generatedByDefaultAsIdentity({ name: "states_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
state: varchar({ length: 50 }),
|
||||
|
||||
Reference in New Issue
Block a user