Skip to content

Commit

Permalink
Make initializeDatabase call the correct DDL file (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzollove authored Oct 25, 2023
1 parent cb150be commit 0f8933b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 172 deletions.
6 changes: 5 additions & 1 deletion R/dbUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ initializeDatabase <- function(connectionDetails, overwrite = FALSE, testing = F
return()
}
}
DatabaseConnector::executeSql(conn, sql = readr::read_file(system.file("sql", "backbone_ddl.sql", package="gaiaCore")))
DatabaseConnector::executeSql(conn, sql = "CREATE SCHEMA IF NOT EXISTS backbone AUTHORIZATION postgres;")
# TODO the sequences file is not autogenerated. Add it to the create/writeDdl script?
DatabaseConnector::executeSql(conn, sql = readr::read_file(system.file("ddl", "001", "gaiadb_001_sequences.sql", package="gaiaCore")))
DatabaseConnector::executeSql(conn, sql = readr::read_file(system.file("ddl", "001", "gaiadb_001_ddl.sql", package="gaiaCore")))
# DatabaseConnector::executeSql(conn, sql = readr::read_file(system.file("sql", "backbone_ddl.sql", package="gaiaCore")))
message("backbone schema created.")
if (!testing) {
dataSource <- readr::read_csv(system.file(file.path("csv", paste0("data_source.csv")), package = 'gaiaCore'))
Expand Down
2 changes: 0 additions & 2 deletions inst/csv/data_source.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ data_source_uuid,org_id,org_set_id,dataset_name,dataset_version,geom_type,geom_s
8888,EPA,AQS,annual_conc_by_cbsa_2018,2018,,,cbsa,1,10184,file,zip,csv,annual_aqi_by_cbsa_2018.csv,https://aqs.epa.gov/aqsweb/airdata/annual_aqi_by_cbsa_2018.zip,,https://www.epa.gov/aqs
7777,EPA,AQS,annual_conc_by_monitor_2018,2018,point,,,1,7777,file,zip,csv,annual_conc_by_monitor_2018.csv,https://aqs.epa.gov/aqsweb/airdata/annual_conc_by_monitor_2018.zip,,https://www.epa.gov/aqs
1234,Census,TIGER/Line,us-county-2018,2018,polygon,"{""stage_transform"":[""dplyr::mutate(staged,geom_source_coding='GEOID',geom_source_value=GEOID,geom_name=dplyr::select(sf::st_drop_geometry(staged), n = if('NAME' %in% colnames(staged)) 'NAME' else 'NAMELSAD')$n,geom_local_value=geometry,geom_local_epsg=sf::st_crs(staged, paramaters=TRUE)$epsg)""]}",county,0,,file,zip,shp,tl_2018_us_county.shp,https://www2.census.gov/geo/tiger/TIGER2018/COUNTY/tl_2018_us_county.zip,,https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html
6666,WaterQualityData.us,WQX,station,,point,,,0,,API,zip,csv,station.csv,https://www.waterqualitydata.us/data/Station/search?mimeType=csv&zip=yes,,https://www.waterqualitydata.us/webservices_documentation
9999,CDC/ATSDR,SVI,us-county-2018,2018,,,county,1,1234,file,zip,gdb,SVI2018_US_county.gdb,https://svi.cdc.gov/Documents/Data/2018/db/states_counties/SVI_2018_US_county.zip,,https://www.atsdr.cdc.gov/placeandhealth/svi/index.html
5555,WaterQualityData.us,WQX,result,,,,,1,6666,API,zip,csv,result.csv,https://www.waterqualitydata.us/data/Result/search?characterticName={param1}&mimeType=csv&zip=yes,,https://www.waterqualitydata.us/webservices_documentation
10148,Census,TIGER/Line,us-zcta5-2014,2014,polygon,"{""stage_transform"":[""dplyr::mutate(staged,geom_source_coding='GEOID',geom_source_value=GEOID10,geom_local_value=geometry,geom_local_epsg=sf::st_crs(staged, paramaters=TRUE)$epsg)""]}",zcta5,0,,file,zip,shp,tl_2014_us_zcta510.shp,https://www2.census.gov/geo/tiger/TIGER2014/ZCTA5/tl_2014_us_zcta510.zip,,https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html
10159,Census,TIGER/Line,us-zcta5-2015,2015,polygon,"{""stage_transform"":[""dplyr::mutate(staged,geom_source_coding='GEOID',geom_source_value=GEOID10,geom_local_value=geometry,geom_local_epsg=sf::st_crs(staged, paramaters=TRUE)$epsg)""]}",zcta5,0,,file,zip,shp,tl_2015_us_zcta510.shp,https://www2.census.gov/geo/tiger/TIGER2015/ZCTA5/tl_2015_us_zcta510.zip,,https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html
7878,EPA,AQS,daily_aqi_by_county_2018,2018,,,county,1,1234,file,zip,csv,daily_aqi_by_county_2018.csv,https://aqs.epa.gov/aqsweb/airdata/daily_aqi_by_county_2018.zip,,https://www.epa.gov/aqs
Expand Down
2 changes: 1 addition & 1 deletion inst/csv/gaia001fieldLevel.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data_source,dataset_name,Yes,varchar(100),,,No,No,,,,,
data_source,dataset_version,Yes,varchar(100),,,No,No,,,,,
data_source,geom_type,No,varchar(100),,,No,No,,,,,
data_source,geom_spec,No,text,,,No,No,,,,,
data_source,boundary_type,Yes,varchar(100),,,No,No,,,,,
data_source,boundary_type,No,varchar(100),,,No,No,,,,,
data_source,has_attributes,No,int4,,,No,No,,,,,
data_source,geom_dependency_uuid,No,int4,,,No,Yes,data_source,data_source_uuid,,,
data_source,download_method,Yes,varchar(100),,,No,No,,,,,
Expand Down
2 changes: 1 addition & 1 deletion inst/ddl/001/gaiadb_001_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE backbone.data_source (
dataset_version varchar(100) NOT NULL,
geom_type varchar(100) NULL,
geom_spec text NULL,
boundary_type varchar(100) NOT NULL,
boundary_type varchar(100) NULL,
has_attributes int4 NULL,
geom_dependency_uuid int4 NULL,
download_method varchar(100) NOT NULL,
Expand Down
43 changes: 43 additions & 0 deletions inst/ddl/001/gaiadb_001_sequences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CREATE SEQUENCE IF NOT EXISTS backbone.attr_index_attr_index_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
START 1
CACHE 1
NO CYCLE;
-- DROP SEQUENCE backbone.attr_template_attr_record_id_seq;

CREATE SEQUENCE IF NOT EXISTS backbone.attr_template_attr_record_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
START 1
CACHE 1
NO CYCLE;
-- DROP SEQUENCE backbone.variable_source_variable_source_id_seq;

CREATE SEQUENCE IF NOT EXISTS backbone.variable_source_variable_source_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
START 1
CACHE 1
NO CYCLE;
-- DROP SEQUENCE backbone.geom_index_geom_index_id_seq;

CREATE SEQUENCE IF NOT EXISTS backbone.geom_index_geom_index_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
START 1
CACHE 1
NO CYCLE;
-- DROP SEQUENCE backbone.geom_template_geom_record_id_seq;

CREATE SEQUENCE IF NOT EXISTS backbone.geom_template_geom_record_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 2147483647
START 1
CACHE 1
NO CYCLE;-- backbone.attr_index definition
167 changes: 0 additions & 167 deletions inst/sql/backbone_ddl.sql

This file was deleted.

0 comments on commit 0f8933b

Please sign in to comment.