@@ -18,6 +18,27 @@ import {
1818 configChangePassword ,
1919 loadCredentialsToEnv ,
2020} from './commands/config.js' ;
21+ import {
22+ initializeAdapter ,
23+ initializeSettingsRepo ,
24+ initializeConfigServicesRepo ,
25+ initializeLocalProvidersRepo ,
26+ initializePluginsRepo ,
27+ seedConfigServices ,
28+ } from '@ownpilot/gateway' ;
29+
30+ /**
31+ * Initialize database adapter and all repository caches.
32+ * Must run before any code that accesses settings or local providers.
33+ */
34+ async function initializeAll ( ) : Promise < void > {
35+ await initializeAdapter ( ) ;
36+ await initializeSettingsRepo ( ) ;
37+ await initializeConfigServicesRepo ( ) ;
38+ await seedConfigServices ( ) ;
39+ await initializePluginsRepo ( ) ;
40+ await initializeLocalProvidersRepo ( ) ;
41+ }
2142import {
2243 channelList ,
2344 channelAdd ,
@@ -54,7 +75,7 @@ program
5475 . option ( '-p, --password <password>' , 'Master password (will prompt if not provided)' )
5576 . action ( setup ) ;
5677
57- // Server command - loads credentials before starting
78+ // Server command - initializes repos before starting
5879program
5980 . command ( 'server' )
6081 . description ( 'Start the HTTP API server' )
@@ -63,6 +84,7 @@ program
6384 . option ( '--no-auth' , 'Disable authentication' )
6485 . option ( '--no-rate-limit' , 'Disable rate limiting' )
6586 . action ( async ( options ) => {
87+ await initializeAll ( ) ;
6688 await loadCredentialsToEnv ( ) ;
6789 await startServer ( options ) ;
6890 } ) ;
@@ -76,17 +98,19 @@ program
7698 . option ( '--users <ids>' , 'Comma-separated allowed user IDs' )
7799 . option ( '--chats <ids>' , 'Comma-separated allowed chat IDs' )
78100 . action ( async ( options ) => {
101+ await initializeAll ( ) ;
79102 await loadCredentialsToEnv ( ) ;
80103 await startBot ( options ) ;
81104 } ) ;
82105
83- // Start all command - loads credentials before starting
106+ // Start all command - initializes repos before starting
84107program
85108 . command ( 'start' )
86109 . description ( 'Start both server and bot' )
87110 . option ( '-p, --port <port>' , 'Server port' , '8080' )
88111 . option ( '--no-bot' , 'Skip starting the Telegram bot' )
89112 . action ( async ( options ) => {
113+ await initializeAll ( ) ;
90114 await loadCredentialsToEnv ( ) ;
91115 await startAll ( options ) ;
92116 } ) ;
0 commit comments