Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace mongodb with turso #56

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*.png
*.txt
*.service
*.toml
*.prisma
node_modules/
bun.lockb
yarn.lock
Expand Down
19 changes: 14 additions & 5 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
semi: true
tabWidth: 2
useTabs: false
endOfLine: 'lf'
endOfLine: lf
printWidth: 100
singleQuote: true
proseWrap: 'always'
arrowParens: 'avoid'
trailingComma: 'es5'
proseWrap: always
arrowParens: avoid
trailingComma: es5
bracketSpacing: true
quoteProps: 'as-needed'
quoteProps: as-needed

plugins:
- prettier-plugin-sql

# for SQL
keywordCase: lower
dataTypeCase: lower
functionCase: lower
identifierCase: lower
Binary file modified bun.lockb
Binary file not shown.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@
"start": "bun src/index.ts",
"lint": "tsc --noEmit",
"format": "prettier --write '**/?*.*'",
"wc": "find src tests -type f -exec wc {} +"
"wc": "find src tests -type f -exec wc {} +",
"sqlgen": "bun scripts/sqlgen.ts",
"typegen": "prisma generate"
},
"dependencies": {
"@discordjs/rest": "^2.4.0",
"@elysiajs/bearer": "^1.2.0",
"@elysiajs/static": "^1.2.0",
"@libsql/client": "^0.14.0",
"@mongodb-js/zstd": "^2.0.0",
"@prisma/adapter-libsql": "^6.1.0",
"@prisma/client": "^6.1.0",
"bytes": "^3.1.2",
"date-fns": "^4.1.0",
"discord-api-types": "^0.37.114",
"elysia": "^1.2.6",
"elysia": "^1.2.9",
"ioredis": "^5.4.2",
"lru-cache": "^11.0.2",
"mongoose": "^8.9.2",
Expand All @@ -51,6 +56,8 @@
"@types/bun": "^1.1.14",
"@types/bytes": "^3.1.5",
"prettier": "^3.4.2",
"prettier-plugin-sql": "^0.18.1",
"prisma": "^6.1.0",
"typescript": "^5.7.2"
},
"trustedDependencies": [
Expand Down
134 changes: 134 additions & 0 deletions prisma/db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
--- SQL that was actually executed into database
--- Observe changes in generated.sql and apply them here
--- DO NOT REWRITE THIS FILE IN ANY WAY
--- Just add new changes to the end of the file
create table "Variable" (
"id" text not null primary key,
"value" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "Game" (
"id" text not null primary key,
"save" text not null,
"preview" text,
"name" text,
"turns" integer not null default 0,
"currentPlayer" text,
"playerId" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "User" (
"id" text not null primary key,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "UsersInGame" (
"gameId" text not null,
"userId" text not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
primary key ("userId", "gameId"),
constraint "UsersInGame_gameId_fkey" foreign key ("gameId") references "Game" ("id") on delete restrict on update cascade,
constraint "UsersInGame_userId_fkey" foreign key ("userId") references "User" ("id") on delete restrict on update cascade
);

create table "Profile" (
"id" integer not null primary key autoincrement,
"discordId" bigint,
"rating" real not null default 1000,
"dmChannel" bigint,
"notifications" text not null default 'enabled',
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "UsersInProfile" (
"userId" text not null,
"profileId" integer not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
primary key ("userId", "profileId"),
constraint "UsersInProfile_userId_fkey" foreign key ("userId") references "User" ("id") on delete restrict on update cascade,
constraint "UsersInProfile_profileId_fkey" foreign key ("profileId") references "Profile" ("id") on delete restrict on update cascade
);

create table "ErrorLog" (
"id" integer not null primary key autoincrement,
"type" text not null,
"message" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "DiscordPoll" (
"id" bigint not null primary key,
"authorId" bigint not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

create table "DiscordPollEntry" (
"id" integer not null primary key autoincrement,
"label" text not null,
"pollId" bigint not null,
"count" integer not null default 0,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
constraint "DiscordPollEntry_pollId_fkey" foreign key ("pollId") references "DiscordPoll" ("id") on delete restrict on update cascade
);

create table "DiscordPollVote" (
"id" integer not null primary key autoincrement,
"entryId" integer not null,
"discordId" bigint not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
constraint "DiscordPollVote_entryId_fkey" foreign key ("entryId") references "DiscordPollEntry" ("id") on delete restrict on update cascade
);

create unique index "Variable_id_key" on "Variable" ("id");

create index "Variable_createdAt_idx" on "Variable" ("createdAt");

create index "Variable_updatedAt_idx" on "Variable" ("updatedAt");

create index "Game_playerId_idx" on "Game" ("playerId");

create index "Game_createdAt_idx" on "Game" ("createdAt");

create index "Game_updatedAt_idx" on "Game" ("updatedAt");

create index "User_createdAt_idx" on "User" ("createdAt");

create index "UsersInGame_userId_idx" on "UsersInGame" ("userId");

create index "UsersInGame_gameId_idx" on "UsersInGame" ("gameId");

create index "UsersInGame_createdAt_idx" on "UsersInGame" ("createdAt");

create index "Profile_createdAt_idx" on "Profile" ("createdAt");

create index "Profile_updatedAt_idx" on "Profile" ("updatedAt");

create index "Profile_discordId_idx" on "Profile" ("discordId");

create index "Profile_dmChannel_idx" on "Profile" ("dmChannel");

create unique index "UsersInProfile_userId_key" on "UsersInProfile" ("userId");

create index "UsersInProfile_userId_idx" on "UsersInProfile" ("userId");

create index "UsersInProfile_profileId_idx" on "UsersInProfile" ("profileId");

create index "UsersInProfile_createdAt_idx" on "UsersInProfile" ("createdAt");

create index "ErrorLog_createdAt_idx" on "ErrorLog" ("createdAt");

create index "DiscordPoll_createdAt_idx" on "DiscordPoll" ("createdAt");

create index "DiscordPollEntry_createdAt_idx" on "DiscordPollEntry" ("createdAt");

create index "DiscordPollEntry_updatedAt_idx" on "DiscordPollEntry" ("updatedAt");

create index "DiscordPollVote_createdAt_idx" on "DiscordPollVote" ("createdAt");

create unique index "DiscordPollVote_entryId_discordId_key" on "DiscordPollVote" ("entryId", "discordId");
164 changes: 164 additions & 0 deletions prisma/generated.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
-- CreateTable
create table "Variable" (
"id" text not null primary key,
"value" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "Game" (
"id" text not null primary key,
"save" text not null,
"preview" text,
"name" text,
"turns" integer not null default 0,
"currentPlayer" text,
"playerId" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "User" (
"id" text not null primary key,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "UsersInGame" (
"gameId" text not null,
"userId" text not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
primary key ("userId", "gameId"),
constraint "UsersInGame_gameId_fkey" foreign key ("gameId") references "Game" ("id") on delete restrict on update cascade,
constraint "UsersInGame_userId_fkey" foreign key ("userId") references "User" ("id") on delete restrict on update cascade
);

-- CreateTable
create table "Profile" (
"id" integer not null primary key autoincrement,
"discordId" bigint,
"rating" real not null default 1000,
"dmChannel" bigint,
"notifications" text not null default 'enabled',
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "UsersInProfile" (
"userId" text not null,
"profileId" integer not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
primary key ("userId", "profileId"),
constraint "UsersInProfile_userId_fkey" foreign key ("userId") references "User" ("id") on delete restrict on update cascade,
constraint "UsersInProfile_profileId_fkey" foreign key ("profileId") references "Profile" ("id") on delete restrict on update cascade
);

-- CreateTable
create table "ErrorLog" (
"id" integer not null primary key autoincrement,
"type" text not null,
"message" text,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "DiscordPoll" (
"id" bigint not null primary key,
"authorId" bigint not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer))
);

-- CreateTable
create table "DiscordPollEntry" (
"id" integer not null primary key autoincrement,
"label" text not null,
"pollId" bigint not null,
"count" integer not null default 0,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
"updatedAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
constraint "DiscordPollEntry_pollId_fkey" foreign key ("pollId") references "DiscordPoll" ("id") on delete restrict on update cascade
);

-- CreateTable
create table "DiscordPollVote" (
"id" integer not null primary key autoincrement,
"entryId" integer not null,
"discordId" bigint not null,
"createdAt" bigint not null default (cast(1000 * unixepoch ('subsec') as integer)),
constraint "DiscordPollVote_entryId_fkey" foreign key ("entryId") references "DiscordPollEntry" ("id") on delete restrict on update cascade
);

-- CreateIndex
create unique index "Variable_id_key" on "Variable" ("id");

-- CreateIndex
create index "Variable_createdAt_idx" on "Variable" ("createdAt");

-- CreateIndex
create index "Variable_updatedAt_idx" on "Variable" ("updatedAt");

-- CreateIndex
create index "Game_playerId_idx" on "Game" ("playerId");

-- CreateIndex
create index "Game_createdAt_idx" on "Game" ("createdAt");

-- CreateIndex
create index "Game_updatedAt_idx" on "Game" ("updatedAt");

-- CreateIndex
create index "User_createdAt_idx" on "User" ("createdAt");

-- CreateIndex
create index "UsersInGame_userId_idx" on "UsersInGame" ("userId");

-- CreateIndex
create index "UsersInGame_gameId_idx" on "UsersInGame" ("gameId");

-- CreateIndex
create index "UsersInGame_createdAt_idx" on "UsersInGame" ("createdAt");

-- CreateIndex
create index "Profile_createdAt_idx" on "Profile" ("createdAt");

-- CreateIndex
create index "Profile_updatedAt_idx" on "Profile" ("updatedAt");

-- CreateIndex
create index "Profile_discordId_idx" on "Profile" ("discordId");

-- CreateIndex
create index "Profile_dmChannel_idx" on "Profile" ("dmChannel");

-- CreateIndex
create unique index "UsersInProfile_userId_key" on "UsersInProfile" ("userId");

-- CreateIndex
create index "UsersInProfile_userId_idx" on "UsersInProfile" ("userId");

-- CreateIndex
create index "UsersInProfile_profileId_idx" on "UsersInProfile" ("profileId");

-- CreateIndex
create index "UsersInProfile_createdAt_idx" on "UsersInProfile" ("createdAt");

-- CreateIndex
create index "ErrorLog_createdAt_idx" on "ErrorLog" ("createdAt");

-- CreateIndex
create index "DiscordPoll_createdAt_idx" on "DiscordPoll" ("createdAt");

-- CreateIndex
create index "DiscordPollEntry_createdAt_idx" on "DiscordPollEntry" ("createdAt");

-- CreateIndex
create index "DiscordPollEntry_updatedAt_idx" on "DiscordPollEntry" ("updatedAt");

-- CreateIndex
create index "DiscordPollVote_createdAt_idx" on "DiscordPollVote" ("createdAt");

-- CreateIndex
create unique index "DiscordPollVote_entryId_discordId_key" on "DiscordPollVote" ("entryId", "discordId");
Loading
Loading