From c4e8c8dc3a1dec7d2ea8e0a7a807eedaaf7584bd Mon Sep 17 00:00:00 2001 From: db123 Date: Tue, 23 Jun 2026 21:42:39 +0330 Subject: [PATCH] fix: make schema idempotent with IF NOT EXISTS Add i18n locale files to Docker image and fix all CREATE statements to use IF NOT EXISTS to survive container restarts. --- Dockerfile | 1 + db/schema.sql | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a65313..9572d41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ WORKDIR /data COPY --from=builder /usr/local/bin/worktime-bot /usr/local/bin/worktime-bot COPY --from=builder /src/db/schema.sql ./db/schema.sql +COPY --from=builder /src/pkg/i18n/ ./i18n/ VOLUME ["/data"] diff --git a/db/schema.sql b/db/schema.sql index 93884c5..b9e813a 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,4 +1,4 @@ -CREATE TABLE events ( +CREATE TABLE IF NOT EXISTS events ( id INTEGER PRIMARY KEY, event_type TEXT NOT NULL CHECK (event_type IN ('in', 'out')), @@ -9,7 +9,7 @@ CREATE TABLE events ( DEFAULT (unixepoch()) ); -CREATE INDEX idx_events_occurred_at +CREATE INDEX IF NOT EXISTS idx_events_occurred_at ON events(occurred_at); CREATE TABLE IF NOT EXISTS settings ( @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS settings ( value TEXT NOT NULL DEFAULT '' ); -CREATE TABLE days_off ( +CREATE TABLE IF NOT EXISTS days_off ( date TEXT PRIMARY KEY CHECK (date = strftime('%Y-%m-%d', date)), reason TEXT NOT NULL DEFAULT '',