-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_init.R
30 lines (23 loc) · 987 Bytes
/
db_init.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
library(DBI)
library(readr)
library(RPostgres)
library(purrr)
library(tibble)
library(config)
library(dplyr)
library(dbplyr)
db_config <- config::get(file = "inst/database/config.yml")$local_container
# db_config <- config::get(file = "inst/database/config.yml")$spawn
conn <- dbx::dbxConnect(db_config$conn_string)
connections::connection_view(conn)
# Create the database
DBI::dbExecute(conn, 'CREATE DATABASE IF NOT EXISTS postgres;')
# Extensions
dbx::dbxExecute(conn, 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
# Custom ENUM Types:
dbx::dbxExecute(conn, "CREATE TYPE GENDER AS ENUM ('Male', 'Female');")
dbx::dbxExecute(conn, "CREATE TYPE CLAIM_STATUS AS ENUM ('Open', 'Closed', 'Re-Opened');")
dbx::dbxExecute(conn, "CREATE TYPE ALAE_TREATMENT AS ENUM ('Loss', 'LossALAE', 'ProRata');")
tbls <- fs::dir_ls("data-raw/database/SQL") |> basename() |> fs::path_ext_remove()
db_data <- purrrgress::pro_walk(tbls, create_tbl, conn = conn)
create_tbl(conn, tbl_name = "claims")