about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-21 12:47:46 +0200
committerEmile <hanemile@protonmail.com>2019-10-21 12:47:46 +0200
commita2be5112ba26dabbb932f4eef336d7bab768a6de (patch)
treedb38527e9acaeb9fb1119ad38f516b93f419e515 /src
parent397ff3989efed6ba52c762291a3fcc1f1a306ca2 (diff)
create table if not exist yet function
Diffstat (limited to 'src')
-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
+}