feat: Initialize database and restructure application source code.
This commit is contained in:
@@ -6,6 +6,4 @@ DB_HOST=db
|
|||||||
DISCORD_BOT_TOKEN=your-discord-bot-token
|
DISCORD_BOT_TOKEN=your-discord-bot-token
|
||||||
DISCORD_CLIENT_ID=your-discord-client-id
|
DISCORD_CLIENT_ID=your-discord-client-id
|
||||||
DISCORD_GUILD_ID=your-discord-guild-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
|
DATABASE_URL=postgres://kyoko:kyoko@db:5432/kyoko
|
||||||
|
|||||||
39
.gitignore
vendored
39
.gitignore
vendored
@@ -2,4 +2,41 @@
|
|||||||
node_modules
|
node_modules
|
||||||
db-logs
|
db-logs
|
||||||
db-data
|
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
34
app/.gitignore
vendored
@@ -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
|
|
||||||
@@ -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;
|
|
||||||
@@ -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": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "7",
|
|
||||||
"dialect": "postgresql",
|
|
||||||
"entries": [
|
|
||||||
{
|
|
||||||
"idx": 0,
|
|
||||||
"version": "7",
|
|
||||||
"when": 1764930369542,
|
|
||||||
"tag": "0000_big_obadiah_stane",
|
|
||||||
"breakpoints": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -9,20 +9,19 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "${DB_PORT}:5432"
|
- "${DB_PORT}:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ${DB_DATA_DIR}:/var/lib/postgresql/data
|
- ./src/db/data:/var/lib/postgresql/data
|
||||||
- ${DB_LOG_DIR}:/var/log/postgresql
|
- ./src/db/log:/var/log/postgresql
|
||||||
|
|
||||||
app:
|
app:
|
||||||
container_name: kyoko_app
|
container_name: kyoko_app
|
||||||
image: kyoko-app
|
image: kyoko-app
|
||||||
build:
|
build:
|
||||||
context: ./app
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
volumes:
|
volumes:
|
||||||
- ./app:/app
|
- .:/app
|
||||||
- /app/node_modules
|
- /app/node_modules
|
||||||
environment:
|
environment:
|
||||||
- DB_USER=${DB_USER}
|
- DB_USER=${DB_USER}
|
||||||
@@ -42,13 +41,13 @@ services:
|
|||||||
container_name: kyoko_studio
|
container_name: kyoko_studio
|
||||||
image: kyoko-app
|
image: kyoko-app
|
||||||
build:
|
build:
|
||||||
context: ./app
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
ports:
|
ports:
|
||||||
- "4983:4983"
|
- "4983:4983"
|
||||||
volumes:
|
volumes:
|
||||||
- ./app:/app
|
- .:/app
|
||||||
environment:
|
environment:
|
||||||
- DB_USER=${DB_USER}
|
- DB_USER=${DB_USER}
|
||||||
- DB_PASSWORD=${DB_PASSWORD}
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
|
|||||||
@@ -12,10 +12,9 @@
|
|||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"generate": "drizzle-kit generate",
|
"generate": "docker compose run --rm app drizzle-kit generate",
|
||||||
"migrate": "drizzle-kit migrate",
|
"migrate": "docker compose run --rm app drizzle-kit migrate",
|
||||||
"db:push": "drizzle-kit push",
|
"db:push": "docker compose run --rm app drizzle-kit push",
|
||||||
"deploy": "docker compose run --rm app bun src/scripts/deploy.ts",
|
|
||||||
"dev": "bun --watch src/index.ts",
|
"dev": "bun --watch src/index.ts",
|
||||||
"db:studio": "drizzle-kit studio --host 0.0.0.0"
|
"db:studio": "drizzle-kit studio --host 0.0.0.0"
|
||||||
},
|
},
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { pgTable, integer, text, timestamp, serial } from "drizzle-orm/pg-core";
|
import { pgTable, integer, text, timestamp, serial } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
export const users = pgTable("users", {
|
export const users = pgTable("users", {
|
||||||
userId: text("user_id").primaryKey().notNull().unique(),
|
userId: text("user_id").primaryKey().notNull(),
|
||||||
balance: integer("balance").notNull().default(0),
|
balance: integer("balance").notNull().default(0),
|
||||||
lastDaily: timestamp("last_daily"),
|
lastDaily: timestamp("last_daily"),
|
||||||
dailyStreak: integer("daily_streak").notNull().default(0),
|
dailyStreak: integer("daily_streak").notNull().default(0),
|
||||||
@@ -9,7 +9,7 @@ export const users = pgTable("users", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const transactions = pgTable("transactions", {
|
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),
|
fromUserId: text("from_user_id").references(() => users.userId),
|
||||||
toUserId: text("to_user_id").references(() => users.userId),
|
toUserId: text("to_user_id").references(() => users.userId),
|
||||||
amount: integer("amount").notNull(),
|
amount: integer("amount").notNull(),
|
||||||
@@ -25,22 +25,22 @@
|
|||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
"noPropertyAccessFromIndexSignature": false,
|
"noPropertyAccessFromIndexSignature": false,
|
||||||
// Aliases
|
// Aliases
|
||||||
"baseUrl": "./src",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": [
|
"@/*": [
|
||||||
"./*"
|
"./src/*"
|
||||||
],
|
],
|
||||||
"@commands/*": [
|
"@commands/*": [
|
||||||
"./commands/*"
|
"./src/commands/*"
|
||||||
],
|
],
|
||||||
"@db/*": [
|
"@db/*": [
|
||||||
"./db/*"
|
"./src/db/*"
|
||||||
],
|
],
|
||||||
"@lib/*": [
|
"@lib/*": [
|
||||||
"./lib/*"
|
"./src/lib/*"
|
||||||
],
|
],
|
||||||
"@modules/*": [
|
"@modules/*": [
|
||||||
"./modules/*"
|
"./src/modules/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user