1
1
#!/usr/bin/env node
2
2
3
- import { PrismaClient } from '@prisma/client' ;
3
+ import { Prisma , PrismaClient } from '@prisma/client' ;
4
4
import consola from 'consola' ;
5
5
6
6
import { encodeCertPayload } from '@common/utils/certs/encode-node-payload' ;
@@ -16,6 +16,7 @@ const prisma = new PrismaClient({
16
16
17
17
const enum CLI_ACTIONS {
18
18
EXIT = 'exit' ,
19
+ FIX_POSTGRES_COLLATION = 'fix-postgres-collation' ,
19
20
GET_SSL_CERT_FOR_NODE = 'get-ssl-cert-for-node' ,
20
21
RESET_CERTS = 'reset-certs' ,
21
22
RESET_SUPERADMIN = 'reset-superadmin' ,
@@ -139,6 +140,36 @@ async function getSslCertForNode() {
139
140
}
140
141
}
141
142
143
+ async function fixPostgresCollation ( ) {
144
+ consola . start ( '🔄 Fixing Collation...' ) ;
145
+
146
+ const answer = await consola . prompt ( 'Are you sure you want to fix Collation?' , {
147
+ type : 'confirm' ,
148
+ required : true ,
149
+ } ) ;
150
+
151
+ if ( ! answer ) {
152
+ consola . error ( '❌ Aborted.' ) ;
153
+ process . exit ( 1 ) ;
154
+ }
155
+
156
+ try {
157
+ const result = await prisma . $queryRaw <
158
+ { dbname : string } [ ]
159
+ > `SELECT current_database() as dbname;` ;
160
+ const dbName = result [ 0 ] . dbname ;
161
+
162
+ consola . info ( `🔄 Refreshing Collation for database: ${ dbName } ` ) ;
163
+
164
+ await prisma . $executeRaw `ALTER DATABASE ${ Prisma . raw ( dbName ) } REFRESH COLLATION VERSION;` ;
165
+ consola . success ( '✅ Collation fixed successfully.' ) ;
166
+ process . exit ( 0 ) ;
167
+ } catch ( error ) {
168
+ consola . error ( '❌ Failed to fix Collation:' , error ) ;
169
+ process . exit ( 1 ) ;
170
+ }
171
+ }
172
+
142
173
async function main ( ) {
143
174
consola . box ( 'Remnawave Rescue CLI v0.2' ) ;
144
175
@@ -169,12 +200,17 @@ async function main() {
169
200
label : 'Get SSL_CERT for a Remnawave Node' ,
170
201
hint : 'Get SSL_CERT in cases, where you can not get from Panel' ,
171
202
} ,
203
+ {
204
+ value : CLI_ACTIONS . FIX_POSTGRES_COLLATION ,
205
+ label : 'Fix Collation' ,
206
+ hint : 'Fix Collation issues for current database' ,
207
+ } ,
172
208
{
173
209
value : CLI_ACTIONS . EXIT ,
174
210
label : 'Exit' ,
175
211
} ,
176
212
] ,
177
- initial : CLI_ACTIONS . RESET_SUPERADMIN ,
213
+ initial : CLI_ACTIONS . EXIT ,
178
214
} ) ;
179
215
180
216
switch ( action ) {
@@ -187,6 +223,9 @@ async function main() {
187
223
case CLI_ACTIONS . GET_SSL_CERT_FOR_NODE :
188
224
await getSslCertForNode ( ) ;
189
225
break ;
226
+ case CLI_ACTIONS . FIX_POSTGRES_COLLATION :
227
+ await fixPostgresCollation ( ) ;
228
+ break ;
190
229
case CLI_ACTIONS . EXIT :
191
230
consola . info ( '👋 Exiting...' ) ;
192
231
process . exit ( 0 ) ;
0 commit comments