Skip to content

Commit

Permalink
Reduce DB size
Browse files Browse the repository at this point in the history
  • Loading branch information
johnisom committed Dec 13, 2023
1 parent 519ee63 commit 86bc3c4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 58 deletions.
13 changes: 0 additions & 13 deletions db/export-from-original-database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@

SELECT
OBJECTID AS id,
SOURCE_SYSTEM_TYPE AS source_system_type,
SOURCE_SYSTEM AS source_system,
SOURCE_REPORTING_UNIT AS source_reporting_unit,
SOURCE_REPORTING_UNIT_NAME AS source_reporting_unit_name,
NWCG_REPORTING_AGENCY AS nwcg_reporting_agency,
NWCG_REPORTING_UNIT_ID AS nwcg_reporting_unit_id,
NWCG_REPORTING_UNIT_NAME AS nwcg_reporting_unit_name,
LOCAL_FIRE_REPORT_ID AS local_fire_report_id,
LOCAL_INCIDENT_ID AS local_incident_id,
CAST(OWNER_CODE AS INTEGER) AS owner_code,
OWNER_DESCR AS owner_descr,
FIRE_CODE AS fire_code,
FIRE_NAME AS fire_name,
FIRE_YEAR AS fire_year,
CAST(CASE WHEN DISCOVERY_TIME IS NULL THEN STRFTIME('%s', DATETIME(DISCOVERY_DATE)) ELSE STRFTIME('%s', DATETIME(DISCOVERY_DATE, CAST(CAST(DISCOVERY_TIME AS integer)/100 AS STRING) || ' hours', CAST(CAST(DISCOVERY_TIME AS integer)%100 AS STRING) || ' minutes')) END AS INTEGER) AS discovery_datetime,
CAST(CASE WHEN CONT_TIME IS NULL THEN STRFTIME('%s', DATETIME(CONT_DATE)) ELSE STRFTIME('%s', DATETIME(CONT_DATE, CAST(CAST(CONT_TIME AS integer)/100 AS STRING) || ' hours', CAST(CAST(CONT_TIME AS integer) %100 AS STRING) || ' minutes')) END AS INTEGER) AS contained_datetime,
Expand Down
13 changes: 0 additions & 13 deletions db/fires-schema.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
CREATE TABLE fires(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
source_system_type TEXT(255),
source_system TEXT(30),
source_reporting_unit TEXT(30),
source_reporting_unit_name TEXT(255),
nwcg_reporting_agency TEXT(255),
nwcg_reporting_unit_id TEXT(255),
nwcg_reporting_unit_name TEXT(255),
local_fire_report_id TEXT(255),
local_incident_id TEXT(255),
owner_code INTEGER,
owner_descr TEXT(100),
fire_code TEXT(10),
fire_name TEXT(255),
fire_year INTEGER,
discovery_datetime INTEGER,
contained_datetime INTEGER,
Expand Down
4 changes: 2 additions & 2 deletions db/fires.sqlite
Git LFS file not shown
47 changes: 17 additions & 30 deletions db/import-to-new-database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,23 @@
--check for "<null>" to replace with NULL

SELECT
SUM(CASE WHEN id = '<null>' THEN 1 ELSE 0 END) AS id_null_count,
SUM(CASE WHEN source_system_type = '<null>' THEN 1 ELSE 0 END) AS source_system_type_null_count,
SUM(CASE WHEN source_system = '<null>' THEN 1 ELSE 0 END) AS source_system_null_count,
SUM(CASE WHEN source_reporting_unit = '<null>' THEN 1 ELSE 0 END) AS source_reporting_unit_null_count,
SUM(CASE WHEN source_reporting_unit_name = '<null>' THEN 1 ELSE 0 END) AS source_reporting_unit_name_null_count,
SUM(CASE WHEN nwcg_reporting_agency = '<null>' THEN 1 ELSE 0 END) AS nwcg_reporting_agency_null_count,
SUM(CASE WHEN nwcg_reporting_unit_id = '<null>' THEN 1 ELSE 0 END) AS nwcg_reporting_unit_id_null_count,
SUM(CASE WHEN nwcg_reporting_unit_name = '<null>' THEN 1 ELSE 0 END) AS nwcg_reporting_unit_name_null_count,
SUM(CASE WHEN local_fire_report_id = '<null>' THEN 1 ELSE 0 END) AS local_fire_report_id_null_count,
SUM(CASE WHEN local_incident_id = '<null>' THEN 1 ELSE 0 END) AS local_incident_id_null_count,
SUM(CASE WHEN owner_code = '<null>' THEN 1 ELSE 0 END) AS owner_code_null_count,
SUM(CASE WHEN owner_descr = '<null>' THEN 1 ELSE 0 END) AS owner_descr_null_count,
SUM(CASE WHEN fire_code = '<null>' THEN 1 ELSE 0 END) AS fire_code_null_count,
SUM(CASE WHEN fire_name = '<null>' THEN 1 ELSE 0 END) AS fire_name_null_count,
SUM(CASE WHEN fire_year = '<null>' THEN 1 ELSE 0 END) AS fire_year_null_count,
SUM(CASE WHEN discovery_datetime = '<null>' THEN 1 ELSE 0 END) AS discovery_datetime_null_count,
SUM(CASE WHEN contained_datetime = '<null>' THEN 1 ELSE 0 END) AS contained_datetime_null_count,
SUM(CASE WHEN stat_cause_code = '<null>' THEN 1 ELSE 0 END) AS stat_cause_code_null_count,
SUM(CASE WHEN stat_cause_descr = '<null>' THEN 1 ELSE 0 END) AS stat_cause_descr_null_count,
SUM(CASE WHEN fire_size = '<null>' THEN 1 ELSE 0 END) AS fire_size_null_count,
SUM(CASE WHEN fire_size_class = '<null>' THEN 1 ELSE 0 END) AS fire_size_class_null_count,
SUM(CASE WHEN longitude = '<null>' THEN 1 ELSE 0 END) AS longitude_null_count,
SUM(CASE WHEN latitude = '<null>' THEN 1 ELSE 0 END) AS latitude_null_count,
SUM(CASE WHEN state_name = '<null>' THEN 1 ELSE 0 END) AS state_name_null_count,
SUM(CASE WHEN state_alpha_code = '<null>' THEN 1 ELSE 0 END) AS state_alpha_code_null_count,
SUM(CASE WHEN state_fips_code = '<null>' THEN 1 ELSE 0 END) AS state_fips_code_null_count,
SUM(CASE WHEN county_name = '<null>' THEN 1 ELSE 0 END) AS county_name_null_count,
SUM(CASE WHEN county_fips_name = '<null>' THEN 1 ELSE 0 END) AS county_fips_name_null_count,
SUM(CASE WHEN county_fips_code = '<null>' THEN 1 ELSE 0 END) AS county_fips_code_null_count,
SUM(CASE WHEN combined_fips_code = '<null>' THEN 1 ELSE 0 END) AS combined_fips_code_null_count
SUM(CASE WHEN id is NULL THEN 1 ELSE 0 END) AS id_null_count,
SUM(CASE WHEN fire_year is NULL THEN 1 ELSE 0 END) AS fire_year_null_count,
SUM(CASE WHEN discovery_datetime is NULL THEN 1 ELSE 0 END) AS discovery_datetime_null_count,
SUM(CASE WHEN contained_datetime is NULL THEN 1 ELSE 0 END) AS contained_datetime_null_count,
SUM(CASE WHEN stat_cause_code is NULL THEN 1 ELSE 0 END) AS stat_cause_code_null_count,
SUM(CASE WHEN stat_cause_descr is NULL THEN 1 ELSE 0 END) AS stat_cause_descr_null_count,
SUM(CASE WHEN fire_size is NULL THEN 1 ELSE 0 END) AS fire_size_null_count,
SUM(CASE WHEN fire_size_class is NULL THEN 1 ELSE 0 END) AS fire_size_class_null_count,
SUM(CASE WHEN longitude is NULL THEN 1 ELSE 0 END) AS longitude_null_count,
SUM(CASE WHEN latitude is NULL THEN 1 ELSE 0 END) AS latitude_null_count,
SUM(CASE WHEN state_name is NULL THEN 1 ELSE 0 END) AS state_name_null_count,
SUM(CASE WHEN state_alpha_code is NULL THEN 1 ELSE 0 END) AS state_alpha_code_null_count,
SUM(CASE WHEN state_fips_code is NULL THEN 1 ELSE 0 END) AS state_fips_code_null_count,
SUM(CASE WHEN county_name is NULL THEN 1 ELSE 0 END) AS county_name_null_count,
SUM(CASE WHEN county_fips_name is NULL THEN 1 ELSE 0 END) AS county_fips_name_null_count,
SUM(CASE WHEN county_fips_code is NULL THEN 1 ELSE 0 END) AS county_fips_code_null_count,
SUM(CASE WHEN combined_fips_code is NULL THEN 1 ELSE 0 END) AS combined_fips_code_null_count
FROM fires;

-- then, for each column with value "<null>", run (replacing **colname** with the actual column name):
Expand Down

0 comments on commit 86bc3c4

Please sign in to comment.