From 52c6cdb25225ba551fd676ad39dde8ec06e8f101 Mon Sep 17 00:00:00 2001 From: Emile Date: Fri, 8 Mar 2019 12:56:00 +0100 Subject: updated the creation of the tables making sure not to create a new table if one allready exists and added default values --- backend/init.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'backend/init.go') diff --git a/backend/init.go b/backend/init.go index 4db3009..20f7c2e 100644 --- a/backend/init.go +++ b/backend/init.go @@ -7,7 +7,6 @@ import ( // InitStarsTable initialises the stars table func InitStarsTable(db *sql.DB) { - log.Println("Preparing the query") var query = `CREATE TABLE IF NOT EXISTS public.stars ( star_id bigserial, @@ -21,9 +20,9 @@ func InitStarsTable(db *sql.DB) { OIDS = FALSE ); -ALTER TABLE public.stars - OWNER to postgres;` - log.Println("Executing the query") +ALTER TABLE public.stars OWNER to postgres;` + + log.Println(query) _, err := db.Exec(query) if err != nil { log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query) @@ -33,30 +32,28 @@ ALTER TABLE public.stars // InitNodesTable initialises the nodes table func InitNodesTable(db *sql.DB) { - log.Println("creating the query") var query = `CREATE TABLE IF NOT EXISTS public.nodes ( node_id bigserial NOT NULL, box_width numeric, - total_mass numeric, + total_mass numeric DEFAULT 0, depth integer, - star_id bigint, - root_id bigint, + timestep integer, + star_id bigint DEFAULT 0, + root_id bigint DEFAULT 0, isleaf boolean, box_center numeric[], - center_of_mass numeric[], - subnodes bigint[], + center_of_mass numeric[] DEFAULT '{0,0}'::numeric[], + subnode bigint[] DEFAULT '{0,0,0,0}'::bigint[], PRIMARY KEY (node_id) ) WITH ( OIDS = FALSE ); -ALTER TABLE public.nodes - OWNER to postgres;` - log.Println("done creating the query") - log.Println("executing the query") +ALTER TABLE public.nodes OWNER to postgres;` + + log.Println(query) _, err := db.Exec(query) - log.Println("done executing the query") if err != nil { log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query) } -- cgit 1.4.1