-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves database interactions from raw SQL to Prisma ORM.
- Loading branch information
Showing
14 changed files
with
323 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE IF NOT EXISTS botguilds ( | ||
channel_id TEXT NOT NULL, | ||
guild_id TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS bots ( | ||
id TEXT NOT NULL, | ||
owner_id TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS email_verifications ( | ||
id TEXT NOT NULL, | ||
token TEXT | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS klines ( | ||
user_id TEXT, | ||
ip TEXT, | ||
reason TEXT | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS tokens ( | ||
id TEXT NOT NULL, | ||
token TEXT NOT NULL, | ||
seed TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS users ( | ||
id TEXT NOT NULL, | ||
username TEXT NOT NULL, | ||
pfp TEXT, | ||
email TEXT, | ||
password TEXT, | ||
activated BOOLEAN DEFAULT false NOT NULL, | ||
role BIGINT DEFAULT 2 NOT NULL, | ||
bot BOOLEAN DEFAULT false NOT NULL | ||
); |
33 changes: 33 additions & 0 deletions
33
prisma/migrations/20241108083501_set_unique_fields/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- AlterTable | ||
ALTER TABLE botguilds | ||
ADD PRIMARY KEY (channel_id); | ||
|
||
-- AlterTable | ||
ALTER TABLE bots | ||
ADD PRIMARY KEY (id); | ||
|
||
-- AlterTable | ||
ALTER TABLE email_verifications | ||
ADD PRIMARY KEY (id); | ||
|
||
-- AlterTable | ||
ALTER TABLE klines | ||
ADD COLUMN id SERIAL, | ||
ADD PRIMARY KEY (id); | ||
|
||
-- AlterTable | ||
ALTER TABLE tokens | ||
ADD PRIMARY KEY (seed); | ||
|
||
-- AlterTable | ||
ALTER TABLE users | ||
ADD PRIMARY KEY (id); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "users_username_key" ON "users"("username"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "email_verifications_token_key" ON "email_verifications"("token"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- AlterTable | ||
ALTER TABLE botguilds | ||
ALTER COLUMN channel_id TYPE BIGINT USING channel_id::BIGINT, | ||
ALTER COLUMN guild_id TYPE BIGINT USING guild_id::BIGINT; | ||
|
||
-- AlterTable | ||
ALTER TABLE bots | ||
ALTER COLUMN id TYPE BIGINT USING id::BIGINT, | ||
ALTER COLUMN owner_id TYPE BIGINT USING owner_id::BIGINT; | ||
|
||
-- AlterTable | ||
ALTER TABLE email_verifications | ||
ALTER COLUMN id TYPE BIGINT USING id::BIGINT; | ||
|
||
-- AlterTable | ||
ALTER TABLE klines | ||
ALTER COLUMN user_id TYPE BIGINT USING user_id::BIGINT; | ||
|
||
-- AlterTable | ||
ALTER TABLE tokens | ||
ALTER COLUMN id TYPE BIGINT USING id::BIGINT; | ||
|
||
-- AlterTable | ||
ALTER TABLE users | ||
ALTER COLUMN id TYPE BIGINT USING id::BIGINT, | ||
ALTER COLUMN role TYPE INT USING role::INT; | ||
ALTER TABLE users RENAME COLUMN pfp TO avatar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- AddForeignKey | ||
ALTER TABLE "bots" ADD CONSTRAINT "bots_owner_id_fkey" FOREIGN KEY ("owner_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "bots" ADD CONSTRAINT "bots_id_fkey" FOREIGN KEY ("id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("POSTGRES_URL") | ||
} | ||
|
||
model User { | ||
id BigInt @id | ||
username String @unique | ||
avatar String? | ||
email String? @unique | ||
password String? | ||
activated Boolean @default(false) | ||
role Int @default(2) | ||
bot Boolean @default(false) | ||
bots Bot[] @relation("bot_owner") | ||
bot_info Bot? @relation("bot_user_connection") | ||
@@map("users") | ||
} | ||
|
||
model Bot { | ||
id BigInt @id | ||
owner_id BigInt | ||
owner User @relation("bot_owner", fields: [owner_id], references: [id]) | ||
user User @relation("bot_user_connection", fields: [id], references: [id]) | ||
@@map("bots") | ||
} | ||
|
||
model Token { | ||
id BigInt | ||
token String | ||
seed String @id | ||
@@map("tokens") | ||
} | ||
|
||
model EmailVerification { | ||
id BigInt @id | ||
token String? @unique | ||
@@map("email_verifications") | ||
} | ||
|
||
model KLine { | ||
id Int @id @default(autoincrement()) | ||
user_id BigInt? | ||
ip String? | ||
reason String? | ||
@@map("klines") | ||
} | ||
|
||
// Only used for the bot, not really needed in the backend | ||
model BotGuild { | ||
channel_id BigInt @id | ||
guild_id BigInt | ||
@@map("botguilds") | ||
} |
Oops, something went wrong.