about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/db.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/db.go b/src/db.go
index 3ec9b71..75cc93a 100644
--- a/src/db.go
+++ b/src/db.go
@@ -145,3 +145,25 @@ func dbDeleteChallengeByUUID(uuid string) error {
 
 	return nil
 }
+
+func dbCreateTableIfNotExist(db *sql.DB) error {
+	log.Println("Creating a table in case it doesn't exist")
+	query := `CREATE TABLE public.challenges
+(
+	uuid uuid NOT NULL DEFAULT uuid_generate_v4(),
+	name character varying COLLATE pg_catalog."default" NOT NULL,
+	description character varying COLLATE pg_catalog."default",
+	flag character varying COLLATE pg_catalog."default",
+	container character varying COLLATE pg_catalog."default",
+	category character varying COLLATE pg_catalog."default",
+	points integer,
+	static boolean NOT NULL,
+	CONSTRAINT challenges_pkey PRIMARY KEY (uuid)
+)`
+
+	_, err := db.Exec(query)
+	if err != nil {
+		return err
+	}
+	return nil
+}