From 5d7a7c0c86457872ecc99743da5f827c8adf0793 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 7 Mar 2019 18:06:20 +0100 Subject: updated the query, now only creating a new table if it does not exist yet --- backend/init.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'backend') diff --git a/backend/init.go b/backend/init.go index 351028b..4db3009 100644 --- a/backend/init.go +++ b/backend/init.go @@ -7,7 +7,8 @@ import ( // InitStarsTable initialises the stars table func InitStarsTable(db *sql.DB) { - query := `CREATE TABLE public.stars + log.Println("Preparing the query") + var query = `CREATE TABLE IF NOT EXISTS public.stars ( star_id bigserial, x numeric, @@ -16,23 +17,24 @@ func InitStarsTable(db *sql.DB) { vy numeric, m numeric, PRIMARY KEY (star_id) -) - WITH ( - OIDS = FALSE - ); +) WITH ( + OIDS = FALSE +); ALTER TABLE public.stars OWNER to postgres;` + log.Println("Executing the query") _, err := db.Exec(query) if err != nil { log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query) } + log.Println("DONE") } // InitNodesTable initialises the nodes table func InitNodesTable(db *sql.DB) { log.Println("creating the query") - query := `CREATE TABLE public.nodes + var query = `CREATE TABLE IF NOT EXISTS public.nodes ( node_id bigserial NOT NULL, box_width numeric, @@ -45,10 +47,9 @@ func InitNodesTable(db *sql.DB) { center_of_mass numeric[], subnodes bigint[], PRIMARY KEY (node_id) -) - WITH ( - OIDS = FALSE - ); +) WITH ( + OIDS = FALSE +); ALTER TABLE public.nodes OWNER to postgres;` -- cgit 1.4.1