Skip to content

Commit

Permalink
chore: move database name and username to GH secret
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Nov 29, 2024
1 parent 18f7abe commit 6279e98
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 74 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VITE_DISCOVER_QUAD_WORD=
VITE_FIREBASE_CONFIG=
VITE_PROXY_URL=
VITE_DATABASE_CONFIG=
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
env:
VITE_DISCOVER: ${{ secrets.DISCOVER }}
VITE_FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
VITE_DATABASE_CONFIG: ${{ secrets.DATABASE_CONFIG }}

deploy-prod:
name: Deploy to production
Expand Down Expand Up @@ -72,6 +73,7 @@ jobs:
env:
VITE_DISCOVER: ${{ secrets.DISCOVER }}
VITE_FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
VITE_DATABASE_CONFIG: ${{ secrets.DATABASE_CONFIG }}

notify:
name: Notifications
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ugrc",
"usgs",
"vite",
"WILDADMIN",
"wkid",
"wrimaps"
],
Expand Down
16 changes: 6 additions & 10 deletions scripts/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import arcpy
import pyodbc

import swq_secrets as secrets


def zip_fgdb(path, zip):
path = normpath(path)
for (dirpath, dirnames, filenames) in walk(path):
Expand Down Expand Up @@ -87,20 +87,17 @@ def main(ids, type):
arcpy.management.CopyFeatures(events_layer, join(fgdb, 'SamplingEvents'))

arcpy.AddMessage('copying stations feature class')
stations_where = 'STATION_ID IN (SELECT STATION_ID FROM {}.WILDADMIN.SamplingEvents_evw where {})'.format(
secrets.DATABASE, events_where)
stations_where = f'STATION_ID IN (SELECT STATION_ID FROM {secrets.DATABASE}.{secrets.USERNAME}.SamplingEvents_evw where {events_where})'
stations_layer = arcpy.management.MakeFeatureLayer(join(sde, 'Stations'), 'stations_layer', stations_where)
arcpy.management.CopyFeatures(stations_layer, join(fgdb, 'Stations'))

arcpy.AddMessage('copying streams feature class')
stations_where = 'Permanent_Identifier IN (SELECT WATER_ID FROM {}.WILDADMIN.Stations_evw where {})'.format(
secrets.DATABASE, stations_where)
stations_where = f'Permanent_Identifier IN (SELECT WATER_ID FROM {secrets.DATABASE}.{secrets.USERNAME}.Stations_evw where {stations_where})'
streams_layer = arcpy.management.MakeFeatureLayer(join(sde, 'UDWRStreams'), 'streams_layer', stations_where)
arcpy.management.CopyFeatures(streams_layer, join(fgdb, 'UDWRStreams'))

arcpy.AddMessage('copying lakes feature class')
stations_where = 'Permanent_Identifier IN (SELECT WATER_ID FROM {}.WILDADMIN.Stations_evw where {})'.format(
secrets.DATABASE, stations_where)
stations_where = f'Permanent_Identifier IN (SELECT WATER_ID FROM {secrets.DATABASE}.{secrets.USERNAME}.Stations_evw where {stations_where})'
lakes_layer = arcpy.management.MakeFeatureLayer(join(sde, 'UDWRLakes'), 'lakes_layer', stations_where)
arcpy.management.CopyFeatures(lakes_layer, join(fgdb, 'UDWRLakes'))

Expand All @@ -116,8 +113,7 @@ def copy_related_tables(dataset):
destination_is_table = arcpy.Describe(join(sde, destination)).datasetType == 'Table'
if destination.split('.')[-1] != dataset and destination_is_table:
arcpy.AddMessage('copying {} table'.format(destination))
where = '{} IN (SELECT {} FROM {}.WILDADMIN.{} where {})'.format(
foreign_key, primary_key, secrets.DATABASE, dataset, events_where)
where = f'{foreign_key} IN (SELECT {primary_key} FROM {secrets.DATABASE}.{secrets.USERNAME}.{dataset} where {events_where})'
layer = arcpy.management.MakeTableView(join(sde, destination), destination + '_layer', where)
arcpy.management.CopyRows(layer, join(fgdb, destination))

