This commit is contained in:
2025-12-05 23:23:22 +05:30
24 changed files with 55 additions and 255 deletions

View File

@@ -6,6 +6,4 @@ DB_HOST=db
DISCORD_BOT_TOKEN=your-discord-bot-token
DISCORD_CLIENT_ID=your-discord-client-id
DISCORD_GUILD_ID=your-discord-guild-id
DB_DATA_DIR=./db-data
DB_LOG_DIR=./db-logs
DATABASE_URL=postgres://kyoko:kyoko@db:5432/kyoko

39
.gitignore vendored
View File

@@ -2,4 +2,41 @@
node_modules
db-logs
db-data
.cursor
.cursor
# dependencies (bun install)
node_modules
# output
out
dist
*.tgz
# code coverage
coverage
*.lcov
# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# caches
.eslintcache
.cache
*.tsbuildinfo
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store
src/db/data
src/db/log

34
app/.gitignore vendored
View File

@@ -1,34 +0,0 @@
# dependencies (bun install)
node_modules
# output
out
dist
*.tgz
# code coverage
coverage
*.lcov
# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# caches
.eslintcache
.cache
*.tsbuildinfo
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

View File

@@ -1,22 +0,0 @@
CREATE TABLE "transactions" (
"transaction_id" serial PRIMARY KEY NOT NULL,
"from_user_id" text,
"to_user_id" text,
"amount" integer NOT NULL,
"occured_at" timestamp DEFAULT now(),
"type" text NOT NULL,
"description" text,
CONSTRAINT "transactions_transaction_id_unique" UNIQUE("transaction_id")
);
--> statement-breakpoint
CREATE TABLE "users" (
"user_id" text PRIMARY KEY NOT NULL,
"balance" integer DEFAULT 0 NOT NULL,
"last_daily" timestamp,
"daily_streak" integer DEFAULT 0 NOT NULL,
"created_at" timestamp DEFAULT now(),
CONSTRAINT "users_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_from_user_id_users_user_id_fk" FOREIGN KEY ("from_user_id") REFERENCES "public"."users"("user_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_to_user_id_users_user_id_fk" FOREIGN KEY ("to_user_id") REFERENCES "public"."users"("user_id") ON DELETE no action ON UPDATE no action;

View File

@@ -1,164 +0,0 @@
{
"id": "e5884b86-8257-466d-86f8-5fef47cfcd50",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.transactions": {
"name": "transactions",
"schema": "",
"columns": {
"transaction_id": {
"name": "transaction_id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"from_user_id": {
"name": "from_user_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"to_user_id": {
"name": "to_user_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"amount": {
"name": "amount",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"occured_at": {
"name": "occured_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"transactions_from_user_id_users_user_id_fk": {
"name": "transactions_from_user_id_users_user_id_fk",
"tableFrom": "transactions",
"tableTo": "users",
"columnsFrom": [
"from_user_id"
],
"columnsTo": [
"user_id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"transactions_to_user_id_users_user_id_fk": {
"name": "transactions_to_user_id_users_user_id_fk",
"tableFrom": "transactions",
"tableTo": "users",
"columnsFrom": [
"to_user_id"
],
"columnsTo": [
"user_id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"transactions_transaction_id_unique": {
"name": "transactions_transaction_id_unique",
"nullsNotDistinct": false,
"columns": [
"transaction_id"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"balance": {
"name": "balance",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"last_daily": {
"name": "last_daily",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"daily_streak": {
"name": "daily_streak",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_user_id_unique": {
"name": "users_user_id_unique",
"nullsNotDistinct": false,
"columns": [
"user_id"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -1,13 +0,0 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1764930369542,
"tag": "0000_big_obadiah_stane",
"breakpoints": true
}
]
}

View File

@@ -9,20 +9,19 @@ services:
ports:
- "${DB_PORT}:5432"
volumes:
- ${DB_DATA_DIR}:/var/lib/postgresql/data
- ${DB_LOG_DIR}:/var/log/postgresql
- ./src/db/data:/var/lib/postgresql/data
- ./src/db/log:/var/log/postgresql
app:
container_name: kyoko_app
image: kyoko-app
build:
context: ./app
context: .
dockerfile: Dockerfile
working_dir: /app
ports:
- "3000:3000"
volumes:
- ./app:/app
- .:/app
- /app/node_modules
environment:
- DB_USER=${DB_USER}
@@ -42,13 +41,13 @@ services:
container_name: kyoko_studio
image: kyoko-app
build:
context: ./app
context: .
dockerfile: Dockerfile
working_dir: /app
ports:
- "4983:4983"
volumes:
- ./app:/app
- .:/app
environment:
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}

View File

@@ -12,10 +12,9 @@
"typescript": "^5"
},
"scripts": {
"generate": "drizzle-kit generate",
"migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"deploy": "docker compose run --rm app bun src/scripts/deploy.ts",
"generate": "docker compose run --rm app drizzle-kit generate",
"migrate": "docker compose run --rm app drizzle-kit migrate",
"db:push": "docker compose run --rm app drizzle-kit push",
"dev": "bun --watch src/index.ts",
"db:studio": "drizzle-kit studio --host 0.0.0.0"
},

View File

@@ -1,7 +1,7 @@
import { pgTable, integer, text, timestamp, serial } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
userId: text("user_id").primaryKey().notNull().unique(),
userId: text("user_id").primaryKey().notNull(),
balance: integer("balance").notNull().default(0),
lastDaily: timestamp("last_daily"),
dailyStreak: integer("daily_streak").notNull().default(0),
@@ -9,7 +9,7 @@ export const users = pgTable("users", {
});
export const transactions = pgTable("transactions", {
transactionId: serial("transaction_id").primaryKey().notNull().unique(),
transactionId: serial("transaction_id").primaryKey().notNull(),
fromUserId: text("from_user_id").references(() => users.userId),
toUserId: text("to_user_id").references(() => users.userId),
amount: integer("amount").notNull(),

View File

@@ -25,22 +25,22 @@
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false,
// Aliases
"baseUrl": "./src",
"baseUrl": ".",
"paths": {
"@/*": [
"./*"
"./src/*"
],
"@commands/*": [
"./commands/*"
"./src/commands/*"
],
"@db/*": [
"./db/*"
"./src/db/*"
],
"@lib/*": [
"./lib/*"
"./src/lib/*"
],
"@modules/*": [
"./modules/*"
"./src/modules/*"
]
}
}