about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-03-08 12:56:00 +0100
committerEmile <hanemile@protonmail.com>2019-03-08 12:56:00 +0100
commit52c6cdb25225ba551fd676ad39dde8ec06e8f101 (patch)
treea9da9213167fe022106205aa48373004d409db6c
parentda6a03ea5cd734685f8f2ac702b85a42dc23715d (diff)
updated the creation of the tables making sure not to create a new table if one allready exists and added default values
-rw-r--r--backend/init.go27
1 files changed, 12 insertions, 15 deletions
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)
 	}