Expand Down Expand Up @@ -155,7 +151,7 @@ def copy_related_tables(dataset):
csv_name = basename(query_file).replace('sql', 'csv')
arcpy.AddMessage(csv_name)
with open(query_file, 'r') as file:
query = file.read().format(secrets.DATABASE, formatted_ids)
query = file.read().format(secrets.DATABASE, formatted_ids, secrets.USERNAME)
cursor.execute(query)

csv_file_path = join(arcpy.env.scratchFolder, csv_name)
Expand Down
10 changes: 5 additions & 5 deletions scripts/sql/Equipment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ SELECT
e.CATHODE_LEN,
e.CATHODE_DIAMETER

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Equipment_evw as e
INNER JOIN {0}.{2}.Equipment_evw as e
ON e.EVENT_ID = se.EVENT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions scripts/sql/Equipment2Anodes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ SELECT
a.EQUIPMENT_ID,
a.ANODE_SHAPE

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Equipment_evw as e
INNER JOIN {0}.{2}.Equipment_evw as e
ON e.EVENT_ID = se.EVENT_ID

INNER JOIN {0}.WILDADMIN.Anodes_evw as a
INNER JOIN {0}.{2}.Anodes_evw as a
ON e.EQUIPMENT_ID = a.EQUIPMENT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
10 changes: 5 additions & 5 deletions scripts/sql/Fish1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ SELECT
f.WEIGHT,
f.NOTES

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Fish_evw as f
INNER JOIN {0}.{2}.Fish_evw as f
ON f.EVENT_ID = se.EVENT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions scripts/sql/Fish2Diet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ SELECT
d.MEASUREMENT_TYPE,
d.MEASUREMENT

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Fish_evw as f
INNER JOIN {0}.{2}.Fish_evw as f
ON f.EVENT_ID = se.EVENT_ID

INNER JOIN {0}.WILDADMIN.Diet_evw as d
INNER JOIN {0}.{2}.Diet_evw as d
ON d.FISH_ID = f.FISH_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions scripts/sql/Fish3Tags.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ SELECT
t.TRANSMITTER_FREQ,
t.TRANSMITTER_FREQ_TYPE

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Fish_evw as f
INNER JOIN {0}.{2}.Fish_evw as f
ON f.EVENT_ID = se.EVENT_ID

INNER JOIN {0}.WILDADMIN.Tags_evw as t
INNER JOIN {0}.{2}.Tags_evw as t
ON t.FISH_ID = f.FISH_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions scripts/sql/Fish4Health.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ SELECT
h.OPERCLE,
h.COLLECTION_PART

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Fish_evw as f
INNER JOIN {0}.{2}.Fish_evw as f
ON f.EVENT_ID = se.EVENT_ID

INNER JOIN {0}.WILDADMIN.Health_evw as h
INNER JOIN {0}.{2}.Health_evw as h
ON h.FISH_ID = f.FISH_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
10 changes: 5 additions & 5 deletions scripts/sql/Habitat1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ SELECT
h.BACKWATER,
h.PH

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Habitat_evw as h
INNER JOIN {0}.{2}.Habitat_evw as h
ON h.EVENT_ID = se.EVENT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
10 changes: 5 additions & 5 deletions scripts/sql/Habitat2Transect.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ SELECT
t.STARTING_BANK,
t.TRANSECT_ID

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Transect_evw as t
INNER JOIN {0}.{2}.Transect_evw as t
ON t.EVENT_ID = se.EVENT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions scripts/sql/Habitat3TransectMeasurements.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ SELECT
tm.DISTANCE_START,
tm.TRANSECT_ID

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

INNER JOIN {0}.WILDADMIN.Transect_evw as t
INNER JOIN {0}.{2}.Transect_evw as t
ON t.EVENT_ID = se.EVENT_ID

