Skip to content

Commit 4d11c91

Browse files
committed
Pull and insert SL animal events
Includes test endpoint at end of admin_api.py
1 parent 81906a2 commit 4d11c91

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/server/alembic/versions/9687db7928ee_shelterluv_animals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Create SL_animals table
22
33
Revision ID: 9687db7928ee
4-
Revises: a3ba63dee8f4
4+
Revises: 45a668fa6325
55
Create Date: 2021-12-24 21:15:33.399197
66
77
"""
@@ -11,7 +11,7 @@
1111

1212
# revision identifiers, used by Alembic.
1313
revision = '9687db7928ee'
14-
down_revision = 'fc7325372396'
14+
down_revision = '45a668fa6325'
1515
branch_labels = None
1616
depends_on = None
1717

src/server/api/API_ingest/shelterluv_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def insert_events(event_list):
9393
metadata = MetaData()
9494
sla = Table("sl_animal_events", metadata, autoload=True, autoload_with=engine)
9595

96-
# TODO: Pull from DB
96+
# TODO: Pull from DB - inserted in db_setup/base_users.py/populate_sl_event_types()
9797
event_map = {
9898
"Outcome.Adoption": 1,
9999
"Outcome.Foster": 2,

src/server/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
# command.stamp(alembic_cfg, "head")
4040

4141
with engine.connect() as connection:
42-
import user_mgmt.base_users
43-
user_mgmt.base_users.create_base_roles() # IFF there are no roles already
44-
user_mgmt.base_users.create_base_users() # IFF there are no users already
45-
user_mgmt.base_users.populate_rfm_mapping_table() # Set to True to force loading latest version of populate script
42+
import db_setup.base_users
43+
db_setup.base_users.create_base_roles() # IFF there are no roles already
44+
db_setup.base_users.create_base_users() # IFF there are no users already
45+
db_setup.base_users.populate_sl_event_types() # IFF there are no event types already
46+
db_setup.base_users.populate_rfm_mapping_table() # Set to True to force loading latest version of populate script
4647
# found in the server/alembic directory
4748

4849
# Create these directories only one time - when initializing
File renamed without changes.
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sqlalchemy as sa
44
import os
55

6-
6+
# This started as the place to create base users but a couple of other setup taks added.
77

88
try:
99
from secrets_dict import BASEUSER_PW, BASEEDITOR_PW, BASEADMIN_PW
@@ -135,4 +135,21 @@ def table_empty():
135135
else:
136136
print("rfm_mapping table already populated; overwrite not True so not changing.")
137137

138-
return
138+
return
139+
140+
141+
def populate_sl_event_types():
142+
"""If not present, insert values for shelterluv animal event types."""
143+
with engine.connect() as connection:
144+
result = connection.execute("select id from sl_event_types")
145+
type_count = len(result.fetchall())
146+
if type_count == 0:
147+
print("Inserting SL event types")
148+
connection.execute("""INSERT into sl_event_types values
149+
(1, 'Outcome.Adoption'),
150+
(2, 'Outcome.Foster'),
151+
(3, 'Outcome.ReturnToOwner'),
152+
(4, 'Intake.AdoptionReturn'),
153+
(5, 'Intake.FosterReturn'); """)
154+
else:
155+
print(type_count, " event types already present in DB, not creating")

0 commit comments

Comments
 (0)