Add Prisma schema, .env, and initial migration for trading bot database

This commit is contained in:
root
2025-07-09 10:31:53 +02:00
parent 51a728457a
commit cfa6660abb
6 changed files with 323 additions and 8 deletions

BIN
prisma/dev.db Normal file

Binary file not shown.

View File

@@ -0,0 +1,102 @@
-- CreateTable
CREATE TABLE "users" (
"id" TEXT NOT NULL PRIMARY KEY,
"email" TEXT NOT NULL,
"name" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "api_keys" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"provider" TEXT NOT NULL,
"keyName" TEXT NOT NULL,
"encryptedKey" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "api_keys_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "user_settings" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"autoTrading" BOOLEAN NOT NULL DEFAULT false,
"tradingAmount" REAL NOT NULL DEFAULT 100,
"riskPercentage" REAL NOT NULL DEFAULT 2,
"maxDailyTrades" INTEGER NOT NULL DEFAULT 5,
"enableNotifications" BOOLEAN NOT NULL DEFAULT true,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "user_settings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "trades" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"symbol" TEXT NOT NULL,
"side" TEXT NOT NULL,
"amount" REAL NOT NULL,
"price" REAL NOT NULL,
"status" TEXT NOT NULL DEFAULT 'PENDING',
"driftTxId" TEXT,
"profit" REAL,
"fees" REAL,
"screenshotUrl" TEXT,
"aiAnalysis" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"executedAt" DATETIME,
"closedAt" DATETIME,
CONSTRAINT "trades_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "trading_journals" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"date" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"screenshotUrl" TEXT NOT NULL,
"aiAnalysis" TEXT NOT NULL,
"marketSentiment" TEXT,
"keyLevels" JSONB,
"recommendation" TEXT NOT NULL,
"confidence" REAL NOT NULL,
"notes" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "trading_journals_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "screenshots" (
"id" TEXT NOT NULL PRIMARY KEY,
"url" TEXT NOT NULL,
"filename" TEXT NOT NULL,
"fileSize" INTEGER NOT NULL,
"mimeType" TEXT NOT NULL,
"metadata" JSONB,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "system_logs" (
"id" TEXT NOT NULL PRIMARY KEY,
"level" TEXT NOT NULL,
"message" TEXT NOT NULL,
"metadata" JSONB,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE UNIQUE INDEX "api_keys_userId_provider_keyName_key" ON "api_keys"("userId", "provider", "keyName");
-- CreateIndex
CREATE UNIQUE INDEX "user_settings_userId_key" ON "user_settings"("userId");

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"

114
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,114 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique
name String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
apiKeys ApiKey[]
trades Trade[]
journals TradingJournal[]
settings UserSettings?
@@map("users")
}
model ApiKey {
id String @id @default(cuid())
userId String
provider String
keyName String
encryptedKey String
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([userId, provider, keyName])
@@map("api_keys")
}
model UserSettings {
id String @id @default(cuid())
userId String @unique
autoTrading Boolean @default(false)
tradingAmount Float @default(100)
riskPercentage Float @default(2)
maxDailyTrades Int @default(5)
enableNotifications Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("user_settings")
}
model Trade {
id String @id @default(cuid())
userId String
symbol String
side String
amount Float
price Float
status String @default("PENDING")
driftTxId String?
profit Float?
fees Float?
screenshotUrl String?
aiAnalysis String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
executedAt DateTime?
closedAt DateTime?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("trades")
}
model TradingJournal {
id String @id @default(cuid())
userId String
date DateTime @default(now())
screenshotUrl String
aiAnalysis String
marketSentiment String?
keyLevels Json?
recommendation String
confidence Float
notes String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("trading_journals")
}
model Screenshot {
id String @id @default(cuid())
url String
filename String
fileSize Int
mimeType String
metadata Json?
createdAt DateTime @default(now())
@@map("screenshots")
}
model SystemLog {
id String @id @default(cuid())
level String
message String
metadata Json?
createdAt DateTime @default(now())
@@map("system_logs")
}