about summary refs log tree commit diff
path: root/backend/init.go
blob: 4db30090f39b93c0f330d505099e02b195c4a340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package backend

import (
	"database/sql"
	"log"
)

// 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,
  x numeric,
  y numeric,
  vx numeric,
  vy numeric,
  m numeric,
  PRIMARY KEY (star_id)
) 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")
	var query = `CREATE TABLE IF NOT EXISTS public.nodes
(
  node_id bigserial NOT NULL,
  box_width numeric,
  total_mass numeric,
  depth integer,
  star_id bigint,
  root_id bigint,
  isleaf boolean,
  box_center numeric[],
  center_of_mass numeric[],
  subnodes 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")
	_, 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)
	}
}