diff --git a/bcts/lrm/forest/ddl/activity.sql b/bcts/lrm/forest/ddl/activity.sql new file mode 100644 index 0000000..8d1fcfa --- /dev/null +++ b/bcts/lrm/forest/ddl/activity.sql @@ -0,0 +1,35 @@ +CREATE TABLE lrm_replication.activity ( + acti_seq_nbr NUMERIC(15) NOT NULL, + cutb_seq_nbr NUMERIC(15) NULL, + perm_seq_nbr NUMERIC(15) NULL, + actt_seq_nbr NUMERIC(15) NOT NULL, + ctor_seq_nbr NUMERIC(15) NULL, + acti_status_ind VARCHAR(30) NULL, + acti_status_date TIMESTAMP NULL, + acti_comments VARCHAR(2000) NULL, + acti_cost NUMERIC(15, 2) NULL, + acti_harv_seas_id VARCHAR(40) NULL, + acti_responsibility VARCHAR(160) NULL, + acti_area NUMERIC(11, 6) NULL, + acti_harvest_vol NUMERIC(15, 6) NULL, + acti_int_reason VARCHAR(40) NULL, + acti_target_date TIMESTAMP NULL, + acti_fdp_reason VARCHAR(40) NULL, + acti_target_cost NUMERIC(15, 2) NULL, + plan_seq_nbr NUMERIC(15) NULL, + licn_seq_nbr NUMERIC(15) NULL, + mark_seq_nbr NUMERIC(15) NULL, + cloc_seq_nbr NUMERIC(15) NULL, + acti_digitized_ind VARCHAR(4) NULL, + acti_cost_uom VARCHAR(120) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + documentkey NUMERIC(9) NULL, + accl_description VARCHAR(160) NULL, + PRIMARY KEY (acti_seq_nbr) +); + diff --git a/bcts/lrm/forest/ddl/activity_class.sql b/bcts/lrm/forest/ddl/activity_class.sql new file mode 100644 index 0000000..4b3be61 --- /dev/null +++ b/bcts/lrm/forest/ddl/activity_class.sql @@ -0,0 +1,15 @@ +CREATE TABLE lrm_replication.activity_class ( + accl_seq_nbr NUMERIC(15) NOT NULL, + accl_description VARCHAR(40) NULL, + accl_object_type VARCHAR(1) NULL, + accl_display_order NUMERIC(3) NULL, + divi_div_nbr NUMERIC(2) NULL, + accl_key_ind VARCHAR(12) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (accl_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/activity_type.sql b/bcts/lrm/forest/ddl/activity_type.sql new file mode 100644 index 0000000..ed62134 --- /dev/null +++ b/bcts/lrm/forest/ddl/activity_type.sql @@ -0,0 +1,30 @@ +CREATE TABLE lrm_replication.activity_type ( + actt_seq_nbr NUMERIC(15) NOT NULL, + accl_seq_nbr NUMERIC(15) NOT NULL, + actt_description VARCHAR(200) NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + actt_default_ind VARCHAR(4) NULL, + actt_responsibility VARCHAR(160) NULL, + actt_display_order NUMERIC(2) NULL, + actt_key_ind VARCHAR(10) NULL, + actt_status_ind VARCHAR(4) NULL, + actt_date_relative VARCHAR(20) NULL, + ctor_contractor_id VARCHAR(40) NULL, + actt_view_level NUMERIC(2) NULL, + actt_system_ind VARCHAR(4) NULL, + ctor_seq_nbr NUMERIC(15) NULL, + actt_active_ind VARCHAR(4) NOT NULL, + actt_key_pair VARCHAR(40) NULL, + actt_harvs_ind VARCHAR(4) NULL, + actt_trvol_ind VARCHAR(4) NULL, + actt_indirect_cost_ind VARCHAR(8) NULL, + actt_default_cost NUMERIC(9, 2) NULL, + actt_cost_uom VARCHAR(120) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (actt_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/block_admin_zone.sql b/bcts/lrm/forest/ddl/block_admin_zone.sql new file mode 100644 index 0000000..c232f9f --- /dev/null +++ b/bcts/lrm/forest/ddl/block_admin_zone.sql @@ -0,0 +1,13 @@ +CREATE TABLE lrm_replication.block_admin_zone ( + blaz_admin_zone_id VARCHAR(40) NOT NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + blaz_admin_zone_desc VARCHAR(200) NULL, + blaz_active_ind VARCHAR(1) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (blaz_admin_zone_id, divi_div_nbr) +); diff --git a/bcts/lrm/forest/ddl/block_allocation.sql b/bcts/lrm/forest/ddl/block_allocation.sql new file mode 100644 index 0000000..9931664 --- /dev/null +++ b/bcts/lrm/forest/ddl/block_allocation.sql @@ -0,0 +1,31 @@ +CREATE TABLE lrm_replication.block_allocation ( + cutb_seq_nbr NUMERIC(15) NOT NULL, + blal_seq_nbr NUMERIC(15) NOT NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + licn_seq_nbr NUMERIC(15) NULL, + perm_seq_nbr NUMERIC(15) NULL, + mark_seq_nbr NUMERIC(15) NULL, + blal_gross_ha_area NUMERIC(11, 6) NULL, + blal_merch_ha_area NUMERIC(11, 6) NULL, + blal_cruise_m3_vol NUMERIC(15, 6) NULL, + blal_harvested_m3_vol NUMERIC(15, 6) NULL, + blal_harvested_ha_area NUMERIC(11, 6) NULL, + blal_firs_cutblock_id VARCHAR(80) NULL, + blal_firs_timbermark_id VARCHAR(80) NULL, + blal_estimated_area NUMERIC(7, 2) NULL, + manu_seq_nbr NUMERIC(15) NULL, + blal_digi_ind VARCHAR(1) NULL, + blal_primary_ind VARCHAR(4) NULL, + blal_actual_partition_vol NUMERIC(15, 2) NULL, + blal_usr_cruise_m3_vol NUMERIC(15, 6) NULL, + blal_rw_vol NUMERIC(15, 6) NULL, + blal_rw_ha_area NUMERIC(11, 6) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + blal_data_source VARCHAR(120) NULL, + PRIMARY KEY (blal_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/code_lookup.sql b/bcts/lrm/forest/ddl/code_lookup.sql new file mode 100644 index 0000000..8fcbbf5 --- /dev/null +++ b/bcts/lrm/forest/ddl/code_lookup.sql @@ -0,0 +1,17 @@ +CREATE TABLE lrm_replication.code_lookup ( + colu_lookup_type VARCHAR(4) NOT NULL, + colu_lookup_id VARCHAR(30) NOT NULL, + colu_lookup_desc VARCHAR(150) NOT NULL, + colu_user_defined_ind VARCHAR(4) NULL, + colu_display_ind VARCHAR(1) NULL, + colu_display_order NUMERIC(10) NULL, + colu_comment VARCHAR(4000) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + hq_display_ind VARCHAR(1) NULL, + PRIMARY KEY (colu_lookup_type, colu_lookup_id) +); diff --git a/bcts/lrm/forest/ddl/cut_block.sql b/bcts/lrm/forest/ddl/cut_block.sql new file mode 100644 index 0000000..cf3297a --- /dev/null +++ b/bcts/lrm/forest/ddl/cut_block.sql @@ -0,0 +1,131 @@ +CREATE TABLE lrm_replication.cut_block ( + cutb_seq_nbr NUMERIC(15) NOT NULL, + cutb_block_id VARCHAR(20) NOT NULL, + cutb_block_number VARCHAR(15) NULL, + divi_div_nbr NUMERIC(2) NULL, + cutb_devt_plan_status_code VARCHAR(8) NULL, + cutb_devt_plan_apprvl_date TIMESTAMP NULL, + cutb_silvi_plan_status_code VARCHAR(8) NULL, + cutb_silvi_plan_apprvl_date TIMESTAMP NULL, + cutb_block_memo VARCHAR(4000) NULL, + cutb_woods_run_km_nbr NUMERIC(15, 6) NULL, + cutb_hauling_km_nbr NUMERIC(15, 6) NULL, + cutb_hlcptr_drop_cruise_ind VARCHAR(4) NULL, + cutb_logging_plan_status_code VARCHAR(8) NULL, + cutb_logging_plan_apprvl_date TIMESTAMP NULL, + opar_operating_area_id VARCHAR(10) NULL, + bioz_zone_id VARCHAR(40) NULL, + cutb_gross_ha_area NUMERIC(11, 6) NULL, + cutb_bcgs VARCHAR(15) NULL, + cutb_opening VARCHAR(15) NULL, + cutb_nts VARCHAR(60) NULL, + cutb_ext_ha_area NUMERIC(11, 6) NULL, + cutb_photos VARCHAR(800) NULL, + cutb_field_work_by VARCHAR(200) NULL, + cutb_field_work_date TIMESTAMP NULL, + cutb_site_class VARCHAR(20) NULL, + fdps_status_id VARCHAR(10) NULL, + cutb_site_index NUMERIC(5) NULL, + cutb_cpi_slope_pct NUMERIC(7, 4) NULL, + cutb_cpi_road_access_km NUMERIC(13, 3) NULL, + cutb_cpi_road_block_km NUMERIC(13, 3) NULL, + cutb_cpi_road_num_landings NUMERIC(10) NULL, + cutb_cpi_road_haul_km NUMERIC(13, 3) NULL, + sblk_supply_block_id VARCHAR(10) NULL, + cutb_formc_harvest_print_date TIMESTAMP NULL, + cutb_formc_regen_print_date TIMESTAMP NULL, + cutb_formc_freegrow_print_date TIMESTAMP NULL, + fund_funding_code VARCHAR(15) NULL, + cutb_highway_ind VARCHAR(1) NULL, + cutb_winter_road_ind CHAR NULL, + finz_forest_inventory_zone_id VARCHAR(40) NULL, + cutb_user_mapsheet_id VARCHAR(120) NULL, + cutb_cell_number VARCHAR(60) NULL, + fjap_fdp_joint_approval VARCHAR(40) NULL, + pmod_modifier_id VARCHAR(40) NULL, + cutb_traverse_method_code VARCHAR(40) NULL, + cutb_critical_date_ind CHAR NULL, + cutb_greenup_date TIMESTAMP NULL, + grns_greenup_source VARCHAR(40) NULL, + pmpo_operating_zone VARCHAR(40) NULL, + lsun_landscape_unit VARCHAR(40) NULL, + plan_seq_nbr NUMERIC(15) NULL, + cutb_forma_print_date TIMESTAMP NULL, + cutb_block_state VARCHAR(20) NULL, + cutb_digi_ind VARCHAR(4) NULL, + sttp_stand_type VARCHAR(40) NULL, + ttac_timbertype_age_class VARCHAR(40) NULL, + ttsc_timbertype_stock_class VARCHAR(40) NULL, + tthc_timbertype_height_class VARCHAR(40) NULL, + cutb_site_plan_exempt_ind VARCHAR(4) NULL, + sssc_source_code VARCHAR(40) NULL, + cutb_vol_data_source VARCHAR(40) NULL, + cutb_vol_data_source_type VARCHAR(16) NULL, + cutb_heli_flight_dist NUMERIC(10) NULL, + cutb_harvest_sequence NUMERIC(6) NULL, + cutb_prov_forest_conflict VARCHAR(40) NULL, + treg_seq_nbr NUMERIC(15) NULL, + bcat_category_code VARCHAR(40) NULL, + cutb_traverse_start_point VARCHAR(160) NULL, + cutb_traverse_end_point VARCHAR(160) NULL, + cutb_forma_printed VARCHAR(4) NULL, + cutb_system_id VARCHAR(15) NULL, + cutb_block_status VARCHAR(40) NULL, + cutb_latitude_bak VARCHAR(40) NULL, + cutb_longitude_bak VARCHAR(40) NULL, + cutb_damage_type VARCHAR(40) NULL, + cutb_opening_id NUMERIC(10) NULL, + silp_use_block_num_ind VARCHAR(1) NOT NULL, + cutb_location VARCHAR(800) NULL, + cutb_silv_act_harv_link VARCHAR(120) NULL, + cutb_file_id VARCHAR(72) NULL, + suop_subop_area_id VARCHAR(40) NULL, + cutb_selling_price_period TIMESTAMP NULL, + cutb_synch_status VARCHAR(120) NULL, + cutb_block_grouping_id VARCHAR(80) NULL, + pers_seq_nbr NUMERIC(15) NULL, + ctor_seq_nbr NUMERIC(15) NULL, + cutb_variant_id VARCHAR(60) NULL, + cutb_season_id VARCHAR(120) NULL, + cutb_volume NUMERIC(15, 6) NULL, + cloc_seq_nbr NUMERIC(15) NULL, + cutb_parent_seq NUMERIC(15) NULL, + cutb_prev_forma_print_date TIMESTAMP NULL, + sila_seq_nbr NUMERIC(15) NULL, + cutb_cruise_lock_ind VARCHAR(4) NULL, + cutb_ref_dec CHAR NULL, + cutb_reg_code VARCHAR(12) NULL, + cutb_apr_eff_date TIMESTAMP NULL, + siph_seq_nbr NUMERIC(15) NULL, + cdat_seq_nbr INTEGER NULL, + cutb_access_restriction VARCHAR(4000) NULL, + cutb_planned_vol NUMERIC(15, 6) NULL, + cutb_row_ind VARCHAR(4) NOT NULL, + cutb_tim_dev_date TIMESTAMP NULL, + cutb_ebm_ind VARCHAR(4) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + documentkey NUMERIC(9) NULL, + log_start_cascade_date_ind VARCHAR(12) NULL, + pricing_date TIMESTAMP NULL, + cutb_latitude_dd NUMERIC(9, 6) NULL, + cutb_longitude_dd NUMERIC(9, 6) NULL, + cutb_latitude VARCHAR(40) NULL, + cutb_longitude VARCHAR(40) NULL, + marked_for_del_ind NUMERIC(1) NULL, + marked_for_del_by VARCHAR(120) NULL, + marked_for_del_on TIMESTAMP NULL, + cutb_archive_reason VARCHAR(4) NULL, + cutb_archive_date TIMESTAMP NULL, + cutb_cprp_protection_ind VARCHAR(1) NULL, + cutb_rc_risk_rating VARCHAR(1) NULL, + cutb_rc_risk_source VARCHAR(5) NULL, + cutb_rc_risk_comments VARCHAR(2000) NULL, + operational_site_factor VARCHAR(4000) NULL, + safety_concern VARCHAR(4000) NULL, + PRIMARY KEY (cutb_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/cut_permit.sql b/bcts/lrm/forest/ddl/cut_permit.sql new file mode 100644 index 0000000..d8e7b6f --- /dev/null +++ b/bcts/lrm/forest/ddl/cut_permit.sql @@ -0,0 +1,70 @@ +CREATE TABLE lrm_replication.cut_permit ( + perm_seq_nbr NUMERIC(15) NOT NULL, + regn_region_id VARCHAR(10) NULL, + perm_permit_id VARCHAR(40) NOT NULL, + perm_revision_date TIMESTAMP NULL, + papr_point_of_apprsl_id VARCHAR(16) NULL, + lsee_licensee_id VARCHAR(10) NULL, + admin_dsct_district_name VARCHAR(60) NULL, + geo_dsct_district_name VARCHAR(240) NULL, + perm_mgmt_unit_code VARCHAR(12) NULL, + perm_tsb_name VARCHAR(200) NULL, + perm_expiry_date TIMESTAMP NULL, + perm_remote_oper_ind VARCHAR(4) NULL, + perm_basic_silvi_ind VARCHAR(4) NULL, + perm_road_mtce_ind VARCHAR(4) NULL, + perm_road_land_use_chrg NUMERIC(15, 2) NULL, + perm_cost_eff_date TIMESTAMP NULL, + perm_rate_eff_date TIMESTAMP NULL, + perm_water_transport_ind VARCHAR(4) NULL, + perm_primary_block_seq_nbr NUMERIC(15) NULL, + perm_primary_mark_id VARCHAR(40) NULL, + perm_haul_ind VARCHAR(4) NULL, + tsar_tsa_nbr NUMERIC(3) NULL, + sblk_supply_block_id VARCHAR(40) NULL, + sptc_support_centre_name VARCHAR(50) NULL, + divi_div_nbr NUMERIC(2) NULL, + perm_damage_status VARCHAR(20) NULL, + perm_support_centre_dist NUMERIC(6, 2) NULL, + opty_opening_type_id VARCHAR(40) NULL, + pers_seq_nbr NUMERIC(15) NULL, + perm_permit_state VARCHAR(80) NULL, + perm_logprod_external_ind VARCHAR(4) NULL, + perm_logprod_customer_id VARCHAR(60) NULL, + perm_cruise_res_source VARCHAR(4) NULL, + perm_jurisdiction VARCHAR(40) NULL, + perm_application_description VARCHAR(4000) NULL, + perm_primary_species VARCHAR(40) NULL, + mkme_marking_method_code VARCHAR(40) NULL, + mkin_marking_instrument_code VARCHAR(40) NULL, + perm_prov_forest_conflict VARCHAR(40) NULL, + perm_cruise_based_ind VARCHAR(40) NULL, + perm_lsee_representative NUMERIC(15) NULL, + perm_traverse_start_point VARCHAR(160) NULL, + perm_traverse_end_point VARCHAR(160) NULL, + perm_digi_ind VARCHAR(4) NULL, + perm_bdt_conversion NUMERIC(15, 7) NULL, + cpcl_permit_class VARCHAR(40) NULL, + perm_parent_permit NUMERIC(15) NULL, + perm_spuc VARCHAR(40) NULL, + perm_salvage_ind VARCHAR(4) NULL, + perm_location VARCHAR(800) NULL, + perm_status VARCHAR(40) NULL, + ctor_seq_nbr NUMERIC(15) NULL, + cloc_seq_nbr NUMERIC(15) NULL, + perm_fst_seq_nbr NUMERIC(15) NULL, + perm_bid_amount NUMERIC(10, 2) NULL, + perm_total_cost NUMERIC(10, 2) NULL, + perm_legal_description VARCHAR(400) NULL, + perm_gross_area NUMERIC(15, 7) NULL, + perm_high_lvl_pln VARCHAR(120) NULL, + perm_lcn_hvst_auth VARCHAR(120) NULL, + perm_lcn_reg CHAR NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (perm_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/division.sql b/bcts/lrm/forest/ddl/division.sql new file mode 100644 index 0000000..d2349b3 --- /dev/null +++ b/bcts/lrm/forest/ddl/division.sql @@ -0,0 +1,33 @@ +CREATE TABLE lrm_replication.division ( + divi_div_nbr NUMERIC(2) NOT NULL, + divi_country_code VARCHAR(40) NOT NULL, + divi_prov_state_code VARCHAR(40) NOT NULL, + divi_division_name VARCHAR(50) NOT NULL, + divi_startup_date TIMESTAMP NULL, + divi_end_date TIMESTAMP NULL, + divi_short_code VARCHAR(15) NULL, + divi_line1_addr VARCHAR(120) NULL, + divi_line2_addr VARCHAR(120) NULL, + divi_line3_addr VARCHAR(120) NULL, + divi_city_name VARCHAR(200) NULL, + divi_postal_code VARCHAR(40) NULL, + divi_intl_routing_code VARCHAR(60) NULL, + divi_phone_nbr VARCHAR(40) NULL, + divi_fax_nbr VARCHAR(40) NULL, + divi_stmpg_acctcd VARCHAR(200) NULL, + divi_stmpg_offset_acctcd VARCHAR(200) NULL, + divi_walker_entity_acctcd VARCHAR(60) NULL, + divi_gst_pay_acctcd VARCHAR(200) NULL, + divi_gst_recovery_acctd VARCHAR(200) NULL, + divi_operation_location_ind VARCHAR(4) NULL, + divi_client_location_code VARCHAR(40) NULL, + divi_abbreviation_code VARCHAR(16) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (divi_div_nbr) +); + diff --git a/bcts/lrm/forest/ddl/division_code_lookup.sql b/bcts/lrm/forest/ddl/division_code_lookup.sql new file mode 100644 index 0000000..151289a --- /dev/null +++ b/bcts/lrm/forest/ddl/division_code_lookup.sql @@ -0,0 +1,12 @@ +CREATE TABLE lrm_replication.division_code_lookup ( + colu_lookup_type VARCHAR(4) NOT NULL, + colu_lookup_id VARCHAR(120) NOT NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (colu_lookup_type, colu_lookup_id, divi_div_nbr) +); diff --git a/bcts/lrm/forest/ddl/licence.sql b/bcts/lrm/forest/ddl/licence.sql new file mode 100644 index 0000000..ad9f294 --- /dev/null +++ b/bcts/lrm/forest/ddl/licence.sql @@ -0,0 +1,44 @@ +CREATE TABLE lrm_replication.licence ( + licn_seq_nbr NUMERIC(15) NOT NULL, + licn_licence_id VARCHAR(15) NOT NULL, + licn_licence_desc VARCHAR(53) NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + licn_crown_land CHAR NULL, + licn_annual_allowable_cut NUMERIC(9) NULL, + lsee_licensee_id VARCHAR(10) NULL, + tent_seq_nbr NUMERIC(15) NULL, + licn_licence_state VARCHAR(20) NULL, + licn_permit_exists_ind VARCHAR(4) NULL, + licn_salvage_ind VARCHAR(1) NULL, + licn_category_id VARCHAR(10) NULL, + licn_field_team_id VARCHAR(10) NULL, + ctor_seq_nbr NUMERIC(15) NULL, + cloc_seq_nbr NUMERIC(15) NULL, + blaz_admin_zone_id VARCHAR(10) NULL, + licn_digi_ind VARCHAR(1) NULL, + licl_licence_class VARCHAR(10) NULL, + licn_parent_licence NUMERIC(15) NULL, + licn_crown_granted_ind VARCHAR(4) NULL, + licn_client_loc_code VARCHAR(20) NULL, + licn_category_type VARCHAR(16) NULL, + licn_licence_to_cut_code VARCHAR(10) NULL, + linc_cert_level_id VARCHAR(10) NULL, + licn_mgr_seq_nbr NUMERIC(15) NULL, + licn_fst_seq_nbr NUMERIC(15) NULL, + licn_gross_area NUMERIC(11, 6) NULL, + licn_net_area NUMERIC(11, 6) NULL, + licn_comment VARCHAR(4000) NULL, + licn_apportion_tenure_type VARCHAR(30) NULL, + team_seq_nbr NUMERIC(15) NULL, + licn_hammermark VARCHAR(60) NULL, + licn_client_location_code VARCHAR(40) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + licn_archive_ind VARCHAR(3) NULL, + licn_archive_date TIMESTAMP NULL, + PRIMARY KEY (licn_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/management_unit.sql b/bcts/lrm/forest/ddl/management_unit.sql new file mode 100644 index 0000000..b2f3253 --- /dev/null +++ b/bcts/lrm/forest/ddl/management_unit.sql @@ -0,0 +1,26 @@ +CREATE TABLE lrm_replication.management_unit ( + manu_seq_nbr NUMERIC(15) NOT NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + manu_id VARCHAR(60) NOT NULL, + manu_name VARCHAR(200) NULL, + manu_comment VARCHAR(4000) NULL, + manu_type_id VARCHAR(40) NULL, + manu_operating_zone VARCHAR(40) NULL, + manu_mgr_seq_nbr NUMERIC(15) NULL, + manu_fst_seq_nbr NUMERIC(15) NULL, + manu_digitize_ind VARCHAR(20) NULL, + manu_area NUMERIC(11, 6) NULL, + manu_net_area NUMERIC(11, 6) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + nat_res_area VARCHAR(1) NULL, + nat_res_region VARCHAR(2) NULL, + manu_aac_effect_date TIMESTAMP NULL, + manu_aac NUMERIC(10, 2) NULL, + non_bcts_aac_ind NUMERIC(1) NULL, + PRIMARY KEY (manu_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/mark.sql b/bcts/lrm/forest/ddl/mark.sql new file mode 100644 index 0000000..b42cea7 --- /dev/null +++ b/bcts/lrm/forest/ddl/mark.sql @@ -0,0 +1,20 @@ +CREATE TABLE lrm_replication.mark ( + mark_seq_nbr NUMERIC(15) NOT NULL, + mark_mark_id VARCHAR(15) NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + mark_mark_desc VARCHAR(160) NULL, + mark_mark_state VARCHAR(80) NULL, + mark_crown_granted_ind VARCHAR(4) NULL, + mark_aac_partition VARCHAR(40) NULL, + mark_apportionment VARCHAR(40) NULL, + mark_endemic_percent NUMERIC(4, 2) NULL, + mark_species_type VARCHAR(8) NULL, + mark_all_log_grades_ind VARCHAR(4) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (mark_seq_nbr) +); diff --git a/bcts/lrm/forest/ddl/tenure_type.sql b/bcts/lrm/forest/ddl/tenure_type.sql new file mode 100644 index 0000000..88408da --- /dev/null +++ b/bcts/lrm/forest/ddl/tenure_type.sql @@ -0,0 +1,15 @@ +CREATE TABLE lrm_replication.tenure_type ( + tent_seq_nbr NUMERIC(15) NOT NULL, + divi_div_nbr NUMERIC(2) NOT NULL, + tent_tenure_id VARCHAR(40) NOT NULL, + tent_tenure_name VARCHAR(160) NULL, + tety_tenure_type VARCHAR(40) NULL, + tent_active_ind VARCHAR(4) NULL, + modifiedby VARCHAR(120) NULL, + modifiedon TIMESTAMP NULL, + modifiedusing VARCHAR(120) NULL, + createdby VARCHAR(120) NULL, + createdon TIMESTAMP NULL, + createdusing VARCHAR(120) NULL, + PRIMARY KEY (tent_seq_nbr) +); diff --git a/bcts/lrm/forest/dml/cdc_master_table_list.sql b/bcts/lrm/forest/dml/cdc_master_table_list.sql new file mode 100644 index 0000000..f8afb46 --- /dev/null +++ b/bcts/lrm/forest/dml/cdc_master_table_list.sql @@ -0,0 +1,29 @@ +DO $$ +DECLARE + tables text[] := ARRAY['DIVISION','BLOCK_ALLOCATION','MANAGEMENT_UNIT','LICENCE','BLOCK_ADMIN_ZONE','DIVISION_CODE_LOOKUP','CODE_LOOKUP','TENURE_TYPE','CUT_PERMIT','MARK','CUT_BLOCK','ACTIVITY_CLASS','ACTIVITY_TYPE','ACTIVITY']; + table_name text; +BEGIN + -- Loop through the list of table names + FOREACH table_name IN ARRAY tables + LOOP + INSERT INTO ods_data_management.cdc_master_table_list + VALUES ( + NULL, + 'lrm', + NULL, + 'forest', + table_name, + 'lrm_replication', + table_name, + 'Y', + NULL, + NULL, + NULL, + 'Y', + 1, + 'N', + NULL, + 'Oracle' + ); + END LOOP; +END $$; diff --git a/shared/pg-transformations/Annual_Developed_Volume_Query.sql b/shared/pg-transformations/Annual_Developed_Volume_Query.sql new file mode 100644 index 0000000..a6a894f --- /dev/null +++ b/shared/pg-transformations/Annual_Developed_Volume_Query.sql @@ -0,0 +1,114 @@ +DROP TABLE IF EXISTS bcts_reporting.annual_developed_volume; + +CREATE TABLE bcts_reporting.annual_developed_volume AS +WITH annual_developed_volume AS +( + SELECT DISTINCT + CASE + WHEN d.divi_short_code IN ( 'TBA', 'TPL', 'TPG', 'TSK', 'TSN', + 'TCC', 'TKA', 'TKO', 'TOC' ) THEN + 'Interior' + WHEN d.divi_short_code IN ( 'TCH', 'TST', 'TSG' ) THEN + 'Coast' + END AS business_area_region_category, + CASE + WHEN d.divi_short_code IN ( 'TBA', 'TPL', 'TPG', 'TSK', 'TSN' ) THEN + 'North Interior' + WHEN d.divi_short_code IN ( 'TCC', 'TKA', 'TKO', 'TOC' ) THEN + 'South Interior' + WHEN d.divi_short_code IN ( 'TCH', 'TST', 'TSG' ) THEN + 'Coast' + END AS business_area_region, + CASE WHEN d.divi_division_name = 'Seaward' THEN 'Seaward-Tlasta' ELSE d.divi_division_name END + || ' (' + || d.divi_short_code + || ')' AS business_area, + d.divi_short_code AS business_area_code, + cl.colu_lookup_desc AS "Field Team", + mu.manu_id, + l.licn_licence_id AS licence, + tn.tent_tenure_id AS "File Type", + l.blaz_admin_zone_id AS agreement_type_code, + z.blaz_admin_zone_desc AS agreement_type, + cp.perm_permit_id AS permit, + m.mark_mark_id AS mark, + b.cutb_block_id AS block, + b.cutb_system_id AS ubi, + b.cutb_block_state AS block_state, + ba.blal_cruise_m3_vol AS cruise_volume, + ba.blal_rw_vol AS rw_volume, + actb.rc_done, + EXTRACT(YEAR FROM (actb.rc_done + INTERVAL '9 months')) AS rc_done_fiscal, + actb.dr_done, + EXTRACT(YEAR FROM (actb.dr_done + INTERVAL '9 months')) AS dr_done_fiscal, + actb.dvs_done, + EXTRACT(YEAR FROM (actb.dvs_done + INTERVAL '9 months')) AS dvs_done_fiscal, + actb.dvc_done, + EXTRACT(YEAR FROM (actb.dvc_done + INTERVAL '9 months')) AS dvc_done_fiscal, + b.cutb_seq_nbr + FROM + lrm_replication.division d + INNER JOIN lrm_replication.block_allocation ba + ON d.divi_div_nbr = ba.divi_div_nbr + INNER JOIN lrm_replication.management_unit mu + ON ba.manu_seq_nbr = mu.manu_seq_nbr + INNER JOIN lrm_replication.licence l + ON ba.licn_seq_nbr = l.licn_seq_nbr + LEFT OUTER JOIN lrm_replication.block_admin_zone z + ON l.divi_div_nbr = z.divi_div_nbr + AND l.blaz_admin_zone_id = z.blaz_admin_zone_id + AND ba.licn_seq_nbr = l.licn_seq_nbr + AND l.divi_div_nbr = z.divi_div_nbr + AND l.blaz_admin_zone_id = z.blaz_admin_zone_id + LEFT OUTER JOIN lrm_replication.division_code_lookup dcl + ON l.licn_field_team_id = dcl.colu_lookup_id + AND l.divi_div_nbr = dcl.divi_div_nbr + LEFT OUTER JOIN lrm_replication.code_lookup cl + ON dcl.colu_lookup_type = cl.colu_lookup_type + AND dcl.colu_lookup_id = cl.colu_lookup_id + LEFT JOIN lrm_replication.tenure_type tn + ON l.tent_seq_nbr = tn.tent_seq_nbr + LEFT OUTER JOIN lrm_replication.cut_permit cp + ON ba.perm_seq_nbr = cp.perm_seq_nbr + LEFT JOIN lrm_replication.mark m + ON ba.mark_seq_nbr = m.mark_seq_nbr + INNER JOIN lrm_replication.cut_block b + ON ba.cutb_seq_nbr = b.cutb_seq_nbr + INNER JOIN + ( + SELECT + A.CUTB_SEQ_NBR, + MAX(CASE WHEN ACTT_KEY_IND = 'RC' THEN DATE_TRUNC('DAY', ACTI_STATUS_DATE) END)::DATE AS RC_Done, + MAX(CASE WHEN ACTT_KEY_IND = 'DR' THEN DATE_TRUNC('DAY',ACTI_STATUS_DATE) END)::DATE AS DR_Done, + MAX(CASE WHEN ACTT_KEY_IND = 'DVS' THEN DATE_TRUNC('DAY',ACTI_STATUS_DATE) END)::DATE AS DVS_Done, + MAX(CASE WHEN ACTT_KEY_IND = 'DVC' THEN DATE_TRUNC('DAY',ACTI_STATUS_DATE) END)::DATE AS DVC_Done + FROM + lrm_replication.ACTIVITY_CLASS C, + lrm_replication.ACTIVITY_TYPE T, + lrm_replication.ACTIVITY A + WHERE + C.ACCL_SEQ_NBR = T.ACCL_SEQ_NBR + AND T.ACTT_SEQ_NBR = A.ACTT_SEQ_NBR + AND C.ACCL_DESCRIPTION = 'CMB' + AND T.ACTT_KEY_IND In ('RC', 'DR', 'DVS', 'DVC') + AND A.ACTI_STATUS_IND = 'D' + GROUP BY A.CUTB_SEQ_NBR, T.ACTT_KEY_IND + ) ACTB + ON ba.cutb_seq_nbr = actb.cutb_seq_nbr + AND actb.dvc_done BETWEEN TO_DATE('2024-04-01', 'YYYY-MM-DD') -- Date: beginning of current fiscal + AND TO_DATE('2024-09-30', 'YYYY-MM-DD') -- Date: end of reporting period +) + +SELECT * +FROM annual_developed_volume +ORDER BY + length(business_area_region) desc, + business_area_region, + business_area, + "Field Team", + MANU_ID, + licence, + permit, + mark, + block +; \ No newline at end of file diff --git a/shared/pg-transformations/Dockerfile b/shared/pg-transformations/Dockerfile new file mode 100644 index 0000000..659932c --- /dev/null +++ b/shared/pg-transformations/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.11.4-slim-buster + +# PostgreSQL library + +RUN apt-get update \ + && apt-get -y install libpq-dev gcc \ + && pip install psycopg2 + +WORKDIR /app + +COPY . . + diff --git a/shared/pg-transformations/bcts_etl.py b/shared/pg-transformations/bcts_etl.py new file mode 100644 index 0000000..cb9a0c2 --- /dev/null +++ b/shared/pg-transformations/bcts_etl.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# coding: utf-8 + +#Imports +import os, time +import psycopg2 +import logging +import sys + +start = time.time() + +# Retrieve Postgres database configuration +postgres_username = os.environ['ODS_USERNAME'] +postgres_password = os.environ['ODS_PASSWORD'] +postgres_host = os.environ['ODS_HOST'] +postgres_port = os.environ['ODS_PORT'] +postgres_database = os.environ['ODS_DATABASE'] + +# Configure logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s', + handlers=[ + logging.StreamHandler() + ] +) + +def run_sql_script(script_path): + # Establish database connection + try: + connection = psycopg2.connect( + dbname=postgres_database, + user=postgres_username, + password=postgres_password, + host=postgres_host, + port=postgres_port + ) + cursor = connection.cursor() + logging.info("Database connection established.") + except psycopg2.Error as e: + logging.error(f"Error connecting to the database: {e}") + return + + # Read and execute the SQL script + try: + with open(script_path, 'r') as file: + sql_script = file.read() + + # Execute the SQL script + cursor.execute(sql_script) + connection.commit() + logging.info(f"SQL script executed successfully from {script_path}.") + except psycopg2.Error as e: + logging.error(f"Error executing the SQL script: {e}") + connection.rollback() + except FileNotFoundError: + logging.error(f"SQL script not found: {script_path}") + finally: + # Clean up + cursor.close() + connection.close() + logging.info("Database connection closed.") + +if __name__ == "__main__": + if len(sys.argv) > 1: + filename = sys.argv[1] + print(f"Processing file: {filename}") + run_sql_script(filename) + else: + print("No filename provided.") +