@@ -13,26 +13,26 @@ const uid = userInfo().uid;
1313export let db : Database ;
1414
1515try {
16- const databasePath = path . join ( dataFolder , "dockstatapi.db" ) ;
17- console . log ( "Database path:" , databasePath ) ;
18- console . log ( `Running as: ${ username } (${ uid } :${ gid } )` ) ;
16+ const databasePath = path . join ( dataFolder , "dockstatapi.db" ) ;
17+ console . log ( "Database path:" , databasePath ) ;
18+ console . log ( `Running as: ${ username } (${ uid } :${ gid } )` ) ;
1919
20- if ( ! existsSync ( dataFolder ) ) {
21- await mkdir ( dataFolder , { recursive : true , mode : 0o777 } ) ;
22- console . log ( "Created data directory:" , dataFolder ) ;
23- }
20+ if ( ! existsSync ( dataFolder ) ) {
21+ await mkdir ( dataFolder , { recursive : true , mode : 0o777 } ) ;
22+ console . log ( "Created data directory:" , dataFolder ) ;
23+ }
2424
25- db = new Database ( databasePath , { create : true } ) ;
26- console . log ( "Database opened successfully" ) ;
25+ db = new Database ( databasePath , { create : true } ) ;
26+ console . log ( "Database opened successfully" ) ;
2727
28- db . exec ( "PRAGMA journal_mode = WAL;" ) ;
28+ db . exec ( "PRAGMA journal_mode = WAL;" ) ;
2929} catch ( error ) {
30- console . error ( `Cannot start DockStatAPI: ${ error } ` ) ;
31- process . exit ( 500 ) ;
30+ console . error ( `Cannot start DockStatAPI: ${ error } ` ) ;
31+ process . exit ( 500 ) ;
3232}
3333
3434export function init ( ) {
35- db . exec ( `
35+ db . exec ( `
3636 CREATE TABLE IF NOT EXISTS backend_log_entries (
3737 timestamp STRING NOT NULL,
3838 level TEXT NOT NULL,
@@ -59,7 +59,7 @@ export function init() {
5959 );
6060
6161 CREATE TABLE IF NOT EXISTS host_stats (
62- hostId INTEGER PRIMARY KEY NOT NULL,
62+ hostId INTEGER NOT NULL,
6363 hostName TEXT NOT NULL,
6464 dockerVersion TEXT NOT NULL,
6565 apiVersion TEXT NOT NULL,
@@ -72,7 +72,8 @@ export function init() {
7272 containersRunning INTEGER NOT NULL,
7373 containersStopped INTEGER NOT NULL,
7474 containersPaused INTEGER NOT NULL,
75- images INTEGER NOT NULL
75+ images INTEGER NOT NULL,
76+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
7677 );
7778
7879 CREATE TABLE IF NOT EXISTS container_stats (
@@ -94,25 +95,25 @@ export function init() {
9495 );
9596 ` ) ;
9697
97- const configRow = db
98- . prepare ( "SELECT COUNT(*) AS count FROM config" )
99- . get ( ) as { count : number } ;
100-
101- if ( configRow . count === 0 ) {
102- db . prepare (
103- 'INSERT INTO config (keep_data_for, fetching_interval, api_key) VALUES (7, 5, "changeme")' ,
104- ) . run ( ) ;
105- }
106-
107- const hostRow = db
108- . prepare ( "SELECT COUNT(*) AS count FROM docker_hosts" )
109- . get ( ) as { count : number } ;
110-
111- if ( hostRow . count === 0 ) {
112- db . prepare (
113- "INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)" ,
114- ) . run ( "Localhost" , "localhost:2375" , false ) ;
115- }
98+ const configRow = db
99+ . prepare ( "SELECT COUNT(*) AS count FROM config" )
100+ . get ( ) as { count : number } ;
101+
102+ if ( configRow . count === 0 ) {
103+ db . prepare (
104+ 'INSERT INTO config (keep_data_for, fetching_interval, api_key) VALUES (7, 5, "changeme")'
105+ ) . run ( ) ;
106+ }
107+
108+ const hostRow = db
109+ . prepare ( "SELECT COUNT(*) AS count FROM docker_hosts" )
110+ . get ( ) as { count : number } ;
111+
112+ if ( hostRow . count === 0 ) {
113+ db . prepare (
114+ "INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)"
115+ ) . run ( "Localhost" , "localhost:2375" , false ) ;
116+ }
116117}
117118
118119init ( ) ;
0 commit comments