fix betterauth db serial issue
This commit is contained in:
parent
6b6a1d170e
commit
9aa4ba157b
6 changed files with 32 additions and 32 deletions
|
|
@ -5,10 +5,10 @@ EXCEPTION
|
|||
END $$;
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "account" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"account_id" text NOT NULL,
|
||||
"provider_id" text NOT NULL,
|
||||
"user_id" serial NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"access_token" text,
|
||||
"refresh_token" text,
|
||||
"id_token" text,
|
||||
|
|
@ -24,7 +24,7 @@ CREATE TABLE IF NOT EXISTS "coin" (
|
|||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"symbol" varchar(10) NOT NULL,
|
||||
"creator_id" serial NOT NULL,
|
||||
"creator_id" integer,
|
||||
"initial_supply" numeric(28, 8) NOT NULL,
|
||||
"circulating_supply" numeric(28, 8) NOT NULL,
|
||||
"current_price" numeric(19, 8) NOT NULL,
|
||||
|
|
@ -47,20 +47,20 @@ CREATE TABLE IF NOT EXISTS "price_history" (
|
|||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "session" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"expires_at" timestamp with time zone NOT NULL,
|
||||
"token" text NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"ip_address" text,
|
||||
"user_agent" text,
|
||||
"user_id" serial NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
CONSTRAINT "session_token_unique" UNIQUE("token")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "transaction" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"user_id" serial NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"coin_id" integer NOT NULL,
|
||||
"type" "transaction_type" NOT NULL,
|
||||
"quantity" numeric(28, 8) NOT NULL,
|
||||
|
|
@ -85,7 +85,7 @@ CREATE TABLE IF NOT EXISTS "user" (
|
|||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "user_portfolio" (
|
||||
"user_id" serial NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"coin_id" integer NOT NULL,
|
||||
"quantity" numeric(28, 8) NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
|
|
@ -93,7 +93,7 @@ CREATE TABLE IF NOT EXISTS "user_portfolio" (
|
|||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "verification" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"identifier" text NOT NULL,
|
||||
"value" text NOT NULL,
|
||||
"expires_at" timestamp with time zone NOT NULL,
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"id": "c69a25a2-291e-48c8-847d-6d39c4251cab",
|
||||
"id": "d8f103f7-02e7-4506-95a5-4993abe53030",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -132,9 +132,9 @@
|
|||
},
|
||||
"creator_id": {
|
||||
"name": "creator_id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": false
|
||||
},
|
||||
"initial_supply": {
|
||||
"name": "initial_supply",
|
||||
|
|
@ -292,7 +292,7 @@
|
|||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -336,7 +336,7 @@
|
|||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
|
|
@ -380,7 +380,7 @@
|
|||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -551,7 +551,7 @@
|
|||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "serial",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -621,7 +621,7 @@
|
|||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1747913144586,
|
||||
"tag": "0000_loose_abomination",
|
||||
"when": 1747913743324,
|
||||
"tag": "0000_romantic_firebrand",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { apiKey } from "better-auth/plugins";
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
import { db } from "./server/db";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
if (!env.GOOGLE_CLIENT_ID) throw new Error('GOOGLE_CLIENT_ID is not set');
|
||||
if (!env.GOOGLE_CLIENT_SECRET) throw new Error('GOOGLE_CLIENT_SECRET is not set');
|
||||
|
|
@ -53,4 +50,7 @@ export const auth = betterAuth({
|
|||
},
|
||||
deleteUser: { enabled: true }
|
||||
},
|
||||
advanced: {
|
||||
generateId: false,
|
||||
}
|
||||
});
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
import { type VariantProps, tv } from "tailwind-variants";
|
||||
|
||||
export const buttonVariants = tv({
|
||||
base: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium outline-none transition-all focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
base: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium outline-none transition-all focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer",
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
||||
|
|
|
|||
|
|
@ -20,21 +20,21 @@ export const user = pgTable("user", {
|
|||
});
|
||||
|
||||
export const session = pgTable("session", {
|
||||
id: text("id").primaryKey(),
|
||||
id: serial("id").primaryKey(),
|
||||
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
ipAddress: text("ip_address"),
|
||||
userAgent: text("user_agent"),
|
||||
userId: serial("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
userId: integer("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
});
|
||||
|
||||
export const account = pgTable("account", {
|
||||
id: text("id").primaryKey(),
|
||||
id: serial("id").primaryKey(),
|
||||
accountId: text("account_id").notNull(),
|
||||
providerId: text("provider_id").notNull(),
|
||||
userId: serial("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
userId: integer("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
accessToken: text("access_token"),
|
||||
refreshToken: text("refresh_token"),
|
||||
idToken: text("id_token"),
|
||||
|
|
@ -47,7 +47,7 @@ export const account = pgTable("account", {
|
|||
});
|
||||
|
||||
export const verification = pgTable("verification", {
|
||||
id: text("id").primaryKey(),
|
||||
id: serial("id").primaryKey(),
|
||||
identifier: text("identifier").notNull(),
|
||||
value: text("value").notNull(),
|
||||
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
||||
|
|
@ -59,7 +59,7 @@ export const coin = pgTable("coin", {
|
|||
id: serial("id").primaryKey(),
|
||||
name: varchar("name", { length: 255 }).notNull(),
|
||||
symbol: varchar("symbol", { length: 10 }).notNull().unique(),
|
||||
creatorId: serial("creator_id").references(() => user.id, { onDelete: "set null", }), // Coin can exist even if creator is deleted
|
||||
creatorId: integer("creator_id").references(() => user.id, { onDelete: "set null", }), // Coin can exist even if creator is deleted
|
||||
initialSupply: decimal("initial_supply", { precision: 28, scale: 8 }).notNull(),
|
||||
circulatingSupply: decimal("circulating_supply", { precision: 28, scale: 8 }).notNull(),
|
||||
currentPrice: decimal("current_price", { precision: 19, scale: 8 }).notNull(), // Price in base currency
|
||||
|
|
@ -74,7 +74,7 @@ export const coin = pgTable("coin", {
|
|||
});
|
||||
|
||||
export const userPortfolio = pgTable("user_portfolio", {
|
||||
userId: serial("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
userId: integer("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
coinId: integer("coin_id").notNull().references(() => coin.id, { onDelete: "cascade" }),
|
||||
quantity: decimal("quantity", { precision: 28, scale: 8 }).notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
|
|
@ -88,7 +88,7 @@ export const userPortfolio = pgTable("user_portfolio", {
|
|||
|
||||
export const transaction = pgTable("transaction", {
|
||||
id: serial("id").primaryKey(),
|
||||
userId: serial("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
userId: integer("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||
coinId: integer("coin_id").notNull().references(() => coin.id, { onDelete: "cascade" }),
|
||||
type: transactionTypeEnum("type").notNull(),
|
||||
quantity: decimal("quantity", { precision: 28, scale: 8 }).notNull(),
|
||||
|
|
|
|||
Reference in a new issue