Skip to content

Commit 10e3cda

Browse files
committed
feat(tg-bot): add guarded tg-only Prisma push schema
Made-with: Cursor
1 parent 2eec575 commit 10e3cda

3 files changed

Lines changed: 129 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dev": "nodemon src/index.js",
99
"test": "jest --passWithNoTests",
1010
"lint": "eslint src/**/*.js",
11-
"lint:fix": "eslint src/**/*.js --fix"
11+
"lint:fix": "eslint src/**/*.js --fix",
12+
"prisma:push:safe": "node scripts/prisma-safe-push.mjs"
1213
},
1314
"keywords": [
1415
"licensechain",

prisma/schema.push.prisma

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Safe push schema for Telegram Bot only.
2+
// IMPORTANT:
3+
// - Uses TG_PRISMA_PUSH_URL (not DATABASE_URL).
4+
// - Intended for a TG-scoped database/schema only (for example: ...?schema=tg_bot).
5+
// - Do NOT point TG_PRISMA_PUSH_URL to the shared ecosystem public schema.
6+
7+
generator client {
8+
provider = "prisma-client-js"
9+
}
10+
11+
datasource db {
12+
provider = "postgresql"
13+
url = env("TG_PRISMA_PUSH_URL")
14+
}
15+
16+
model TgBotUser {
17+
id String @id @default(cuid())
18+
telegram_id BigInt @unique
19+
username String?
20+
first_name String?
21+
last_name String?
22+
created_at DateTime @default(now())
23+
updated_at DateTime @updatedAt
24+
25+
commands TgBotCommand[]
26+
validations TgBotValidation[]
27+
user_settings TgBotUserSetting?
28+
tickets TgBotTicket[]
29+
30+
@@map("tg_bot_users")
31+
}
32+
33+
model TgBotCommand {
34+
id String @id @default(cuid())
35+
user_id String
36+
command String
37+
created_at DateTime @default(now())
38+
39+
user TgBotUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
40+
41+
@@index([user_id])
42+
@@index([created_at])
43+
@@map("tg_bot_commands")
44+
}
45+
46+
model TgBotValidation {
47+
id String @id @default(cuid())
48+
user_id String
49+
license_key String
50+
is_valid Boolean
51+
created_at DateTime @default(now())
52+
53+
user TgBotUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
54+
55+
@@index([user_id])
56+
@@index([created_at])
57+
@@map("tg_bot_validations")
58+
}
59+
60+
model TgBotUserSetting {
61+
id String @id @default(cuid())
62+
user_id String @unique
63+
notifications_enabled Int @default(1)
64+
analytics_enabled Int @default(1)
65+
language String @default("en")
66+
updated_at DateTime @updatedAt
67+
68+
user TgBotUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
69+
70+
@@map("tg_bot_user_settings")
71+
}
72+
73+
model TgBotLicense {
74+
id String @id @default(cuid())
75+
user_id String?
76+
license_key String?
77+
created_at DateTime @default(now())
78+
79+
@@index([user_id])
80+
@@map("tg_bot_licenses")
81+
}
82+
83+
model TgBotTicket {
84+
id String @id @default(cuid())
85+
ticket_id String @unique
86+
user_id String
87+
subject String
88+
description String?
89+
status String @default("open")
90+
created_at DateTime @default(now())
91+
updated_at DateTime @updatedAt
92+
93+
user TgBotUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
94+
95+
@@index([user_id])
96+
@@index([status])
97+
@@index([created_at])
98+
@@map("tg_bot_tickets")
99+
}
100+
101+
model TgBotBotStatus {
102+
id String @id @default(cuid())
103+
status String
104+
updated_by String?
105+
updated_at DateTime @updatedAt
106+
107+
@@map("tg_bot_bot_status")
108+
}

scripts/prisma-safe-push.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { spawnSync } from 'node:child_process';
2+
3+
const url = process.env.TG_PRISMA_PUSH_URL || '';
4+
5+
if (!url) {
6+
console.error('TG_PRISMA_PUSH_URL is required.');
7+
process.exit(1);
8+
}
9+
10+
if (!url.includes('schema=tg_bot')) {
11+
console.error('Refusing to run: TG_PRISMA_PUSH_URL must target a tg_bot-scoped schema (expected query param schema=tg_bot).');
12+
process.exit(1);
13+
}
14+
15+
const cmd = './node_modules/.bin/prisma';
16+
const args = ['db', 'push', '--schema', 'prisma/schema.push.prisma', '--skip-generate'];
17+
18+
const result = spawnSync(cmd, args, { stdio: 'inherit', shell: true });
19+
process.exit(result.status ?? 1);

0 commit comments

Comments
 (0)