From fc49c3bfa9b61b5d6234a64804354c29e6a50c56 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 29 Jun 2023 19:05:40 -0400 Subject: [PATCH] =?UTF-8?q?Ajouter=20seed=20automatique=20de=20la=20base?= =?UTF-8?q?=20de=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajuster message d'erreur de dataClient.DB.Ping() dans apiCmd Ajouter dataClient.Seed() à apiCmd Ajouter IF NOT EXISTS à CREATE TABLE dans models.Schema --- cmd/api.go | 6 +++++- models/models.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index ad702dc..2aa156b 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -81,11 +81,15 @@ var apiCmd = &cobra.Command{ defer dataClient.DB.Close() if err := dataClient.DB.Ping(); err != nil { - log.Fatalf("[bottin-agenda db] dataClient.DB.Ping(): %s", err) + log.Fatalf("[bottin-agenda db] dataClient.DB.Ping() failed: %s", err) } else { log.Println("[bottin-agenda db] ok") } + if _, err = dataClient.Seed(); err != nil { + log.Fatalf("[bottin-agenda db] dataClient.Seed() failed: %s", err) + } + // Execution e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", apiPort))) diff --git a/models/models.go b/models/models.go index 691afc0..f3e6858 100644 --- a/models/models.go +++ b/models/models.go @@ -3,7 +3,7 @@ package models import "time" var Schema = ` -CREATE TABLE transactions ( +CREATE TABLE IF NOT EXISTS transactions ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, membre_id VARCHAR(7), given_at TIMESTAMP,