Skip to content

Commit

Permalink
fix schema and metadata propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Oct 23, 2024
1 parent 37b59db commit 333876f
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions crawler/vea_industrial_load_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from sqlalchemy import create_engine, text
from tqdm import tqdm

from common.base_crawler import create_schema_only, set_metadata_only
from common.config import db_uri


log = logging.getLogger("vea-industrial-load-profiles")


Expand Down Expand Up @@ -188,19 +190,7 @@ def write_to_database(db_conn: str, data: pd.DataFrame, name: str) -> None:
log.info("Successfully inserted into databse")


def create_schema():
log.info("Trying to create schema")

engine = create_engine(db_uri)

with engine.begin() as conn:
query = text('CREATE SCHEMA IF NOT EXISTS "vea-industrial-load-profiles"')
conn.execute(query)

log.info("Succesfully created schema")


def convert_to_hypertable(relation_name: str):
def convert_to_hypertable(db_conn: str, relation_name: str):
"""
Converts table to hypertable.
Expand Down Expand Up @@ -233,8 +223,9 @@ def main(schema_name):
# extract files from response
master_file, hlt_file, load_file = extract_files(response=response)

# creat schema
create_schema()
# create schema
engine = create_engine(db_uri(schema_name))
create_schema_only(engine, schema_name)

# read load_data
load_data = read_file(load_file, filename="load")
Expand Down Expand Up @@ -264,10 +255,10 @@ def main(schema_name):
del master_data

# convert to hypertable
convert_to_hypertable(db_conn=db_conn, "high_load_times")
convert_to_hypertable(db_conn=db_conn, "load")
convert_to_hypertable("high_load_times")
convert_to_hypertable("load")
convert_to_hypertable(db_conn, "high_load_times")
convert_to_hypertable(db_conn, "load")

set_metadata_only(engine, metadata_info)


if __name__ == "__main__":
Expand All @@ -277,4 +268,4 @@ def main(schema_name):
datefmt="%d-%m-%Y %H:%M:%S",
)

main()
main("industrial_load_profiles")

0 comments on commit 333876f

Please sign in to comment.