-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_database.R
45 lines (31 loc) · 1.08 KB
/
init_database.R
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
######################################################################
# creates an new empty database
######################################################################
# !!!WARNING!!!!
# this script removes an old database if it exists
######################################################################
library(tidyverse)
library(RSQLite)
library(pool)
library(ATdatabase)
library(here)
library(logger)
source(here::here("funs","database_fun.R"))
db.path <- get_database_path()
if(file.exists(db.path)) {
unlink(db.path)
}
pool <- dbPool(
drv = SQLite(),
dbname = db.path
)
ATdatabase::create_database_tables(pool)
municipalities <- read_csv(here("prepped_data", "municipalities.csv"),
col_names = F)
projects <- read_csv(here("prepped_data", "projects.csv"),
col_names = F)
ATdatabase::add_doc("application", "municipalities", municipalities, conn = pool,
overwrite = TRUE)
ATdatabase::add_doc("application", "projects", projects, conn = pool,
overwrite = TRUE)
poolClose(pool)