diff --git a/.dockerignore b/.dockerignore index 842ed4a..c118800 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,5 @@ README.md license.txt Dockerfile Makefile -*_matomo \ No newline at end of file +*_matomo +*.sql \ No newline at end of file diff --git a/matomo_pull/settings.py b/matomo_pull/settings.py index a0b7837..b18bf78 100644 --- a/matomo_pull/settings.py +++ b/matomo_pull/settings.py @@ -116,7 +116,7 @@ def update_dates(mtm_vars): return mtm_vars -def is_database_created(table_name='visits'): +def is_database_created(table_name='matomo.visits'): try: return bool(connection.execute(f"select * from {table_name}")) except Exception: @@ -127,7 +127,7 @@ def update_start_date_regarding_database_state(mtm_vars): if is_database_created(): last_update = ( connection.execute( - "select date from visits order by date desc limit 1" + "select date from matomo.visits order by date desc limit 1" ).fetchall()[0][0] ).date() return last_update + timedelta(days=1) diff --git a/matomo_pull/sql_handling.py b/matomo_pull/sql_handling.py index f2436eb..2b553a5 100644 --- a/matomo_pull/sql_handling.py +++ b/matomo_pull/sql_handling.py @@ -35,6 +35,7 @@ def convert_data_object_to_sql(table_name, table_params, data_object): df.to_sql( table_name, s.connection, - if_exists='append' + if_exists='append', + schema='matomo' ) print(table_name) diff --git a/tests/test_settings.py b/tests/test_settings.py index 2377701..2e4fb18 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -54,11 +54,11 @@ def test_database_already_up_to_date(settings_setup, monkeypatch): def test_database_creation(settings_setup): conn = settings.set_database_connection(os.environ['db_name']) conn.execute( - "create table visits(id int primary key not null, date date);" + "create table matomo.visits(id int primary key not null, date date);" ) assert settings.is_database_created() - conn.execute("drop table visits;") + conn.execute("drop table matomo.visits;") assert not settings.is_database_created() @@ -69,10 +69,10 @@ def test_updating_dates(settings_setup): conn = settings.set_database_connection(os.environ['db_name']) conn.execute( - "create table visits(id int primary key not null, date timestamp);" + "create table matomo.visits(id int primary key not null, date timestamp);" ) conn.execute( - f"insert into visits(id,date) values(1, '{last_update_date}')" + f"insert into matomo.visits(id,date) values(1, '{last_update_date}')" ) vars = settings.check_mtm_vars(settings.mtm_vars)