about summary refs log tree commit diff
path: root/backend/init.go
blob: 20f7c2e00cd1da60a2bb24d66db25b5eef8eeb18 (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
package backend

import (
	"database/sql"
	"log"
)

// InitStarsTable initialises the stars table
func InitStarsTable(db *sql.DB) {
	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(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) {
	var query = `CREATE TABLE IF NOT EXISTS public.nodes
(
  node_id bigserial NOT NULL,
  box_width numeric,
  total_mass numeric DEFAULT 0,
  depth integer,
  timestep integer,
  star_id bigint DEFAULT 0,
  root_id bigint DEFAULT 0,
  isleaf boolean,
  box_center numeric[],
  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(query)
	_, err := db.Exec(query)
	if err != nil {
		log.Fatalf("[ E ] InitNodesTable query: %v \n\t\t\tquery: %s\n", err, query)
	}
}