INNER JOIN {0}.WILDADMIN.TransectMeasurements_evw as tm
INNER JOIN {0}.{2}.TransectMeasurements_evw as tm
ON tm.TRANSECT_ID = t.TRANSECT_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE se.EVENT_ID IN ({1})
8 changes: 4 additions & 4 deletions scripts/sql/Location.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ SELECT
se.OBSERVERS,
se.SURVEY_PURPOSE

FROM {0}.WILDADMIN.SamplingEvents_evw as se
FROM {0}.{2}.SamplingEvents_evw as se

INNER JOIN {0}.WILDADMIN.Stations_evw as s
INNER JOIN {0}.{2}.Stations_evw as s
ON s.STATION_ID = se.STATION_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRLakes_evw as l
LEFT OUTER JOIN {0}.{2}.UDWRLakes_evw as l
ON l.Permanent_Identifier = s.WATER_ID

LEFT OUTER JOIN {0}.WILDADMIN.UDWRStreams_evw as st
LEFT OUTER JOIN {0}.{2}.UDWRStreams_evw as st
ON st.Permanent_Identifier = s.WATER_ID

WHERE EVENT_ID IN ({1})
12 changes: 6 additions & 6 deletions src/components/queryHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('getStationQuery', () => {
},
];
const expected = removeIrrelevantWhiteSpace(
`(${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM ${config.databaseName}.WILDADMIN.TableOne
`(${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM DB_NAME.USER.TableOne
WHERE 1 = 1 AND 1 = 2))
AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM ${config.databaseName}.WILDADMIN.TableTwo
AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM DB_NAME.USER.TableTwo
WHERE 1 = 3))
AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM ${config.databaseName}.WILDADMIN.TableThree
AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM DB_NAME.USER.TableThree
WHERE 1 = 4))`,
);

Expand All @@ -45,7 +45,7 @@ describe('getStationQuery', () => {
table: 'TableOne',
},
];
const expected = `(1 = 1) AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM ${config.databaseName}.WILDADMIN.TableOne WHERE 1 = 2))`;
const expected = `(1 = 1) AND (${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID} FROM DB_NAME.USER.TableOne WHERE 1 = 2))`;

const results = getStationQuery(input);
expect(results).toBe(expected);
Expand Down Expand Up @@ -74,9 +74,9 @@ describe('getStationQuery', () => {
},
];
const expected = removeIrrelevantWhiteSpace(`(${config.fieldNames.STATION_ID} IN (
SELECT ${config.fieldNames.STATION_ID} FROM ${config.databaseName}.WILDADMIN.${config.tableNames.events}
SELECT ${config.fieldNames.STATION_ID} FROM DB_NAME.USER.${config.tableNames.events}
WHERE ${config.fieldNames.EVENT_ID} IN (
SELECT ${config.fieldNames.EVENT_ID} FROM ${config.databaseName}.WILDADMIN.${config.tableNames.fish}
SELECT ${config.fieldNames.EVENT_ID} FROM DB_NAME.USER.${config.tableNames.fish}
WHERE 1 = 1
) AND 2 = 2
))`);
Expand Down
4 changes: 2 additions & 2 deletions src/components/queryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getStationQuery(queryInfos: QueryInfo[]): string {
info.table = config.tableNames.events;
info.where = `${config.fieldNames.EVENT_ID} IN (
SELECT ${config.fieldNames.EVENT_ID} FROM
${config.databaseName}.WILDADMIN.${config.tableNames.fish}
${config.databaseSecrets.databaseName}.${config.databaseSecrets.user}.${config.tableNames.fish}
WHERE ${info.where})`;
}

Expand All @@ -41,7 +41,7 @@ export function getStationQuery(queryInfos: QueryInfo[]): string {
}

return `${previous}(${config.fieldNames.STATION_ID} IN (SELECT ${config.fieldNames.STATION_ID}
FROM ${config.databaseName}.WILDADMIN.${current} WHERE ${where}))`;
FROM ${config.databaseSecrets.databaseName}.${config.databaseSecrets.user}.${current} WHERE ${where}))`;
}, '');

return removeIrrelevantWhiteSpace(query);
Expand Down
Loading

0 comments on commit 6279e98

Please sign in to comment.